-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-motion): add replayKey prop to replay motion without remounting #36108
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
robertpenner
wants to merge
10
commits into
microsoft:master
Choose a base branch
from
robertpenner:feat/motion-component-replay-key
base: master
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.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9cdbd70
feat(react-motion): add replayKey prop to replay motion without remou…
robertpenner 775a630
chore: add change file for react-motion replayKey
robertpenner b0e512f
fix(react-motion): wrap replayKey @example in code fence to fix TSDoc…
robertpenner fc8d65c
feat(react-motion): add replayKey story with side-by-side before/afte…
robertpenner 9889399
chore(react-motion): polish replayKey story — primary button, explici…
robertpenner 35c8ed7
fix(react-motion): fix ref type in TrackedChild test helper
robertpenner 79d7dc5
refactor(react-motion): replay replayKey imperatively via cancel+play…
robertpenner 3a0c21b
test(react-motion): add test for onMotionStart and onMotionFinish fir…
robertpenner 79f0f83
refactor(react-motion): DRY up handle wiring into startHandle; add te…
robertpenner fce9549
refactor(react-motion): rename startAnimationHandle to activateAnimat…
robertpenner 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
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-motion-b1997662-a01c-4258-b43e-d8022aab59b3.json
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,7 @@ | ||
| { | ||
| "type": "minor", | ||
| "comment": "feat(react-motion): add replayKey prop to replay motion without remounting", | ||
| "packageName": "@fluentui/react-motion", | ||
| "email": "robertpenner@microsoft.com", | ||
| "dependentChangeType": "patch" | ||
| } | ||
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
1 change: 1 addition & 0 deletions
1
...ion/stories/src/CreateMotionComponent/CreateMotionComponentReplayKey.stories.md
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 @@ | ||
| The `replayKey` prop retriggers the animation each time its value changes, without remounting the component. Unlike changing a React `key`, which destroys and recreates the subtree, `replayKey` reruns only the animation while keeping the DOM, focus, and child state intact. |
77 changes: 77 additions & 0 deletions
77
...react-motion/stories/src/CreateMotionComponent/CreateMotionComponentReplayKey.stories.tsx
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,77 @@ | ||
| import { Button, Card, makeStyles, Text, tokens } from '@fluentui/react-components'; | ||
| import { Scale } from '@fluentui/react-motion-components-preview'; | ||
| import * as React from 'react'; | ||
| import type { JSXElement } from '@fluentui/react-components'; | ||
|
|
||
| import description from './CreateMotionComponentReplayKey.stories.md'; | ||
|
|
||
| const useClasses = makeStyles({ | ||
| root: { | ||
| display: 'grid', | ||
| gridTemplateColumns: '1fr 1fr', | ||
| gridTemplateRows: 'auto auto auto', | ||
| gridTemplateAreas: `"labelBefore labelAfter" "cardBefore cardAfter" "controls controls"`, | ||
| gap: '12px 20px', | ||
| }, | ||
|
|
||
| label: { | ||
| textAlign: 'center', | ||
| }, | ||
|
|
||
| card: { | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| minHeight: '160px', | ||
| }, | ||
|
|
||
| controls: { | ||
| gridArea: 'controls', | ||
| display: 'flex', | ||
| justifyContent: 'center', | ||
| }, | ||
|
|
||
| counter: { | ||
| color: tokens.colorBrandForeground1, | ||
| fontSize: tokens.fontSizeHero900, | ||
| fontWeight: tokens.fontWeightBold, | ||
| lineHeight: '1', | ||
| }, | ||
| }); | ||
|
|
||
| export const CreateMotionComponentReplayKey = (): JSXElement => { | ||
| const classes = useClasses(); | ||
| const [count, setCount] = React.useState(0); | ||
|
|
||
| return ( | ||
| <div className={classes.root}> | ||
| <Text className={classes.label} weight="semibold"> | ||
| Without replayKey | ||
| </Text> | ||
| <Text className={classes.label} weight="semibold"> | ||
| With replayKey | ||
| </Text> | ||
|
|
||
| <Card className={classes.card} style={{ gridArea: 'cardBefore' }}> | ||
| <Scale.In duration={2000} outScale={1.5} animateOpacity={false}> | ||
| <span className={classes.counter}>{count}</span> | ||
| </Scale.In> | ||
| </Card> | ||
| <Card className={classes.card} style={{ gridArea: 'cardAfter' }}> | ||
| <Scale.In duration={2000} outScale={1.5} animateOpacity={false} replayKey={count}> | ||
| <span className={classes.counter}>{count}</span> | ||
| </Scale.In> | ||
| </Card> | ||
|
|
||
| <div className={classes.controls}> | ||
| <Button appearance="primary" onClick={() => setCount(n => n + 1)}> | ||
| Increment | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| CreateMotionComponentReplayKey.parameters = { | ||
| docs: { description: { story: description } }, | ||
| }; |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.