import React from 'react' import { Dropdown } from 'mdui' import useEventListener from '../useEventListener.ts' import PreferenceUpdater from "./PreferenceUpdater.ts" interface Args extends React.HTMLAttributes { title: string icon: string id: string disabled?: boolean selections: { [id: string]: string } state: string } export default function SelectPreference({ title, icon, id: preferenceId, selections, state, disabled }: Args) { const updater = React.useContext(PreferenceUpdater) const dropDownRef = React.useRef(null) const [isDropDownOpen, setDropDownOpen] = React.useState(false) useEventListener(dropDownRef, 'closed', () => { setDropDownOpen(false) }) return setDropDownOpen(!isDropDownOpen)}> {title} { e.stopPropagation() setDropDownOpen(false) }}> { Object.keys(selections).map((id) => // @ts-ignore: selected 确实存在, 但是并不对外公开使用 { updater(preferenceId, id) }}>{selections[id]} ) } {selections[state]} }