Skip to content

Commit

Permalink
docs: migrate to Algolia DocSearch v3 (#6410)
Browse files Browse the repository at this point in the history
* docs: migrate to Algolia DocSearch v3

* make search bar full width
  • Loading branch information
kyletsang committed Jul 29, 2022
1 parent 5940109 commit f66cf79
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 843 deletions.
1 change: 1 addition & 0 deletions www/gatsby-browser.js
@@ -1,4 +1,5 @@
require('./src/css/global.scss');
require('@docsearch/css/dist/style.css');

// prevent FontAwesome icons' flash from a very large one down to a properly sized one
require('@fortawesome/fontawesome-svg-core/styles.css');
Expand Down
3 changes: 2 additions & 1 deletion www/package.json
Expand Up @@ -30,6 +30,8 @@
}
},
"devDependencies": {
"@docsearch/css": "^3.1.1",
"@docsearch/react": "^3.1.1",
"@fortawesome/fontawesome-svg-core": "^1.3.0",
"@fortawesome/free-brands-svg-icons": "^5.15.4",
"@fortawesome/free-solid-svg-icons": "^5.15.4",
Expand All @@ -44,7 +46,6 @@
"classnames": "^2.3.1",
"common-tags": "^1.8.2",
"copy-text-to-clipboard": "^3.0.1",
"docsearch.js": "^2.6.3",
"dom-helpers": "^5.2.1",
"formik": "^2.2.9",
"gatsby": "^2.32.13",
Expand Down
26 changes: 6 additions & 20 deletions www/src/components/SideNav.js
@@ -1,8 +1,8 @@
import { DocSearch } from '@docsearch/react';
import startCase from 'lodash/startCase';
import classNames from 'classnames';
import * as React from 'react';
import Nav from 'react-bootstrap/Nav';
import FormControl from 'react-bootstrap/FormControl';

import styled from 'astroturf';
import Button from 'react-bootstrap/Button';
Expand Down Expand Up @@ -158,19 +158,6 @@ const components = [

const utilities = ['transitions', 'ratio', 'restart-ui'];

// We need to configure this
function attachSearch(ref) {
if (ref && window)
import('docsearch.js').then(({ default: docsearch }) => {
docsearch({
apiKey: '00f98b765b687b91399288e7c4c68ce1',
indexName: 'react_bootstrap_v4',
inputSelector: `#${ref.id}`,
debug: process.env.NODE_ENV !== 'production', // Set debug to true if you want to inspect the dropdown
});
});
}

const nameOverrides = {
'why-react-bootstrap': 'Why React-Bootstrap',
rtl: 'RTL',
Expand Down Expand Up @@ -219,12 +206,11 @@ class SideNav extends React.Component {
const { location, ...props } = this.props;
return (
<SidePanel {...props}>
<form className="py-3 d-flex align-items-center">
<FormControl
id="docs-search-input"
type="text"
placeholder="Search…"
ref={attachSearch}
<form className="py-3 d-flex align-items-center justify-content-between">
<DocSearch
appId="C38ZI55F9H"
apiKey="33985ee571397d832ef243988ff4c891"
indexName="react_bootstrap_v4"
/>
<MenuButton onClick={this.handleCollapse}>
<svg
Expand Down
8 changes: 8 additions & 0 deletions www/src/css/algolia.scss
@@ -0,0 +1,8 @@
// Removes a tiny vertical scrollbar in the list item.
.DocSearch-Hit-content-wrapper {
overflow: hidden;
}

.DocSearch-Button {
flex-grow: 1;
}

0 comments on commit f66cf79

Please sign in to comment.