Something went wrong. Try again.
Mirror — see github.com/blacksky-algorithms/blacksky.community
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677import {forwardRef, useCallback} from 'react'import {StyleSheet, type TextInput, type TextInputProps} from 'react-native'// @ts-expect-error untypedimport {unstable_createElement} from 'react-native-web'
import {type DateFieldProps} from '#/components/forms/DateField/types'import {toSimpleDateString} from '#/components/forms/DateField/utils'import * as TextField from '#/components/forms/TextField'import {CalendarDays_Stroke2_Corner0_Rounded as CalendarDays} from '#/components/icons/CalendarDays'
export * as utils from '#/components/forms/DateField/utils'export const LabelText = TextField.LabelText
const InputBase = forwardRef<HTMLInputElement, TextInputProps>( ({style, ...props}, ref) => { return unstable_createElement('input', { ...props, ref, type: 'date', style: [ StyleSheet.flatten(style), { background: 'transparent', border: 0, }, ], }) },)
InputBase.displayName = 'InputBase'
const Input = TextField.createInput(InputBase as unknown as typeof TextInput)
export function DateField({ value, inputRef, onChangeDate, onConfirm, label, isInvalid, testID, accessibilityHint, maximumDate, minimumDate,}: DateFieldProps) { const handleOnChange = useCallback( (e: any) => { const date = e.target.valueAsDate || e.target.value
if (date) { const formatted = toSimpleDateString(date) onChangeDate(formatted) onConfirm?.(formatted) } }, [onChangeDate, onConfirm], )
return ( <TextField.Root isInvalid={isInvalid}> <TextField.Icon icon={CalendarDays} /> <Input value={value === '' ? '' : toSimpleDateString(value)} inputRef={inputRef as React.Ref<React.ComponentRef<typeof TextInput>>} label={label} onChange={handleOnChange} testID={testID} accessibilityHint={accessibilityHint} // @ts-expect-error not typed as <input type="date"> even though it is one max={maximumDate ? toSimpleDateString(maximumDate) : undefined} min={minimumDate ? toSimpleDateString(minimumDate) : undefined} /> </TextField.Root> )}