index.tsx46 lines · main
1import { Book } from 'lucide-react'
2
3import {
4 PageType,
5 useRegisterCommands,
6 useRegisterPage,
7 useSetPage,
8 type CommandOptions,
9 type ICommand,
10} from '../..'
11import { DocsSearchPage } from './DocsSearchPage'
12
13const DOCS_SEARCH_COMMANDS = {
14 PAGE_NAME: 'Docs search',
15 SECTION_NAME: 'Docs',
16}
17
18const identity = <T,>(x: T) => x
19
20const useDocsSearchCommands = ({
21 modify = identity,
22 options,
23}: { modify?: (command: ICommand) => ICommand; options?: CommandOptions } = {}) => {
24 const setCommandPage = useSetPage()
25 useRegisterPage(DOCS_SEARCH_COMMANDS.PAGE_NAME, {
26 type: PageType.Component,
27 component: DocsSearchPage,
28 })
29
30 useRegisterCommands(
31 DOCS_SEARCH_COMMANDS.SECTION_NAME,
32 [
33 {
34 id: 'search-docs',
35 name: 'Search the docs',
36 action: () => {
37 setCommandPage(DOCS_SEARCH_COMMANDS.PAGE_NAME, true)
38 },
39 icon: () => <Book />,
40 },
41 ].map(modify),
42 options
43 )
44}
45
46export { useDocsSearchCommands }