import { h, type FunctionComponent } from 'preact' import { useCallback, useEffect, useRef, useState } from 'preact/hooks' import cn from 'classnames' import mergeStyles from '../utils/merge_styles.ts' type Props = { autoFocus?: boolean className?: string cols?: number defaultValue?: string disabled?: boolean label: string name: string placeholder?: string required?: boolean rows: number showValidity?: boolean } export default function textareaFactory(styles: { base?: string touched?: string element?: string label?: string statusIcon?: string }): FunctionComponent { if (Array.isArray(styles)) { styles = mergeStyles(styles) } const Textarea = ({ autoFocus, className, cols, defaultValue, disabled, label, name, placeholder, required, rows, showValidity = true, }: Props) => { const [touched, setTouched] = useState(false) const textareaRef = useRef(null) const onBlur = useCallback(() => setTouched(true), []) useEffect(() => { const form = textareaRef.current!.form! const resetTouched = setTouched.bind(null, false) form.addEventListener('reset', resetTouched) return () => form.removeEventListener('reset', resetTouched) }, []) return (