import React from 'react'; import PropTypes from 'prop-types'; import { storiesOf } from '@storybook/react'; import Autosuggest from 'react-autosuggest'; import algoliasearch from 'algoliasearch/lite'; import { Configure, InstantSearch, Index, Highlight, Pagination, SearchBox, SortBy, connectHits, connectAutoComplete, connectStateResults, } from 'react-instantsearch-dom'; import { Content as StoryWrapper } from './util'; const searchClient = algoliasearch( 'latency', '6be0576ff61c053d5f9a3225e2a90f76' ); const stories = storiesOf('', module); stories .add('MultiHits', () => (

index: bestbuy

index: instant_search

index: instant_search with brand:Apple

index: instant_search with brand:Samsung

index: instant_search with brand:Microsoft

)) .add('AutoComplete', () => ( )) .add('with SortBy nested in same Index as Root', () => (
)) .add('with conditional rendering', () => (
Categories:
Brand:
Products:
)) .add('with Hits & Configure', () => ( )); const AutoComplete = connectAutoComplete( ({ hits, currentRefinement, refine }) => ( refine(value)} onSuggestionsClearRequested={() => refine('')} getSuggestionValue={(hit) => hit.name} renderSuggestion={(hit) => hit.brand ? : } inputProps={{ placeholder: 'Search for a category, brand or product', value: currentRefinement, onChange: () => {}, }} renderSectionTitle={(section) => section.index} getSectionSuggestions={(section) => section.hits} /> ) ); const CustomCategoriesOrBrands = connectHits(({ hits }) => { const categoryOrBrand = hits.map((hit) => ( )); return
{categoryOrBrand}
; }); const CategoryOrBrand = ({ hit }) => (
); CategoryOrBrand.propTypes = { hit: PropTypes.object.isRequired, }; const CustomProducts = connectHits(({ hits }) => { const products = hits.map((hit) => ); return
{products}
; }); const Product = ({ hit }) => { const image = `https://ecommerce-images.algolia.com/img/produit/nano/${hit.objectID}-1.jpg%3Falgolia`; return (
- ${hit.price}
); }; Product.propTypes = { hit: PropTypes.object.isRequired, }; const Content = connectStateResults( ({ searchState, searchResults, children }) => searchResults && searchResults.nbHits !== 0 ? ( children ) : (
No results has been found for {searchState.query} and index{' '} {searchResults ? searchResults.index : ''}
) ); const Results = connectStateResults(({ allSearchResults, children }) => { const noResults = allSearchResults && Object.values(allSearchResults).reduce( (acc, results) => results.nbHits === 0, false ); return noResults ? (
No results in category, products or brand
) : ( children ); });