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' // interface Styles { // base?: string // touched?: string // element?: string // label?: string // } export default function selectFactory({ styles }): FunctionComponent<{ autoFocus?: boolean className?: string defaultValue?: string disabled?: boolean name: string noEmpty?: boolean label: string placeholder?: string required?: boolean options: string[] | number[] | { label: string; value: string | number } }> { if (Array.isArray(styles)) { styles = mergeStyles(styles) } const Select = ({ autoFocus, className, color, defaultValue, design = 'main', disabled, icon, name, label, noEmpty, onChange, placeholder, required, size = 'medium', options, }) => { const [touched, setTouched] = useState(false) const selectRef = useRef() console.log(options) const onBlur = useCallback(() => setTouched(true), []) useEffect(() => { const form = selectRef.current!.form const resetTouched = setTouched.bind(null, false) form!.addEventListener('reset', resetTouched) return () => form!.removeEventListener('reset', resetTouched) }, []) useEffect(() => { if (autoFocus) selectRef.current!.focus() }, [autoFocus]) return (
{icon &&
} {/** *
) } return Select }