Skip to content

Commit c52b8a5

Browse files
committed
Update docsearch component.
1 parent b5a9181 commit c52b8a5

File tree

3 files changed

+513
-636
lines changed

3 files changed

+513
-636
lines changed

packages/react-renderer-demo/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"@data-driven-forms/editor-pro": "0.0.13",
3232
"@data-driven-forms/mui-component-mapper": "*",
3333
"@data-driven-forms/react-form-renderer": "*",
34+
"@docsearch/css": "^3.2.1",
35+
"@docsearch/react":"^3.2.1",
3436
"@emotion/cache": "^11.10.3",
3537
"@emotion/react": "^11.10.4",
3638
"@emotion/server": "^11.10.0",
@@ -48,7 +50,6 @@
4850
"@stackblitz/sdk": "^1.5.3",
4951
"clsx": "^1.1.1",
5052
"codesandbox": "2.2.3",
51-
"docsearch.js": "^2.6.3",
5253
"evergreen-ui": "^6.9.10",
5354
"firebase-admin": "^10.0.1",
5455
"firebase-functions": "^3.16.0",
Lines changed: 17 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,21 @@
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';
83

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';
516

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+
);
8620

8721
export default DocSearch;

0 commit comments

Comments
 (0)