Skip to content

Commit

Permalink
refactor(react-positioning): migrate opacity transition to Fade compo…
Browse files Browse the repository at this point in the history
…nent
  • Loading branch information
robertpenner committed Dec 9, 2024
1 parent 9fbffc9 commit d529ef8
Showing 1 changed file with 6 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,12 @@ import { DATA_POSITIONING_PLACEMENT } from './constants';
* @returns Griffel styles to spread to a slot
*/
export function createSlideStyles(mainAxis: number): GriffelStyle {
const fadeIn = {
from: {
opacity: 0,
},
to: {
opacity: 1,
},
};

const slideDistanceVarX = '--fui-positioning-slide-distance-x';
const slideDistanceVarY = '--fui-positioning-slide-distance-y';

return {
// The fade has absolute values, whereas the slide amount is relative.
animationComposition: 'replace, accumulate',
// The slide amount is relative
animationComposition: 'accumulate',
animationDuration: tokens.durationSlower,
animationTimingFunction: tokens.curveDecelerateMid,
[slideDistanceVarX]: `0px`,
Expand All @@ -43,7 +34,6 @@ export function createSlideStyles(mainAxis: number): GriffelStyle {
},

animationName: [
fadeIn,
{
from: {
transform: `translate(var(${slideDistanceVarX}), var(${slideDistanceVarY}))`,
Expand All @@ -55,17 +45,16 @@ export function createSlideStyles(mainAxis: number): GriffelStyle {
// Note: at-rules have more specificity in Griffel
'@media(prefers-reduced-motion)': {
[`&[${DATA_POSITIONING_PLACEMENT}]`]: {
animationComposition: 'replace',
animationDuration: '1ms',
animationName: fadeIn,
// Omit the slide animation
animationName: {},
},
},

// Tested in Firefox 79
'@supports not (animation-composition: accumulate)': {
[`&[${DATA_POSITIONING_PLACEMENT}]`]: {
animationComposition: 'replace',
animationName: fadeIn,
// Omit the slide animation
animationName: {},
},
},
};
Expand Down

0 comments on commit d529ef8

Please sign in to comment.