import React from 'react' import { type Meta, type StoryObj } from '@storybook/react-vite' import { type DateRange } from 'react-day-picker' import { toast } from '../Toast/Toast' import { DocsTemplate } from '../../../.storybook' import DatePickerComponent from './DatePicker' const meta: Meta = { title: 'Components/DatePicker', component: DatePickerComponent, parameters: { layout: 'centered', design: { type: 'figma', url: 'https://www.figma.com/design/RvhKD82948FMQnh5MyCi0o/Web-Design-System?node-id=9423-61089&p=f&t=dpvdmOj1lXymCIvb-0', }, docs: { page: () => ( The DatePicker component allows users to select a single date or a range of dates. It supports predefined ranges like "Last 7 Days" and "This Month" for quick selection and provides a calendar interface for manual date selection. } infoBullets={[ Use the DatePicker for forms, dashboards, or anywhere date selection is required. , Supports both single and range date selection modes. , Includes validation for manual date input. , Can restrict date selection to specific ranges using the{' '} dateRestrictions prop. , ]} /> ), }, }, } export default meta type Story = StoryObj const DatePicker = (args) => { const [selectedDateRange, setSelectedDateRange] = React.useState< Date | DateRange | undefined >(args.selectedDateRange) const [selectedDate, setSelectedDate] = React.useState( args.selectedDate, ) if (args.type === 'range') { return ( { setSelectedDateRange(date) toast({ message: `New date range selected : ${date.from} - ${date.to}} `, type: 'info', }) }} selectedDateRange={selectedDateRange} /> ) } else { return ( { setSelectedDate(date) toast({ message: `New date selected : ${date} `, type: 'info', }) }} selectedDate={selectedDate} /> ) } } const Template: Story = { render: (args) => (
), } export const Basic: Story = { ...Template, } export const exposed: Story = { ...Template, args: { isExposed: true, }, } export const withoutTextInput: Story = { ...Template, args: { showDateValue: false, }, } export const WithLabel: Story = { ...Template, args: { labelText: 'Pick a Date', }, } export const SingleDisabledWithoutExposed: Story = { ...Template, args: { disabled: true, }, } export const WithDefaultDate: Story = { ...Template, args: { selectedDate: new Date(), reset: true, }, } export const withLayerPosition: Story = { ...Template, args: { layerPosition: 2, }, } export const RangeBasic: Story = { ...Template, args: { type: 'range', }, } export const rangeExposed: Story = { ...Template, args: { type: 'range', isExposed: true, }, } export const RangeWithPlaceholder: Story = { ...Template, args: { type: 'range', placeholder: 'Created On', }, } export const RangeWithDefaultDateRange: Story = { ...Template, args: { type: 'range', selectedDateRange: { from: new Date(new Date().setDate(new Date().getDate() - 7)), to: new Date(), }, reset: true, }, } export const rangeWithoutTextInput: Story = { ...Template, args: { showDateValue: false, type: 'range', }, } export const WithDateRestrictionsBeforeToday: Story = { ...Template, args: { dateRestrictions: { beforeDate: new Date(), }, }, } export const WithDateRestrictionsAfterToday: Story = { ...Template, args: { dateRestrictions: { afterDate: new Date(), }, }, } export const WithPastRestrictionRange: Story = { ...Template, args: { type: 'range', dateRestrictions: { beforeDate: new Date(), }, }, } export const WithFutureRestrictionRange: Story = { ...Template, args: { type: 'range', dateRestrictions: { afterDate: new Date(), }, }, } export const DisableAutoClose: Story = { ...Template, args: { disableAutoClose: true, }, } export const SingleWithClearButton: Story = { ...Template, args: { clear: true, }, } export const RangeWithClearButton: Story = { ...Template, args: { type: 'range', clear: true, }, } export const RangeWithSelectedStartDateOutsideRestrictions: Story = { ...Template, args: { type: 'range', // Selected date range starts 30 days ago (which will be outside restrictions) selectedDateRange: { from: new Date(new Date().setDate(new Date().getDate() - 30)), to: new Date(), }, // Date restrictions only allow dates from 7 days ago onwards dateRestrictions: { beforeDate: new Date(new Date().setDate(new Date().getDate() - 7)), }, labelText: 'Test Restricted Start Date', }, } export const RangeWithSelectedEndDateOutsideRestrictions: Story = { ...Template, args: { type: 'range', // Selected date range ends 5 days from now (which will be outside restrictions) selectedDateRange: { from: new Date(new Date().setDate(new Date().getDate() - 7)), to: new Date(new Date().setDate(new Date().getDate() + 5)), }, dateRestrictions: { afterDate: new Date(new Date().setDate(new Date().getDate())), }, labelText: 'Test Restricted End Date', }, } export const SingleWithSelectedDateOutsideRestrictions: Story = { ...Template, args: { type: 'single', // Selected date is 5 days from now (which will be outside restrictions) selectedDate: new Date(new Date().setDate(new Date().getDate() + 5)), dateRestrictions: { afterDate: new Date(new Date().setDate(new Date().getDate())), }, labelText: 'Test Restricted Future Date', }, } export const WithDescription: Story = { ...Template, args: { labelTooltip: { tooltipContent: 'This is the label tooltip for the date picker.', }, labelText: 'Pick a Date', }, } export const WithErrorText: Story = { ...Template, args: { error: { text: 'This is the error text for the date picker', showError: true, }, labelText: 'Pick a Date', }, } export const RangeNoButtons: Story = { ...Template, args: { type: 'range', actionButtons: { last7Days: false, next7Days: false, thisWeekToDate: false, thisWeek: false, lastWeek: false, nextWeek: false, lastMonth: false, thisMonth: false, thisMonthToDate: false, nextMonth: false, thisQuarter: false, thisQuarterToDate: false, lastQuarter: false, nextQuarter: false, thisYear: false, thisYearToDate: false, lastYear: false, nextYear: false, }, }, } export const SingleNoButtons: Story = { ...Template, args: { type: 'single', actionButtons: { today: false, yesterday: false, tomorrow: false, }, }, } export const WithActionButtons: Story = { ...Template, args: { type: 'range', actionButtons: { last7Days: false, next7Days: false, nextWeek: false, nextMonth: false, thisQuarter: false, thisYear: false, nextYear: false, }, }, } export const WithDatePickerPosition: Story = { ...Template, args: { type: 'range', position: 'right', }, }