mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {Pressable, View} from 'react-native'
3import {useLingui} from '@lingui/react'
4
5import {android, atoms as a, useTheme, web} from '#/alf'
6import * as TextField from '#/components/forms/TextField'
7import {useInteractionState} from '#/components/hooks/useInteractionState'
8import {CalendarDays_Stroke2_Corner0_Rounded as CalendarDays} from '#/components/icons/CalendarDays'
9import {Text} from '#/components/Typography'
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 {i18n} = useLingui()
29 const t = useTheme()
30
31 const {
32 state: pressed,
33 onIn: onPressIn,
34 onOut: onPressOut,
35 } = useInteractionState()
36 const {
37 state: hovered,
38 onIn: onHoverIn,
39 onOut: onHoverOut,
40 } = useInteractionState()
41 const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
42
43 const {chromeHover, chromeFocus, chromeError, chromeErrorHover} =
44 TextField.useSharedInputStyles()
45
46 return (
47 <View
48 style={[a.relative, a.w_full]}
49 {...web({
50 onMouseOver: onHoverIn,
51 onMouseOut: onHoverOut,
52 })}>
53 <Pressable
54 aria-label={label}
55 accessibilityLabel={label}
56 accessibilityHint={accessibilityHint}
57 onPress={onPress}
58 onPressIn={onPressIn}
59 onPressOut={onPressOut}
60 onFocus={onFocus}
61 onBlur={onBlur}
62 style={[
63 {
64 paddingTop: 12,
65 paddingBottom: 12,
66 paddingLeft: 14,
67 paddingRight: 14,
68 borderColor: 'transparent',
69 borderWidth: 2,
70 },
71 android({
72 minHeight: 57.5,
73 }),
74 a.flex_row,
75 a.flex_1,
76 a.w_full,
77 a.rounded_sm,
78 t.atoms.bg_contrast_25,
79 a.align_center,
80 hovered ? chromeHover : {},
81 focused || pressed ? chromeFocus : {},
82 isInvalid || isInvalid ? chromeError : {},
83 (isInvalid || isInvalid) && (hovered || focused)
84 ? chromeErrorHover
85 : {},
86 ]}>
87 <TextField.Icon icon={CalendarDays} />
88 <Text
89 style={[
90 a.text_md,
91 a.pl_xs,
92 t.atoms.text,
93 {lineHeight: a.text_md.fontSize * 1.1875},
94 ]}>
95 {i18n.date(value, {timeZone: 'UTC'})}
96 </Text>
97 </Pressable>
98 </View>
99 )
100}