-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(react-motions): rework docs (#29860)
- Loading branch information
1 parent
81bc562
commit 4c1cd4b
Showing
15 changed files
with
422 additions
and
22 deletions.
There are no files selected for viewing
9 changes: 0 additions & 9 deletions
9
packages/react-components/react-motions-preview/stories/CreateAtom/index.stories.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
packages/react-components/react-motions-preview/stories/CreateTransition/index.stories.ts
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
.../react-components/react-motions-preview/stories/Motion/AtomPlayState.stories.md
This file contains 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 @@ | ||
By default, the child component will be animated when it first mounts. A motion can be paused by setting the `playState` prop to `"paused"`. |
106 changes: 106 additions & 0 deletions
106
packages/react-components/react-motions-preview/stories/Motion/AtomPlayState.stories.tsx
This file contains 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,106 @@ | ||
import { makeStyles, shorthands, tokens, Label, Slider, useId, Checkbox } from '@fluentui/react-components'; | ||
import { atoms, createAtom } from '@fluentui/react-motions-preview'; | ||
import * as React from 'react'; | ||
|
||
import description from './TransitionUnmountOnExit.stories.md'; | ||
|
||
const useClasses = makeStyles({ | ||
container: { | ||
display: 'grid', | ||
gridTemplateColumns: '1fr', | ||
...shorthands.gap('10px'), | ||
}, | ||
card: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
|
||
...shorthands.border('3px', 'solid', tokens.colorNeutralForeground3), | ||
...shorthands.borderRadius(tokens.borderRadiusMedium), | ||
...shorthands.padding('10px'), | ||
|
||
alignItems: 'center', | ||
}, | ||
item: { | ||
backgroundColor: tokens.colorBrandBackground, | ||
...shorthands.borderRadius('50%'), | ||
|
||
width: '100px', | ||
height: '100px', | ||
}, | ||
description: { | ||
...shorthands.margin('5px'), | ||
}, | ||
controls: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
|
||
marginTop: '20px', | ||
|
||
...shorthands.border('3px', 'solid', tokens.colorNeutralForeground3), | ||
...shorthands.borderRadius(tokens.borderRadiusMedium), | ||
...shorthands.padding('10px'), | ||
}, | ||
}); | ||
|
||
const FadeEnter = createAtom(atoms.fade.enterUltraSlow()); | ||
|
||
export const AtomPlayState = () => { | ||
const classes = useClasses(); | ||
const sliderId = useId(); | ||
|
||
const elementRef = React.useRef<HTMLDivElement>(null); | ||
const [playbackRate, setPlaybackRate] = React.useState<number>(30); | ||
const [isRunning, setIsRunning] = React.useState<boolean>(false); | ||
|
||
React.useEffect(() => { | ||
elementRef.current?.getAnimations().forEach(animation => { | ||
animation.playbackRate = playbackRate / 100; | ||
}); | ||
}, [playbackRate, isRunning]); | ||
|
||
return ( | ||
<> | ||
<div className={classes.container}> | ||
<div className={classes.card}> | ||
<FadeEnter playState={isRunning ? 'running' : 'paused'} iterations={Infinity}> | ||
<div className={classes.item} ref={elementRef} /> | ||
</FadeEnter> | ||
|
||
<code className={classes.description}>fadeEnterSlow</code> | ||
</div> | ||
</div> | ||
|
||
<div className={classes.controls}> | ||
<div> | ||
<Checkbox | ||
label={isRunning ? '⏸️ Pause' : '▶️ Play'} | ||
checked={isRunning} | ||
onChange={() => setIsRunning(v => !v)} | ||
/> | ||
</div> | ||
<div> | ||
<Label htmlFor={sliderId}> | ||
<code>playbackRate</code>: {playbackRate}% | ||
</Label> | ||
<Slider | ||
aria-valuetext={`Value is ${playbackRate}%`} | ||
value={playbackRate} | ||
onChange={(ev, data) => setPlaybackRate(data.value)} | ||
min={0} | ||
id={sliderId} | ||
max={100} | ||
step={10} | ||
/> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
AtomPlayState.parameters = { | ||
docs: { | ||
description: { | ||
story: description, | ||
}, | ||
}, | ||
}; |
1 change: 1 addition & 0 deletions
1
...ges/react-components/react-motions-preview/stories/Motion/CreateAtom.stories.md
This file contains 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 @@ | ||
`createAtom()` is a factory function that creates a React component based on the provided atom definition. This component can be used to animate any element. |
This file contains 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
...act-components/react-motions-preview/stories/Motion/CreateTransition.stories.md
This file contains 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 @@ | ||
`createTransition()` is a factory function that creates a React component based on the provided transition definition. This component can be used to animate any element and intended to have a state via the `visible` prop. |
This file contains 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
43 changes: 43 additions & 0 deletions
43
packages/react-components/react-motions-preview/stories/Motion/MotionDefault.stories.tsx
This file contains 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,43 @@ | ||
import { makeStyles, shorthands, tokens } from '@fluentui/react-components'; | ||
import { atoms, createAtom } from '@fluentui/react-motions-preview'; | ||
import * as React from 'react'; | ||
|
||
const useClasses = makeStyles({ | ||
container: { | ||
display: 'flex', | ||
}, | ||
card: { | ||
...shorthands.border('3px', 'solid', tokens.colorNeutralForeground3), | ||
...shorthands.borderRadius(tokens.borderRadiusMedium), | ||
|
||
...shorthands.padding('20px'), | ||
...shorthands.margin('20px'), | ||
}, | ||
item: { | ||
backgroundColor: tokens.colorBrandBackground, | ||
...shorthands.borderRadius('50%'), | ||
|
||
width: '100px', | ||
height: '100px', | ||
}, | ||
}); | ||
|
||
const motionAtom = atoms.fade.enterUltraSlow(); | ||
const FadeEnter = createAtom({ | ||
keyframes: motionAtom.keyframes, | ||
options: { ...motionAtom.options, duration: 2000 }, | ||
}); | ||
|
||
export const MotionDefault = () => { | ||
const classes = useClasses(); | ||
|
||
return ( | ||
<div className={classes.container}> | ||
<div className={classes.card}> | ||
<FadeEnter iterations={Infinity}> | ||
<div className={classes.item} /> | ||
</FadeEnter> | ||
</div> | ||
</div> | ||
); | ||
}; |
6 changes: 6 additions & 0 deletions
6
...ages/react-components/react-motions-preview/stories/Motion/MotionDescription.md
This file contains 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,6 @@ | ||
`@fluentui/react-motions` implements definitions for motion animations that can be used in Fluent UI components. These animations are used to provide visual feedback to users when they interact with components. | ||
|
||
This implementation is based on [Web Animations API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Animations_API) and defines atoms & transitions that can be used to create animation components. | ||
|
||
- Atoms are the smallest building blocks of animations | ||
- Transitions are the combination of atoms that define the in/out animation |
1 change: 1 addition & 0 deletions
1
...act-components/react-motions-preview/stories/Motion/TransitionAppear.stories.md
This file contains 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 @@ | ||
By default, the child component does not perform the enter transition when it first mounts, regardless of the value of `visible`. If you want this behavior, set both `appear` and `visible` props to be true. |
104 changes: 104 additions & 0 deletions
104
packages/react-components/react-motions-preview/stories/Motion/TransitionAppear.stories.tsx
This file contains 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,104 @@ | ||
import { makeStyles, shorthands, tokens, Label, Slider, useId, Checkbox } from '@fluentui/react-components'; | ||
import { createTransition, transitions } from '@fluentui/react-motions-preview'; | ||
import * as React from 'react'; | ||
|
||
import description from './TransitionUnmountOnExit.stories.md'; | ||
|
||
const useClasses = makeStyles({ | ||
container: { | ||
display: 'grid', | ||
gridTemplateColumns: '1fr', | ||
...shorthands.gap('10px'), | ||
}, | ||
card: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
|
||
...shorthands.border('3px', 'solid', tokens.colorNeutralForeground3), | ||
...shorthands.borderRadius(tokens.borderRadiusMedium), | ||
...shorthands.padding('10px'), | ||
|
||
alignItems: 'center', | ||
}, | ||
item: { | ||
backgroundColor: tokens.colorBrandBackground, | ||
...shorthands.borderRadius('50%'), | ||
|
||
width: '100px', | ||
height: '100px', | ||
}, | ||
description: { | ||
...shorthands.margin('5px'), | ||
}, | ||
controls: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
|
||
marginTop: '20px', | ||
|
||
...shorthands.border('3px', 'solid', tokens.colorNeutralForeground3), | ||
...shorthands.borderRadius(tokens.borderRadiusMedium), | ||
...shorthands.padding('10px'), | ||
}, | ||
}); | ||
|
||
const Fade = createTransition(transitions.fade.slow()); | ||
|
||
export const TransitionAppear = () => { | ||
const classes = useClasses(); | ||
const sliderId = useId(); | ||
|
||
const elementRef = React.useRef<HTMLDivElement>(null); | ||
const [playbackRate, setPlaybackRate] = React.useState<number>(30); | ||
const [isMounted, setIsMounted] = React.useState<boolean>(false); | ||
|
||
React.useEffect(() => { | ||
elementRef.current?.getAnimations().forEach(animation => { | ||
animation.playbackRate = playbackRate / 100; | ||
}); | ||
}, [playbackRate, isMounted]); | ||
|
||
return ( | ||
<> | ||
<div className={classes.container}> | ||
<div className={classes.card}> | ||
{isMounted && ( | ||
<Fade appear visible> | ||
<div className={classes.item} ref={elementRef} /> | ||
</Fade> | ||
)} | ||
|
||
<code className={classes.description}>fadeSlow</code> | ||
</div> | ||
</div> | ||
|
||
<div className={classes.controls}> | ||
<div> | ||
<Checkbox label="Mount an element?" checked={isMounted} onChange={() => setIsMounted(v => !v)} /> | ||
</div> | ||
<div> | ||
<Label htmlFor={sliderId}> | ||
<code>playbackRate</code>: {playbackRate}% | ||
</Label> | ||
<Slider | ||
aria-valuetext={`Value is ${playbackRate}%`} | ||
value={playbackRate} | ||
onChange={(ev, data) => setPlaybackRate(data.value)} | ||
min={0} | ||
id={sliderId} | ||
max={100} | ||
step={10} | ||
/> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
TransitionAppear.parameters = { | ||
docs: { | ||
description: { | ||
story: description, | ||
}, | ||
}, | ||
}; |
1 change: 1 addition & 0 deletions
1
...ponents/react-motions-preview/stories/Motion/TransitionUnmountOnExit.stories.md
This file contains 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 @@ | ||
By default, the child component stays mounted after the animation reaches the `"finished"` state. Set `unmountOnExit` if you'd prefer to unmount the component after it finishes the animation. |
Oops, something went wrong.