/** * Copyright (c) Paymium. * * This source code is licensed under the MIT license found in the * LICENSE file in the root of this projects source tree. */ import { TextInput, type TextInputProps } from 'react-native'; import { forwardRef, useCallback, useState, type ReactNode } from 'react'; import { form } from '../styles/form'; import { composeStyles, CrossedMethods, useInteraction } from '@crossed/styled'; import { FormControl, FormField, FormLabel } from './Form'; import { CloseButton } from '../buttons/CloseButton'; import { useUncontrolled } from '@crossed/core'; import { XBox } from '../layout/XBox'; import { Text } from '../typography/Text'; import { YBox } from '../layout/YBox'; export type TextareaProps = Omit & { label?: string; clearable?: boolean; elementLeft?: ReactNode; elementRight?: ReactNode; error?: string; description?: string; extra?: string; style?: CrossedMethods; disabled?: boolean; }; export const Textarea = forwardRef( ( { error, label, clearable, defaultValue, value: valueProps, onChangeText, disabled, elementRight, elementLeft, description, extra, ...props }, ref ) => { const [value, setValue] = useUncontrolled({ value: valueProps, defaultValue, onChange: onChangeText, }); const [elementLeftWidth, setElementLeftWidth] = useState(0); const [elementRightWidth, setElementRightWidth] = useState(0); const { state, props: propsInteraction } = useInteraction(props); const { color } = form.placeholder.style().style; const onClear = useCallback(() => { setValue(''); }, [setValue]); const showClear = clearable && value; return ( {(label || description || extra) && ( {label && {label}} {description && ( {description} )} {extra && ( {extra} )} )} {elementLeft && ( setElementLeftWidth(layout.width) } > {elementLeft} )} setElementRightWidth(layout.width) } > {showClear && } {elementRight} {error && {error.toString()}} ); } );