import Dialog from "@material-ui/core/Dialog"; import Downshift from "downshift"; import hotkeys from "hotkeys-js"; import React from "react"; import { useIntl } from "react-intl"; import { getActions, getCatalog, getCustomers, getViews, hasActions, hasCatalog, hasCustomers, hasViews } from "./modes/utils"; import NavigatorInput from "./NavigatorInput"; import NavigatorSection from "./NavigatorSection"; import { QuickSearchAction } from "./types"; import useQuickSearch from "./useQuickSearch"; const navigatorHotkey = "ctrl+k, command+k"; function getItemOffset( actions: QuickSearchAction[], cbs: Array ): number { return cbs.reduce((acc, cb) => cb(actions).length + acc, 0); } const Navigator: React.FC = () => { const [visible, setVisible] = React.useState(false); const input = React.useRef(null); const [query, mode, change, actions] = useQuickSearch(visible, input); const intl = useIntl(); React.useEffect(() => { hotkeys(navigatorHotkey, event => { event.preventDefault(); setVisible(!visible); }); return () => hotkeys.unbind(navigatorHotkey); }, []); return ( setVisible(false)} fullWidth maxWidth="sm" > (item ? item.label : "")} onSelect={(item: QuickSearchAction) => { setVisible(false); item.onClick(); }} onInputValueChange={value => change({ target: { name: "query", value } }) } defaultHighlightedIndex={0} > {({ getInputProps, getItemProps, highlightedIndex }) => (
{hasViews(actions) && ( )} {hasActions(actions) && ( )} {hasCustomers(actions) && ( )} {hasCatalog(actions) && ( )}
)}
); }; export default Navigator;