|
1 |
| -import React, { useEffect } from 'react'; |
2 |
| -import TextField from '@mui/material/TextField'; |
3 |
| -import InputAdornment from '@mui/material/InputAdornment'; |
4 |
| -import Search from '@mui/icons-material/Search'; |
5 |
| -import docsearch from 'docsearch.js'; |
6 |
| -import { useRouter } from 'next/router'; |
7 |
| -import { styled } from '@mui/material/styles'; |
| 1 | +import React from 'react'; |
| 2 | +import { DocSearch as AlgDocSearch } from '@docsearch/react'; |
8 | 3 |
|
9 |
| -const Root = styled('form')(({ theme }) => ({ |
10 |
| - '&.wrapper': { |
11 |
| - marginRight: 16, |
12 |
| - '& .algolia-docsearch-suggestion.algolia-docsearch-suggestion__main.algolia-docsearch-suggestion__secondary': { |
13 |
| - textDecoration: 'none', |
14 |
| - }, |
15 |
| - '& .algolia-autocomplete .algolia-docsearch-suggestion--title': { |
16 |
| - marginBottom: 0, |
17 |
| - }, |
18 |
| - '& .ds-dropdown-menu': { |
19 |
| - [theme.breakpoints.down('md')]: { |
20 |
| - position: 'fixed !important', |
21 |
| - top: '50px !important', |
22 |
| - maxWidth: '100% !important', |
23 |
| - minWidth: '100%', |
24 |
| - }, |
25 |
| - '& [class^=ds-dataset-]': { |
26 |
| - borderRadius: 0, |
27 |
| - }, |
28 |
| - '&:before': { |
29 |
| - display: 'none', |
30 |
| - }, |
31 |
| - }, |
32 |
| - }, |
33 |
| - '& .search-input': { |
34 |
| - '& input': { |
35 |
| - color: 'white', |
36 |
| - }, |
37 |
| - '& .MuiInput-underline:hover:not(.Mui-disabled):before': { |
38 |
| - borderBottomColor: 'white', |
39 |
| - }, |
40 |
| - '& .MuiInput-underline:after': { |
41 |
| - borderBottomColor: 'white', |
42 |
| - }, |
43 |
| - '& .MuiInput-underline:before': { |
44 |
| - borderBottomColor: 'transparent', |
45 |
| - }, |
46 |
| - }, |
47 |
| - '& .search-icon': { |
48 |
| - fill: 'white', |
49 |
| - }, |
50 |
| -})); |
| 4 | +import '@docsearch/css'; |
| 5 | +import Link from 'next/link'; |
51 | 6 |
|
52 |
| -const DocSearch = () => { |
53 |
| - const { push } = useRouter(); |
54 |
| - useEffect(() => { |
55 |
| - docsearch({ |
56 |
| - apiKey: '5e9dbd314423e38339595e183d1ae7b6', |
57 |
| - indexName: 'data-driven-forms', |
58 |
| - inputSelector: '#data-driven-forms-search', |
59 |
| - handleSelected: (input, event, suggestion) => { |
60 |
| - event.button = 0; |
61 |
| - push(suggestion.url.replace('https://data-driven-forms.org', '')); |
62 |
| - input.close(); |
63 |
| - }, |
64 |
| - // debug: true, // Set debug to true if you want to inspect the dropdown. |
65 |
| - }); |
66 |
| - }, [push]); |
67 |
| - return ( |
68 |
| - <Root className="wrapper"> |
69 |
| - <TextField |
70 |
| - variant="standard" |
71 |
| - id="data-driven-forms-search" |
72 |
| - type="search" |
73 |
| - placeholder="Search..." |
74 |
| - className="search-input" |
75 |
| - InputProps={{ |
76 |
| - startAdornment: ( |
77 |
| - <InputAdornment position="start"> |
78 |
| - <Search className="search-icon" /> |
79 |
| - </InputAdornment> |
80 |
| - ), |
81 |
| - }} |
82 |
| - /> |
83 |
| - </Root> |
84 |
| - ); |
85 |
| -}; |
| 7 | +const DocSearch = () => ( |
| 8 | + <AlgDocSearch |
| 9 | + hitComponent={({ hit, children }) => ( |
| 10 | + <Link href={hit.url.replace('https://data-driven-forms.org', '')}> |
| 11 | + <a href={hit.url.replace('https://data-driven-forms.org', '')}>{children}</a> |
| 12 | + </Link> |
| 13 | + )} |
| 14 | + debug |
| 15 | + apiKey="89894d702d5ead6999eaf04e3b34012a" |
| 16 | + appId="4KH6MQCYWM" |
| 17 | + indexName="data-driven-forms" |
| 18 | + /> |
| 19 | +); |
86 | 20 |
|
87 | 21 | export default DocSearch;
|
0 commit comments