import type { Meta, StoryObj } from '@storybook/vue3-vite' import { ref } from 'vue' import CpDate from '@/components/CpDate.vue' import { docCellStyle, docLabelStyle, docRowColumnStyle } from '@/stories/documentationStyles' const dateStackStyle = `${docCellStyle} width: 100%; max-width: 360px;` const meta = { title: 'Atoms/CpDate', component: CpDate, argTypes: { size: { control: 'select', options: ['sm', 'md', 'lg'], description: 'The size of the date input', }, modelValue: { control: 'text', description: 'The date value (ISO format)', }, label: { control: 'text', description: 'Label text for the date input', }, required: { control: 'boolean', description: 'Whether the field is required', }, disabled: { control: 'boolean', description: 'Whether the field is disabled', }, isInvalid: { control: 'boolean', description: 'Whether the field is in an invalid state', }, errorMessage: { control: 'text', description: 'Custom error message to display', }, displayErrorMessage: { control: 'boolean', description: 'Whether to display error messages', }, autocompleteBirthday: { control: 'boolean', description: 'Whether to enable birthday autocomplete', }, locale: { control: 'text', description: 'Locale for date formatting', }, minDate: { control: 'text', description: 'Minimum allowed date', }, maxDate: { control: 'text', description: 'Maximum allowed date', }, }, } satisfies Meta export default meta type Story = StoryObj /** * Default date input. Use the controls to experiment with each prop in isolation. */ export const Default: Story = { args: { label: 'Date', required: false, disabled: false, isInvalid: false, displayErrorMessage: true, }, render: (args) => ({ components: { CpDate }, setup() { const date = ref('') return { args, date } }, template: `
`, }), } /* -------------------------------------------------------------------------- */ /* States */ /* -------------------------------------------------------------------------- */ /** * Default, required, disabled and invalid states compared side by side. */ export const States: Story = { parameters: { controls: { disable: true } }, render: () => ({ components: { CpDate }, setup() { const date = ref('') return { date, docRowColumnStyle, dateStackStyle, docLabelStyle } }, template: `
Default
Required
Disabled
Invalid
`, }), } /** * Compares input ordering by locale (day/month in French, month/day in US English). */ export const LocaleOrdering: Story = { parameters: { controls: { disable: true } }, render: () => ({ components: { CpDate }, setup() { const frenchDate = ref('') const usDate = ref('') return { frenchDate, usDate, docRowColumnStyle, dateStackStyle, docLabelStyle } }, template: `
fr-FR (day / month / year)
en-US (month / day / year)
`, }), } /** * Combines a date input with a text input on the same line. */ export const NextToInput: Story = { args: { label: 'Date', required: false, disabled: false, isInvalid: false, displayErrorMessage: true, }, render: (args) => ({ components: { CpDate }, setup() { const date = ref('') const textModel = ref('') return { args, date, textModel } }, template: `
`, }), }