-
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
Storybook: Add UnitControl story #67346
base: trunk
Are you sure you want to change the base?
Conversation
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @im3dabasia! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
cf31838
to
da9cedf
Compare
Hey @t-hamano, I have refactored this PR to align with the patterns suggested in the issue. Please review my work when you have a moment. Thank you! Screen.Recording.2024-12-23.at.2.42.02.PM.mov |
Would it be a good idea to show a story with custom units? I had considered adding this but have removed it for now. Let me know if it makes sense to include a story for this. |
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 the PR!
We may also want to add the following three props to match the README:
- disabledUnits
- isPressEnterToChange
- isUnitSelectTabbable
canvas: { sourceState: 'shown' }, | ||
description: { | ||
component: | ||
'UnitControl allows the user to set a numeric quantity as well as a unit ', |
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.
'UnitControl allows the user to set a numeric quantity as well as a unit ', | |
'UnitControl allows the user to set a numeric quantity as well as a unit.', |
render: function Template( { onChange, onUnitChange, value, ...args } ) { | ||
const [ componentValue, setComponentValue ] = useState( value || '' ); | ||
|
||
useEffect( () => { | ||
setComponentValue( value ); | ||
}, [ value ] ); | ||
|
||
const handleValueChange = ( newValue ) => { | ||
setComponentValue( newValue ); | ||
if ( onChange ) { | ||
onChange( newValue ); | ||
} | ||
}; | ||
|
||
return ( | ||
<UnitControl | ||
{ ...args } | ||
value={ componentValue } | ||
onChange={ handleValueChange } | ||
onUnitChange={ onUnitChange } | ||
/> | ||
); | ||
}, |
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.
render: function Template( { onChange, onUnitChange, value, ...args } ) { | |
const [ componentValue, setComponentValue ] = useState( value || '' ); | |
useEffect( () => { | |
setComponentValue( value ); | |
}, [ value ] ); | |
const handleValueChange = ( newValue ) => { | |
setComponentValue( newValue ); | |
if ( onChange ) { | |
onChange( newValue ); | |
} | |
}; | |
return ( | |
<UnitControl | |
{ ...args } | |
value={ componentValue } | |
onChange={ handleValueChange } | |
onUnitChange={ onUnitChange } | |
/> | |
); | |
}, | |
render: function Template( { onChange, ...args } ) { | |
const [ value, setValue ] = useState(); | |
return ( | |
<UnitControl | |
{ ...args } | |
value={ value } | |
onChange={ ( ...changeArgs ) => { | |
onChange( ...changeArgs ); | |
setValue( ...changeArgs ); | |
} } | |
/> | |
); | |
}, | |
args: { | |
label: 'Label', | |
}, |
Is there a reason you implemented it this way? The above implementation should work too.
At the same time, it might be a good idea to display a default label, just like with the components package.
}, | ||
labelPosition: { | ||
control: 'radio', | ||
options: [ 'top', 'side', 'bottom' ], |
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.
options: [ 'top', 'side', 'bottom' ], | |
options: [ 'top', 'side', 'bottom', 'edge' ], |
}, | ||
}, | ||
value: { | ||
control: 'text', |
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.
control: 'text', | |
control: { type: null }, |
I believe the control is not necessary since the value can be updated directly via the UI.
This component is a kind of wrapper component for the Considering this, I think one story is enough. |
Part of #67165
What?
This PR will add stories for UnitControl component in the Storybook.
Why?
As part of the ongoing effort to improve component documentation and testing (tracked in #22891), we need comprehensive stories for all Block Editor components.
Testing Instructions
Screenshots or screencast
Screen.Recording.2024-11-27.at.4.57.25.PM.mov