Repository navigation
Storybook: Use SelectControl in Motion tokens story #80790
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import type { Meta, StoryObj } from '@storybook/react-vite'; | ||
| import { useState, useCallback, useId } from '@wordpress/element'; | ||
| import { Button, Field, InputControl, Select, Stack } from '@wordpress/ui'; | ||
| import { useState, useCallback } from '@wordpress/element'; | ||
| import { Button, InputControl, SelectControl, Stack } from '@wordpress/ui'; | ||
|
|
||
| const EASING_TOKENS = [ | ||
| { | ||
|
|
@@ -52,14 +52,15 @@ const DURATION_TOKENS = [ | |
| ]; | ||
|
|
||
| const DURATION_OPTIONS = [ | ||
| { label: 'xs', value: 'var(--wpds-motion-duration-xs)' }, | ||
| { label: 'sm', value: 'var(--wpds-motion-duration-sm)' }, | ||
| { label: 'md', value: 'var(--wpds-motion-duration-md)' }, | ||
| { label: 'lg', value: 'var(--wpds-motion-duration-lg)' }, | ||
| { label: 'xl', value: 'var(--wpds-motion-duration-xl)' }, | ||
| { label: 'Custom', value: 'custom' }, | ||
| ...DURATION_TOKENS.map( ( token ) => ( { | ||
| label: token.name, | ||
| value: token.variable, | ||
| } ) ), | ||
| { label: 'custom', value: 'custom' }, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just changed this |
||
| ]; | ||
|
|
||
| const DEFAULT_DURATION_OPTION = DURATION_OPTIONS[ 4 ]; | ||
|
|
||
| const labelStyle = { | ||
| fontFamily: 'var(--wpds-typography-font-family-mono)', | ||
| fontSize: 'var(--wpds-typography-font-size-sm)', | ||
|
|
@@ -138,11 +139,10 @@ function AnimationRow( { | |
| } | ||
|
|
||
| function MotionDemo() { | ||
| const durationSelectId = useId(); | ||
| const [ animKey, setAnimKey ] = useState( 0 ); | ||
| const replay = useCallback( () => setAnimKey( ( k ) => k + 1 ), [] ); | ||
| const [ selectedDuration, setSelectedDuration ] = useState( | ||
| 'var(--wpds-motion-duration-xl)' | ||
| DEFAULT_DURATION_OPTION.value | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, fewer magic values, more single source of truth 👍 |
||
| ); | ||
| const [ customDuration, setCustomDuration ] = useState( '600' ); | ||
|
|
||
|
|
@@ -163,33 +163,24 @@ function MotionDemo() { | |
| <Stack direction="column" gap="lg"> | ||
| <h3>Easing curves</h3> | ||
| <Stack align="end" gap="md" wrap="wrap"> | ||
| <Field.Root style={ { minWidth: '180px' } }> | ||
| <Field.Label htmlFor={ durationSelectId }> | ||
| Duration | ||
| </Field.Label> | ||
| <Select.Root | ||
| value={ selectedDuration } | ||
| onValueChange={ ( value ) => { | ||
| if ( typeof value !== 'string' ) { | ||
| <div style={ { minWidth: '180px' } }> | ||
| <SelectControl | ||
| label="Duration" | ||
| items={ DURATION_OPTIONS } | ||
| defaultValue={ DEFAULT_DURATION_OPTION } | ||
| triggerContent={ ( item ) => item.value } | ||
| onValueChange={ ( item ) => { | ||
| if ( | ||
| ! item || | ||
| typeof item.value !== 'string' | ||
| ) { | ||
| return; | ||
| } | ||
| setSelectedDuration( value ); | ||
| setSelectedDuration( item.value ); | ||
| setAnimKey( ( k ) => k + 1 ); | ||
| } } | ||
| > | ||
| <Select.Trigger id={ durationSelectId } /> | ||
| <Select.Popup> | ||
| { DURATION_OPTIONS.map( ( opt ) => ( | ||
| <Select.Item | ||
| key={ opt.value } | ||
| value={ opt.value } | ||
| > | ||
| { opt.label } | ||
| </Select.Item> | ||
| ) ) } | ||
| </Select.Popup> | ||
| </Select.Root> | ||
| </Field.Root> | ||
| /> | ||
| </div> | ||
| { selectedDuration === 'custom' && ( | ||
| <InputControl | ||
| label="Value (ms)" | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 refactor 🙏