-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAmplitudeIndicators.tsx
59 lines (56 loc) · 1.5 KB
/
AmplitudeIndicators.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/** @jsxImportSource @emotion/react */
import { css, Interpolation, Theme } from "@emotion/react";
import { AnimationControls, motion } from "framer-motion";
import { ComponentProps } from "react";
export type AmplitudeIndicatorsProps = {
/** The amplitudes to display */
amplitudes: number[];
/** The function to generate the style and css for each amplitude */
amplitudeProps: (amplitude: number) => {
animate: AnimationControls;
style: React.CSSProperties;
css: Interpolation<Theme>;
};
/** The gap between the amplitude indicators */
gap: number;
} & ComponentProps<typeof motion.div>;
export default function AmplitudeIndicators({
amplitudes,
amplitudeProps,
gap,
...props
}: AmplitudeIndicatorsProps) {
return (
<motion.div
css={css`
display: flex;
align-items: center;
justify-content: center;
height: 100%;
width: 100%;
& > *:not(:last-child) {
margin-right: ${gap}px;
}
`}
{...props}
>
{amplitudes.map((value, index) => {
const {
animate: amplitudeAnimate,
style: amplitudeStyle,
css: amplitudeCss,
} = amplitudeProps(value);
return (
<motion.div
key={index}
initial={{ opacity: 0 }}
animate={{ opacity: 1, ...amplitudeAnimate }}
exit={{ opacity: 0 }}
style={amplitudeStyle}
css={amplitudeCss}
/>
);
})}
</motion.div>
);
}