npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apollo-algolia-autocomplete

v1.11.0

Published

Algolia autocomplete in React

Downloads

439

Readme

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

Usage

// App.js
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

  • [x] create example site to demo implementation
    • simple Gatsby site at /example
    • use yarn workspaces
  • [x] put this and algolia parsing logic plugin things in same repo
  • [x] odyssey results: only show results for non-internal courses
  • [x] add functionality to the "Can't find what you're looking for?" section
  • [x] optional filtering ~~(press Tab?) -- need to decide what words to allow for filtering~~
    • used Algolia's optionalFilters option
  • [x] query suggestions
  • [ ] odyssey results: include course and lesson name in title
  • [ ] restyle scroll bar
  • [ ] clean up mobile styling
  • [ ] fine tune relevancy (i.e. only show v2 results if explicitly searching for v2, otherwise show v3)
  • [x] padding left section titles
  • [ ] preview description text should provide more information than what's on the left results. longer description, title structure/history
  • [ ] pills on highlight section should link /refer to something useful
  • [x] we can filter out documentation (as we're in the doc
  • [x] no round corners on reuslts hover highlight
  • [ ] placeholder text in search bar should be insightful and guides users on what the can search
  • [x] overall height of overlay could be taller
  • [x] font in search bar could be larger
  • [ ] having the remaining search bar from the page visibile behind the overlay looks strange( we should probably hide it)
  • [ ] click on query suggestion should fill out value in search bar
  • [ ] query suggestions sometimes shows what's is already searched ("client")

Known Bugs 🐛

  • [x] String excerpts for blog records include <p>
  • [ ] Excerpts in results list don't highlight queried term
  • [ ] Some records have no title
  • [ ] Clicking on a query suggestion doesn't fill in the input bar with that term
  • [x] Titles in preview sometimes squish the words together
  • [ ] Duplicate results can show up for Odyssey (possibly if there are less results than hitsPerPage? Not sure if also happens for other categories)

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?