|
| 1 | +import React from 'react'; |
| 2 | +import { |
| 3 | + withKnobs, |
| 4 | + boolean, |
| 5 | + date, |
| 6 | + number, |
| 7 | + select, |
| 8 | + text, |
| 9 | +} from '@storybook/addon-knobs'; |
| 10 | +import { storiesOf } from '@storybook/react'; |
| 11 | +import { Form } from 'semantic-ui-react'; |
| 12 | +import 'semantic-ui-css/semantic.min.css'; |
| 13 | +import SemanticDatepicker from '../src'; |
| 14 | +import { |
| 15 | + Content, |
| 16 | + isWeekday, |
| 17 | + localeMap, |
| 18 | + onChange, |
| 19 | + pointingMap, |
| 20 | + typeMap, |
| 21 | +} from './common'; |
| 22 | +// import { parseISO } from 'date-fns'; |
| 23 | + |
| 24 | +const stories = storiesOf('Datepickers', module); |
| 25 | + |
| 26 | +stories.addDecorator(withKnobs); |
| 27 | +stories.addParameters({ |
| 28 | + info: { |
| 29 | + disable: true, |
| 30 | + }, |
| 31 | + options: { |
| 32 | + panelPosition: 'right', |
| 33 | + }, |
| 34 | +}); |
| 35 | + |
| 36 | +stories.add('Basic usage', () => { |
| 37 | + const type = select('Type', typeMap, typeMap.basic); |
| 38 | + const allowOnlyNumbers = boolean('Allow only numbers', false); |
| 39 | + const clearOnSameDateClick = boolean('Clear on same date click', true); |
| 40 | + const datePickerOnly = boolean('Datepicker only', false); |
| 41 | + const firstDayOfWeek = number('First day of week', 0, { max: 6, min: 0 }); |
| 42 | + const format = text('Format', 'YYYY-MM-DD'); |
| 43 | + const keepOpenOnClear = boolean('Keep open on clear', false); |
| 44 | + const keepOpenOnSelect = boolean('Keep open on select', false); |
| 45 | + const locale = select('Locale', localeMap, localeMap['en-US']); |
| 46 | + const pointing = select('Pointing', pointingMap, pointingMap.left); |
| 47 | + const clearable = boolean('Clearable', true); |
| 48 | + const readOnly = boolean('Read-only', false); |
| 49 | + const showOutsideDays = boolean('Show outside days', false); |
| 50 | + const minDate = new Date(date('Min date', new Date('2018-01-01'))); |
| 51 | + const maxDate = new Date(date('Max date', new Date('2030-01-01'))); |
| 52 | + const onlyWeekdays = boolean('Only weekdays (filterDate example)', false); |
| 53 | + const controlValue = boolean('Control value', false); |
| 54 | + const initialValue = controlValue |
| 55 | + ? type === 'basic' |
| 56 | + ? new Date(date('Initial value')) |
| 57 | + : [new Date(date('Initial value')), new Date(date('Final value'))] |
| 58 | + : undefined; |
| 59 | + const filterDate = onlyWeekdays ? isWeekday : undefined; |
| 60 | + const key = type + format + readOnly; |
| 61 | + |
| 62 | + return ( |
| 63 | + <Content> |
| 64 | + <SemanticDatepicker |
| 65 | + key={key} |
| 66 | + allowOnlyNumbers={allowOnlyNumbers} |
| 67 | + clearOnSameDateClick={clearOnSameDateClick} |
| 68 | + clearable={clearable} |
| 69 | + datePickerOnly={datePickerOnly} |
| 70 | + filterDate={filterDate} |
| 71 | + firstDayOfWeek={firstDayOfWeek} |
| 72 | + format={format} |
| 73 | + keepOpenOnClear={keepOpenOnClear} |
| 74 | + keepOpenOnSelect={keepOpenOnSelect} |
| 75 | + locale={locale} |
| 76 | + maxDate={maxDate} |
| 77 | + minDate={minDate} |
| 78 | + onChange={onChange} |
| 79 | + pointing={pointing} |
| 80 | + readOnly={readOnly} |
| 81 | + showOutsideDays={showOutsideDays} |
| 82 | + type={type} |
| 83 | + value={initialValue} |
| 84 | + /> |
| 85 | + </Content> |
| 86 | + ); |
| 87 | +}); |
| 88 | + |
| 89 | +stories.add('Usage with Form', () => { |
| 90 | + return ( |
| 91 | + <Content> |
| 92 | + <Form> |
| 93 | + <Form.Group width="equals"> |
| 94 | + <SemanticDatepicker |
| 95 | + label="Initial date" |
| 96 | + id="initialDate" |
| 97 | + onChange={onChange} |
| 98 | + required |
| 99 | + /> |
| 100 | + <SemanticDatepicker |
| 101 | + label="Final date" |
| 102 | + id="finalDate" |
| 103 | + onChange={onChange} |
| 104 | + /> |
| 105 | + </Form.Group> |
| 106 | + </Form> |
| 107 | + </Content> |
| 108 | + ); |
| 109 | +}); |
0 commit comments