diff --git a/src/components/DocSearch/DocSearch.js b/src/components/DocSearch/DocSearch.js new file mode 100644 index 00000000..4f3b8ca2 --- /dev/null +++ b/src/components/DocSearch/DocSearch.js @@ -0,0 +1,110 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * @emails react-core + */ + +import React, {Component} from 'react'; +import {colors, media} from 'theme'; + +class DocSearch extends Component { + state = { + disabled: false + } + componentDidMount() { + // Initialize Algolia search. + // TODO Is this expensive? Should it be deferred until a user is about to search? + // eslint-disable-next-line no-undef + if(window.docsearch) { + docsearch({ + apiKey: '36221914cce388c46d0420343e0bb32e', + indexName: 'react', + inputSelector: '#algolia-doc-search', + }); + } else { + this.setState({ disabled: true}) + } + } + + render() { + const {disabled} = this.state + + return ( +
+ ); + } +} + +export default DocSearch; \ No newline at end of file diff --git a/src/components/DocSearch/index.js b/src/components/DocSearch/index.js new file mode 100644 index 00000000..8e2a0ad3 --- /dev/null +++ b/src/components/DocSearch/index.js @@ -0,0 +1,11 @@ +/** + * Copyright (c) 2013-present, Facebook, Inc. + * + * @emails react-core + */ + +'use strict'; + +import DocSearch from './DocSearch'; + +export default DocSearch; diff --git a/src/components/LayoutHeader/Header.js b/src/components/LayoutHeader/Header.js index d3bc48fa..8327a612 100644 --- a/src/components/LayoutHeader/Header.js +++ b/src/components/LayoutHeader/Header.js @@ -13,6 +13,7 @@ import React from 'react'; import {colors, fonts, media} from 'theme'; import {version} from 'site-constants'; import ExternalLinkSvg from 'templates/components/ExternalLinkSvg'; +import DocSearch from 'components/DocSearch'; import logoSvg from 'icons/logo.svg'; @@ -135,78 +136,7 @@ const Header = ({location}) => ( /> - +