// @flow import React from 'react'; // Pkgs import { escapeRegExp } from 'lodash'; // storybook import { storiesOf } from '@storybook/react'; import { withState } from '@dump247/storybook-state'; import { withKnobs, boolean } from '@storybook/addon-knobs'; // components import { Select } from '../source/components/Select'; import { Modal } from '../source/components/Modal'; import { Button } from '../source/components/Button'; // themes import { SimpleTheme } from '../source/themes/simple'; import CustomSelectTheme from './theme-customizations/Select.custom.scss'; // custom styles import styles from './Select.stories.scss'; // images import flagEngland from './images/gb.png'; import flagSpain from './images/es.png'; import flagThailand from './images/th.png'; import flagUSA from './images/us.png'; // constants import { IDENTIFIERS } from '../source/components'; // helpers import { decorateWithSimpleTheme } from './helpers/theming'; import { WALLETS, COUNTRIES, COUNTRIES_WITH_FLAGS, COUNTRIES_WITH_DISABLED_OPTIONS, COUNTRIES_LONG_LIST, } from './helpers/dummyData'; storiesOf('Select', module) .addDecorator(decorateWithSimpleTheme) .addDecorator(withKnobs) // ====== Stories ====== .add('options', withState({ value: '' }, store => ( store.set({ value })} options={boolean('Long list?') ? COUNTRIES_LONG_LIST : COUNTRIES} hasSearch={boolean('hasSearch')} /> )) ) .add('placeholder', withState({ value: '' }, store => ( store.set({ value })} options={COUNTRIES} hasSearch={boolean('hasSearch')} /> )) ) .add('with search and long list', withState({ value: '' }, store => ( store.set({ value })} options={[ { label: 'Escaped values: /.*+?|,()[]{}\\' }, ...COUNTRIES ]} hasSearch onSearch={(searchValue: string, list: Array) => { const regex = new RegExp(escapeRegExp(searchValue), "i"); return list .filter((option) => { const { label, value } = option; return regex.test(label) || regex.test(value); }) .map((option) => { const { label, value } = option; return { value, label: `${label} (${value})`, }; }); }} /> )) ) .add('with error', withState({ value: COUNTRIES[0].value }, store => ( store.set({ value })} options={COUNTRIES_WITH_FLAGS} optionRenderer={option => (
{option.label}
)} optionHeight={56} hasSearch={boolean('hasSearch')} /> )) ) .add('isOpeningUpward', withState({ value: '' }, store => ( store.set({ value })} label="Countries" options={COUNTRIES_WITH_DISABLED_OPTIONS} placeholder="Select your country …" hasSearch={boolean('hasSearch')} /> )) ) .add('disabled (with value)', withState({ value: '' }, store => ( store.set({ value })} label="Countries (has disabled options)" options={COUNTRIES_WITH_DISABLED_OPTIONS} placeholder="Select your country …" hasSearch={boolean('hasSearch')} /> )) ) .add('rtl support', withState({ value: COUNTRIES[0].value }, store => (
store.set({ value })} label="Countries (has disabled options)" options={COUNTRIES_WITH_DISABLED_OPTIONS} placeholder="Select your country …" hasSearch={boolean('hasSearch')} /> )) ) .add('inside a modal', withState({ isOpen: true, value: '' }, store => ( store.state.isOpen ? ( store.set({ isOpen: false })} >

Select in Modal

store.set({ value })} placeholder="Select Wallet" options={WALLETS} optionRenderer={option => (
{option.label}
{option.value}
)} selectionRenderer={option => (
{option.label}
{option.value}
)} optionHeight={63} hasSearch={boolean('hasSearch')} /> )) );