import { Button, MenuItem, Checkbox, ListItemText, } from "@suid/material"; import { createMemo, createSignal, createUniqueId, For, } from "solid-js"; import Menu from "../material/Menu"; import { FilterList, FilterListOff } from "@suid/icons-material"; type Props> = { options: Filters; applied: Record; disabledKeys?: (keyof Filters)[]; onApply(value: Record): void; }; function TootFilterButton>(props: Props) { const buttonId = createUniqueId(); const [open, setOpen] = createSignal(false); const getTextForMultipleEntities = (texts: string[]) => { switch (texts.length) { case 0: return "Nothing"; case 1: return texts[0]; case 2: return `${texts[0]} and ${texts[1]}`; case 3: return `${texts[0]}, ${texts[1]} and ${texts[2]}`; default: return `${texts[0]} and ${texts.length - 1} other${texts.length > 2 ? "s" : ""}`; } }; const optionKeys = () => Object.keys(props.options); const appliedKeys = createMemo(() => { const applied = props.applied; return optionKeys().filter((k) => applied[k]); }); const text = () => { const keys = optionKeys(); const napplied = appliedKeys().length; switch (napplied) { case keys.length: return "All"; default: return getTextForMultipleEntities( appliedKeys().map((k) => props.options[k]), ); } }; const toggleKey = (key: keyof F) => { props.onApply( Object.assign({}, props.applied, { [key]: !props.applied[key], }), ); }; return ( <> document.getElementById(buttonId)!.getBoundingClientRect() } > {(item, idx) => ( <> {props.options[item]} )} ); } export default TootFilterButton;