@dust-tt/sparkle 0.2.512 → 0.2.513
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/dist/cjs/index.js +1 -1
- package/dist/esm/components/Button.js +6 -6
- package/dist/esm/components/Button.js.map +1 -1
- package/dist/esm/components/Spinner.d.ts +3 -2
- package/dist/esm/components/Spinner.d.ts.map +1 -1
- package/dist/esm/components/Spinner.js +84 -28
- package/dist/esm/components/Spinner.js.map +1 -1
- package/dist/esm/stories/Spinner.stories.d.ts.map +1 -1
- package/dist/esm/stories/Spinner.stories.js +20 -36
- package/dist/esm/stories/Spinner.stories.js.map +1 -1
- package/dist/sparkle.css +17 -5
- package/package.json +1 -1
- package/src/components/Button.tsx +6 -6
- package/src/components/Spinner.tsx +142 -40
- package/src/stories/Spinner.stories.tsx +32 -44
|
@@ -8,16 +8,24 @@ import animColorXS from "@sparkle/lottie/spinnerColorXS";
|
|
|
8
8
|
import animDark from "@sparkle/lottie/spinnerDark";
|
|
9
9
|
import animDarkLG from "@sparkle/lottie/spinnerDarkLG";
|
|
10
10
|
import animDarkXS from "@sparkle/lottie/spinnerDarkXS";
|
|
11
|
-
import
|
|
11
|
+
import animLight from "@sparkle/lottie/spinnerLight";
|
|
12
12
|
import animLightLG from "@sparkle/lottie/spinnerLightLG";
|
|
13
|
-
import
|
|
13
|
+
import animLightXS from "@sparkle/lottie/spinnerLightXS";
|
|
14
14
|
|
|
15
15
|
type SpinnerSizeType = (typeof SPINNER_SIZES)[number];
|
|
16
16
|
const SPINNER_SIZES = ["xs", "sm", "md", "lg", "xl", "xxl"] as const;
|
|
17
17
|
|
|
18
|
+
type SpinnerVariant =
|
|
19
|
+
| "mono"
|
|
20
|
+
| "revert"
|
|
21
|
+
| "light"
|
|
22
|
+
| "dark"
|
|
23
|
+
| "color"
|
|
24
|
+
| SpinnerVariantType;
|
|
25
|
+
|
|
18
26
|
export interface SpinnerProps {
|
|
19
27
|
size?: SpinnerSizeType;
|
|
20
|
-
variant?:
|
|
28
|
+
variant?: SpinnerVariant;
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
// Generate all possible color-shade combinations
|
|
@@ -25,9 +33,10 @@ const colorVariants = Object.entries(customColors).flatMap(([color, shades]) =>
|
|
|
25
33
|
Object.keys(shades).map((shade) => `${color}${shade}` as const)
|
|
26
34
|
);
|
|
27
35
|
|
|
28
|
-
const SPINNER_VARIANTS = ["color",
|
|
36
|
+
const SPINNER_VARIANTS = ["color", ...colorVariants] as const;
|
|
29
37
|
|
|
30
38
|
type SpinnerVariantType = (typeof SPINNER_VARIANTS)[number];
|
|
39
|
+
|
|
31
40
|
const pxSizeClasses: Record<SpinnerSizeType, string> = {
|
|
32
41
|
xs: "16",
|
|
33
42
|
sm: "20",
|
|
@@ -48,8 +57,6 @@ const hexToRgba = (hex: string): [number, number, number, number] => {
|
|
|
48
57
|
};
|
|
49
58
|
|
|
50
59
|
const colors: Record<Exclude<SpinnerVariantType, "color">, LottieColorType> = {
|
|
51
|
-
light: [1, 1, 1, 1],
|
|
52
|
-
dark: hexToRgba(customColors.gray[900]),
|
|
53
60
|
...Object.fromEntries(
|
|
54
61
|
colorVariants.map((variant) => {
|
|
55
62
|
const color = variant.match(/[a-z]+/)?.[0] as keyof typeof customColors;
|
|
@@ -87,53 +94,148 @@ const replaceColors = (obj: any, newColor: LottieColorType): any => {
|
|
|
87
94
|
return obj;
|
|
88
95
|
};
|
|
89
96
|
|
|
90
|
-
const Spinner: React.FC<SpinnerProps> = ({
|
|
91
|
-
size = "md",
|
|
92
|
-
variant = "color",
|
|
93
|
-
}) => {
|
|
97
|
+
const Spinner: React.FC<SpinnerProps> = ({ size = "md", variant = "mono" }) => {
|
|
94
98
|
const fullSize = parseInt(pxSizeClasses[size], 10);
|
|
95
99
|
|
|
96
|
-
|
|
100
|
+
// Handle custom color variants
|
|
101
|
+
if (
|
|
102
|
+
variant !== "revert" &&
|
|
103
|
+
variant !== "mono" &&
|
|
104
|
+
variant !== "color" &&
|
|
105
|
+
variant !== "light" &&
|
|
106
|
+
variant !== "dark"
|
|
107
|
+
) {
|
|
108
|
+
let anim;
|
|
109
|
+
switch (size) {
|
|
110
|
+
case "xs":
|
|
111
|
+
anim = animLightXS;
|
|
112
|
+
break;
|
|
113
|
+
case "xl":
|
|
114
|
+
case "xxl":
|
|
115
|
+
anim = animLightLG;
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
anim = animLight;
|
|
119
|
+
}
|
|
120
|
+
const animationData = replaceColors(
|
|
121
|
+
JSON.parse(JSON.stringify(anim)),
|
|
122
|
+
colors[variant]
|
|
123
|
+
);
|
|
124
|
+
return (
|
|
125
|
+
<Lottie
|
|
126
|
+
animationData={animationData}
|
|
127
|
+
style={{ width: `${fullSize}px`, height: `${fullSize}px` }}
|
|
128
|
+
loop
|
|
129
|
+
autoplay
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Handle color variant
|
|
135
|
+
if (variant === "color") {
|
|
136
|
+
let anim;
|
|
137
|
+
switch (size) {
|
|
138
|
+
case "xs":
|
|
139
|
+
anim = animColorXS;
|
|
140
|
+
break;
|
|
141
|
+
case "xl":
|
|
142
|
+
case "xxl":
|
|
143
|
+
anim = animColorLG;
|
|
144
|
+
break;
|
|
145
|
+
default:
|
|
146
|
+
anim = animColor;
|
|
147
|
+
}
|
|
148
|
+
return (
|
|
149
|
+
<Lottie
|
|
150
|
+
animationData={anim}
|
|
151
|
+
style={{ width: `${fullSize}px`, height: `${fullSize}px` }}
|
|
152
|
+
loop
|
|
153
|
+
autoplay
|
|
154
|
+
/>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (variant === "light") {
|
|
159
|
+
let anim;
|
|
160
|
+
switch (size) {
|
|
161
|
+
case "xs":
|
|
162
|
+
anim = animLightXS;
|
|
163
|
+
break;
|
|
164
|
+
case "xl":
|
|
165
|
+
case "xxl":
|
|
166
|
+
anim = animLightLG;
|
|
167
|
+
break;
|
|
168
|
+
default:
|
|
169
|
+
anim = animLight;
|
|
170
|
+
}
|
|
171
|
+
return (
|
|
172
|
+
<Lottie
|
|
173
|
+
animationData={anim}
|
|
174
|
+
style={{ width: `${fullSize}px`, height: `${fullSize}px` }}
|
|
175
|
+
loop
|
|
176
|
+
autoplay
|
|
177
|
+
/>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
97
180
|
|
|
181
|
+
if (variant === "dark") {
|
|
182
|
+
let anim;
|
|
183
|
+
switch (size) {
|
|
184
|
+
case "xs":
|
|
185
|
+
anim = animDarkXS;
|
|
186
|
+
break;
|
|
187
|
+
case "xl":
|
|
188
|
+
case "xxl":
|
|
189
|
+
anim = animDarkLG;
|
|
190
|
+
break;
|
|
191
|
+
default:
|
|
192
|
+
anim = animDark;
|
|
193
|
+
}
|
|
194
|
+
return (
|
|
195
|
+
<Lottie
|
|
196
|
+
animationData={anim}
|
|
197
|
+
style={{ width: `${fullSize}px`, height: `${fullSize}px` }}
|
|
198
|
+
loop
|
|
199
|
+
autoplay
|
|
200
|
+
/>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Handle mono variant (default)
|
|
205
|
+
let lightAnim;
|
|
206
|
+
let darkAnim;
|
|
98
207
|
switch (size) {
|
|
99
208
|
case "xs":
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
? animSimpleLight
|
|
103
|
-
: variant === "dark"
|
|
104
|
-
? animDarkXS
|
|
105
|
-
: animColorXS;
|
|
209
|
+
lightAnim = animLightXS;
|
|
210
|
+
darkAnim = animDarkXS;
|
|
106
211
|
break;
|
|
107
212
|
case "xl":
|
|
108
213
|
case "xxl":
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
? animLightLG
|
|
112
|
-
: variant === "dark"
|
|
113
|
-
? animDarkLG
|
|
114
|
-
: animColorLG;
|
|
214
|
+
lightAnim = animLightLG;
|
|
215
|
+
darkAnim = animDarkLG;
|
|
115
216
|
break;
|
|
116
217
|
default:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
? animLightXS
|
|
120
|
-
: variant === "dark"
|
|
121
|
-
? animDark
|
|
122
|
-
: animColor;
|
|
218
|
+
lightAnim = animLight;
|
|
219
|
+
darkAnim = animDark;
|
|
123
220
|
}
|
|
124
221
|
|
|
125
|
-
const animationData =
|
|
126
|
-
variant === "color"
|
|
127
|
-
? anim
|
|
128
|
-
: replaceColors(JSON.parse(JSON.stringify(anim)), colors[variant]);
|
|
129
|
-
|
|
130
222
|
return (
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
223
|
+
<>
|
|
224
|
+
<Lottie
|
|
225
|
+
animationData={variant && variant === "mono" ? darkAnim : lightAnim}
|
|
226
|
+
className="s-block dark:s-hidden"
|
|
227
|
+
style={{ width: `${fullSize}px`, height: `${fullSize}px` }}
|
|
228
|
+
loop
|
|
229
|
+
autoplay
|
|
230
|
+
/>
|
|
231
|
+
<Lottie
|
|
232
|
+
animationData={variant && variant === "mono" ? lightAnim : darkAnim}
|
|
233
|
+
className="s-hidden dark:s-block"
|
|
234
|
+
style={{ width: `${fullSize}px`, height: `${fullSize}px` }}
|
|
235
|
+
loop
|
|
236
|
+
autoplay
|
|
237
|
+
/>
|
|
238
|
+
</>
|
|
137
239
|
);
|
|
138
240
|
};
|
|
139
241
|
|
|
@@ -14,100 +14,88 @@ type Story = StoryObj<typeof meta>;
|
|
|
14
14
|
export const SpinnerExample = () => {
|
|
15
15
|
return (
|
|
16
16
|
<div className="s-flex s-flex-col s-gap-4">
|
|
17
|
-
|
|
17
|
+
<div className="s-heading-base s-text-foreground dark:s-text-white">
|
|
18
|
+
Size = XS
|
|
19
|
+
</div>
|
|
18
20
|
<div className="s-flex s-gap-4">
|
|
19
21
|
<div className="s-p-20">
|
|
20
22
|
<Spinner variant="color" size="xs" />
|
|
21
23
|
</div>
|
|
22
|
-
<div className="s-bg-primary-900 s-p-20">
|
|
23
|
-
<Spinner variant="light" size="xs" />
|
|
24
|
-
</div>
|
|
25
|
-
<div className="s-bg-blue-500 s-p-20">
|
|
26
|
-
<Spinner variant="light" size="xs" />
|
|
27
|
-
</div>
|
|
28
24
|
<div className="s-p-20">
|
|
29
|
-
<Spinner variant="
|
|
25
|
+
<Spinner variant="mono" size="xs" />
|
|
30
26
|
</div>
|
|
31
27
|
<div className="s-p-20">
|
|
32
28
|
<Spinner variant="rose300" size="xs" />
|
|
33
29
|
</div>
|
|
34
30
|
</div>
|
|
35
|
-
|
|
31
|
+
<div className="s-heading-base s-text-foreground dark:s-text-white">
|
|
32
|
+
Size = SM
|
|
33
|
+
</div>
|
|
36
34
|
<div className="s-flex s-gap-4">
|
|
37
35
|
<div className="s-p-20">
|
|
38
36
|
<Spinner variant="color" size="sm" />
|
|
39
37
|
</div>
|
|
40
|
-
<div className="s-bg-primary-900 s-p-20">
|
|
41
|
-
<Spinner variant="light" size="sm" />
|
|
42
|
-
</div>
|
|
43
|
-
<div className="s-bg-blue-500 s-p-20">
|
|
44
|
-
<Spinner variant="light" size="sm" />
|
|
45
|
-
</div>
|
|
46
38
|
<div className="s-p-20">
|
|
47
|
-
<Spinner variant="
|
|
39
|
+
<Spinner variant="mono" size="sm" />
|
|
48
40
|
</div>
|
|
49
41
|
<div className="s-p-20">
|
|
50
42
|
<Spinner variant="rose300" size="sm" />
|
|
51
43
|
</div>
|
|
52
44
|
</div>
|
|
53
|
-
|
|
45
|
+
<div className="s-heading-base s-text-foreground dark:s-text-white">
|
|
46
|
+
Size = MD
|
|
47
|
+
</div>
|
|
54
48
|
<div className="s-flex s-gap-4">
|
|
55
49
|
<div className="s-p-20">
|
|
56
50
|
<Spinner variant="color" size="md" />
|
|
57
51
|
</div>
|
|
58
|
-
<div className="s-
|
|
59
|
-
<Spinner variant="
|
|
60
|
-
</div>
|
|
61
|
-
<div className="s-bg-blue-500 s-p-20">
|
|
62
|
-
<Spinner variant="light" size="md" />
|
|
52
|
+
<div className="s-p-20">
|
|
53
|
+
<Spinner variant="mono" size="md" />
|
|
63
54
|
</div>
|
|
64
55
|
<div className="s-p-20">
|
|
65
|
-
<Spinner variant="
|
|
56
|
+
<Spinner variant="rose300" size="md" />
|
|
66
57
|
</div>
|
|
67
58
|
</div>
|
|
68
|
-
|
|
59
|
+
<div className="s-heading-base s-text-foreground dark:s-text-white">
|
|
60
|
+
Size = LG
|
|
61
|
+
</div>
|
|
69
62
|
<div className="s-flex s-gap-4">
|
|
70
63
|
<div className="s-p-20">
|
|
71
64
|
<Spinner variant="color" size="lg" />
|
|
72
65
|
</div>
|
|
73
|
-
<div className="s-
|
|
74
|
-
<Spinner variant="
|
|
75
|
-
</div>
|
|
76
|
-
<div className="s-bg-blue-500 s-p-20">
|
|
77
|
-
<Spinner variant="light" size="lg" />
|
|
66
|
+
<div className="s-p-20">
|
|
67
|
+
<Spinner variant="mono" size="lg" />
|
|
78
68
|
</div>
|
|
79
69
|
<div className="s-p-20">
|
|
80
|
-
<Spinner variant="
|
|
70
|
+
<Spinner variant="rose300" size="lg" />
|
|
81
71
|
</div>
|
|
82
72
|
</div>
|
|
83
|
-
|
|
73
|
+
<div className="s-heading-base s-text-foreground dark:s-text-white">
|
|
74
|
+
Size = XL
|
|
75
|
+
</div>
|
|
84
76
|
<div className="s-flex s-gap-4">
|
|
85
77
|
<div className="s-p-20">
|
|
86
78
|
<Spinner variant="color" size="xl" />
|
|
87
79
|
</div>
|
|
88
|
-
<div className="s-
|
|
89
|
-
<Spinner variant="
|
|
90
|
-
</div>
|
|
91
|
-
<div className="s-bg-blue-500 s-p-20">
|
|
92
|
-
<Spinner variant="light" size="xl" />
|
|
80
|
+
<div className="s-p-20">
|
|
81
|
+
<Spinner variant="mono" size="xl" />
|
|
93
82
|
</div>
|
|
94
83
|
<div className="s-p-20">
|
|
95
|
-
<Spinner variant="
|
|
84
|
+
<Spinner variant="rose300" size="xl" />
|
|
96
85
|
</div>
|
|
97
86
|
</div>
|
|
98
|
-
|
|
87
|
+
<div className="s-heading-base s-text-foreground dark:s-text-white">
|
|
88
|
+
Size = XXL
|
|
89
|
+
</div>
|
|
99
90
|
<div className="s-flex s-gap-4">
|
|
100
91
|
<div className="s-p-20">
|
|
101
92
|
<Spinner variant="color" size="xxl" />
|
|
102
93
|
</div>
|
|
103
|
-
<div className="s-
|
|
104
|
-
<Spinner variant="
|
|
105
|
-
</div>
|
|
106
|
-
<div className="s-bg-blue-500 s-p-20">
|
|
107
|
-
<Spinner variant="light" size="xxl" />
|
|
94
|
+
<div className="s-p-20">
|
|
95
|
+
<Spinner variant="mono" size="xxl" />
|
|
108
96
|
</div>
|
|
109
97
|
<div className="s-p-20">
|
|
110
|
-
<Spinner variant="
|
|
98
|
+
<Spinner variant="rose300" size="xxl" />
|
|
111
99
|
</div>
|
|
112
100
|
</div>
|
|
113
101
|
</div>
|