Skip to content

Commit

Permalink
Pass onChange up to storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed May 16, 2022
1 parent 493e8ff commit 2c98110
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
13 changes: 12 additions & 1 deletion packages/components/src/date-time/stories/date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const meta: ComponentMeta< typeof DatePicker > = {
component: DatePicker,
argTypes: {
currentDate: { control: 'date' },
onChange: { action: 'onChange', control: { type: null } },
},
parameters: {
controls: { expanded: true },
Expand All @@ -29,13 +30,23 @@ export default meta;

const Template: ComponentStory< typeof DatePicker > = ( {
currentDate,
onChange,
...args
} ) => {
const [ date, setDate ] = useState( currentDate );
useEffect( () => {
setDate( currentDate );
}, [ currentDate ] );
return <DatePicker { ...args } currentDate={ date } onChange={ setDate } />;
return (
<DatePicker
{ ...args }
currentDate={ date }
onChange={ ( newDate ) => {
setDate( newDate );
onChange?.( newDate );
} }
/>
);
};

export const Default: ComponentStory< typeof DatePicker > = Template.bind( {} );
Expand Down
11 changes: 10 additions & 1 deletion packages/components/src/date-time/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const meta: ComponentMeta< typeof DateTimePicker > = {
component: DateTimePicker,
argTypes: {
currentDate: { control: 'date' },
onChange: { action: 'onChange', control: { type: null } },
},
parameters: {
controls: { expanded: true },
Expand All @@ -29,14 +30,22 @@ export default meta;

const Template: ComponentStory< typeof DateTimePicker > = ( {
currentDate,
onChange,
...args
} ) => {
const [ date, setDate ] = useState( currentDate );
useEffect( () => {
setDate( currentDate );
}, [ currentDate ] );
return (
<DateTimePicker { ...args } currentDate={ date } onChange={ setDate } />
<DateTimePicker
{ ...args }
currentDate={ date }
onChange={ ( newDate ) => {
setDate( newDate );
onChange?.( newDate );
} }
/>
);
};

Expand Down
13 changes: 12 additions & 1 deletion packages/components/src/date-time/stories/time.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const meta: ComponentMeta< typeof TimePicker > = {
component: TimePicker,
argTypes: {
currentTime: { control: 'date' },
onChange: { action: 'onChange', control: { type: null } },
},
parameters: {
controls: { expanded: true },
Expand All @@ -28,13 +29,23 @@ export default meta;

const Template: ComponentStory< typeof TimePicker > = ( {
currentTime,
onChange,
...args
} ) => {
const [ time, setTime ] = useState( currentTime );
useEffect( () => {
setTime( currentTime );
}, [ currentTime ] );
return <TimePicker { ...args } currentTime={ time } onChange={ setTime } />;
return (
<TimePicker
{ ...args }
currentTime={ time }
onChange={ ( newTime ) => {
setTime( newTime );
onChange?.( newTime );
} }
/>
);
};

export const Default: ComponentStory< typeof TimePicker > = Template.bind( {} );

0 comments on commit 2c98110

Please sign in to comment.