import { cn } from '@cherrystudio/ui/lib/utils' import { composeEventHandlers } from '@radix-ui/primitive' import { useCallbackRef } from '@radix-ui/react-use-callback-ref' import { useControllableState } from '@radix-ui/react-use-controllable-state' import { cva } from 'class-variance-authority' import * as React from 'react' /* ------------------------------------------------------------------------------------------------- * Variants * -----------------------------------------------------------------------------------------------*/ const textareaVariants = cva( cn( 'flex field-sizing-content min-h-16 w-full border bg-transparent px-4 py-3 text-lg shadow-xs transition-[color,box-shadow] outline-none resize-y', 'rounded-xs', 'border-input text-foreground placeholder:text-foreground-secondary', 'focus-visible:border-primary focus-visible:ring-ring focus-visible:ring-[3px]', 'disabled:cursor-not-allowed disabled:opacity-50', 'md:text-sm' ), { variants: { hasError: { true: 'aria-invalid:border-destructive aria-invalid:ring-destructive/20', false: '' } }, defaultVariants: { hasError: false } } ) /* ------------------------------------------------------------------------------------------------- * TextareaInput * -----------------------------------------------------------------------------------------------*/ const INPUT_NAME = 'TextareaInput' interface TextareaInputProps extends Omit, 'value' | 'defaultValue'> { value?: string defaultValue?: string onValueChange?: (value: string) => void hasError?: boolean ref?: React.Ref } function TextareaInput({ value: valueProp, defaultValue, onValueChange, hasError = false, className, ref, ...props }: TextareaInputProps) { const [value = '', setValue] = useControllableState({ prop: valueProp, defaultProp: defaultValue ?? '', onChange: onValueChange }) const handleChange = useCallbackRef((event: React.ChangeEvent) => { const newValue = event.target.value if (props.maxLength && newValue.length > props.maxLength) { return } setValue(newValue) }) return (