Repository navigation
feat(core): the animator's springs follow the theme's tempo #8677
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
Open
vjeux
wants to merge
3
commits into
meta:main
Choose a base branch
from
vjeux:uikit/f1-theme-motion-springs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+944
−59
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| '@astryxdesign/cli': patch | ||
| --- | ||
|
|
||
| [feat] Motion: a theme's `tempo` now times the springs of touch motion as well as its CSS durations. Each spring keeps its shape and takes `tempo` times as long, and so does the animated-layout glide. Finger tracking and busy loops stay as measured. A theme with only a duration scale keeps its springs at tempo 1, even inside a theme with a tempo. The springs don't follow `character` yet. The motion doc says so. | ||
|
|
||
| @vjeux |
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 |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| import {useRef, useState} from 'react'; | ||
| import type {Meta, StoryObj} from '@storybook/react'; | ||
| import {Collapsible} from '@astryxdesign/core/Collapsible'; | ||
| import {useAnimatedLayout} from '@astryxdesign/core/hooks'; | ||
| import {ScrollableArea} from '@astryxdesign/core/ScrollableArea'; | ||
| import { | ||
| SegmentedControl, | ||
| SegmentedControlItem, | ||
| } from '@astryxdesign/core/SegmentedControl'; | ||
| import {Slider} from '@astryxdesign/core/Slider'; | ||
| import {Switch} from '@astryxdesign/core/Switch'; | ||
| import {Theme, defineTheme} from '@astryxdesign/core/theme'; | ||
|
|
||
| const meta: Meta = { | ||
| title: 'Core/Theme motion tempo', | ||
| parameters: {layout: 'padded'}, | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj; | ||
|
|
||
| const TEMPOS = [0.75, 1, 1.5] as const; | ||
|
|
||
| const THEMES = TEMPOS.map(tempo => | ||
| defineTheme({ | ||
| name: `motion-tempo-${String(tempo).replace('.', '-')}`, | ||
| motion: {tempo}, | ||
| }), | ||
| ); | ||
|
|
||
| const NAMES: Record<(typeof TEMPOS)[number], string> = { | ||
| 0.75: 'Tempo 0.75, the quickest', | ||
| 1: "Tempo 1, Astryx's own", | ||
| 1.5: 'Tempo 1.5, the slowest', | ||
| }; | ||
|
|
||
| const card = { | ||
| display: 'grid', | ||
| gap: 16, | ||
| padding: 12, | ||
| borderRadius: 12, | ||
| border: '1px solid var(--color-border)', | ||
| background: 'var(--color-background-surface)', | ||
| color: 'var(--color-text-primary)', | ||
| fontFamily: 'var(--font-family-body)', | ||
| fontSize: 14, | ||
| } as const; | ||
|
|
||
| const title = { | ||
| margin: '0 0 6px', | ||
| fontSize: 12, | ||
| fontWeight: 600, | ||
| color: 'var(--color-text-secondary)', | ||
| fontFamily: 'var(--font-family-body)', | ||
| } as const; | ||
|
|
||
| /** | ||
| * Details that open with a glide: the content after them glides on the tempo | ||
| * of the theme they are in. | ||
| */ | ||
| function Details({label}: {label: string}) { | ||
| const containerRef = useRef<HTMLDivElement>(null); | ||
| const animatedLayout = useAnimatedLayout({containerRef}); | ||
| return ( | ||
| <ScrollableArea ref={containerRef} height={180} label={label}> | ||
| <Collapsible | ||
| trigger="Shipping details" | ||
| defaultIsOpen={false} | ||
| animatedLayout={animatedLayout}> | ||
| <p style={{margin: '4px 0'}}>Ships in 2 business days.</p> | ||
| <p style={{margin: '4px 0'}}>Free returns for 30 days.</p> | ||
| </Collapsible> | ||
| <p data-after-collapsible style={{margin: '8px 0 0'}}> | ||
| The content after it glides on the theme's tempo. | ||
| </p> | ||
| </ScrollableArea> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * One theme's controls: their touch springs and the Collapsible's glide play | ||
| * at the theme's tempo. | ||
| */ | ||
| function Row({index}: {index: number}) { | ||
| const tempo = TEMPOS[index]; | ||
| const [isOn, setIsOn] = useState(false); | ||
| const [volume, setVolume] = useState(40); | ||
| const [view, setView] = useState('day'); | ||
| return ( | ||
| <section data-tempo={tempo} style={{margin: '0 0 20px', maxWidth: 420}}> | ||
| <div style={title}>{NAMES[tempo]}</div> | ||
| <Theme theme={THEMES[index]} mode="light"> | ||
| <div style={card}> | ||
| <Switch label="Wi-Fi" value={isOn} onChange={setIsOn} /> | ||
| <Slider label="Volume" value={volume} onChange={setVolume} /> | ||
| <SegmentedControl value={view} onChange={setView} label="Range"> | ||
| <SegmentedControlItem value="day" label="Day" /> | ||
| <SegmentedControlItem value="week" label="Week" /> | ||
| <SegmentedControlItem value="month" label="Month" /> | ||
| </SegmentedControl> | ||
| <Details label={`Details at tempo ${tempo}`} /> | ||
| </div> | ||
| </Theme> | ||
| </section> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * The same controls under three themes that set only `motion.tempo`. On a | ||
| * touch screen, try each row: toggle the switch, drag the slider, slide the | ||
| * segments and open the details. Every spring and the glide take the tempo | ||
| * times their own time. | ||
| */ | ||
| export const ThreeTempos: Story = { | ||
| name: 'Three tempos', | ||
| render: () => ( | ||
| <div> | ||
| {TEMPOS.map((tempo, index) => ( | ||
| <Row key={tempo} index={index} /> | ||
| ))} | ||
| </div> | ||
| ), | ||
| }; | ||
|
|
||
| /** A theme that sets only a duration scale, as an existing theme does. */ | ||
| const durationScaleTheme = defineTheme({ | ||
| name: 'motion-duration-scale', | ||
| motion: {fast: 130, medium: 310, ratio: 0.75}, | ||
| }); | ||
|
|
||
| /** | ||
| * A theme with only a duration scale, nested in a theme at tempo 1.5. Its | ||
| * glide keeps the pace of its own durations, as on a page with no tempo. The | ||
| * glide beside it, in the outer theme, takes 1.5 times as long. | ||
| */ | ||
| export const NestedDurationScale: Story = { | ||
| name: 'A duration scale nested in a tempo', | ||
| render: () => ( | ||
| <div style={{maxWidth: 420}}> | ||
| <section data-row="plain" style={{margin: '0 0 20px'}}> | ||
| <div style={title}>No theme tempo</div> | ||
| <div style={card}> | ||
| <Details label="Details with no theme tempo" /> | ||
| </div> | ||
| </section> | ||
| <Theme theme={THEMES[TEMPOS.indexOf(1.5)]} mode="light"> | ||
| <section data-row="outer" style={{margin: '0 0 20px'}}> | ||
| <div style={title}>Tempo 1.5</div> | ||
| <div style={card}> | ||
| <Details label="Details at tempo 1.5" /> | ||
| </div> | ||
| </section> | ||
| <Theme theme={durationScaleTheme} mode="light"> | ||
| <section data-row="nested" style={{margin: '0 0 20px'}}> | ||
| <div style={title}>A duration scale inside tempo 1.5</div> | ||
| <div style={card}> | ||
| <Details label="Details in a duration scale" /> | ||
| </div> | ||
| </section> | ||
| </Theme> | ||
| </Theme> | ||
| </div> | ||
| ), | ||
| }; |
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
These still say the opposite:
defineTheme.ts:296-297("touch motion's springs don't read it yet"),packages/cli/assets/theme.template.ts:184-185,packages/cli/assets/docs/author-a-theme.doc.mjs:44andpackages/core/src/theme/themeMotion.ts:16("No spring reads the knobs yet"). Please update them to match this sentence.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.
Fixed in 6755a6a:
defineTheme.ts, the theme template,author-a-theme.doc.mjsand thethemeMotion.tsheader now say the springs followtempobut notcharacteryet.