/* eslint-disable react-hooks/rules-of-hooks */ import * as React from 'react'; 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 [date, setDate] = React.useState(new Date('July 9, 2018')); return ( { setDate(newDate); }} placeholder="Date" value={date} yearRange={yearRange} /> ); }; export const basicWithKeyboardInput = () => { const MIN_TIME = new Date(0); const TODAY = new Date('July 18, 2018'); const yearRange = [MIN_TIME.getFullYear(), TODAY.getFullYear()]; const [date, setDate] = React.useState(new Date('July 9, 2018')); return ( { setDate(newDate); }} placeholder="Date" value={date} yearRange={yearRange} /> ); }; export const withDescription = () => ( ); export const manuallyEditable = () => ( ); export const manuallyEditableAndAccessible = () => ( ); export const withLimitedDateRange = () => { const maxDate = new Date('February 25, 2021'); const sixDays = 1000 * 60 * 60 * 24 * 6; const minDate = new Date(maxDate.valueOf() - sixDays); return ( ); }; export const alwaysVisibleWithCustomInputField = () => { const [date, setDate] = React.useState(new Date('February 26, 2021')); const customInput = ( ); return (
{ setDate(newDate); }} placeholder="Date" value={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 [fromDate, setFromDate] = React.useState(null); const [toDate, setToDate] = React.useState(null); return (
{ setFromDate(newDate); }} placeholder="Choose a Date" value={fromDate} /> { setToDate(newDate); }} placeholder="Choose a Date" value={toDate} />
); }; export const withRangeAndKeyboardInput = () => { const MAX_TIME = new Date('3000-01-01T00:00:00.000Z'); const MIN_TIME = new Date(0); const TODAY = new Date(); const [fromDate, setFromDate] = React.useState(null); const [toDate, setToDate] = React.useState(null); return (
{ setFromDate(date); }} placeholder="Choose a Date" value={fromDate} /> { setToDate(date); }} placeholder="Choose a Date" value={toDate} />
); }; export default { title: 'Components/DatePicker', component: DatePicker, parameters: { notes, }, };