-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Convert FontSizePicker to TypeScript #44449
Conversation
Size Change: +39 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
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.
Great job!
I left a few comments, but this is already looking great. So far, I mostly focused on doing a code review, in the next round I'll do some more testing on Storybook and in the editor
}, | ||
}, | ||
}, | ||
argTypes: {}, |
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.
We usually keep components controlled in Storybook
argTypes: {}, | |
argTypes: { | |
value: { control: { type: 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.
Ah yeah that makes sense 👍
parameters: { | ||
controls: { expanded: true }, | ||
docs: { source: { state: 'open' } }, | ||
}, |
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.
Let's leverage Storybook's actions! We can do so by flagging on*
callbacks as actions, and passing through the onChange
prop in FontSizePickerWithState
:
diff --git a/packages/components/src/font-size-picker/stories/index.tsx b/packages/components/src/font-size-picker/stories/index.tsx
index 4937214fca..51bc3c3831 100644
--- a/packages/components/src/font-size-picker/stories/index.tsx
+++ b/packages/components/src/font-size-picker/stories/index.tsx
@@ -16,8 +16,11 @@ import FontSizePicker from '../';
const meta: ComponentMeta< typeof FontSizePicker > = {
title: 'Components/FontSizePicker',
component: FontSizePicker,
argTypes: {},
parameters: {
+ actions: { argTypesRegex: '^on.*' },
controls: { expanded: true },
docs: { source: { state: 'open' } },
},
@@ -26,6 +29,7 @@ export default meta;
const FontSizePickerWithState: ComponentStory< typeof FontSizePicker > = ( {
value,
+ onChange,
...props
} ) => {
const [ fontSize, setFontSize ] = useState( value );
@@ -33,7 +37,10 @@ const FontSizePickerWithState: ComponentStory< typeof FontSizePicker > = ( {
<FontSizePicker
{ ...props }
value={ fontSize }
- onChange={ setFontSize }
+ onChange={ ( v ) => {
+ setFontSize( v );
+ onChange?.( v );
+ } }
/>
);
};
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.
You are a fountain of knowledge, Marco!
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! We can merge this PR once the couple of leftover comments are addressed 🚀
(I also tested the component with the experimental viz reg that we've recently introduced)
Oh wow that's cool. |
It really is — props to Lena for working on it! Hopefully it will help us with components like Popover, Button, FontSizePicker and more |
What?
Part of #35744
Converts
FontSizePicker
to TypeScript so as to add types toFontSizePicker
.Why?
One step closer to all of
@wordpress/components
being in TypeScript. Also I'm about to make some changes toFontSizePicker
and some type checking might be helpful.How?
https://github.com/WordPress/gutenberg/blob/trunk/packages/components/CONTRIBUTING.md#refactoring-a-component-to-typescript
Testing Instructions
Check that tests pass and the storybook for
FontSizePicker
still functions correctly.