import React from 'react' import {Keyboard, View} from 'react-native' import DatePicker from 'react-native-date-picker' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' import {DateFieldProps} from '#/components/forms/DateField/types' import {toSimpleDateString} from '#/components/forms/DateField/utils' import * as TextField from '#/components/forms/TextField' import {DateFieldButton} from './index.shared' export * as utils from '#/components/forms/DateField/utils' export const LabelText = TextField.LabelText /** * Date-only input. Accepts a date in the format YYYY-MM-DD, and reports date * changes in the same format. * * For dates of unknown format, convert with the * `utils.toSimpleDateString(Date)` export of this file. */ export function DateField({ value, onChangeDate, testID, label, isInvalid, accessibilityHint, }: DateFieldProps) { const {_} = useLingui() const t = useTheme() const control = Dialog.useDialogControl() const onChangeInternal = React.useCallback( (date: Date | undefined) => { if (date) { const formatted = toSimpleDateString(date) onChangeDate(formatted) } }, [onChangeDate], ) return ( <> { Keyboard.dismiss() control.open() }} isInvalid={isInvalid} accessibilityHint={accessibilityHint} /> ) }