import ArrowDropDown from '@mui/icons-material/ArrowDropDown' import { Button, ListItemIcon, ListItemText, Menu, MenuItem, Typography } from '@mui/material' import { useState, type ReactNode } from 'react' import { MONOSPACED } from './fonts.ts' /** * An item of a SwitcherMenu: its key, the label and icon of the button and the menu, and optionally a second line in * the Monospaced font, a hint at the right end, such as the key that opens it, and whether it can be chosen. */ export type SwitcherItem = { key: K label: string icon: ReactNode secondary?: string hint?: string disabled?: boolean } /** * A button naming the item chosen, current, with its icon, whose menu chooses another with onChoose. title is the * button's tooltip. */ export default function SwitcherMenu(props: { items: SwitcherItem[]; current: SwitcherItem; title?: string; onChoose: (key: K) => void }) { const { items, current } = props const [anchor, setAnchor] = useState(null) return ( <> setAnchor(null)}> {items.map((item, index) => ( { setAnchor(null) props.onChoose(item.key) }} > {item.icon} {item.hint !== undefined && {item.hint}} ))} ) }