-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
feat(motion): add Slide motion component #33878
Draft
robertpenner
wants to merge
6
commits into
microsoft:master
Choose a base branch
from
robertpenner:feat/slide-component
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.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cb4f0f8
feat(motion): start implementing Slide by copying Scale files and ren…
robertpenner dccbb4e
feat(motion): implement Slide presence component
robertpenner f7b682e
chore(motion): `yarn change`
robertpenner 1ca02be
chore: `yarn nx run react-components:build`
robertpenner 35a6858
feat(Slide): update variant values to match motion spec
robertpenner 2074731
chore(Slide): fix unit test
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-components-preview-771971d3-7650-4672-85ff-dd59b892969e.json
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,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Add Slide motion component", | ||
"packageName": "@fluentui/react-motion-components-preview", | ||
"email": "robertpenner@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
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
35 changes: 35 additions & 0 deletions
35
packages/react-components/react-motion-components-preview/library/src/atoms/slide-atom.ts
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,35 @@ | ||
import { PresenceDirection, AtomMotion } from '@fluentui/react-motion/src/types'; | ||
import { SlideOrientation } from '../components/Slide/Slide.types'; | ||
|
||
/** | ||
* Generates a motion atom object for a horizontal or vertical translation, from a specified distance to zero. | ||
* @param direction - The functional direction of the motion: 'enter' or 'exit'. | ||
* @param orientation - The axis of the translation: 'X' or 'Y'. | ||
* @param distance - The distance of the slide relative to the natural position. It can be pixels or other length unit. | ||
* @param duration - The duration of the motion in milliseconds. | ||
* @param easing - The easing curve for the motion. | ||
*/ | ||
export const slideAtom = ({ | ||
direction, | ||
orientation, | ||
distance, | ||
duration, | ||
easing, | ||
}: { | ||
direction: PresenceDirection; | ||
orientation: SlideOrientation; | ||
distance: string; | ||
duration: number; | ||
easing: string; | ||
}): AtomMotion => { | ||
const axis: 'X' | 'Y' = orientation === 'horizontal' ? 'X' : 'Y'; | ||
const keyframes = [{ transform: `translate${axis}(${distance})` }, { transform: `translate${axis}(0)` }]; | ||
if (direction === 'exit') { | ||
keyframes.reverse(); | ||
} | ||
return { | ||
keyframes, | ||
duration, | ||
easing, | ||
}; | ||
}; |
24 changes: 24 additions & 0 deletions
24
...ges/react-components/react-motion-components-preview/library/src/atoms/visibility-atom.ts
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,24 @@ | ||
import { AtomMotion, PresenceDirection } from '@fluentui/react-motion'; | ||
|
||
/** | ||
* Generates a motion atom object for visibility, toggling between 'visible' and 'hidden'. | ||
* This is useful for making elements disappear when there is no fade-out. | ||
* @param direction - The functional direction of the motion: 'enter' or 'exit'. | ||
* @param duration - The duration of the motion in milliseconds. | ||
* @returns A motion atom object with visibility keyframes and the supplied duration. | ||
*/ | ||
export const visibilityAtom = ({ | ||
direction, | ||
duration, | ||
}: { | ||
direction: PresenceDirection; | ||
duration: number; | ||
}): AtomMotion => { | ||
const visibility = direction === 'enter' ? 'visible' : 'hidden'; | ||
// For the exit animation, offset is 1 so the keyframe to set visibility to 'hidden' is at the end of the animation. | ||
const offset = direction === 'enter' ? 0 : 1; | ||
return { | ||
keyframes: [{ visibility, offset }], | ||
duration, | ||
}; | ||
}; |
12 changes: 12 additions & 0 deletions
12
...act-components/react-motion-components-preview/library/src/components/Slide/Slide.test.ts
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,12 @@ | ||
import { expectPresenceMotionFunction, expectPresenceMotionArray } from '../../testing/testUtils'; | ||
import { Slide } from './Slide'; | ||
|
||
describe('Slide', () => { | ||
it('stores its motion definition as a static function', () => { | ||
expectPresenceMotionFunction(Slide); | ||
}); | ||
|
||
it('generates a motion definition from the static function', () => { | ||
expectPresenceMotionArray(Slide); | ||
}); | ||
}); |
88 changes: 88 additions & 0 deletions
88
...es/react-components/react-motion-components-preview/library/src/components/Slide/Slide.ts
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,88 @@ | ||
import { motionTokens, createPresenceComponent, AtomMotion } from '@fluentui/react-motion'; | ||
import { PresenceMotionFnCreator } from '../../types'; | ||
import { SlideRuntimeParams_unstable, SlideVariantParams_unstable } from './Slide.types'; | ||
import { fadeAtom } from '../../atoms/fade-atom'; | ||
import { slideAtom } from '../../atoms/slide-atom'; | ||
import { visibilityAtom } from '../../atoms/visibility-atom'; | ||
|
||
/** Define a presence motion for slide in/out */ | ||
export const createSlidePresence: PresenceMotionFnCreator<SlideVariantParams_unstable, SlideRuntimeParams_unstable> = | ||
({ | ||
enterDuration = motionTokens.durationNormal, | ||
enterEasing = motionTokens.curveDecelerateMid, | ||
exitDuration = enterDuration, // defaults to the enter duration for symmetry | ||
exitEasing = motionTokens.curveAccelerateMid, | ||
} = {}) => | ||
({ animateOpacity = true, orientation = 'vertical', distance = '20px' }) => { | ||
// ----- ENTER ----- | ||
const enterAtoms: AtomMotion[] = [ | ||
slideAtom({ | ||
direction: 'enter', | ||
orientation, | ||
distance, | ||
duration: enterDuration, | ||
easing: enterEasing, | ||
}), | ||
]; | ||
if (animateOpacity) { | ||
enterAtoms.push( | ||
fadeAtom({ | ||
direction: 'enter', | ||
duration: enterDuration, | ||
easing: enterEasing, | ||
}), | ||
); | ||
} else { | ||
// Since there is no fade-in, use visibility to show the element | ||
enterAtoms.push(visibilityAtom({ direction: 'enter', duration: enterDuration })); | ||
} | ||
|
||
// ----- EXIT ----- | ||
const exitAtoms: AtomMotion[] = [ | ||
slideAtom({ | ||
direction: 'exit', | ||
orientation, | ||
distance, | ||
duration: exitDuration, | ||
easing: exitEasing, | ||
}), | ||
]; | ||
if (animateOpacity) { | ||
exitAtoms.push( | ||
fadeAtom({ | ||
direction: 'exit', | ||
duration: exitDuration, | ||
easing: exitEasing, | ||
}), | ||
); | ||
} else { | ||
// Since there is no fade-out, use visibility to hide the element | ||
enterAtoms.push(visibilityAtom({ direction: 'exit', duration: exitDuration })); | ||
} | ||
|
||
return { | ||
enter: enterAtoms, | ||
exit: exitAtoms, | ||
}; | ||
}; | ||
|
||
/** A React component that applies slide in/out transitions to its children. */ | ||
export const Slide = createPresenceComponent(createSlidePresence()); | ||
|
||
export const SlideSnappy = createPresenceComponent( | ||
createSlidePresence({ | ||
enterDuration: motionTokens.durationNormal, | ||
enterEasing: motionTokens.curveDecelerateMax, | ||
exitDuration: motionTokens.durationNormal, | ||
exitEasing: motionTokens.curveAccelerateMax, | ||
}), | ||
); | ||
|
||
export const SlideRelaxed = createPresenceComponent( | ||
createSlidePresence({ | ||
enterDuration: motionTokens.durationGentle, | ||
enterEasing: motionTokens.curveDecelerateMid, | ||
exitDuration: motionTokens.durationGentle, | ||
exitEasing: motionTokens.curveAccelerateMid, | ||
}), | ||
); |
35 changes: 35 additions & 0 deletions
35
...ct-components/react-motion-components-preview/library/src/components/Slide/Slide.types.ts
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,35 @@ | ||
export type SlideOrientation = 'horizontal' | 'vertical'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export type SlideVariantParams_unstable = { | ||
/** Time (ms) for the enter transition. Defaults to the `durationNormal` value (200 ms). */ | ||
enterDuration?: number; | ||
|
||
/** Easing curve for the enter transition. Defaults to the `easeEaseMax` value. */ | ||
enterEasing?: string; | ||
|
||
/** Time (ms) for the exit transition. Defaults to the `enterDuration` param for symmetry. */ | ||
exitDuration?: number; | ||
|
||
/** Easing curve for the exit transition. Defaults to the `enterEasing` param for symmetry. */ | ||
exitEasing?: string; | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export type SlideRuntimeParams_unstable = { | ||
/** Whether to animate the opacity. Defaults to `true`. */ | ||
animateOpacity?: boolean; | ||
|
||
/** | ||
* The orientation of the slide animation: 'horizontal' or 'vertical' | ||
* @default 'vertical' | ||
*/ | ||
orientation?: SlideOrientation; | ||
|
||
/** | ||
* The distance of the slide, relative to the content's natural position. | ||
* Can be positive or negative, in pixels or other length units. | ||
* @default '10px' | ||
*/ | ||
distance?: string; | ||
}; |
1 change: 1 addition & 0 deletions
1
...es/react-components/react-motion-components-preview/library/src/components/Slide/index.ts
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 @@ | ||
export { Slide, SlideRelaxed, SlideSnappy, createSlidePresence } from './Slide'; |
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
19 changes: 19 additions & 0 deletions
19
...ages/react-components/react-motion-components-preview/stories/src/Slide/Slide.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,19 @@ | ||
import * as React from 'react'; | ||
import { PresenceComponentProps } from '@fluentui/react-components'; | ||
import { Slide } from '@fluentui/react-motion-components-preview'; | ||
|
||
const LoremIpsum = React.forwardRef<HTMLDivElement, React.HTMLProps<HTMLDivElement>>((props, ref) => ( | ||
<div ref={ref} {...props}> | ||
{'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. '.repeat( | ||
10, | ||
)} | ||
</div> | ||
)); | ||
|
||
export const DefaultSlide = (props: PresenceComponentProps) => { | ||
return ( | ||
<Slide {...props}> | ||
<LoremIpsum /> | ||
</Slide> | ||
); | ||
}; |
22 changes: 22 additions & 0 deletions
22
...react-motion-components-preview/stories/src/Slide/SlideCustomization.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,22 @@ | ||
- The predefined fade transition can be disabled by setting `animateOpacity` to `false`. | ||
- A scale variant can be created with the factory function `createSlidePresence()`, then converting the result to a React component using `createPresenceComponent()`: | ||
|
||
```tsx | ||
import { motionTokens, createPresenceComponentVariant } from '@fluentui/react-components'; | ||
import { createSlidePresence } from '@fluentui/react-motion-components-preview'; | ||
|
||
const CustomSlideVariant = createPresenceComponent( | ||
createSlidePresence({ | ||
enterDuration: motionTokens.durationSlow, | ||
enterEasing: motionTokens.curveEasyEaseMax, | ||
exitDuration: motionTokens.durationNormal, | ||
exitEasing: motionTokens.curveEasyEaseMax, | ||
}), | ||
); | ||
|
||
const CustomSlide = ({ visible }) => ( | ||
<CustomSlideVariant animateOpacity={false} unmountOnExit visible={visible}> | ||
{/* Content */} | ||
</CustomSlideVariant> | ||
); | ||
``` |
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.
🕵🏾♀️ visual regressions to review in the fluentuiv9 Visual Regression Report
Drawer 1 screenshots