Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 24 additions & 33 deletions storybook/stories/design-system/tokens/motion.story.tsx
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 = [
{
Expand Down Expand Up @@ -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,
} ) ),
Comment on lines -55 to +58

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor 🙏

{ label: 'custom', value: 'custom' },

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just changed this custom label to lowercase because it seems to match the other options better.

];

const DEFAULT_DURATION_OPTION = DURATION_OPTIONS[ 4 ];

const labelStyle = {
fontFamily: 'var(--wpds-typography-font-family-mono)',
fontSize: 'var(--wpds-typography-font-size-sm)',
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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' );

Expand All @@ -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)"
Expand Down
Loading