@sonardigital/carbon-ui 1.2.17 → 1.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/atoms/bounce/Bounce.tsx +55 -0
- package/src/components/atoms/bounce/index.ts +2 -0
- package/src/components/atoms/index.ts +2 -0
- package/src/components/atoms/pulsing-badge/PulsingBadge.tsx +106 -0
- package/src/components/atoms/pulsing-badge/index.ts +1 -0
package/package.json
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { motion, useReducedMotion, type Transition } from 'framer-motion';
|
|
2
|
+
|
|
3
|
+
export type BounceProps = React.PropsWithChildren<{
|
|
4
|
+
className?: string;
|
|
5
|
+
style?: React.CSSProperties;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
tapScale?: number;
|
|
8
|
+
tapY?: number;
|
|
9
|
+
transition?: Transition;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export function Bounce({
|
|
13
|
+
children,
|
|
14
|
+
className,
|
|
15
|
+
style,
|
|
16
|
+
disabled = false,
|
|
17
|
+
tapScale = 0.98,
|
|
18
|
+
tapY = 0,
|
|
19
|
+
transition,
|
|
20
|
+
}: BounceProps): React.ReactElement {
|
|
21
|
+
const reducedMotion = useReducedMotion();
|
|
22
|
+
|
|
23
|
+
const effectiveDisabled = disabled || reducedMotion;
|
|
24
|
+
const effectiveTransition: Transition = transition ?? {
|
|
25
|
+
type: 'spring',
|
|
26
|
+
stiffness: 520,
|
|
27
|
+
damping: 22,
|
|
28
|
+
mass: 0.55,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<motion.span
|
|
33
|
+
className={className}
|
|
34
|
+
style={{
|
|
35
|
+
display: 'inline-flex',
|
|
36
|
+
willChange: effectiveDisabled ? undefined : 'transform',
|
|
37
|
+
transform: effectiveDisabled ? undefined : 'translateZ(0)',
|
|
38
|
+
backfaceVisibility: 'hidden',
|
|
39
|
+
transformOrigin: 'center',
|
|
40
|
+
...style,
|
|
41
|
+
}}
|
|
42
|
+
whileTap={
|
|
43
|
+
effectiveDisabled
|
|
44
|
+
? undefined
|
|
45
|
+
: {
|
|
46
|
+
...(tapScale != null ? { scale: tapScale } : null),
|
|
47
|
+
...(tapY ? { y: tapY } : null),
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
transition={effectiveTransition}
|
|
51
|
+
>
|
|
52
|
+
{children}
|
|
53
|
+
</motion.span>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Box, keyframes, type BoxProps } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
const pulseRing = keyframes`
|
|
4
|
+
0% {
|
|
5
|
+
transform: scale(1);
|
|
6
|
+
opacity: 0.5;
|
|
7
|
+
}
|
|
8
|
+
100% {
|
|
9
|
+
transform: scale(1.35);
|
|
10
|
+
opacity: 0;
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
13
|
+
|
|
14
|
+
const pulseScale = keyframes`
|
|
15
|
+
0%, 100% {
|
|
16
|
+
transform: scale(1);
|
|
17
|
+
}
|
|
18
|
+
50% {
|
|
19
|
+
transform: scale(1.04);
|
|
20
|
+
}
|
|
21
|
+
`;
|
|
22
|
+
|
|
23
|
+
export type PulsingBadgeProps = BoxProps & {
|
|
24
|
+
children: React.ReactNode;
|
|
25
|
+
showBadge?: boolean;
|
|
26
|
+
badgePosition?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left';
|
|
27
|
+
badgeSize?: number;
|
|
28
|
+
badgeColor?: string;
|
|
29
|
+
pulseContent?: boolean;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function PulsingBadge({
|
|
33
|
+
children,
|
|
34
|
+
showBadge = true,
|
|
35
|
+
badgePosition = 'top-right',
|
|
36
|
+
badgeSize = 10,
|
|
37
|
+
badgeColor = 'primary.main',
|
|
38
|
+
pulseContent = false,
|
|
39
|
+
sx,
|
|
40
|
+
...props
|
|
41
|
+
}: PulsingBadgeProps): React.ReactElement {
|
|
42
|
+
const badgeOffsets =
|
|
43
|
+
badgePosition === 'top-left'
|
|
44
|
+
? { top: -4, left: -4 }
|
|
45
|
+
: badgePosition === 'bottom-right'
|
|
46
|
+
? { bottom: -4, right: -4 }
|
|
47
|
+
: badgePosition === 'bottom-left'
|
|
48
|
+
? { bottom: -4, left: -4 }
|
|
49
|
+
: { top: -4, right: -4 };
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<Box
|
|
53
|
+
{...props}
|
|
54
|
+
sx={{
|
|
55
|
+
position: 'relative',
|
|
56
|
+
display: 'inline-flex',
|
|
57
|
+
'& > *': {
|
|
58
|
+
position: 'relative',
|
|
59
|
+
zIndex: 1,
|
|
60
|
+
...(pulseContent
|
|
61
|
+
? { animation: `${pulseScale} 2s ease-in-out infinite` }
|
|
62
|
+
: null),
|
|
63
|
+
},
|
|
64
|
+
...(showBadge
|
|
65
|
+
? {
|
|
66
|
+
'& .PulsingBadge-badge': {
|
|
67
|
+
position: 'absolute',
|
|
68
|
+
zIndex: 2,
|
|
69
|
+
width: badgeSize,
|
|
70
|
+
height: badgeSize,
|
|
71
|
+
borderRadius: 999,
|
|
72
|
+
backgroundColor: badgeColor,
|
|
73
|
+
boxShadow: theme =>
|
|
74
|
+
`0 0 0 2px ${theme.palette.background.paper}`,
|
|
75
|
+
pointerEvents: 'none',
|
|
76
|
+
...badgeOffsets,
|
|
77
|
+
'&::before': {
|
|
78
|
+
content: '""',
|
|
79
|
+
position: 'absolute',
|
|
80
|
+
inset: -6,
|
|
81
|
+
borderRadius: 999,
|
|
82
|
+
border: '2px solid',
|
|
83
|
+
borderColor: badgeColor,
|
|
84
|
+
opacity: 0.6,
|
|
85
|
+
animation: `${pulseRing} 1.8s ease-out infinite`,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
}
|
|
89
|
+
: null),
|
|
90
|
+
'@media (prefers-reduced-motion: reduce)': {
|
|
91
|
+
'& .PulsingBadge-badge::before': {
|
|
92
|
+
animation: 'none',
|
|
93
|
+
opacity: 0,
|
|
94
|
+
},
|
|
95
|
+
'& > *': { animation: 'none' },
|
|
96
|
+
},
|
|
97
|
+
...sx,
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
{showBadge ? (
|
|
102
|
+
<Box component="span" className="PulsingBadge-badge" />
|
|
103
|
+
) : null}
|
|
104
|
+
</Box>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PulsingBadge';
|