import React, { useState } from 'react'; import { storiesOf } from '@storybook/react'; import { InputNumber } from '../src'; storiesOf('InputNumber', module).add('Primary - Single', () => { function Parent({ children }) { const [value, setValue] = useState(0); const handleInputChange = (e) => { const formattedValue = !Number.isNaN(parseInt(e.target.value, 10)) ? parseInt(e.target.value, 10) : null; setValue(formattedValue); }; return
{children(value, setValue, handleInputChange)}
; } return ( {(value, setValue, handleInputChange) => ( handleInputChange(e)} display="single" /> )} ); }); storiesOf('InputNumber', module).add('Multiple with custom style', () => { function Parent({ children }) { const [value, setValue] = useState(0); const [limitValues, setLimitValues] = useState<{ minValue: number | object; maxValue: number | object; }>({ minValue: 0, maxValue: 0, }); const handleInputChange = (e, id: string) => { const formattedValue = !Number.isNaN(parseInt(e.target.value, 10)) ? parseInt(e.target.value, 10) : null; if (formattedValue === null) { return; } if (id === 'min') { setLimitValues({ ...limitValues, ...{ minValue: formattedValue } }); } else if (id === 'max') { setLimitValues({ ...limitValues, ...{ maxValue: formattedValue } }); } else { setValue(formattedValue); } }; return (
{children( value, setValue, limitValues, setLimitValues, handleInputChange )}
); } return ( {(value, setValue, limitValues, setLimitValues, handleInputChange) => ( )} ); });