Skip to content

Commit

Permalink
feat: updated storybook to reflect controlled and uncontrolled model
Browse files Browse the repository at this point in the history
  • Loading branch information
Dias, Diego committed Aug 27, 2024
1 parent 5913632 commit bf555fd
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions packages/ui/src/components/Datepicker/Datepicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default {
},
} as Meta;

const Template: StoryFn<DatepickerProps> = (args) => {
const ControlledTemplate: StoryFn<DatepickerProps> = (args) => {
const [selectedDate, setSelectedDate] = useState<Date | null>(args.value ?? null);

const handleChange = (date: Date | null) => {
Expand All @@ -57,8 +57,28 @@ const Template: StoryFn<DatepickerProps> = (args) => {

return <Datepicker {...args} value={selectedDate} onChange={handleChange}/>;
};
export const DefaultEmpty = Template.bind({});
DefaultEmpty.args = {

const Template: StoryFn<DatepickerProps> = (args) => {
// https://github.com/storybookjs/storybook/issues/11822
if (args.minDate) {
args.minDate = new Date(args.minDate);
}
if (args.maxDate) {
args.maxDate = new Date(args.maxDate);
}

// update defaultDate based on the range
if (args.minDate && args.maxDate) {
if (args.defaultDate) {
args.defaultDate = getFirstDateInRange(args.defaultDate, args.minDate, args.maxDate);
}
}

return <Datepicker {...args}/>;
};

export const ControlledDefaultEmpty = ControlledTemplate.bind({});
ControlledDefaultEmpty.args = {
open: false,
autoHide: true,
showClearButton: true,
Expand Down Expand Up @@ -103,7 +123,6 @@ DateValueSet.args = {
autoHide: true,
showClearButton: true,
showTodayButton: true,
customValue: new Date(2022, 11, 25),
minDate: undefined,
maxDate: undefined,
language: "en",
Expand Down

0 comments on commit bf555fd

Please sign in to comment.