import * as React from "react"; import { unstable_useComboboxListGridState as useComboboxListGridState, unstable_Combobox as Combobox, unstable_ComboboxList as ComboboxList, unstable_ComboboxGridRow as ComboboxGridRow, unstable_ComboboxGridCell as ComboboxGridCell, } from "reakit/Combobox"; import Block from "./Block"; import BlockGrid from "./BlockGrid"; import { data } from "./data"; type Props = Omit, "list"> & { initialItems: typeof data; }; function getValues(items: typeof data) { return items.map((item) => item.title); } function getIconFromValue(items: typeof data, value: string) { return items.find((item) => item.title === value)?.icon; } function onOptionClick(event: React.MouseEvent) { event.preventDefault(); } export default function BlockList({ initialItems, ...props }: Props) { const ref = React.useRef(null); const initialValues = React.useMemo(() => getValues(initialItems), [ initialItems, ]); const combobox = useComboboxListGridState({ values: initialValues, limit: false, columns: 3, autoSelect: true, wrap: "horizontal", shift: true, minValueLength: 1, }); return ( <> {combobox.inputValue ? ( combobox.matches.length ? ( {combobox.matches.map((values, i) => ( {values.map((val) => ( ))} ))} ) : ( No results found ) ) : ( { const { key } = event; if (key && key.length === 1) { ref.current?.focus(); } }} /> )} ); }