import { Page } from 'puppeteer' import React, { useState } from 'react' import { Button, DateInput, Flex, StatusMessage } from '../' import { Action, actions, HIDE_CONTROL, HIDE_STYLED, Story, STRING } from '../helpers/storybook' export default { title: 'DateInput', component: DateInput, argTypes: { ...HIDE_STYLED, locale: HIDE_CONTROL, isValidDate: HIDE_CONTROL, defaultValue: HIDE_CONTROL, value: { control: 'text', mapping: STRING.mapping }, type: { options: ['date', 'time', 'datetime'] }, name: STRING, status: { options: ['success', 'error', 'warning'] }, id: STRING, ...actions('onChange', 'onFocus', 'onBlur', 'onInvalidDate'), }, args: { id: 'date-input', type: 'date', disabled: false, }, } as const type DateStory = Story< typeof DateInput, { onInvalidDate: Action onChange: Action> // In these stories, type always has a value. type: 'date' | 'time' | 'datetime' } > export const BasicUsage: DateStory = (args) => { const [invalidDate, setInvalidDate] = useState(false) return ( {invalidDate && ( The date you've selected is invalid. Please pick another date. )} ) } export const ControlledWithDate: DateStory = (args) => { const [value, setValue] = React.useState(new Date('10/1/2020')) return ( <> ) } ControlledWithDate.argTypes = { value: HIDE_CONTROL } ControlledWithDate.storyName = 'Controlled with Date' ControlledWithDate.parameters = { cactus: { overrides: { flexDirection: 'column' }, }, beforeScreenshot: async (page: Page) => { await page.click('button') }, } export const ControlledWithString: DateStory = (args) => { const [value, setValue] = React.useState('2019-09-16') return ( ) } ControlledWithString.argTypes = { value: HIDE_CONTROL } ControlledWithString.args = { format: 'YYYY-MM-dd' } ControlledWithString.storyName = 'Controlled with string' ControlledWithString.parameters = { cactus: { overrides: { alignItems: 'start' } }, } export const TypeTime: DateStory = (args) => { const [invalidDate, setInvalidDate] = useState(false) return ( {invalidDate && ( The date you've selected is invalid. Please pick another date. )} ) } TypeTime.args = { type: 'time' } TypeTime.storyName = 'type="time"' export const TypeDatetime: DateStory = (args) => { const [invalidDate, setInvalidDate] = useState(false) return ( {invalidDate && ( The date you've selected is invalid. Please pick another date. )} ) } TypeDatetime.args = { type: 'datetime' } TypeDatetime.storyName = 'type="datetime"' export const WithIsValidDate: DateStory = (args) => (
{ const day = date.getDay() return day !== 0 && day !== 6 }} />

Only business days are allowed.

) WithIsValidDate.storyName = 'with isValidDate'