-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use TypeScript and controls for DateTimePicker
's stories
#40986
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
@@ -21,15 +21,11 @@ export type UpdateOnBlurAsIntegerFieldProps = { | |||
children?: ReactNode; | |||
}; | |||
|
|||
export type DateTimeString = string; | |||
|
|||
export type ValidDateTimeInput = Date | string | number | null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚢
85859e3
to
2c98110
Compare
What?
Converts the stories for
DateTimePicker
,DatePicker
andTimePicker
to TypeScript and rewrites them to use controls not knobs.Why?
Continues from #40775 which converted
DateTimePicker
itself 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.md
guide, and copying what we've done forInputControl
.Testing Instructions
npm run storybook:dev
.DateTimePicker
,DatePicker
andTimePicker
stories.