Dialog text input

This commit is contained in:
Eric Bailey
2024-01-15 16:42:00 -06:00
parent 48abb5ac37
commit 4d3128aa12
4 changed files with 225 additions and 204 deletions
+4
View File
@@ -3,12 +3,14 @@ import {View, Dimensions} from 'react-native'
import BottomSheet, { import BottomSheet, {
BottomSheetBackdrop, BottomSheetBackdrop,
BottomSheetScrollView, BottomSheetScrollView,
BottomSheetTextInput,
BottomSheetView, BottomSheetView,
} from '@gorhom/bottom-sheet' } from '@gorhom/bottom-sheet'
import {useSafeAreaInsets} from 'react-native-safe-area-context' import {useSafeAreaInsets} from 'react-native-safe-area-context'
import {useTheme, atoms as a} from '#/alf' import {useTheme, atoms as a} from '#/alf'
import {Portal} from '#/components/Portal' import {Portal} from '#/components/Portal'
import {createTextInput} from '#/components/forms/InputText'
import { import {
DialogOuterProps, DialogOuterProps,
@@ -19,6 +21,8 @@ import {Context} from '#/components/Dialog/context'
export {useDialogControl, useDialogContext} from '#/components/Dialog/context' export {useDialogControl, useDialogContext} from '#/components/Dialog/context'
export * from '#/components/Dialog/types' export * from '#/components/Dialog/types'
// @ts-ignore
export const InputText = createTextInput(BottomSheetTextInput)
export function Outer({ export function Outer({
children, children,
+1
View File
@@ -13,6 +13,7 @@ import {Context, useDialogContext} from '#/components/Dialog/context'
export {useDialogControl, useDialogContext} from '#/components/Dialog/context' export {useDialogControl, useDialogContext} from '#/components/Dialog/context'
export * from '#/components/Dialog/types' export * from '#/components/Dialog/types'
export {InputText} from '#/components/forms/InputText'
const stopPropagation = (e: any) => e.stopPropagation() const stopPropagation = (e: any) => e.stopPropagation()
+13 -5
View File
@@ -20,7 +20,8 @@ type Props = BaseProps &
suffix?: React.FunctionComponent<any> suffix?: React.FunctionComponent<any>
} }
export function InputText({ export function createTextInput(Input: typeof TextInput) {
return function InputText({
value: initialValue, value: initialValue,
onChange, onChange,
testID, testID,
@@ -31,7 +32,7 @@ export function InputText({
icon: Icon, icon: Icon,
suffix: Suffix, suffix: Suffix,
...props ...props
}: Props) { }: Props) {
const labelId = React.useId() const labelId = React.useId()
const t = useTheme() const t = useTheme()
const [value, setValue] = React.useState<string>(initialValue) const [value, setValue] = React.useState<string>(initialValue)
@@ -75,7 +76,9 @@ export function InputText({
if (hasError) { if (hasError) {
base.push({ base.push({
backgroundColor: backgroundColor:
t.name === 'light' ? t.palette.negative_25 : t.palette.negative_900, t.name === 'light'
? t.palette.negative_25
: t.palette.negative_900,
borderColor: borderColor:
t.name === 'light' t.name === 'light'
? t.palette.negative_300 ? t.palette.negative_300
@@ -86,7 +89,9 @@ export function InputText({
}) })
focus.push({ focus.push({
backgroundColor: backgroundColor:
t.name === 'light' ? t.palette.negative_25 : t.palette.negative_900, t.name === 'light'
? t.palette.negative_25
: t.palette.negative_900,
borderColor: tokens.color.red_500, borderColor: tokens.color.red_500,
}) })
} }
@@ -155,7 +160,7 @@ export function InputText({
</Text> </Text>
)} )}
<TextInput <Input
{...props} {...props}
value={value} value={value}
testID={testID} testID={testID}
@@ -237,4 +242,7 @@ export function InputText({
)} )}
</View> </View>
) )
}
} }
export const InputText = createTextInput(TextInput)
+8
View File
@@ -56,6 +56,14 @@ export function Dialogs() {
<View style={[a.relative, a.gap_md, a.w_full]}> <View style={[a.relative, a.gap_md, a.w_full]}>
<H3 nativeID="dialog-title">Dialog</H3> <H3 nativeID="dialog-title">Dialog</H3>
<P nativeID="dialog-description">Description</P> <P nativeID="dialog-description">Description</P>
<Dialog.InputText
testID=""
value=""
onChange={() => {}}
placeholder="Type here"
accessibilityLabel="Type"
accessibilityHint="Type"
/>
<View style={{height: 1000}} /> <View style={{height: 1000}} />
<View style={[a.flex_row, a.justify_end]}> <View style={[a.flex_row, a.justify_end]}>
<Button <Button