import type { Meta, StoryObj } from '@storybook/vue3' import { addWeeks, startOfISOWeek } from 'date-fns' import { ref } from 'vue' import FdsWeekCalendar from './FdsWeekCalendar.vue' const meta: Meta = { title: 'FDS/FdsWeekCalendar', component: FdsWeekCalendar, tags: ['autodocs'], parameters: { actions: { handles: ['change-date-range', 'select-date', 'increment-week', 'decrement-week'], }, }, argTypes: { previewOtherDays: { control: { type: 'boolean' } }, enableHorizontalAnimation: { control: { type: 'boolean' } }, weekLabel: { control: { type: 'text' } }, selected: { control: { type: 'date' } }, maxDate: { control: { type: 'date' } }, }, args: { previewOtherDays: true, enableHorizontalAnimation: true, weekLabel: 'Week', selected: null, maxDate: undefined, }, } export default meta type Story = StoryObj const toDateOrUndefined = (value: unknown): Date | undefined => { if (value instanceof Date) return value if (typeof value === 'number' || typeof value === 'string') { const parsed = new Date(value) if (!Number.isNaN(parsed.getTime())) return parsed } return undefined } const toDateOrNull = (value: unknown): Date | null => toDateOrUndefined(value) ?? null export const Default: Story = { render: (args: NonNullable) => ({ components: { FdsWeekCalendar }, setup: () => { const selected = ref(toDateOrNull(args.selected)) const currentMaxDate = ref(toDateOrUndefined(args.maxDate)) return { args, selected, currentMaxDate, onSelectedDay: (day: Date | null) => { selected.value = day }, } }, template: `
`, }), args: { previewOtherDays: false, maxDate: undefined, disablePreviousWeek: false, disableNextWeek: false, }, } export const WithMaxDate: Story = { render: (args: NonNullable) => ({ components: { FdsWeekCalendar }, setup: () => { const monday = startOfISOWeek(new Date()) const selected = ref(monday) const maxDate = ref(addWeeks(monday, 2)) return { args, selected, maxDate, onSelectedDay: (day: Date | null) => { selected.value = day }, } }, template: `
`, }), args: { previewOtherDays: false, enableHorizontalAnimation: false, }, }