import { type ComponentChildren } from 'preact' import { useState, useRef, useEffect } from 'preact/hooks' import { clsx, isMobile } from './lib/util' import { PhosphorIcon } from './Icon' export const ComboBox = ({ value, setValue, children, }: { value: string setValue: (s: string) => void children: Record }) => { const [cloak, setCloak] = useState(true) const [open, setOpen] = useState(true) const comboRef = useRef(null) useEffect(() => { const handleClick = (e: MouseEvent) => { if (comboRef.current && !comboRef.current.contains(e.target as Node)) { setOpen(false) } } document.addEventListener('mousedown', handleClick) return () => document.removeEventListener('mousedown', handleClick) }, []) const [itemWidth, setItemWidth] = useState(200) useEffect(() => { setOpen(false) setCloak(false) }, []) return (
setOpen(!open)}>
{children[value]}
{/* expand_more */}
{open && (
{ if (!el) return setItemWidth(el.offsetWidth) }} > {Object.keys(children).map(key => (
{ setValue(key) setOpen(false) }} > {children[key]}
))}
)}
) }