import React from 'react'; import { storiesOf } from '@storybook/react'; import { connectHits } from 'react-instantsearch-core'; import { QueryRuleCustomData, Panel, Highlight } 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('QueryRuleCustomData', module); const StoryHits = connectHits(({ hits }: { hits: MovieHit[] }) => (
{hits.map((hit) => (
))}
)); const storyProps = { appId: 'latency', apiKey: 'af044fb0788d6bb15f807e4420592bc5', indexName: 'instant_search_movies', linkedStoryGroup: 'QueryRuleCustomData.stories.tsx', hitsElement: , }; stories .add('default', () => (

Type music and a banner will appear.

{({ items }: { items: CustomDataItem[] }) => items.map(({ banner, title, link }) => { if (!banner) { return null; } return (

{title}

{title}
); }) }
)) .add('with default banner', () => (

Kill Bill appears whenever no other results are promoted. Type{' '} music to see another movie promoted.

{ if (items.length > 0) { return items; } return [ { title: 'Kill Bill', banner: 'http://static.bobatv.net/IMovie/mv_2352/poster_2352.jpg', link: 'https://www.netflix.com/title/60031236', }, ]; }} > {({ items }: { items: CustomDataItem[] }) => items.map(({ banner, title, link }) => { if (!banner) { return null; } return (

{title}

{title}
); }) }
)) .add('with Panel', () => (

Type music and a banner will appear.

{({ items }: { items: CustomDataItem[] }) => items.map(({ banner, title, link }) => { if (!banner) { return null; } return (

{title}

{title}
); }) }
));