import { $ } from 'mdui/jq' import React from 'react' import { Dropdown } from 'mdui' import useEventListener from '../useEventListener.ts' // value as { [id: string]: string } export default function SelectPreference({ title, icon, updater, selections, defaultCheckedId, disabled } = { disabled: false, }) { const [ checkedId, setCheckedId ] = React.useState(defaultCheckedId) const dropDownRef = React.useRef(null) const [isDropDownOpen, setDropDownOpen] = React.useState(false) useEventListener(dropDownRef, 'closed', (e) => { setDropDownOpen(false) }) return setDropDownOpen(!isDropDownOpen)}> { title } { e.stopPropagation() setDropDownOpen(false) }}> { Object.keys(selections).map((id) => { setCheckedId(id) updater(id) }}>{selections[id]} ) } { selections[checkedId] } }