forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocSearch.js
More file actions
57 lines (49 loc) · 1.38 KB
/
DocSearch.js
File metadata and controls
57 lines (49 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import Input from '@codesandbox/common/lib/components/Input';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import DocSearchStyle from '../css/docSearch';
const StyledInput = styled(Input)`
border: 1px solid ${props => props.theme.background2.lighten(0.3)};
transition: all 300ms ease;
box-sizing: border-box;
padding-left: 0.5rem;
border-radius: 4px;
padding-right: 30px;
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.25);
&:focus,
&:hover {
border: 1px solid #0d7bc9;
box-shadow: inset 0 2px 2px rgba(0, 0, 0, 0.6);
}
`;
const DocSearch = () => {
const [enabled, setEnabled] = useState(true);
useEffect(() => {
// Initialize Algolia search.
if (window.docsearch) {
window.docsearch({
apiKey: '45db7de01ac97a7c4c673846830c4117',
debug: false,
indexName: 'codesandbox',
inputSelector: '#algolia-doc-search',
});
} else {
// eslint-disable-next-line
console.warn('Search has failed to load and now is being disabled');
setEnabled(false);
}
}, []);
return enabled ? (
<form style={{ margin: 0 }}>
<StyledInput
aria-label="Search docs"
block
id="algolia-doc-search"
placeholder="Search our docs"
type="search"
/>
<DocSearchStyle />
</form>
) : null;
};
export default DocSearch;