mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {Pressable, View} from 'react-native'
3
4import {android, atoms as a, useTheme, web} from '#/alf'
5import * as TextField from '#/components/forms/TextField'
6import {useInteractionState} from '#/components/hooks/useInteractionState'
7import {CalendarDays_Stroke2_Corner0_Rounded as CalendarDays} from '#/components/icons/CalendarDays'
8import {Text} from '#/components/Typography'
9import {localizeDate} from './utils'
10
11// looks like a TextField.Input, but is just a button. It'll do something different on each platform on press
12// iOS: open a dialog with an inline date picker
13// Android: open the date picker modal
14
15export function DateFieldButton({
16 label,
17 value,
18 onPress,
19 isInvalid,
20 accessibilityHint,
21}: {
22 label: string
23 value: string
24 onPress: () => void
25 isInvalid?: boolean
26 accessibilityHint?: string
27}) {
28 const t = useTheme()
29
30 const {
31 state: pressed,
32 onIn: onPressIn,
33 onOut: onPressOut,
34 } = useInteractionState()
35 const {
36 state: hovered,
37 onIn: onHoverIn,
38 onOut: onHoverOut,
39 } = useInteractionState()
40 const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
41
42 const {chromeHover, chromeFocus, chromeError, chromeErrorHover} =
43 TextField.useSharedInputStyles()
44
45 return (
46 <View
47 style={[a.relative, a.w_full]}
48 {...web({
49 onMouseOver: onHoverIn,
50 onMouseOut: onHoverOut,
51 })}>
52 <Pressable
53 aria-label={label}
54 accessibilityLabel={label}
55 accessibilityHint={accessibilityHint}
56 onPress={onPress}
57 onPressIn={onPressIn}
58 onPressOut={onPressOut}
59 onFocus={onFocus}
60 onBlur={onBlur}
61 style={[
62 {
63 paddingTop: 12,
64 paddingBottom: 12,
65 paddingLeft: 14,
66 paddingRight: 14,
67 borderColor: 'transparent',
68 borderWidth: 2,
69 },
70 android({
71 minHeight: 57.5,
72 }),
73 a.flex_row,
74 a.flex_1,
75 a.w_full,
76 a.rounded_sm,
77 t.atoms.bg_contrast_25,
78 a.align_center,
79 hovered ? chromeHover : {},
80 focused || pressed ? chromeFocus : {},
81 isInvalid || isInvalid ? chromeError : {},
82 (isInvalid || isInvalid) && (hovered || focused)
83 ? chromeErrorHover
84 : {},
85 ]}>
86 <TextField.Icon icon={CalendarDays} />
87 <Text
88 style={[
89 a.text_md,
90 a.pl_xs,
91 t.atoms.text,
92 {lineHeight: a.text_md.fontSize * 1.1875},
93 ]}>
94 {localizeDate(value)}
95 </Text>
96 </Pressable>
97 </View>
98 )
99}