import React, { useState } from 'react'; import type { Meta, StoryObj } from '@storybook/react-vite'; import { Form } from 'react-aria-components'; import { Button } from '../Button/Button.quanta'; import { DatePicker } from './DatePicker.quanta'; // DatePicker Stories const meta = { title: 'Quanta/DatePicker', component: DatePicker, parameters: { layout: 'centered', backgrounds: { disable: true }, }, tags: ['autodocs'], args: { label: 'Date', }, } satisfies Meta; export default meta; type Story = StoryObj; // Basic Stories export const Default: Story = { render: (args) => , args: { name: 'date', label: 'Select date', description: 'Date picker for selecting dates only', }, }; export const WithDefaultValue: Story = { render: (args) => , args: { name: 'date-default', label: 'Birth date', description: 'Date picker with default value', defaultValue: '2025-05-17', }, }; // Controlled Example const ControlledExample = (args: any) => { const [value, setValue] = useState('2024-01-15'); return (
Current value: {value || 'null'}
); }; export const Controlled: Story = { render: ControlledExample, args: { name: 'date-controlled', label: 'Controlled date picker', description: 'Value managed by parent component', }, }; // States export const Required: Story = { render: (args) => , args: { name: 'required-date', label: 'Required date', description: 'This field is required', isRequired: true, }, }; export const Disabled: Story = { render: (args) => , args: { name: 'disabled-date', label: 'Disabled picker', defaultValue: '2024-05-17', isDisabled: true, }, }; export const ReadOnly: Story = { render: (args) => , args: { name: 'readonly-date', label: 'Read-only picker', defaultValue: '2024-05-17', isReadOnly: true, }, }; export const WithError: Story = { render: (args) => , args: { name: 'errored-date', label: 'With error', description: 'Shows error state styling', errorMessage: 'Please select a valid date', isInvalid: true, isRequired: true, defaultValue: '2024-01-15', }, }; export const NotResettable: Story = { render: (args) => , args: { name: 'not-resettable', label: 'Non-resettable', description: 'No clear button available', defaultValue: '2024-05-17', resettable: false, }, }; // Custom Validation Example const CustomValidationExample = () => { const [value, setValue] = useState(null); const [error, setError] = useState(null); const handleChange = (newValue: string | null) => { setValue(newValue); // Custom validation logic for date values if (!newValue) { setError('Date is required'); return; } try { const date = new Date(newValue); const dayOfWeek = date.getDay(); // Don't allow weekends if (dayOfWeek === 0 || dayOfWeek === 6) { setError('Weekend dates are not allowed'); return; } // Don't allow dates in the past const today = new Date(); today.setHours(0, 0, 0, 0); if (date < today) { setError('Past dates are not allowed'); return; } setError(null); } catch { setError('Invalid date format'); } }; return (
{value &&
Selected: {value}
}
); }; export const CustomValidation: Story = { render: CustomValidationExample, }; // Form Integration const FormExample = () => (
); export const FormIntegration: Story = { render: FormExample, }; // Date Range Example (using two DatePickers) const DateRangeExample = () => { const [startDate, setStartDate] = useState(null); const [endDate, setEndDate] = useState(null); return (
{startDate && endDate && (
Selected range: {startDate} to {endDate}
)}
); }; export const DateRange: Story = { render: DateRangeExample, };