@orsetra/shared-ui 1.10.32 → 1.10.33
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/components/ui/spinner.tsx +55 -53
- package/package.json +1 -1
|
@@ -3,80 +3,82 @@ import * as React from "react"
|
|
|
3
3
|
import { cn } from "../../lib/utils"
|
|
4
4
|
|
|
5
5
|
export interface SpinnerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
6
|
-
size?: "sm" | "md" | "lg"
|
|
6
|
+
size?: "xs" | "sm" | "md" | "lg"
|
|
7
|
+
/** "inverse" draws the whole sign in white, for a blue or dark surface such as a primary button. */
|
|
8
|
+
tone?: "default" | "inverse"
|
|
7
9
|
/** Accessible label announced to screen readers while loading. */
|
|
8
10
|
label?: string
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
const SIZE_PX: Record<NonNullable<SpinnerProps["size"]>, number> = {
|
|
14
|
+
xs: 16,
|
|
12
15
|
sm: 20,
|
|
13
16
|
md: 32,
|
|
14
17
|
lg: 48,
|
|
15
18
|
}
|
|
16
19
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const TONES: Record<NonNullable<SpinnerProps["tone"]>, { parties: string; exchange: string }> = {
|
|
21
|
+
default: { parties: "#161616", exchange: "#0F62FE" },
|
|
22
|
+
inverse: { parties: "#FFFFFF", exchange: "#FFFFFF" },
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const STEP_DELAY_S = 0.3
|
|
26
|
+
|
|
27
|
+
const MOTION = `
|
|
28
|
+
@keyframes cx-spinner-relay {
|
|
29
|
+
0%, 60%, 100% { opacity: 0.22; }
|
|
30
|
+
18%, 34% { opacity: 1; }
|
|
31
|
+
}
|
|
32
|
+
@keyframes cx-spinner-calm {
|
|
33
|
+
0%, 100% { opacity: 1; }
|
|
34
|
+
50% { opacity: 0.35; }
|
|
35
|
+
}
|
|
36
|
+
.cx-spinner-part {
|
|
37
|
+
opacity: 0.22;
|
|
38
|
+
animation: cx-spinner-relay 1.5s cubic-bezier(0.2, 0, 0.38, 0.9) infinite;
|
|
39
|
+
}
|
|
40
|
+
@media (prefers-reduced-motion: reduce) {
|
|
41
|
+
.cx-spinner-part { opacity: 1; animation: none; }
|
|
42
|
+
.cx-spinner-exchange { animation: cx-spinner-calm 2.4s ease-in-out infinite; }
|
|
43
|
+
}
|
|
44
|
+
`
|
|
45
|
+
|
|
46
|
+
function Spinner({ size = "md", tone = "default", label = "Loading", className, ...props }: SpinnerProps) {
|
|
22
47
|
const px = SIZE_PX[size]
|
|
23
|
-
const
|
|
48
|
+
const colors = TONES[tone]
|
|
49
|
+
const delay = (step: number): React.CSSProperties => ({ animationDelay: `${step * STEP_DELAY_S}s` })
|
|
24
50
|
|
|
25
51
|
return (
|
|
26
52
|
<div
|
|
27
53
|
role="status"
|
|
28
54
|
aria-label={label}
|
|
29
|
-
className={cn("
|
|
55
|
+
className={cn("inline-flex items-center justify-center flex-shrink-0", className)}
|
|
30
56
|
style={{ width: px, height: px }}
|
|
31
57
|
{...props}
|
|
32
58
|
>
|
|
33
|
-
<svg
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
<circle
|
|
41
|
-
cx="16"
|
|
42
|
-
cy="16"
|
|
43
|
-
r="14.5"
|
|
44
|
-
fill="none"
|
|
45
|
-
stroke="#0F62FE"
|
|
46
|
-
strokeOpacity="0.15"
|
|
47
|
-
strokeWidth="2.5"
|
|
59
|
+
<svg width={px} height={px} viewBox="0 0 64 64" aria-hidden="true">
|
|
60
|
+
<style>{MOTION}</style>
|
|
61
|
+
<polygon
|
|
62
|
+
className="cx-spinner-part"
|
|
63
|
+
style={delay(0)}
|
|
64
|
+
fill={colors.parties}
|
|
65
|
+
points="5,8 13,8 25,32 13,56 5,56 17,32"
|
|
48
66
|
/>
|
|
49
|
-
<
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
67
|
+
<rect
|
|
68
|
+
className="cx-spinner-part cx-spinner-exchange"
|
|
69
|
+
style={delay(1)}
|
|
70
|
+
fill={colors.exchange}
|
|
71
|
+
x="27"
|
|
72
|
+
y="27"
|
|
73
|
+
width="10"
|
|
74
|
+
height="10"
|
|
75
|
+
/>
|
|
76
|
+
<polygon
|
|
77
|
+
className="cx-spinner-part"
|
|
78
|
+
style={delay(2)}
|
|
79
|
+
fill={colors.parties}
|
|
80
|
+
points="59,8 51,8 39,32 51,56 59,56 47,32"
|
|
58
81
|
/>
|
|
59
|
-
</svg>
|
|
60
|
-
<svg
|
|
61
|
-
width={iconPx}
|
|
62
|
-
height={iconPx}
|
|
63
|
-
viewBox="0 0 32 32"
|
|
64
|
-
className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2"
|
|
65
|
-
>
|
|
66
|
-
<rect width="32" height="32" rx="7" fill="#0F62FE" />
|
|
67
|
-
<text
|
|
68
|
-
x="16.5"
|
|
69
|
-
y="17"
|
|
70
|
-
fontFamily="Helvetica Neue, Arial, sans-serif"
|
|
71
|
-
fontWeight="700"
|
|
72
|
-
fontSize="13"
|
|
73
|
-
letterSpacing="-0.75"
|
|
74
|
-
fill="#FFFFFF"
|
|
75
|
-
textAnchor="middle"
|
|
76
|
-
dominantBaseline="central"
|
|
77
|
-
>
|
|
78
|
-
CX
|
|
79
|
-
</text>
|
|
80
82
|
</svg>
|
|
81
83
|
<span className="sr-only">{label}</span>
|
|
82
84
|
</div>
|