UNPKG

1.86 kBJavaScriptView Raw
1import { keyframes, css } from '@emotion/css';
2import { VisuallyHidden } from '@spark-web/a11y';
3import { Box } from '@spark-web/box';
4import { createIcon } from '@spark-web/icon';
5import { useSynchronizedAnimation } from '@spark-web/utils';
6import { jsx, jsxs } from 'react/jsx-runtime';
7
8function 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 /*#__PURE__*/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: [/*#__PURE__*/jsx(VisuallyHidden, {
27 children: "Image of a partial circle indicating \"loading\"."
28 }), /*#__PURE__*/jsx(SpinnerIcon, {
29 size: size,
30 tone: tone,
31 ref: strokeAnimationRef,
32 "aria-hidden": "true"
33 })]
34 });
35}
36Spinner.displayName = 'Spinner';
37var SpinnerIcon = createIcon( /*#__PURE__*/jsx("circle", {
38 cx: 12,
39 cy: 12,
40 r: 9
41}), 'SpinnerIcon');
42var spinAnimation = keyframes({
43 from: {
44 transform: 'rotate(0deg)'
45 },
46 to: {
47 transform: 'rotate(360deg)'
48 }
49});
50var strokeDashAnimation = keyframes({
51 '0%': {
52 strokeDasharray: '1px, 200px',
53 strokeDashoffset: 0
54 },
55 '100%': {
56 strokeDasharray: '200px, 200px',
57 strokeDashoffset: '-55px'
58 }
59});
60
61function 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
70export { Spinner };