diff --git a/src/components/BusinessHoursEditor/BusinessHoursEditor.stories.tsx b/src/components/BusinessHoursEditor/BusinessHoursEditor.stories.tsx index ecf717af..cfffb420 100644 --- a/src/components/BusinessHoursEditor/BusinessHoursEditor.stories.tsx +++ b/src/components/BusinessHoursEditor/BusinessHoursEditor.stories.tsx @@ -1,5 +1,5 @@ import type { Meta, StoryObj } from '@storybook/react'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { BusinessHoursEditor, DaySchedule, @@ -22,6 +22,13 @@ const meta: Meta = { }, }, argTypes: { + // Hide props that are managed by the demo wrapper + value: { table: { disable: true } }, + onChange: { table: { disable: true } }, + className: { table: { disable: true } }, + // use24Hour is not implemented in the component (native time inputs use browser locale) + use24Hour: { table: { disable: true } }, + disabled: { control: 'boolean', description: 'Whether the editor is disabled', @@ -30,10 +37,6 @@ const meta: Meta = { control: 'boolean', description: 'Whether to show description field for each time slot', }, - use24Hour: { - control: 'boolean', - description: 'Use 24-hour format', - }, weekStartsOn: { control: 'radio', options: [0, 1], @@ -44,26 +47,40 @@ const meta: Meta = { description: 'Label for add hours button', }, }, + args: { + disabled: false, + showDescription: true, + weekStartsOn: 0, + addHoursLabel: 'Add Hours', + }, }; export default meta; type Story = StoryObj; // Interactive wrapper -function BusinessHoursEditorWrapper( - props: Partial> -) { +function BusinessHoursEditorWrapper({ + value: initialValue, + onChange: _, + ...restProps +}: Partial>) { const [schedule, setSchedule] = useState( - props.value || createDefaultSchedule() + initialValue || createDefaultSchedule() ); + // Sync schedule state when initialValue changes (e.g., from Storybook controls) + useEffect(() => { + if (initialValue !== undefined) { + setSchedule(initialValue); + } + }, [initialValue]); + return (
@@ -78,18 +95,12 @@ function BusinessHoursEditorWrapper( export const Default: Story = { render: (args) => , - args: { - showDescription: true, - weekStartsOn: 0, - addHoursLabel: 'Add Hours', - }, }; export const Empty: Story = { render: (args) => , args: { value: [], - showDescription: true, }, }; @@ -97,7 +108,6 @@ export const WeekdaysOnly: Story = { render: (args) => , args: { value: createWeekdaySchedule('08:00', '18:00'), - showDescription: true, }, }; @@ -114,7 +124,6 @@ export const MondayStart: Story = { args: { value: createDefaultSchedule(), weekStartsOn: 1, - showDescription: true, }, };