Use TypeScript and controls for DateTimePicker's stories#40986
Conversation
DateTimePicker's stories
|
Size Change: 0 B Total Size: 1.24 MB ℹ️ View Unchanged
|
bca2fdb to
6167a7a
Compare
There was a problem hiding this comment.
@ciampo was right that this doesn't work so well with stories. I mean, it works, but it's not very useful for someone reading the story as documentation to just see ValidDateTimeInput.
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Nice work @noisysocks 👍
This is looking good. I did leave a couple of general questions and suggestions but feel free to take those with a grain of salt.
✅ Type changes make sense, no typing errors
✅ Storybook examples are consistent between trunk and this PR
✅ Storybook examples function as expected
b467327 to
9a6f84b
Compare
|
Thanks @aaronrobertshaw! |
There was a problem hiding this comment.
Thanks for continuing to refine this @noisysocks 👍
After re-testing the component in the Storybook I think we should add some basic change handling like the example conversion of the UnitControl stories in the guidelines.
It makes the examples much more interactive.
Something like the following rough patch for the DateTime might work. What do you think?
Click for example
diff --git a/packages/components/src/date-time/stories/index.tsx b/packages/components/src/date-time/stories/index.tsx
index 7983b31701..6d9d9a735f 100644
--- a/packages/components/src/date-time/stories/index.tsx
+++ b/packages/components/src/date-time/stories/index.tsx
@@ -3,6 +3,11 @@
*/
import type { ComponentMeta, ComponentStory } from '@storybook/react';
+/**
+ * WordPress dependencies
+ */
+import { useState } from '@wordpress/element';
+
/**
* Internal dependencies
*/
@@ -14,6 +19,10 @@ const meta: ComponentMeta< typeof DateTimePicker > = {
component: DateTimePicker,
argTypes: {
currentDate: { control: 'date' },
+ onChange: {
+ action: 'onChange',
+ control: { type: null },
+ },
},
parameters: {
controls: { expanded: true },
@@ -22,9 +31,22 @@ const meta: ComponentMeta< typeof DateTimePicker > = {
};
export default meta;
-const Template: ComponentStory< typeof DateTimePicker > = ( args ) => (
- <DateTimePicker { ...args } />
-);
+const Template: ComponentStory< typeof DateTimePicker > = ( {
+ onChange,
+ ...args
+} ) => {
+ const [ value, setValue ] = useState< string | null >();
+ return (
+ <DateTimePicker
+ { ...args }
+ currentDate={ value }
+ onChange={ ( v ) => {
+ setValue( v );
+ onChange?.( v );
+ } }
+ />
+ );
+};
export const Default: ComponentStory< typeof DateTimePicker > = Template.bind(
{}
|
Good suggestion @aaronrobertshaw. I've done that to all three stories. |
85859e3 to
2c98110
Compare
What?
Converts the stories for
DateTimePicker,DatePickerandTimePickerto TypeScript and rewrites them to use controls not knobs.Why?
Continues from #40775 which converted
DateTimePickeritself to TypeScript.See #35665 for why we're switching from knobs to controls.
How?
I pieced most of this together by reading the controls documentation, the package's
CONTRIBUTING.mdguide, and copying what we've done forInputControl.Testing Instructions
npm run storybook:dev.DateTimePicker,DatePickerandTimePickerstories.