11import React from 'react'
2- import { View , Text , Link } from '../components/styled'
2+ import { View , Text , Link , Pressable } from '../components/styled'
33import { useRouter } from '@green-stack/navigation/useRouter'
44import { ArrowLeftFilled } from '../icons/ArrowLeftFilled'
55import { schema , z } from '@green-stack/schemas'
66
77/* --- Props ----------------------------------------------------------------------------------- */
88
99const BackButtonProps = schema ( 'BackButtonProps' , {
10+ color : z . string ( ) . default ( '#FFFFFF' ) ,
1011 backLink : z . string ( ) . default ( '/' ) ,
1112} )
1213
@@ -16,36 +17,48 @@ type BackButtonProps = z.input<typeof BackButtonProps>
1617
1718const BackButton = ( props : BackButtonProps ) => {
1819 // Props
19- const { backLink } = BackButtonProps . applyDefaults ( props )
20+ const { color , backLink } = BackButtonProps . applyDefaults ( props )
2021
2122 // Routing
2223 const { canGoBack, back } = useRouter ( )
2324
2425 // Vars
2526 const showBackButton = canGoBack ( )
2627
27- // -- Render --
28+ // -- Prerender --
2829
29- return (
30- < View className = "flex flex-row absolute top-8 web:top-0 left-0 p-4 items-center" >
31- < ArrowLeftFilled fill = "#FFFFFF" size = { 18 } />
30+ const innerBackButton = (
31+ < View className = "flex flex-row p-4 items-center" >
32+ < ArrowLeftFilled fill = { color } size = { 18 } />
3233 < View className = "w-[5px]" />
33- { showBackButton ? (
34- < Text
35- className = "text-white text-lg"
36- onPress = { back }
37- >
38- { `Back` }
39- </ Text >
40- ) : (
41- < Link href = { backLink } className = "text-white text-lg no-underline" >
42- { `Back` }
43- </ Link >
44- ) }
34+ < Text
35+ className = { `text-lg text-[${ color } ]` }
36+ style = { { color } }
37+ >
38+ { `Back` }
39+ </ Text >
4540 </ View >
4641 )
42+
43+ // -- Render --
44+
45+ return showBackButton ? (
46+ < Pressable
47+ className = { `absolute top-8 web:top-0 left-0` } // @ts -ignore
48+ onPress = { back }
49+ >
50+ { innerBackButton }
51+ </ Pressable >
52+ ) : (
53+ < Link
54+ className = { `absolute top-8 web:top-0 left-0 text-[${ color } ] no-underline` }
55+ href = { backLink }
56+ >
57+ { innerBackButton }
58+ </ Link >
59+ )
4760}
4861
4962/* --- Exports --------------------------------------------------------------------------------- */
5063
51- export default BackButton
64+ export default BackButton
0 commit comments