-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-motion): add useMotion hook #28699
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
marcosmoura
merged 57 commits into
microsoft:master
from
marcosmoura:feat/use-motion-presence-hook
Aug 28, 2023
Merged
Changes from 46 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
1faa4c8
feat: implement useMotionPresence hook
marcosmoura 230e273
docs: add missing change files
marcosmoura b8128e7
fix: improve performance of duration calculation
marcosmoura c721171
feat: implement useAnimationFrame hook to help controlling the motion…
marcosmoura 6bbf319
fix: improve type definition to avoid typecast
marcosmoura 44b58d5
fix: return a blank style declaration in case global "window" do not …
marcosmoura b3124d6
fix: regenerate API
marcosmoura caef0bd
fix: regenerate API
marcosmoura ac4e941
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura 8fa8f4a
revert: use RefCallback instead of Ref
marcosmoura 45ac91f
fix: regenerate API
marcosmoura 2497b77
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura cceb832
fix: regenerate API
marcosmoura 91cdd11
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura d3cbded
feat: simplify API by removing redundant prop
marcosmoura cfea341
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura ab9ff66
feat: implement useMotion hook instead of useMotionPresence
marcosmoura 76d1b82
feat: remove useMotionPresence hook
marcosmoura 7fd87f9
fix: remove old changefile
marcosmoura 1e16743
feat: expose useAnimationFrame hook
marcosmoura 41e9e8c
fix: add missing changefile
marcosmoura 647b9e5
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura f384b82
fix: mismatch dependencies
marcosmoura ce4d183
feat: add motion docs to public site
marcosmoura 05ba7e1
docs: add documentatio for the hook
marcosmoura e9e8bbe
feat: create useMotion hook accepting either a boolean or motion state
marcosmoura 9152d81
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura 3872d0a
fix: upgrade stories to use latest changes to hook
marcosmoura 6debd98
feat: make package public
marcosmoura 7f27429
fix: add missing change file
marcosmoura 9593026
fix: join two related hooks in one file to be easier to test
marcosmoura fd9970f
fix: remove unused imports
marcosmoura 5cb0a56
docs: move stories to public site
marcosmoura 92ecfed
docs: add title to example
marcosmoura 190493f
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura 9086d1a
fix: remove leftover property
marcosmoura 969ce87
fix: add type to improve useMemo
marcosmoura 1d8e9b8
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura c437db6
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura f09ff57
feat: use boolean instead of function
marcosmoura e6bb24b
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura a1616d2
fix: remove outdated changefile
marcosmoura 74b8257
fix: use correct boolean values
marcosmoura 7942e80
fix: improve typings and documentation
marcosmoura 2d89ef2
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura f006b19
fix: use correct type for MotionOptions
marcosmoura ab6f39b
feat: refactor useMotion to a much more clean/performant logic
marcosmoura f66a01e
fix: remove debug function
marcosmoura 006fc84
fix: set motion as active when animations are disabled
marcosmoura 03a806a
fix: upgrade tests
marcosmoura bb450b8
fix: remove duplicated code due to a merge conflict
marcosmoura e135084
fix: revert changes to CODEOWNERS
marcosmoura 55aee81
fix: generate new API documentation
marcosmoura a9c61f3
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura c5e204d
fix: remove ref from dependencies
marcosmoura 06ae5c6
Merge branch 'master' into feat/use-motion-presence-hook
marcosmoura 83ef7e1
fix: wrong merge
marcosmoura 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
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
60 changes: 60 additions & 0 deletions
60
apps/public-docsite-v9/src/Utilities/Motion/useMotion/MotionExample.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,60 @@ | ||
| import * as React from 'react'; | ||
|
|
||
| import { useMotion } from '@fluentui/react-motion-preview'; | ||
| import { Button, makeStyles, mergeClasses, shorthands, tokens } from '@fluentui/react-components'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| root: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| rowGap: '24px', | ||
| }, | ||
|
|
||
| rectangle: { | ||
| ...shorthands.borderRadius('8px'), | ||
|
|
||
| width: '200px', | ||
| height: '150px', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| backgroundColor: tokens.colorBrandBackground2, | ||
| opacity: 0, | ||
| transform: 'translate3D(0, 0, 0) scale(0.25)', | ||
| transitionDuration: `${tokens.durationNormal}, ${tokens.durationNormal}, ${tokens.durationUltraSlow}`, | ||
| transitionDelay: `${tokens.durationFast}, 0, ${tokens.durationSlow}`, | ||
| transitionProperty: 'opacity, transform, background-color', | ||
| willChange: 'opacity, transform, background-color', | ||
| color: '#fff', | ||
| }, | ||
|
|
||
| visible: { | ||
| opacity: 1, | ||
| transform: 'translate3D(0, 0, 0) scale(1)', | ||
| backgroundColor: tokens.colorBrandBackground, | ||
| }, | ||
| }); | ||
|
|
||
| export const MotionExample = () => { | ||
| const styles = useStyles(); | ||
|
|
||
| const [open, setOpen] = React.useState(false); | ||
| const motion = useMotion<HTMLDivElement>(open); | ||
|
|
||
| return ( | ||
| <div className={styles.root}> | ||
| <Button appearance="primary" onClick={() => setOpen(!open)}> | ||
| Toggle | ||
| </Button> | ||
|
|
||
| {motion.canRender && ( | ||
| <div ref={motion.ref} className={mergeClasses(styles.rectangle, motion.active && styles.visible)}> | ||
| Lorem ipsum | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; |
83 changes: 83 additions & 0 deletions
83
apps/public-docsite-v9/src/Utilities/Motion/useMotion/index.stories.mdx
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,83 @@ | ||
| import { Title, Subtitle, Meta, Description } from '@storybook/addon-docs'; | ||
|
|
||
| import { MotionExample } from './MotionExample.stories'; | ||
|
|
||
| <Title>useMotion</Title> | ||
|
|
||
| <Meta title="Utilities/Motion/useMotion" /> | ||
|
|
||
| <Description> | ||
| A tracker hook, that monitors the state of animations and transitions for a particular element. This hook does not | ||
| directly create animations but instead synchronizes with CSS properties to determine the rendering status, visibility, | ||
| entering, leaving, and ongoing animation of a component. If any CSS changes or properties are overridden, this hook | ||
| will automatically adjust and stay synchronized. | ||
| </Description> | ||
|
|
||
| <Subtitle>Usage</Subtitle> | ||
|
|
||
| ```tsx | ||
| import * as React from 'react'; | ||
|
|
||
| import { useMotion } from '@fluentui/react-motion-preview'; | ||
| import { Button, makeStyles, mergeClasses, shorthands, tokens } from '@fluentui/react-components'; | ||
|
|
||
| const useStyles = makeStyles({ | ||
| root: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| rowGap: '24px', | ||
| }, | ||
|
|
||
| rectangle: { | ||
| ...shorthands.borderRadius('8px'), | ||
|
|
||
| width: '200px', | ||
| height: '150px', | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| backgroundColor: tokens.colorBrandBackground2, | ||
| opacity: 0, | ||
| transform: 'translate3D(0, 0, 0) scale(0.25)', | ||
| transitionDuration: `${tokens.durationNormal}, ${tokens.durationNormal}, ${tokens.durationUltraSlow}`, | ||
| transitionDelay: `${tokens.durationFast}, 0, ${tokens.durationSlow}`, | ||
| transitionProperty: 'opacity, transform, background-color', | ||
| willChange: 'opacity, transform, background-color', | ||
| color: '#fff', | ||
| }, | ||
|
|
||
| visible: { | ||
| opacity: 1, | ||
| transform: 'translate3D(0, 0, 0) scale(1)', | ||
| backgroundColor: tokens.colorBrandBackground, | ||
| }, | ||
| }); | ||
|
|
||
| export const MotionExample = () => { | ||
| const styles = useStyles(); | ||
|
|
||
| const [open, setOpen] = React.useState(false); | ||
| const motion = useMotion<HTMLDivElement>(open); | ||
|
|
||
| return ( | ||
| <div className={styles.root}> | ||
| <Button appearance="primary" onClick={() => setOpen(!open)}> | ||
| Toggle | ||
| </Button> | ||
|
|
||
| {motion.canRender() && ( | ||
| <div ref={motion.ref} className={mergeClasses(styles.rectangle, motion.isActive() && styles.visible)}> | ||
| Lorem ipsum | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
| ``` | ||
|
|
||
| <Subtitle>Example</Subtitle> | ||
|
|
||
| <MotionExample /> |
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-motion-preview-a0e15534-5b7d-4fb8-a6dd-f28e388add2a.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: create react-motion-preview package with useMotion hook", | ||
| "packageName": "@fluentui/react-motion-preview", | ||
| "email": "marcosvmmoura@gmail.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
1 change: 1 addition & 0 deletions
1
packages/react-components/react-motion-preview/src/hooks/index.ts
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 @@ | ||
| export * from './useMotion'; |
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.