diff --git a/src/view/com/forms/InputDate/types.ts b/src/view/com/forms/InputDate/types.ts new file mode 100644 index 0000000000..8a8d8cd1db --- /dev/null +++ b/src/view/com/forms/InputDate/types.ts @@ -0,0 +1,10 @@ +import {TextInputProps} from 'react-native' + +import {BaseProps} from '#/view/com/forms/types' + +export type InputDateProps = BaseProps & { + /** + * **NOTE:** Available only on web + */ + autoFocus?: TextInputProps['autoFocus'] +} diff --git a/src/view/com/forms/InputText.tsx b/src/view/com/forms/InputText.tsx index eb77c6242f..c573a3c650 100644 --- a/src/view/com/forms/InputText.tsx +++ b/src/view/com/forms/InputText.tsx @@ -9,16 +9,23 @@ import { import {useTheme, atoms, web, tokens} from '#/alf' import {Text} from '#/view/com/Typography' +import {useInteractionState} from '#/view/com/util/hooks/useInteractionState' -type Props = Omit & { - label?: string - placeholder: string - hasError?: boolean - icon?: React.FunctionComponent - suffix?: React.FunctionComponent -} +import {BaseProps} from '#/view/com/forms/types' + +type Props = BaseProps & + Omit & { + placeholder: Required['placeholder'] + icon?: React.FunctionComponent + suffix?: React.FunctionComponent + } export function InputText({ + value: initialValue, + onChange, + testID, + accessibilityLabel, + accessibilityHint, label, hasError, icon: Icon, @@ -27,36 +34,15 @@ export function InputText({ }: Props) { const labelId = React.useId() const t = useTheme() - const [state, setState] = React.useState({ - hovered: false, - focused: false, - }) + const [value, setValue] = React.useState(initialValue) const [suffixPadding, setSuffixPadding] = React.useState(0) + const { + state: hovered, + onIn: onHoverIn, + onOut: onHoverOut, + } = useInteractionState() + const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState() - const onHoverIn = React.useCallback(() => { - setState(s => ({ - ...s, - hovered: true, - })) - }, [setState]) - const onHoverOut = React.useCallback(() => { - setState(s => ({ - ...s, - hovered: false, - })) - }, [setState]) - const onFocus = React.useCallback(() => { - setState(s => ({ - ...s, - focused: true, - })) - }, [setState]) - const onBlur = React.useCallback(() => { - setState(s => ({ - ...s, - focused: false, - })) - }, [setState]) const handleSuffixLayout = React.useCallback( (e: LayoutChangeEvent) => { setSuffixPadding(e.nativeEvent.layout.width + 16) @@ -83,7 +69,7 @@ export function InputText({ }) } - if (state.hovered || state.focused) { + if (hovered || focused) { input.push({ borderColor: t.atoms.border_contrast_500.borderColor, }) @@ -96,7 +82,16 @@ export function InputText({ } return {inputStyles: input, iconStyles: icon} - }, [t, state, hasError, Icon]) + }, [t, hovered, focused, hasError, Icon]) + + const handleOnChange = React.useCallback( + (e: any) => { + const value = e.currentTarget.value + onChange(value) + setValue(value) + }, + [onChange, setValue], + ) return ( @@ -114,12 +109,17 @@ export function InputText({ )} - - - - console.log(text)} + /> + console.log(text)} + /> + console.log(text)} + icon={Logo} + /> + console.log(text)} icon={Logo} suffix={() => .bksy.social} />