Skip to content
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

refactor(MessageBar): migrate slide & fade to motion components #33465

Merged
merged 25 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8f8483a
refactor(MessageBar): migrate slide to motion component
robertpenner Dec 13, 2024
67e6aaf
refactor(MessageBar): move motions to own file
robertpenner Dec 13, 2024
0d1b177
chore: `yarn nx generate-api`
robertpenner Dec 13, 2024
7e48afe
chore(MessageBar): delete or deprecate unused code
robertpenner Dec 13, 2024
3b9ff97
chore: `yarn change`
robertpenner Dec 13, 2024
d4bfcac
chore(MessageBar): delete unused MessageBarTransition.tsx
robertpenner Dec 13, 2024
551a4a4
chore(MessageBar): roll back deprecations of MessageBarTransitionContext
robertpenner Dec 13, 2024
9805fc6
chore(MessageBar): ignore lint warning for newly deprecated className
robertpenner Dec 13, 2024
426e458
chore(MessageBar): add todo comments
robertpenner Dec 13, 2024
84168bc
refactor(MessageBar): rename opacityAtom to fadeAtom; add docs
robertpenner Dec 16, 2024
af16966
Merge branch 'master' into refactor/messagebar-slide
robertpenner Dec 17, 2024
0026734
Merge branch 'master' into refactor/messagebar-slide
robertpenner Dec 17, 2024
56708e0
chore: remove fade-atom.ts WIP file which was accidentally committed
robertpenner Dec 17, 2024
ee1613c
refactor(MessageBar): delete and deprecate unused CSS animation code
robertpenner Dec 17, 2024
c8a3437
Merge branch 'master' into refactor/messagebar-slide
robertpenner Dec 18, 2024
925985d
chore: remove trailing whitespace in package.json that was failing CI
robertpenner Dec 18, 2024
e55b7bb
refactor(Collapse): change atom functions to named arguments
robertpenner Dec 18, 2024
d8fea76
refactor(MessageBarGroup): rename and add jsdoc to motion functions
robertpenner Dec 18, 2024
dad61fb
Merge branch 'master' into refactor/messagebar-slide
robertpenner Dec 19, 2024
834480d
refactor(MessageBarGroup): wrap conditional rendering in new MessageB…
robertpenner Dec 19, 2024
01b615a
Merge branch 'master' into refactor/messagebar-slide
robertpenner Dec 19, 2024
8fdaa1d
refactor(MessageBar): move conditional motion inside a single motion …
robertpenner Dec 19, 2024
42f6e03
Merge branch 'master' into refactor/messagebar-slide
robertpenner Dec 19, 2024
2a8fe3d
chore(MessageBar): remove unused import
robertpenner Dec 20, 2024
33eb22a
Merge branch 'master' into refactor/messagebar-slide
robertpenner Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
robertpenner marked this conversation as resolved.
Show resolved Hide resolved
"type": "minor",
"comment": "refactor(MessageBar): migrate slide & fade to motion components",
"packageName": "@fluentui/react-message-bar",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
"@fluentui/react-button": "^9.3.97",
"@fluentui/react-icons": "^2.0.245",
"@fluentui/react-jsx-runtime": "^9.0.47",
"@fluentui/react-motion": "^9.6.4",
"@fluentui/react-motion-components-preview": "^0.4.0",
"@fluentui/react-shared-contexts": "^9.21.1",
"@fluentui/react-link": "^9.3.4",
"@fluentui/react-theme": "^9.1.23",
"@fluentui/react-utilities": "^9.18.18",
"@griffel/react": "^1.5.22",
"@swc/helpers": "^0.5.1",
"react-transition-group": "^4.4.1"
"@swc/helpers": "^0.5.1"
},
"peerDependencies": {
"@types/react": ">=16.8.0 <19.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ export type MessageBarProps = ComponentProps<MessageBarSlots> &
export type MessageBarState = ComponentState<MessageBarSlots> &
Required<Pick<MessageBarProps, 'layout' | 'intent' | 'shape'>> &
Pick<MessageBarContextValue, 'actionsRef' | 'bodyRef' | 'titleId'> & {
/**
* @deprecated Code is unused, replaced by motion components
*/
transitionClassName: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const useMessageBar_unstable = (props: MessageBarProps, ref: React.Ref<HT
const autoReflow = layout === 'auto';
const { ref: reflowRef, reflowing } = useMessageBarReflow(autoReflow);
const computedLayout = autoReflow ? (reflowing ? 'multiline' : 'singleline') : layout;
// eslint-disable-next-line deprecation/deprecation
const { className: transitionClassName, nodeRef } = useMessageBarTransitionContext();
const actionsRef = React.useRef<HTMLDivElement | null>(null);
const bodyRef = React.useRef<HTMLDivElement | null>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export const useMessageBarStyles_unstable = (state: MessageBarState): MessageBar
state.layout === 'multiline' && styles.rootMultiline,
state.shape === 'square' && styles.square,
rootIntentStyles[state.intent],
state.transitionClassName,
state.root.className,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { motionTokens, createPresenceComponent, PresenceDirection, AtomMotion } from '@fluentui/react-motion';

// TODO: import these atoms from react-motion-components-preview once they're available there

/**
* Generates a motion atom object for a fade in or fade out.
* @param direction - The functional direction of the motion: 'enter' or 'exit'.
* @param duration - The duration of the motion in milliseconds.
* @param easing - The easing curve for the motion. Defaults to `motionTokens.curveLinear`.
* @returns A motion atom object with opacity keyframes and the supplied duration and easing.
*/
const fadeAtom = (
direction: PresenceDirection,
duration: number,
easing: string = motionTokens.curveLinear,
): AtomMotion => {
const keyframes = [{ opacity: 0 }, { opacity: 1 }];
if (direction === 'exit') {
keyframes.reverse();
}
return {
keyframes,
duration,
easing,
};
};

/**
* Generates a motion atom object for an X or Y translation, from a specified distance to zero.
* @param direction - The functional direction of the motion: 'enter' or 'exit'.
* @param axis - The axis of the translation: 'X' or 'Y'.
* @param distance - The distance to slide; it can be a percentage or pixels.
* @param duration - The duration of the motion in milliseconds.
* @param easing - The easing curve for the motion. Defaults to `motionTokens.curveDecelerateMid`.
*/
const slideAtom = (
direction: PresenceDirection,
axis: 'X' | 'Y',
distance: string,
duration: number,
easing: string = motionTokens.curveDecelerateMid,
): AtomMotion => {
const keyframes = [{ transform: `translate${axis}(${distance})` }, { transform: 'translate${axis}(0)' }];
if (direction === 'exit') {
keyframes.reverse();
}
return {
keyframes,
duration,
easing,
};
};

export const SlideInFadeOut = createPresenceComponent(() => {
const duration = motionTokens.durationGentle;

return {
enter: [fadeAtom('enter', duration), slideAtom('enter', 'Y', '-100%', duration)],
robertpenner marked this conversation as resolved.
Show resolved Hide resolved

exit: fadeAtom('exit', duration),
};
});

export const FadeOut = createPresenceComponent(() => {
return {
enter: [],

exit: fadeAtom('exit', motionTokens.durationGentle),
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type MessageBarGroupProps = ComponentProps<MessageBarGroupSlots> & {
*/
export type MessageBarGroupState = ComponentState<MessageBarGroupSlots> &
Pick<MessageBarGroupProps, 'animate'> & {
// TODO: deprecate these 2 obsolete props?
robertpenner marked this conversation as resolved.
Show resolved Hide resolved
enterStyles: string;
exitStyles: string;
children: React.ReactElement[];
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { assertSlots } from '@fluentui/react-utilities';
import type { MessageBarGroupState, MessageBarGroupSlots } from './MessageBarGroup.types';
import { TransitionGroup } from 'react-transition-group';
import { MessageBarTransition } from './MessageBarTransition';
import { PresenceGroup } from '@fluentui/react-motion';
import { SlideInFadeOut, FadeOut } from './MessageBarGroup.motions';

/**
* Render the final JSX of MessageBarGroup
Expand All @@ -14,18 +14,17 @@ export const renderMessageBarGroup_unstable = (state: MessageBarGroupState) => {

return (
<state.root>
<TransitionGroup component={null}>
{state.children.map(child => (
<MessageBarTransition
animate={state.animate}
key={child.key}
enterClassName={state.enterStyles}
exitClassName={state.exitStyles}
>
{child}
</MessageBarTransition>
))}
</TransitionGroup>
<PresenceGroup>
{state.children.map(child =>
state.animate === 'both' ? (
// enter with slide and fade; exit with fade
<SlideInFadeOut key={child.key}>{child}</SlideInFadeOut>
) : (
// no enter motion; exit with fade
<FadeOut key={child.key}>{child}</FadeOut>
),
)}
robertpenner marked this conversation as resolved.
Show resolved Hide resolved
</PresenceGroup>
</state.root>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const messageBarGroupClassNames: SlotClassNames<MessageBarGroupSlots> = {
root: 'fui-MessageBarGroup',
};

// TODO: delete this obsolete code to save bytes?
robertpenner marked this conversation as resolved.
Show resolved Hide resolved
/**
* Styles for the root slot
*/
Expand Down Expand Up @@ -49,6 +50,7 @@ export const useMessageBarGroupStyles_unstable = (state: MessageBarGroupState):

const styles = useStyles();
state.root.className = mergeClasses(messageBarGroupClassNames.root, state.root.className);
// TODO: delete these 2 lines to save bytes?
state.enterStyles = mergeClasses(styles.base, styles.enter);
state.exitStyles = mergeClasses(styles.base, styles.exit);
return state;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as React from 'react';

export type MessageBarTransitionContextValue = {
/**
* @deprecated CSS className is no longer used for this transition, replaced by motion components
*/
className: string;
nodeRef: React.Ref<HTMLDivElement | null>;
};
Expand All @@ -16,7 +19,7 @@ export const messageBarTransitionContextDefaultValue: MessageBarTransitionContex
};

/**
* Context to pass animation className to MessageBar components
* Context to pass nodeRef for animation to MessageBar components
* @internal
*/
export const MessageBarTransitionContextProvider = messageBarTransitionContext.Provider;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { PresenceDirection, motionTokens } from '@fluentui/react-motion';
Loading