1 | import { keyframes, css } from '@emotion/css';
|
2 | import { VisuallyHidden } from '@spark-web/a11y';
|
3 | import { Box } from '@spark-web/box';
|
4 | import { createIcon } from '@spark-web/icon';
|
5 | import { useSynchronizedAnimation } from '@spark-web/utils';
|
6 | import { jsx, jsxs } from 'react/jsx-runtime';
|
7 |
|
8 | function Spinner(_ref) {
|
9 | var tone = _ref.tone,
|
10 | _ref$size = _ref.size,
|
11 | size = _ref$size === void 0 ? 'xxsmall' : _ref$size,
|
12 | data = _ref.data;
|
13 | var spinAnimationRef = useSynchronizedAnimation(spinAnimation);
|
14 | var strokeAnimationRef = useSynchronizedAnimation(strokeDashAnimation);
|
15 | var styles = useSpinnerStyles();
|
16 | return jsxs(Box, {
|
17 | as: "span",
|
18 | ref: spinAnimationRef,
|
19 | className: css(styles),
|
20 | height: size,
|
21 | width: size,
|
22 | display: "inline-flex",
|
23 | alignItems: "center",
|
24 | justifyContent: "center",
|
25 | data: data,
|
26 | children: [jsx(VisuallyHidden, {
|
27 | children: "Image of a partial circle indicating \"loading\"."
|
28 | }), jsx(SpinnerIcon, {
|
29 | size: size,
|
30 | tone: tone,
|
31 | ref: strokeAnimationRef,
|
32 | "aria-hidden": "true"
|
33 | })]
|
34 | });
|
35 | }
|
36 | Spinner.displayName = 'Spinner';
|
37 | var SpinnerIcon = createIcon( jsx("circle", {
|
38 | cx: 12,
|
39 | cy: 12,
|
40 | r: 9
|
41 | }), 'SpinnerIcon');
|
42 | var spinAnimation = keyframes({
|
43 | from: {
|
44 | transform: 'rotate(0deg)'
|
45 | },
|
46 | to: {
|
47 | transform: 'rotate(360deg)'
|
48 | }
|
49 | });
|
50 | var strokeDashAnimation = keyframes({
|
51 | '0%': {
|
52 | strokeDasharray: '1px, 200px',
|
53 | strokeDashoffset: 0
|
54 | },
|
55 | '100%': {
|
56 | strokeDasharray: '200px, 200px',
|
57 | strokeDashoffset: '-55px'
|
58 | }
|
59 | });
|
60 |
|
61 | function useSpinnerStyles() {
|
62 | return {
|
63 | animation: "".concat(spinAnimation, " 1.4s linear infinite"),
|
64 | '& circle': {
|
65 | animation: "".concat(strokeDashAnimation, " 1.6s cubic-bezier(0.47, 0, 0.75, 0.72) infinite")
|
66 | }
|
67 | };
|
68 | }
|
69 |
|
70 | export { Spinner };
|