import * as React from 'react'; import { IntlProvider } from 'react-intl'; import { State, Store } from '@sambego/storybook-state'; import { TooltipPosition } from '../tooltip'; import DatePicker from './DatePicker'; import notes from './DatePicker.stories.md'; import { bdlGray10 } from '../../styles/variables'; export const basic = () => { const MIN_TIME = new Date(0); const TODAY = new Date('July 18, 2018'); const yearRange = [MIN_TIME.getFullYear(), TODAY.getFullYear()]; const componentStore = new Store({ date: new Date('July 9, 2018'), fromDate: null, toDate: null, }); return ( {state => ( { componentStore.set({ date }); }} placeholder="Date" value={state.date} yearRange={yearRange} /> )} ); }; export const withDescription = () => ( ); export const manuallyEditable = () => ( ); export const withLimitedDateRange = () => { const maxDate = new Date('February 25, 2021'); const sixDays = 1000 * 60 * 60 * 24 * 6; const minDate = new Date(maxDate.valueOf() - sixDays); const componentStore = new Store({ date: maxDate, fromDate: null, toDate: null, }); return ( {state => ( )} ); }; export const alwaysVisibleWithCustomInputField = () => { const componentStore = new Store({ date: new Date('February 26, 2021'), fromDate: null, toDate: null, }); return ( {state => { const customInput = ( ); return (
{ componentStore.set({ date }); }} placeholder="Date" value={state.date} />

In this example, the DatePicker is bound to a custom hidden input field. The right panel retains the same state as the DatePicker, but is not contained within the DatePicker component.

); }}
); }; export const disabledWithErrorMessage = () => ( ); export const customErrorTooltipPosition = () => ( ); export const withRange = () => { const MAX_TIME = new Date('3000-01-01T00:00:00.000Z'); const MIN_TIME = new Date(0); const TODAY = new Date(); const componentStore: Store<{ date: Date; fromDate: Date | null; toDate: Date | null }> = new Store({ date: new Date(), fromDate: null, toDate: null, }); return ( {state => (
{ componentStore.set({ fromDate: date }); }} placeholder="Choose a Date" value={state.fromDate} /> { componentStore.set({ toDate: date }); }} placeholder="Choose a Date" value={state.toDate} />
)}
); }; export default { title: 'Components|DatePicker', component: DatePicker, parameters: { notes, }, };