Skip to content

Commit 46d6ad5

Browse files
jpggvilacadwesolow
authored andcommitted
Replace three-dots-flashing custom implementation with framer-motion
1 parent db1df30 commit 46d6ad5

File tree

1 file changed

+43
-30
lines changed

1 file changed

+43
-30
lines changed
Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
// Copyright (C) 2022-2025 Intel Corporation
22
// LIMITED EDGE SOFTWARE DISTRIBUTION LICENSE
33

4-
import { CSSProperties } from 'react';
5-
6-
import clsx from 'clsx';
4+
import { motion } from 'framer-motion';
75

86
import { ColorMode } from '../quiet-button/quiet-action-button.component';
97

10-
import classes from './three-dots-flashing.component.module.scss';
11-
128
type Sizes = 'S' | 'M';
139

1410
interface ThreeDotsFlashingProps {
@@ -17,40 +13,57 @@ interface ThreeDotsFlashingProps {
1713
className?: string;
1814
}
1915

16+
const DOT_COLORS: Record<ColorMode, string> = {
17+
[ColorMode.DARK]: 'var(--spectrum-global-color-gray-800)',
18+
[ColorMode.LIGHT]: 'var(--spectrum-global-color-gray-50)',
19+
[ColorMode.BLUE]: 'var(--spectrum-global-color-gray-800)',
20+
};
21+
22+
const DOT_SIZES: Record<Sizes, number> = {
23+
S: 8,
24+
M: 16,
25+
};
26+
2027
export const ThreeDotsFlashing = ({
2128
mode = ColorMode.DARK,
2229
size = 'M',
2330
className,
2431
}: ThreeDotsFlashingProps): JSX.Element => {
25-
const colors: Record<ColorMode, CSSProperties> = {
26-
[ColorMode.DARK]: {
27-
'--bgColorStartAnimation': 'var(--spectrum-global-color-gray-800)',
28-
'--bgColorEndAnimation': 'var(--white-down)',
29-
} as CSSProperties,
30-
[ColorMode.LIGHT]: {
31-
'--bgColorStartAnimation': 'var(--spectrum-global-color-gray-50)',
32-
'--bgColorEndAnimation': 'var(--dark-down)',
33-
} as CSSProperties,
34-
[ColorMode.BLUE]: {
35-
'--bgColorStartAnimation': 'var(--spectrum-global-color-gray-800)',
36-
'--bgColorEndAnimation': 'var(--white-down)',
37-
} as CSSProperties,
38-
};
32+
const dotColor = DOT_COLORS[mode];
33+
const dotSize = DOT_SIZES[size];
3934

40-
const sizes: Record<Sizes, CSSProperties> = {
41-
S: {
42-
'--dotSize': 'var(--spectrum-global-dimension-size-25)',
43-
} as CSSProperties,
44-
M: {
45-
'--dotSize': 'var(--spectrum-global-dimension-size-50)',
46-
} as CSSProperties,
35+
const dotVariants = {
36+
pulse: {
37+
scale: [1, 1.5, 1],
38+
transition: {
39+
duration: 1.2,
40+
repeat: Infinity,
41+
ease: 'easeInOut',
42+
},
43+
},
4744
};
4845

4946
return (
5047
<div
51-
style={{ ...colors[mode], ...sizes[size] }}
52-
className={clsx(classes.flashingAnimation, className)}
53-
aria-label={'three dots flashing animation'}
54-
></div>
48+
style={{ display: 'flex', gap: dotSize, alignItems: 'center', justifyContent: 'center' }}
49+
aria-label='three dots flashing animation'
50+
className={className}
51+
>
52+
{[0, 1, 2].map((i) => (
53+
<motion.div
54+
key={i}
55+
variants={dotVariants}
56+
animate='pulse'
57+
transition={{ delay: i * 0.2 }}
58+
style={{
59+
width: dotSize,
60+
height: dotSize,
61+
borderRadius: '50%',
62+
background: dotColor,
63+
willChange: 'transform',
64+
}}
65+
/>
66+
))}
67+
</div>
5568
);
5669
};

0 commit comments

Comments
 (0)