// @flow import BigNumber from 'bignumber.js'; import React from 'react'; // storybook import { storiesOf } from '@storybook/react'; import { withState } from '@dump247/storybook-state'; // components import { NumericInput } from '../source/components/NumericInput'; // themes import CustomInputTheme from './theme-customizations/Input.custom.scss'; // theme overrides and identifiers import themeOverrides from './theme-overrides/customInput.scss'; // helpers import { decorateWithSimpleTheme } from './helpers/theming'; storiesOf('NumericInput', module) .addDecorator(decorateWithSimpleTheme) // ====== Stories ====== .add( 'plain', withState({ value: null }, (store) => ( store.set({ value })} value={store.state.value} /> )) ) .add( 'value (9999.99)', withState({ value: '9999.99' }, (store) => ( store.set({ value })} value={store.state.value} /> )) ) .add( 'decimalPlaces (6)', withState({ value: 0 }, (store) => ( store.set({ value })} decimalPlaces={6} value={store.state.value} /> )) ) .add( 'invalid BigNumber value', withState({ value: new BigNumber('') }, (store) => ( store.set({ value })} decimalPlaces={6} value={store.state.value} /> )) ) .add( 'format: decimal (comma) group (dot)', withState({ value: 0 }, (store) => ( store.set({ value })} bigNumberFormat={{ decimalSeparator: ',', groupSeparator: '.', }} decimalPlaces={2} value={store.state.value} label="Numeric Input (2 decimal places, ',' as decimal separator, '.' as group separator)" /> )) ) .add( 'format: decimal (dot) group (space)', withState({ value: 0 }, (store) => ( store.set({ value })} bigNumberFormat={{ decimalSeparator: '.', groupSeparator: ' ', }} decimalPlaces={2} value={store.state.value} label="Numeric Input (2 decimal places, '.' as decimal separator, space as group separator)" /> )) ) .add( 'autoFocus', withState({ value: null }, (store) => ( store.set({ value })} value={store.state.value} /> )) ) .add( 'label', withState({ value: null }, (store) => ( store.set({ value })} value={store.state.value} /> )) ) .add( 'placeholder', withState({ value: null }, (store) => ( store.set({ value })} placeholder="18.000000" /> )) ) .add( 'readOnly', withState({ value: 2 }, (store) => ( store.set({ value })} readOnly /> )) ) .add( 'allowSigns = false | allowOnlyIntegers = false', withState({ value: null }, (store) => ( store.set({ value })} allowSigns={false} /> )) ) .add( 'allowSigns = true | allowOnlyIntegers = false', withState({ value: null }, (store) => ( store.set({ value })} allowOnlyIntegers={false} /> )) ) .add( 'allowSigns = false | allowOnlyIntegers = true', withState({ value: null }, (store) => ( store.set({ value })} allowSigns={false} allowOnlyIntegers /> )) ) .add( 'onFocus / onBlur', withState({ value: null, focused: false, blurred: false }, (store) => ( store.set({ value })} onFocus={() => store.set({ focused: true, blurred: false })} onBlur={() => store.set({ blurred: true, focused: false })} /> )) ) .add( 'invalid value', withState({ value: '' }, (store) => ( store.set({ value })} placeholder="placeholder …" label="Invalid values are ignored" /> )) ) .add( 'with error', withState({ value: null }, (store) => ( store.set({ value })} /> )) ) .add( 'theme overrides', withState({ value: null }, (store) => ( store.set({ value })} /> )) ) .add( 'Custom Theme', withState({ value: null }, (store) => ( store.set({ value })} /> )) );