File size: 2,348 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | import React from 'react';
import orderBy from 'lodash.orderby';
import { storiesOf } from '@storybook/react';
import { text } from '@storybook/addon-knobs';
import { MenuSelect, Panel, SearchBox } from 'react-instantsearch-dom';
import { WrapWithHits } from './util';
const stories = storiesOf('MenuSelect', module);
stories
.add('default', () => (
<WrapWithHits hasPlayground={true} linkedStoryGroup="MenuSelect.stories.js">
<MenuSelect attribute="brand" />
</WrapWithHits>
))
.add('with default selected item', () => (
<WrapWithHits hasPlayground={true} linkedStoryGroup="MenuSelect.stories.js">
<MenuSelect attribute="brand" defaultRefinement="Apple" />
</WrapWithHits>
))
.add('with the sort strategy changed', () => (
<WrapWithHits hasPlayground={true} linkedStoryGroup="MenuSelect.stories.js">
<MenuSelect
attribute="brand"
transformItems={(items) =>
orderBy(items, ['label', 'count'], ['asc', 'desc'])
}
/>
</WrapWithHits>
))
.add('playground', () => (
<WrapWithHits linkedStoryGroup="MenuSelect.stories.js">
<MenuSelect
attribute="brand"
defaultRefinement={text('defaultSelectedItem', 'Apple')}
/>
</WrapWithHits>
))
.add('with localized count', () => (
<WrapWithHits linkedStoryGroup="MenuSelect.stories.js">
<MenuSelect
attribute="brand"
defaultRefinement={text('defaultSelectedItem', 'Apple')}
transformItems={(items) =>
items.map(({ count, ...item }) => ({
...item,
count: (count + 1000).toLocaleString(),
}))
}
/>
</WrapWithHits>
))
.add('with Panel', () => (
<WrapWithHits hasPlayground={true} linkedStoryGroup="MenuSelect.stories.js">
<Panel header="Menu select" footer="Footer">
<MenuSelect attribute="brand" />
</Panel>
</WrapWithHits>
))
.add('with Panel but no refinement', () => (
<WrapWithHits
searchBox={false}
hasPlayground={true}
linkedStoryGroup="MenuSelect.stories.js"
>
<Panel header="Menu select" footer="Footer">
<MenuSelect attribute="brand" />
</Panel>
<div style={{ display: 'none' }}>
<SearchBox defaultRefinement="dkjsakdjskajdksjakdjaskj" />
</div>
</WrapWithHits>
));
|