Apollo Algolia Autocomplete
This repo contains a custom Algolia autocomplete React component that powers the search bar in various Apollo GraphQL sites.
Installation
npm i apollo-algolia-autocomplete
Demo
https://apollo-algolia.netlify.app/
![apollo-algolia-autocomplete](https://user-images.githubusercontent.com/32886852/121232457-dfa3f280-c84e-11eb-9ad6-b1179206d98e.gif)
Usage
import React from 'react';
import Autocomplete from './components/autocomplete';
function App() {
return (
<div>
...
<Autocomplete
appId={'YOUR_APP_ID'}
apiKey={'YOUR_API_KEY'}
currentSource="blog"
docset="react"
/>
{/* content that should show up beneath the search bar when the search modal is closed */}
</div>
);
}
export default App;
Props
Name | Description | type | Default value | Required |
---|
appId | Your Algolia app ID | string | -- | yes |
apiKey | Your Algolia API key | string | -- | yes |
currentSource | Algolia index name ('docs', 'blog', 'odyssey') that you want to appear first in the search results | string | 'docs' | no |
docset | Name of the docset by which you want to filter the documentation results | string | '' | no |
sources | Algolia indices to append to the default Autocomplete sources | object | defaultSources var in Autocomplete.js | no |
If a currentSource
prop is provided, the search result sources will be sorted to put the currentSource
at the top.
Any additional props will be passed to the autocomplete
function from @algolia/autocomplete-js.
**This component has the Algolia sources baked in and is therefore not customizable on that front. The only customizable aspect of the Algolia sources is which source results are displayed first (via the currentSource
prop)
Custom styling
This package uses the autocomplete-theme-classic
to provide some default styling. It also uses vanilla CSS to override some of those defaults to better fit the Apollo brand.
You can find the different class names and CSS variables already being used by autocomplete-theme-classic
in the Algolia docs. This will enable you to override any of them with your own styles. Create a .css
file with any overrides and import it wherever you're rendering your Autocomplete
component.
**Some of this package's custom styles stray a bit from the default Algolia theme. Below are the additional classes that have been added:
TO DO
Known Bugs 🐛
UI Ideas
- breadcrumbs so users can see what section within the docs the search result is in
- category tags
- in search results and page previews, have different color for the parts of the text that match the search
- images for blogs/odyssey?