import React, { useState } from 'react'; import type { Meta, StoryObj } from '@storybook/react-vite'; import { Form } from 'react-aria-components'; import { CalendarDate, CalendarDateTime, today, getLocalTimeZone, } from '@internationalized/date'; import { Button } from '../Button/Button.quanta'; import { DateField } from '../DateField/DateField.quanta'; const meta: Meta = { title: 'Quanta/DateField', component: DateField, parameters: { layout: 'centered', }, tags: ['autodocs'], } satisfies Meta; export default meta; type Story = StoryObj; // Basic Stories export const Default: Story = { render: (args) => , args: {}, }; export const WithDefaultValue: Story = { render: (args) => , args: { defaultValue: new CalendarDate(2024, 12, 25), label: 'Christmas Date', description: 'Date input with default value (Christmas 2024)', }, }; // // Controlled Example const ControlledExample = (args: any) => { const [value, setValue] = useState( today(getLocalTimeZone()), ); return (
Current value: {value ? value.toString() : 'null'}
); }; export const Controlled: Story = { render: ControlledExample, args: { label: 'Controlled Date Input', description: 'Value managed by parent component', }, }; // // DateTime Example const DateTimeExample = (args: any) => { const [value, setValue] = useState( new CalendarDateTime(2024, 6, 15, 14, 30), ); return (
Current value: {value ? value.toString() : 'null'}
); }; export const DateTime: Story = { render: DateTimeExample, args: { label: 'Date & Time Input', description: 'Date input with time segments (granularity: minute)', }, }; // // States Example const StatesExample = () => { const [value, setValue] = useState(null); const [error, setError] = useState(null); const handleChange = (newValue: CalendarDate | null) => { setValue(newValue); // Custom validation if (newValue) { const today = new Date(); const selectedDate = new Date( newValue.year, newValue.month - 1, newValue.day, ); if (selectedDate < today) { setError('Past dates are not allowed'); } else { setError(null); } } else { setError(null); } }; return (
{/* Required Field */} {/* Invalid Field */} {/* Disabled Field */} {/* Read-only Field */} {/* Invalid Field with Custom Validation */} {value && !error && (
Selected date: {value.toString()} ✓
)}
); }; export const States: Story = { render: StatesExample, }; // // Form Integration const FormExample = () => { return (
); }; export const FormIntegration: Story = { render: FormExample, }; // Custom Styling export const CustomStyling: Story = { render: (args) => ( ), args: {}, };