docs(nxdev): update algolia types (#11379)
This commit is contained in:
parent
8797915020
commit
15200964ef
@ -1,15 +1,25 @@
|
|||||||
import { DocSearchModal, useDocSearchKeyboardEvents } from '@docsearch/react';
|
import { DocSearchModal, useDocSearchKeyboardEvents } from '@docsearch/react';
|
||||||
|
import {
|
||||||
|
InternalDocSearchHit,
|
||||||
|
StoredDocSearchHit,
|
||||||
|
} from '@docsearch/react/dist/esm/types';
|
||||||
import { SearchIcon } from '@heroicons/react/solid';
|
import { SearchIcon } from '@heroicons/react/solid';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { ReactNode, useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
import { createPortal } from 'react-dom';
|
||||||
|
|
||||||
const ACTION_KEY_DEFAULT = ['Ctrl ', 'Control'];
|
const ACTION_KEY_DEFAULT = ['Ctrl ', 'Control'];
|
||||||
const ACTION_KEY_APPLE = ['⌘', 'Command'];
|
const ACTION_KEY_APPLE = ['⌘', 'Command'];
|
||||||
|
|
||||||
function Hit({ hit, children }) {
|
function Hit({
|
||||||
|
hit,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
hit: InternalDocSearchHit | StoredDocSearchHit;
|
||||||
|
children: ReactNode;
|
||||||
|
}): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<Link href={hit.url}>
|
<Link href={hit.url}>
|
||||||
<a>{children}</a>
|
<a>{children}</a>
|
||||||
@ -17,7 +27,7 @@ function Hit({ hit, children }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AlgoliaSearch() {
|
export function AlgoliaSearch(): JSX.Element {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const searchButtonRef = useRef<HTMLButtonElement>(null);
|
const searchButtonRef = useRef<HTMLButtonElement>(null);
|
||||||
@ -33,9 +43,9 @@ export function AlgoliaSearch() {
|
|||||||
}, [setIsOpen]);
|
}, [setIsOpen]);
|
||||||
|
|
||||||
const handleInput = useCallback(
|
const handleInput = useCallback(
|
||||||
(e) => {
|
(event: KeyboardEvent) => {
|
||||||
setIsOpen(true);
|
setIsOpen(true);
|
||||||
setInitialQuery(e.key);
|
setInitialQuery(event.key);
|
||||||
},
|
},
|
||||||
[setIsOpen, setInitialQuery]
|
[setIsOpen, setInitialQuery]
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user