import React from 'react'; import { storiesOf } from '@storybook/react'; import { connectHits } from 'react-instantsearch-core'; import { QueryRuleCustomData, QueryRuleContext, Highlight, RefinementList, } from 'react-instantsearch-dom'; import { WrapWithHits } from './util'; type CustomDataItem = { title: string; banner: string; link: string; }; type MovieHit = { actors: string[]; color: string; genre: string[]; image: string; objectID: string; score: number; title: string; }; const stories = storiesOf('QueryRuleContext', module); const StoryHits = connectHits(({ hits }: { hits: MovieHit[] }) => (
{hits.map((hit) => (
))}
)); const storyProps = { appId: 'latency', apiKey: 'af044fb0788d6bb15f807e4420592bc5', indexName: 'instant_search_movies', linkedStoryGroup: 'QueryRuleContext.stories.tsx', hitsElement: , }; stories .add('default', () => (
['Drama', 'Thriller'], }} /> {({ items }: { items: CustomDataItem[] }) => items.map(({ banner, title, link }) => { if (!banner) { return null; } return (

{title}

{title}
); }) }
)) .add('with default rule context', () => (
['Drama', 'Thriller'], }} transformRuleContexts={(ruleContexts: string[]) => { if (ruleContexts.length === 0) { return ['ais-genre-Drama']; } return ruleContexts; }} /> {({ items }: { items: CustomDataItem[] }) => items.map(({ banner, title, link }) => { if (!banner) { return null; } return (

{title}

{title}
); }) }
));