Skip to content

Commit

Permalink
refactor(Collapse): move fade atom to own file
Browse files Browse the repository at this point in the history
- put in a new atoms folder that is shared amongst motion components
- rename from opacityAtom to fadeAtom
  • Loading branch information
robertpenner committed Dec 16, 2024
1 parent 868fbc4 commit d84a7fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PresenceDirection, motionTokens } from '@fluentui/react-motion';

export const fadeAtom = (direction: PresenceDirection, duration: number, easing: string = motionTokens.curveLinear) => {
const keyframes = [{ opacity: 0 }, { opacity: 1 }];
if (direction === 'exit') {
keyframes.reverse();
}
return {
keyframes,
duration,
easing,
};
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { motionTokens, createPresenceComponent, AtomMotion } from '@fluentui/react-motion';
import type { PresenceMotionFnCreator } from '../../types';
import type { CollapseDelayedVariantParams, CollapseRuntimeParams, CollapseVariantParams } from './collapse-types';
import { sizeEnterAtom, opacityAtom, whitespaceAtom, sizeExitAtom } from './collapse-atoms';
import { sizeEnterAtom, sizeExitAtom, whitespaceAtom } from './collapse-atoms';
import { fadeAtom } from '../../atoms/fade-atom';

/** Define a presence motion for collapse/expand that can stagger the size and opacity motions by a given delay. */
export const createCollapseDelayedPresence: PresenceMotionFnCreator<
Expand Down Expand Up @@ -30,15 +31,15 @@ export const createCollapseDelayedPresence: PresenceMotionFnCreator<
];
// Fade in only if animateOpacity is true. Otherwise, leave opacity unaffected.
if (animateOpacity) {
enterAtoms.push({ ...opacityAtom('enter', enterOpacityDuration, enterEasing), delay: enterDelay, fill: 'both' });
enterAtoms.push({ ...fadeAtom('enter', enterOpacityDuration, enterEasing), delay: enterDelay, fill: 'both' });
}

// ----- EXIT -----
// The exit transition is an array of up to 3 motion atoms: opacity, size and whitespace.
const exitAtoms: AtomMotion[] = [];
// Fade out only if animateOpacity is true. Otherwise, leave opacity unaffected.
if (animateOpacity) {
exitAtoms.push(opacityAtom('exit', exitOpacityDuration, exitEasing));
exitAtoms.push(fadeAtom('exit', exitOpacityDuration, exitEasing));
}
exitAtoms.push(sizeExitAtom(orientation, exitSizeDuration, exitEasing, element, exitDelay));
exitAtoms.push(whitespaceAtom('exit', orientation, exitSizeDuration, exitEasing, exitDelay));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,3 @@ export const whitespaceAtom = (
}
return atom;
};

// ----- OPACITY -----

export const opacityAtom = (
direction: PresenceDirection,
duration: number,
easing: string = motionTokens.curveLinear,
) => {
const keyframes = [{ opacity: 0 }, { opacity: 1 }];
if (direction === 'exit') {
keyframes.reverse();
}
return {
keyframes,
duration,
easing,
};
};

0 comments on commit d84a7fa

Please sign in to comment.