@splenddev/kreativ-ui 0.2.7 → 0.2.9
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/README.md +987 -1965
- package/dist/index.cjs +1428 -1055
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +235 -269
- package/dist/index.d.ts +235 -269
- package/dist/index.js +1423 -1033
- package/dist/index.js.map +1 -1
- package/dist/styles/index.css +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { createContext, forwardRef, useState, useId, useRef, useEffect, useCallback, useLayoutEffect,
|
|
3
|
+
import { createContext, forwardRef, useState, useId, useRef, useEffect, useMemo, useCallback, useLayoutEffect, useContext, useReducer, Children, isValidElement } from 'react';
|
|
4
4
|
import { useReducedMotion, motion, AnimatePresence } from 'framer-motion';
|
|
5
5
|
import { clsx } from 'clsx';
|
|
6
6
|
import { twMerge } from 'tailwind-merge';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
|
-
import { ChevronDown, X, Heading, Bold, Italic, ListOrdered, ClipboardList, Code, Link, Check, Lock, Hash, Search, Link2, Phone, Mail, EyeOff, Eye, Sun, Moon, Monitor } from 'lucide-react';
|
|
8
|
+
import { ChevronDown, X, Heading, Bold, Italic, ListOrdered, ClipboardList, Code, Link, Minus, Check, Lock, Hash, Search, Link2, Phone, Mail, EyeOff, Eye, Sun, Moon, Monitor } from 'lucide-react';
|
|
9
9
|
import { cva } from 'class-variance-authority';
|
|
10
10
|
|
|
11
11
|
console.log("BANNER TEST");
|
|
@@ -28,20 +28,24 @@ function useTheme() {
|
|
|
28
28
|
return ctx;
|
|
29
29
|
}
|
|
30
30
|
__name(useTheme, "useTheme");
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
var applySizeOffset = /* @__PURE__ */ __name((value, offset) => {
|
|
32
|
+
if (!value || !offset) return value;
|
|
33
|
+
return `calc(${value} - ${offset})`;
|
|
34
|
+
}, "applySizeOffset");
|
|
35
|
+
function useSizeStyle(size, iconOnly = false, componentName = "componentName", options = {}) {
|
|
36
|
+
const { widthFromHeight = false, includeHeight = true, sizeOffset, fontSizeOffset } = options;
|
|
33
37
|
const { theme, fallbackSize } = useTheme();
|
|
34
38
|
return useMemo(() => {
|
|
35
39
|
const scale = theme.sizes;
|
|
36
40
|
const token = scale[size] ?? scale[fallbackSize] ?? Object.values(scale)[0] ?? {};
|
|
37
41
|
const style = {};
|
|
38
42
|
if (includeHeight && token.height) {
|
|
39
|
-
style.height = token.height;
|
|
43
|
+
style.height = applySizeOffset(token.height, sizeOffset);
|
|
40
44
|
}
|
|
41
45
|
if (token.width) {
|
|
42
|
-
style.width = token.width;
|
|
43
|
-
} else if (iconOnly && includeHeight && token.height) {
|
|
44
|
-
style.width = token.height;
|
|
46
|
+
style.width = applySizeOffset(token.width, sizeOffset);
|
|
47
|
+
} else if ((iconOnly || widthFromHeight) && includeHeight && token.height) {
|
|
48
|
+
style.width = applySizeOffset(token.height, sizeOffset);
|
|
45
49
|
}
|
|
46
50
|
if (!iconOnly && token.paddingX) {
|
|
47
51
|
style.paddingLeft = token.paddingX;
|
|
@@ -52,343 +56,32 @@ function useSizeStyle(size, iconOnly = false, component = "button", options = {}
|
|
|
52
56
|
style.paddingBottom = token.paddingY;
|
|
53
57
|
}
|
|
54
58
|
if (token.fontSize) {
|
|
55
|
-
style.fontSize = token.fontSize;
|
|
59
|
+
style.fontSize = applySizeOffset(token.fontSize, fontSizeOffset);
|
|
56
60
|
}
|
|
57
61
|
if (token.gap) {
|
|
58
62
|
style.gap = iconOnly ? 0 : token.gap;
|
|
59
63
|
}
|
|
60
64
|
if (token.radius) {
|
|
61
|
-
const varName = `--kui-${
|
|
65
|
+
const varName = `--kui-${componentName}-radius`;
|
|
62
66
|
style[varName] = token.radius;
|
|
63
67
|
}
|
|
64
68
|
return {
|
|
65
69
|
style,
|
|
66
|
-
iconSize: token.iconSize
|
|
70
|
+
iconSize: token.iconSize,
|
|
71
|
+
fontSize: applySizeOffset(token.fontSize, fontSizeOffset),
|
|
72
|
+
gap: token.gap
|
|
67
73
|
};
|
|
68
|
-
}, [
|
|
74
|
+
}, [
|
|
75
|
+
theme.sizes,
|
|
76
|
+
size,
|
|
77
|
+
fallbackSize,
|
|
78
|
+
iconOnly,
|
|
79
|
+
includeHeight,
|
|
80
|
+
componentName,
|
|
81
|
+
widthFromHeight
|
|
82
|
+
]);
|
|
69
83
|
}
|
|
70
84
|
__name(useSizeStyle, "useSizeStyle");
|
|
71
|
-
|
|
72
|
-
// src/theme/recipes/defineRecipe.ts
|
|
73
|
-
function defineRecipe(recipe) {
|
|
74
|
-
return recipe;
|
|
75
|
-
}
|
|
76
|
-
__name(defineRecipe, "defineRecipe");
|
|
77
|
-
|
|
78
|
-
// src/theme/recipes/mergeRecipes.ts
|
|
79
|
-
function mergeRecipeDefinition(base, override) {
|
|
80
|
-
return {
|
|
81
|
-
...base,
|
|
82
|
-
base: override.base ?? base.base,
|
|
83
|
-
variants: {
|
|
84
|
-
...base.variants,
|
|
85
|
-
...override.variants
|
|
86
|
-
},
|
|
87
|
-
defaultVariants: {
|
|
88
|
-
...base.defaultVariants,
|
|
89
|
-
...override.defaultVariants
|
|
90
|
-
},
|
|
91
|
-
compoundVariants: override.compoundVariants ?? base.compoundVariants
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
__name(mergeRecipeDefinition, "mergeRecipeDefinition");
|
|
95
|
-
function mergeRecipes(base, override) {
|
|
96
|
-
if (!override) {
|
|
97
|
-
return base;
|
|
98
|
-
}
|
|
99
|
-
const result = {
|
|
100
|
-
...base
|
|
101
|
-
};
|
|
102
|
-
for (const [name, recipeOverride] of Object.entries(override)) {
|
|
103
|
-
const baseRecipe = base[name];
|
|
104
|
-
if (!baseRecipe) {
|
|
105
|
-
result[name] = recipeOverride;
|
|
106
|
-
continue;
|
|
107
|
-
}
|
|
108
|
-
result[name] = mergeRecipeDefinition(
|
|
109
|
-
baseRecipe,
|
|
110
|
-
recipeOverride
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
return result;
|
|
114
|
-
}
|
|
115
|
-
__name(mergeRecipes, "mergeRecipes");
|
|
116
|
-
|
|
117
|
-
// src/theme/recipes/resolveRecipe.ts
|
|
118
|
-
function matchesConditions(conditions, props) {
|
|
119
|
-
return Object.entries(conditions).every(
|
|
120
|
-
([key, expected]) => props[key] === expected
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
__name(matchesConditions, "matchesConditions");
|
|
124
|
-
function resolveRecipe(recipe, props = {}) {
|
|
125
|
-
if (!recipe) return "";
|
|
126
|
-
const resolvedProps = {
|
|
127
|
-
...recipe.defaultVariants,
|
|
128
|
-
...props
|
|
129
|
-
};
|
|
130
|
-
const classes = [];
|
|
131
|
-
if (recipe.base) {
|
|
132
|
-
classes.push(recipe.base);
|
|
133
|
-
}
|
|
134
|
-
if (recipe.variants) {
|
|
135
|
-
for (const [variantName, variantValues] of Object.entries(
|
|
136
|
-
recipe.variants
|
|
137
|
-
)) {
|
|
138
|
-
const value = resolvedProps[variantName];
|
|
139
|
-
if (value === void 0) continue;
|
|
140
|
-
const variantClass = variantValues[String(value)];
|
|
141
|
-
if (variantClass) {
|
|
142
|
-
classes.push(variantClass);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (recipe.compoundVariants) {
|
|
147
|
-
for (const compound of recipe.compoundVariants) {
|
|
148
|
-
if (matchesConditions(compound.conditions, resolvedProps)) {
|
|
149
|
-
classes.push(compound.className);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return cn(...classes);
|
|
154
|
-
}
|
|
155
|
-
__name(resolveRecipe, "resolveRecipe");
|
|
156
|
-
|
|
157
|
-
// src/theme/defaults/recipes/button.ts
|
|
158
|
-
var buttonBase = "inline-flex items-center justify-center rounded-[var(--kui-button-radius,var(--kui-radius))] font-medium transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-2 focus-visible:ring-offset-surface disabled:opacity-60 disabled:pointer-events-none";
|
|
159
|
-
var buttonVariants = {
|
|
160
|
-
solid: "",
|
|
161
|
-
outline: "border bg-transparent",
|
|
162
|
-
ghost: "bg-transparent",
|
|
163
|
-
soft: "",
|
|
164
|
-
link: "bg-transparent p-0 h-auto hover:underline"
|
|
165
|
-
};
|
|
166
|
-
var buttonColors = {
|
|
167
|
-
brand: {
|
|
168
|
-
solid: "bg-brand text-brand-fg hover:bg-brand-hover",
|
|
169
|
-
outline: "border-brand text-brand hover:bg-brand/10",
|
|
170
|
-
ghost: "text-brand hover:bg-brand/10",
|
|
171
|
-
soft: "bg-brand/10 text-brand hover:bg-brand/20",
|
|
172
|
-
link: "text-brand"
|
|
173
|
-
},
|
|
174
|
-
destructive: {
|
|
175
|
-
solid: "bg-destructive text-destructive-fg hover:bg-destructive-hover",
|
|
176
|
-
outline: "border-destructive text-destructive hover:bg-destructive/10",
|
|
177
|
-
ghost: "text-destructive hover:bg-destructive/10",
|
|
178
|
-
soft: "bg-destructive/10 text-destructive hover:bg-destructive/20",
|
|
179
|
-
link: "text-destructive"
|
|
180
|
-
},
|
|
181
|
-
success: {
|
|
182
|
-
solid: "bg-success text-success-fg hover:bg-success-hover",
|
|
183
|
-
outline: "border-success text-success hover:bg-success/10",
|
|
184
|
-
ghost: "text-success hover:bg-success/10",
|
|
185
|
-
soft: "bg-success/10 text-success hover:bg-success/20",
|
|
186
|
-
link: "text-success"
|
|
187
|
-
},
|
|
188
|
-
warning: {
|
|
189
|
-
solid: "bg-warning text-warning-fg hover:bg-warning-hover",
|
|
190
|
-
outline: "border-warning text-warning hover:bg-warning/10",
|
|
191
|
-
ghost: "text-warning hover:bg-warning/10",
|
|
192
|
-
soft: "bg-warning/10 text-warning hover:bg-warning/20",
|
|
193
|
-
link: "text-warning"
|
|
194
|
-
},
|
|
195
|
-
info: {
|
|
196
|
-
solid: "bg-info text-info-fg hover:bg-info-hover",
|
|
197
|
-
outline: "border-info text-info hover:bg-info/10",
|
|
198
|
-
ghost: "text-info hover:bg-info/10",
|
|
199
|
-
soft: "bg-info/10 text-info hover:bg-info/20",
|
|
200
|
-
link: "text-info"
|
|
201
|
-
},
|
|
202
|
-
white: {
|
|
203
|
-
solid: "bg-white text-black hover:bg-gray-50",
|
|
204
|
-
outline: "border-white/30 text-white hover:bg-white/10",
|
|
205
|
-
ghost: "text-white hover:bg-white/10",
|
|
206
|
-
soft: "bg-white/10 text-white hover:bg-white/20",
|
|
207
|
-
link: "text-white"
|
|
208
|
-
},
|
|
209
|
-
neutral: {
|
|
210
|
-
solid: "bg-surface-raised text-text hover:bg-surface-sunken",
|
|
211
|
-
outline: "border-border text-text hover:bg-surface-raised",
|
|
212
|
-
ghost: "text-text hover:bg-surface-raised",
|
|
213
|
-
soft: "bg-surface-raised text-text hover:bg-surface-sunken",
|
|
214
|
-
link: "text-text"
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
var buildCompoundVariants = /* @__PURE__ */ __name(() => {
|
|
218
|
-
const compounds = [];
|
|
219
|
-
for (const [color, variantMap] of Object.entries(buttonColors)) {
|
|
220
|
-
for (const [variant, className] of Object.entries(variantMap)) {
|
|
221
|
-
compounds.push({
|
|
222
|
-
conditions: { color, variant },
|
|
223
|
-
className
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return compounds;
|
|
228
|
-
}, "buildCompoundVariants");
|
|
229
|
-
var buttonRecipe = defineRecipe({
|
|
230
|
-
base: buttonBase,
|
|
231
|
-
variants: {
|
|
232
|
-
variant: buttonVariants,
|
|
233
|
-
color: Object.fromEntries(
|
|
234
|
-
Object.keys(buttonColors).map((color) => [color, ""])
|
|
235
|
-
)
|
|
236
|
-
},
|
|
237
|
-
defaultVariants: {
|
|
238
|
-
variant: "solid",
|
|
239
|
-
color: "brand"
|
|
240
|
-
},
|
|
241
|
-
compoundVariants: buildCompoundVariants()
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// src/theme/defaults/recipes/input.ts
|
|
245
|
-
var inputBase = "flex min-w-0 flex-1 font-sans bg-transparent border-0 outline-none transition-colors duration-[var(--kui-duration-fast)] placeholder:text-text-muted disabled:pointer-events-none disabled:cursor-not-allowed";
|
|
246
|
-
var inputRecipe = defineRecipe({
|
|
247
|
-
base: inputBase,
|
|
248
|
-
variants: {
|
|
249
|
-
variant: {
|
|
250
|
-
outline: "",
|
|
251
|
-
filled: "",
|
|
252
|
-
ghost: ""
|
|
253
|
-
}
|
|
254
|
-
},
|
|
255
|
-
defaultVariants: {
|
|
256
|
-
variant: "outline"
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// src/theme/defaults/recipes/formControl.ts
|
|
261
|
-
var formControlBase = "group relative inline-flex items-center rounded-[var(--kui-radii-md)] transition-colors duration-[var(--kui-duration-fast)] focus-within:outline-none focus-within:ring-2 ";
|
|
262
|
-
var formControlVariants = {
|
|
263
|
-
outline: "border border-border bg-transparent text-text hover:border-brand",
|
|
264
|
-
filled: "border border-transparent bg-surface-raised text-text hover:bg-surface",
|
|
265
|
-
ghost: "border border-transparent bg-transparent text-text hover:bg-surface-raised"
|
|
266
|
-
};
|
|
267
|
-
var formControlStates = {
|
|
268
|
-
none: "focus-within:ring-brand/20",
|
|
269
|
-
error: "border-destructive focus-within:ring-destructive/20",
|
|
270
|
-
success: "border-success focus-within:ring-success/20"
|
|
271
|
-
};
|
|
272
|
-
var formControlRecipe = defineRecipe({
|
|
273
|
-
base: formControlBase,
|
|
274
|
-
variants: {
|
|
275
|
-
variant: formControlVariants,
|
|
276
|
-
state: formControlStates,
|
|
277
|
-
rounded: {
|
|
278
|
-
true: "rounded-full",
|
|
279
|
-
false: ""
|
|
280
|
-
},
|
|
281
|
-
fullWidth: {
|
|
282
|
-
true: "w-full",
|
|
283
|
-
false: ""
|
|
284
|
-
},
|
|
285
|
-
disabled: {
|
|
286
|
-
true: "pointer-events-none cursor-not-allowed opacity-50",
|
|
287
|
-
false: ""
|
|
288
|
-
},
|
|
289
|
-
hasAdornment: {
|
|
290
|
-
true: "px-2",
|
|
291
|
-
false: ""
|
|
292
|
-
}
|
|
293
|
-
},
|
|
294
|
-
defaultVariants: {
|
|
295
|
-
variant: "outline",
|
|
296
|
-
state: "none",
|
|
297
|
-
rounded: false,
|
|
298
|
-
fullWidth: true,
|
|
299
|
-
disabled: false,
|
|
300
|
-
hasAdornment: false
|
|
301
|
-
}
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
// src/utils/color.ts
|
|
305
|
-
var HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
306
|
-
function rgbToHex(value) {
|
|
307
|
-
const trimmed = value.trim();
|
|
308
|
-
if (HEX_RE.test(trimmed)) {
|
|
309
|
-
if (trimmed.length === 4) {
|
|
310
|
-
return ("#" + [...trimmed.slice(1)].map((char) => char + char).join("")).toUpperCase();
|
|
311
|
-
}
|
|
312
|
-
return trimmed.toUpperCase();
|
|
313
|
-
}
|
|
314
|
-
const values = trimmed.replace(/[^\d,]/g, "").split(",").map(Number);
|
|
315
|
-
if (values.length !== 3 || values.some(Number.isNaN)) {
|
|
316
|
-
return "#000000";
|
|
317
|
-
}
|
|
318
|
-
return "#" + values.map((x) => x.toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
319
|
-
}
|
|
320
|
-
__name(rgbToHex, "rgbToHex");
|
|
321
|
-
function hexToRgbString(hex) {
|
|
322
|
-
if (!HEX_RE.test(hex)) return null;
|
|
323
|
-
const full = hex.length === 4 ? "#" + [...hex.slice(1)].map((c) => c + c).join("") : hex;
|
|
324
|
-
const r = parseInt(full.slice(1, 3), 16);
|
|
325
|
-
const g = parseInt(full.slice(3, 5), 16);
|
|
326
|
-
const b = parseInt(full.slice(5, 7), 16);
|
|
327
|
-
return `${r} ${g} ${b}`;
|
|
328
|
-
}
|
|
329
|
-
__name(hexToRgbString, "hexToRgbString");
|
|
330
|
-
|
|
331
|
-
// src/utils/resolveTokenReference.ts
|
|
332
|
-
function resolveTokenReference(value, tokens) {
|
|
333
|
-
if (typeof value !== "string") {
|
|
334
|
-
return typeof value === "number" ? value : "";
|
|
335
|
-
}
|
|
336
|
-
const match = value.match(/^\{(.+)\}$/);
|
|
337
|
-
if (!match) {
|
|
338
|
-
return value;
|
|
339
|
-
}
|
|
340
|
-
const path = match[1].split(".");
|
|
341
|
-
let current = tokens;
|
|
342
|
-
for (const key of path) {
|
|
343
|
-
if (typeof current !== "object" || current === null || !(key in current)) {
|
|
344
|
-
return "";
|
|
345
|
-
}
|
|
346
|
-
current = current[key];
|
|
347
|
-
}
|
|
348
|
-
if (typeof current === "object" && current !== null && "value" in current) {
|
|
349
|
-
const tokenValue = current.value;
|
|
350
|
-
if (typeof tokenValue === "string" || typeof tokenValue === "number") {
|
|
351
|
-
return tokenValue;
|
|
352
|
-
}
|
|
353
|
-
return "";
|
|
354
|
-
}
|
|
355
|
-
return typeof current === "string" || typeof current === "number" ? current : "";
|
|
356
|
-
}
|
|
357
|
-
__name(resolveTokenReference, "resolveTokenReference");
|
|
358
|
-
|
|
359
|
-
// src/theme/typography/resolveTypography.ts
|
|
360
|
-
function resolveTypography(typography, tokens) {
|
|
361
|
-
if (!typography) return {};
|
|
362
|
-
return {
|
|
363
|
-
fontFamily: resolveTokenReference(typography.fontFamily, tokens),
|
|
364
|
-
fontSize: resolveTokenReference(typography.fontSize, tokens),
|
|
365
|
-
fontWeight: resolveTokenReference(typography.fontWeight, tokens),
|
|
366
|
-
lineHeight: resolveTokenReference(typography.lineHeight, tokens),
|
|
367
|
-
letterSpacing: resolveTokenReference(
|
|
368
|
-
typography.letterSpacing,
|
|
369
|
-
tokens
|
|
370
|
-
)
|
|
371
|
-
};
|
|
372
|
-
}
|
|
373
|
-
__name(resolveTypography, "resolveTypography");
|
|
374
|
-
|
|
375
|
-
// src/theme/typography/defineTypography.ts
|
|
376
|
-
function defineTypography(typography) {
|
|
377
|
-
return typography;
|
|
378
|
-
}
|
|
379
|
-
__name(defineTypography, "defineTypography");
|
|
380
|
-
|
|
381
|
-
// src/theme/token/defineToken.ts
|
|
382
|
-
function defineToken(value) {
|
|
383
|
-
return {
|
|
384
|
-
value
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
__name(defineToken, "defineToken");
|
|
388
|
-
function defineSemanticToken(light, dark) {
|
|
389
|
-
return { value: { light, dark } };
|
|
390
|
-
}
|
|
391
|
-
__name(defineSemanticToken, "defineSemanticToken");
|
|
392
85
|
var BREAKPOINTS = {
|
|
393
86
|
sm: 640,
|
|
394
87
|
md: 768,
|
|
@@ -440,27 +133,71 @@ function useFloatingSide(triggerRef, open) {
|
|
|
440
133
|
}
|
|
441
134
|
__name(useFloatingSide, "useFloatingSide");
|
|
442
135
|
var TRANSITION_DURATION = 1500;
|
|
443
|
-
function
|
|
444
|
-
const
|
|
445
|
-
const [
|
|
136
|
+
function useStatusTransition(status) {
|
|
137
|
+
const previousStatus = useRef(status);
|
|
138
|
+
const [transitionStatus, setTransitionStatus] = useState();
|
|
446
139
|
useEffect(() => {
|
|
447
|
-
if (
|
|
140
|
+
if (status === previousStatus.current) {
|
|
448
141
|
return;
|
|
449
142
|
}
|
|
450
|
-
|
|
451
|
-
if (
|
|
452
|
-
|
|
143
|
+
previousStatus.current = status;
|
|
144
|
+
if (status === "none") {
|
|
145
|
+
setTransitionStatus(void 0);
|
|
453
146
|
return;
|
|
454
147
|
}
|
|
455
|
-
|
|
148
|
+
setTransitionStatus(status);
|
|
456
149
|
const timeout = window.setTimeout(() => {
|
|
457
|
-
|
|
150
|
+
setTransitionStatus(void 0);
|
|
458
151
|
}, TRANSITION_DURATION);
|
|
459
152
|
return () => window.clearTimeout(timeout);
|
|
460
|
-
}, [
|
|
461
|
-
return
|
|
153
|
+
}, [status]);
|
|
154
|
+
return transitionStatus;
|
|
155
|
+
}
|
|
156
|
+
__name(useStatusTransition, "useStatusTransition");
|
|
157
|
+
|
|
158
|
+
// src/utils/resolveTokenReference.ts
|
|
159
|
+
function resolveTokenReference(value, tokens) {
|
|
160
|
+
if (typeof value !== "string") {
|
|
161
|
+
return typeof value === "number" ? value : "";
|
|
162
|
+
}
|
|
163
|
+
const match = value.match(/^\{(.+)\}$/);
|
|
164
|
+
if (!match) {
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
const path = match[1].split(".");
|
|
168
|
+
let current = tokens;
|
|
169
|
+
for (const key of path) {
|
|
170
|
+
if (typeof current !== "object" || current === null || !(key in current)) {
|
|
171
|
+
return "";
|
|
172
|
+
}
|
|
173
|
+
current = current[key];
|
|
174
|
+
}
|
|
175
|
+
if (typeof current === "object" && current !== null && "value" in current) {
|
|
176
|
+
const tokenValue = current.value;
|
|
177
|
+
if (typeof tokenValue === "string" || typeof tokenValue === "number") {
|
|
178
|
+
return tokenValue;
|
|
179
|
+
}
|
|
180
|
+
return "";
|
|
181
|
+
}
|
|
182
|
+
return typeof current === "string" || typeof current === "number" ? current : "";
|
|
462
183
|
}
|
|
463
|
-
__name(
|
|
184
|
+
__name(resolveTokenReference, "resolveTokenReference");
|
|
185
|
+
|
|
186
|
+
// src/theme/typography/resolveTypography.ts
|
|
187
|
+
function resolveTypography(typography, tokens) {
|
|
188
|
+
if (!typography) return {};
|
|
189
|
+
return {
|
|
190
|
+
fontFamily: resolveTokenReference(typography.fontFamily, tokens),
|
|
191
|
+
fontSize: resolveTokenReference(typography.fontSize, tokens),
|
|
192
|
+
fontWeight: resolveTokenReference(typography.fontWeight, tokens),
|
|
193
|
+
lineHeight: resolveTokenReference(typography.lineHeight, tokens),
|
|
194
|
+
letterSpacing: resolveTokenReference(
|
|
195
|
+
typography.letterSpacing,
|
|
196
|
+
tokens
|
|
197
|
+
)
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
__name(resolveTypography, "resolveTypography");
|
|
464
201
|
|
|
465
202
|
// src/hooks/useTypography.ts
|
|
466
203
|
function useTypography(name) {
|
|
@@ -471,6 +208,62 @@ function useTypography(name) {
|
|
|
471
208
|
);
|
|
472
209
|
}
|
|
473
210
|
__name(useTypography, "useTypography");
|
|
211
|
+
function useClearableField(elementRef, initialValue, onClear) {
|
|
212
|
+
const [hasValue, setHasValue] = useState(() => Boolean(initialValue ?? ""));
|
|
213
|
+
const clear = useCallback(() => {
|
|
214
|
+
const element = elementRef.current;
|
|
215
|
+
if (!element) return;
|
|
216
|
+
const prototype = element instanceof HTMLTextAreaElement ? window.HTMLTextAreaElement.prototype : window.HTMLInputElement.prototype;
|
|
217
|
+
const setter = Object.getOwnPropertyDescriptor(prototype, "value")?.set;
|
|
218
|
+
setter?.call(element, "");
|
|
219
|
+
element.dispatchEvent(new Event("input", { bubbles: true }));
|
|
220
|
+
element.focus();
|
|
221
|
+
setHasValue(false);
|
|
222
|
+
onClear?.();
|
|
223
|
+
}, [elementRef, onClear]);
|
|
224
|
+
return { hasValue, setHasValue, clear };
|
|
225
|
+
}
|
|
226
|
+
__name(useClearableField, "useClearableField");
|
|
227
|
+
|
|
228
|
+
// src/theme/recipes/resolveRecipe.ts
|
|
229
|
+
function matchesConditions(conditions, props) {
|
|
230
|
+
return Object.entries(conditions).every(
|
|
231
|
+
([key, expected]) => props[key] === expected
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
__name(matchesConditions, "matchesConditions");
|
|
235
|
+
function resolveRecipe(recipe, props = {}) {
|
|
236
|
+
if (!recipe) return "";
|
|
237
|
+
const resolvedProps = {
|
|
238
|
+
...recipe.defaultVariants,
|
|
239
|
+
...props
|
|
240
|
+
};
|
|
241
|
+
const classes = [];
|
|
242
|
+
if (recipe.base) {
|
|
243
|
+
classes.push(recipe.base);
|
|
244
|
+
}
|
|
245
|
+
if (recipe.variants) {
|
|
246
|
+
for (const [variantName, variantValues] of Object.entries(
|
|
247
|
+
recipe.variants
|
|
248
|
+
)) {
|
|
249
|
+
const value = resolvedProps[variantName];
|
|
250
|
+
if (value === void 0) continue;
|
|
251
|
+
const variantClass = variantValues[String(value)];
|
|
252
|
+
if (variantClass) {
|
|
253
|
+
classes.push(variantClass);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (recipe.compoundVariants) {
|
|
258
|
+
for (const compound of recipe.compoundVariants) {
|
|
259
|
+
if (matchesConditions(compound.conditions, resolvedProps)) {
|
|
260
|
+
classes.push(compound.className);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return cn(...classes);
|
|
265
|
+
}
|
|
266
|
+
__name(resolveRecipe, "resolveRecipe");
|
|
474
267
|
var ACTIVATION_KEYS = /* @__PURE__ */ new Set(["Enter", " "]);
|
|
475
268
|
var Button = forwardRef(
|
|
476
269
|
({
|
|
@@ -552,6 +345,7 @@ var Button = forwardRef(
|
|
|
552
345
|
className: resolvedClassName,
|
|
553
346
|
style: resolvedStyle,
|
|
554
347
|
disabled: disabled || isLoading,
|
|
348
|
+
"aria-disabled": disabled || isLoading,
|
|
555
349
|
"aria-busy": isLoading || void 0,
|
|
556
350
|
children: content
|
|
557
351
|
});
|
|
@@ -564,9 +358,11 @@ var Button = forwardRef(
|
|
|
564
358
|
className: resolvedClassName,
|
|
565
359
|
style: resolvedStyle,
|
|
566
360
|
"aria-busy": isLoading || void 0,
|
|
361
|
+
"aria-disabled": disabled,
|
|
567
362
|
animate: {
|
|
568
363
|
scale: isKeyboardPressed ? 0.975 : 1
|
|
569
364
|
},
|
|
365
|
+
type: "button",
|
|
570
366
|
whileHover: isInteractive ? { scale: 1.015 } : void 0,
|
|
571
367
|
whileTap: isInteractive ? { scale: 0.975 } : void 0,
|
|
572
368
|
transition: prefersReducedMotion ? { duration: 0 } : {
|
|
@@ -583,6 +379,33 @@ var Button = forwardRef(
|
|
|
583
379
|
}
|
|
584
380
|
);
|
|
585
381
|
Button.displayName = "Button";
|
|
382
|
+
|
|
383
|
+
// src/utils/color.ts
|
|
384
|
+
var HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
385
|
+
function rgbToHex(value) {
|
|
386
|
+
const trimmed = value.trim();
|
|
387
|
+
if (HEX_RE.test(trimmed)) {
|
|
388
|
+
if (trimmed.length === 4) {
|
|
389
|
+
return ("#" + [...trimmed.slice(1)].map((char) => char + char).join("")).toUpperCase();
|
|
390
|
+
}
|
|
391
|
+
return trimmed.toUpperCase();
|
|
392
|
+
}
|
|
393
|
+
const values = trimmed.replace(/[^\d,]/g, "").split(",").map(Number);
|
|
394
|
+
if (values.length !== 3 || values.some(Number.isNaN)) {
|
|
395
|
+
return "#000000";
|
|
396
|
+
}
|
|
397
|
+
return "#" + values.map((x) => x.toString(16).padStart(2, "0")).join("").toUpperCase();
|
|
398
|
+
}
|
|
399
|
+
__name(rgbToHex, "rgbToHex");
|
|
400
|
+
function hexToRgbString(hex) {
|
|
401
|
+
if (!HEX_RE.test(hex)) return null;
|
|
402
|
+
const full = hex.length === 4 ? "#" + [...hex.slice(1)].map((c) => c + c).join("") : hex;
|
|
403
|
+
const r = parseInt(full.slice(1, 3), 16);
|
|
404
|
+
const g = parseInt(full.slice(3, 5), 16);
|
|
405
|
+
const b = parseInt(full.slice(5, 7), 16);
|
|
406
|
+
return `${r} ${g} ${b}`;
|
|
407
|
+
}
|
|
408
|
+
__name(hexToRgbString, "hexToRgbString");
|
|
586
409
|
var defaultTransition = {
|
|
587
410
|
type: "none",
|
|
588
411
|
duration: 300,
|
|
@@ -875,6 +698,8 @@ function useOptionalFormField() {
|
|
|
875
698
|
return useContext(FormFieldContext);
|
|
876
699
|
}
|
|
877
700
|
__name(useOptionalFormField, "useOptionalFormField");
|
|
701
|
+
|
|
702
|
+
// src/utils/mergeRef.ts
|
|
878
703
|
function mergeRefs(...refs) {
|
|
879
704
|
return (node) => {
|
|
880
705
|
refs.forEach((ref) => {
|
|
@@ -896,10 +721,11 @@ var Input = forwardRef(
|
|
|
896
721
|
size = "md",
|
|
897
722
|
error,
|
|
898
723
|
success,
|
|
724
|
+
warning,
|
|
899
725
|
startIcon,
|
|
900
726
|
endIcon,
|
|
901
727
|
fullWidth = true,
|
|
902
|
-
disabled,
|
|
728
|
+
disabled = false,
|
|
903
729
|
rounded = false,
|
|
904
730
|
isLoading = false,
|
|
905
731
|
clearable = false,
|
|
@@ -907,42 +733,62 @@ var Input = forwardRef(
|
|
|
907
733
|
kind = "text",
|
|
908
734
|
hideKindIcon = false,
|
|
909
735
|
id: externalId,
|
|
736
|
+
trim = false,
|
|
910
737
|
type: typeProp,
|
|
911
738
|
inputMode: inputModeProp,
|
|
912
739
|
autoComplete: autoCompleteProp,
|
|
913
740
|
placeholder: placeholderProp,
|
|
914
741
|
onChange: onChangeProp,
|
|
915
|
-
|
|
742
|
+
onValueChange: onValueChangeProp,
|
|
743
|
+
onBlur: onBlurProp,
|
|
916
744
|
value,
|
|
917
745
|
defaultValue,
|
|
918
746
|
style,
|
|
919
747
|
...props
|
|
920
748
|
}, ref) => {
|
|
921
749
|
const autoId = useId();
|
|
750
|
+
const internalRef = useRef(null);
|
|
922
751
|
const { theme } = useTheme();
|
|
923
752
|
const field = useOptionalFormField();
|
|
924
753
|
const id = externalId ?? field?.id ?? autoId;
|
|
925
|
-
const isInvalid = error || field?.invalid || false;
|
|
926
|
-
const describedBy = field?.describedBy ?? void 0;
|
|
927
754
|
const isRequired = field?.required ?? props.required;
|
|
928
|
-
const
|
|
755
|
+
const describedBy = field?.describedBy;
|
|
756
|
+
const state = error ? "error" : success ? "success" : warning ? "warning" : field?.status ?? "none";
|
|
757
|
+
const isInvalid = state === "error";
|
|
758
|
+
const statusTransition = useStatusTransition(state);
|
|
929
759
|
const { style: sizeStyle, iconSize } = useSizeStyle(size, false, "input");
|
|
930
|
-
const [hasValue, setHasValue] = useState(
|
|
931
|
-
() => Boolean(value ?? defaultValue ?? "")
|
|
932
|
-
);
|
|
933
760
|
const [visible, setVisible] = useState(false);
|
|
761
|
+
const { hasValue, setHasValue, clear } = useClearableField(
|
|
762
|
+
internalRef,
|
|
763
|
+
value ?? defaultValue,
|
|
764
|
+
onClear
|
|
765
|
+
);
|
|
934
766
|
useEffect(() => {
|
|
935
767
|
if (value !== void 0) {
|
|
936
768
|
setHasValue(Boolean(value));
|
|
937
769
|
}
|
|
938
|
-
}, [value]);
|
|
770
|
+
}, [value, setHasValue]);
|
|
939
771
|
const kindDefaults = inputKindDefaults[kind];
|
|
940
772
|
const resolvedType = typeProp ?? kindDefaults.type;
|
|
941
773
|
const isPasswordField = resolvedType === "password";
|
|
942
774
|
const effectiveType = isPasswordField ? visible ? "text" : "password" : resolvedType;
|
|
943
775
|
const KindIcon = inputKindIcons[kind];
|
|
944
|
-
const defaultStartIcon = !hideKindIcon && KindIcon ? /* @__PURE__ */ jsx(KindIcon, {
|
|
945
|
-
const
|
|
776
|
+
const defaultStartIcon = !hideKindIcon && KindIcon ? /* @__PURE__ */ jsx(KindIcon, {}) : void 0;
|
|
777
|
+
const startAdornment = useMemo(() => {
|
|
778
|
+
const icon = startIcon ?? defaultStartIcon;
|
|
779
|
+
if (!icon) return null;
|
|
780
|
+
return /* @__PURE__ */ jsx(
|
|
781
|
+
"span",
|
|
782
|
+
{
|
|
783
|
+
className: "flex shrink-0 items-center justify-center",
|
|
784
|
+
style: {
|
|
785
|
+
width: iconSize,
|
|
786
|
+
height: iconSize
|
|
787
|
+
},
|
|
788
|
+
children: icon
|
|
789
|
+
}
|
|
790
|
+
);
|
|
791
|
+
}, [startIcon, defaultStartIcon, iconSize]);
|
|
946
792
|
const builtInEnd = [];
|
|
947
793
|
if (isPasswordField) {
|
|
948
794
|
builtInEnd.push(
|
|
@@ -950,11 +796,27 @@ var Input = forwardRef(
|
|
|
950
796
|
"button",
|
|
951
797
|
{
|
|
952
798
|
type: "button",
|
|
953
|
-
tabIndex: -1,
|
|
954
799
|
onClick: () => setVisible((current) => !current),
|
|
955
800
|
"aria-label": visible ? "Hide password" : "Show password",
|
|
956
|
-
|
|
957
|
-
|
|
801
|
+
"aria-pressed": visible,
|
|
802
|
+
className: "\r\n flex items-center justify-center\r\n text-text-muted\r\n transition-colors\r\n hover:text-text\r\n focus-visible:outline\r\n focus-visible:outline-2\r\n focus-visible:outline-offset-2\r\n ",
|
|
803
|
+
children: visible ? /* @__PURE__ */ jsx(
|
|
804
|
+
EyeOff,
|
|
805
|
+
{
|
|
806
|
+
style: {
|
|
807
|
+
width: iconSize,
|
|
808
|
+
height: iconSize
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
) : /* @__PURE__ */ jsx(
|
|
812
|
+
Eye,
|
|
813
|
+
{
|
|
814
|
+
style: {
|
|
815
|
+
width: iconSize,
|
|
816
|
+
height: iconSize
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
)
|
|
958
820
|
},
|
|
959
821
|
"toggle-visibility"
|
|
960
822
|
)
|
|
@@ -966,28 +828,46 @@ var Input = forwardRef(
|
|
|
966
828
|
"button",
|
|
967
829
|
{
|
|
968
830
|
type: "button",
|
|
969
|
-
|
|
970
|
-
onClick: handleClear,
|
|
831
|
+
onClick: clear,
|
|
971
832
|
"aria-label": "Clear input",
|
|
972
|
-
className: "flex items-center justify-center
|
|
973
|
-
children: /* @__PURE__ */ jsx(
|
|
833
|
+
className: "\r\n flex items-center justify-center\r\n text-text-muted\r\n transition-colors\r\n hover:text-text\r\n focus-visible:outline\r\n focus-visible:outline-2\r\n focus-visible:outline-offset-2\r\n ",
|
|
834
|
+
children: /* @__PURE__ */ jsx(
|
|
835
|
+
X,
|
|
836
|
+
{
|
|
837
|
+
style: {
|
|
838
|
+
width: iconSize,
|
|
839
|
+
height: iconSize
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
)
|
|
974
843
|
},
|
|
975
844
|
"clear"
|
|
976
845
|
)
|
|
977
846
|
);
|
|
978
847
|
}
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
848
|
+
const endAdornment = isLoading ? /* @__PURE__ */ jsx(Spinner, { size: iconSize || 14 }) : endIcon || builtInEnd.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1.5", children: [
|
|
849
|
+
endIcon && /* @__PURE__ */ jsx(
|
|
850
|
+
"span",
|
|
851
|
+
{
|
|
852
|
+
className: "flex items-center justify-center",
|
|
853
|
+
style: {
|
|
854
|
+
width: iconSize,
|
|
855
|
+
height: iconSize
|
|
856
|
+
},
|
|
857
|
+
children: endIcon
|
|
858
|
+
}
|
|
859
|
+
),
|
|
860
|
+
builtInEnd
|
|
861
|
+
] }) : null;
|
|
862
|
+
const hasAdornment = Boolean(startAdornment) || Boolean(endAdornment);
|
|
983
863
|
const wrapperClasses = cn(
|
|
984
864
|
resolveRecipe(theme.recipes.FormControl, {
|
|
985
865
|
variant,
|
|
986
866
|
state,
|
|
987
867
|
rounded,
|
|
988
868
|
fullWidth,
|
|
989
|
-
disabled:
|
|
990
|
-
|
|
869
|
+
disabled: disabled || isLoading,
|
|
870
|
+
hasAdornment
|
|
991
871
|
}),
|
|
992
872
|
className
|
|
993
873
|
);
|
|
@@ -1004,44 +884,42 @@ var Input = forwardRef(
|
|
|
1004
884
|
function handleChange(event) {
|
|
1005
885
|
setHasValue(Boolean(event.target.value));
|
|
1006
886
|
onChangeProp?.(event);
|
|
887
|
+
onValueChangeProp?.(event.target.value);
|
|
1007
888
|
}
|
|
1008
889
|
__name(handleChange, "handleChange");
|
|
1009
|
-
function
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
bubbles: true
|
|
1020
|
-
})
|
|
1021
|
-
);
|
|
1022
|
-
element.focus();
|
|
1023
|
-
setHasValue(false);
|
|
1024
|
-
onClear?.();
|
|
890
|
+
function handleBlur(event) {
|
|
891
|
+
if (trim && !disabled && !isLoading) {
|
|
892
|
+
const trimmedValue = event.currentTarget.value.trim();
|
|
893
|
+
if (trimmedValue !== event.currentTarget.value) {
|
|
894
|
+
event.currentTarget.value = trimmedValue;
|
|
895
|
+
setHasValue(Boolean(trimmedValue));
|
|
896
|
+
onValueChangeProp?.(trimmedValue);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
onBlurProp?.(event);
|
|
1025
900
|
}
|
|
1026
|
-
__name(
|
|
901
|
+
__name(handleBlur, "handleBlur");
|
|
902
|
+
const wasInvalidRef = useRef(isInvalid);
|
|
1027
903
|
useEffect(() => {
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
if (!
|
|
1031
|
-
|
|
904
|
+
const justBecameInvalid = isInvalid && !wasInvalidRef.current;
|
|
905
|
+
wasInvalidRef.current = isInvalid;
|
|
906
|
+
if (!justBecameInvalid) {
|
|
907
|
+
return;
|
|
908
|
+
}
|
|
909
|
+
internalRef.current?.scrollIntoView({
|
|
1032
910
|
behavior: "smooth",
|
|
1033
911
|
block: "center"
|
|
1034
912
|
});
|
|
1035
|
-
}, [
|
|
913
|
+
}, [isInvalid]);
|
|
1036
914
|
return /* @__PURE__ */ jsxs(
|
|
1037
915
|
"div",
|
|
1038
916
|
{
|
|
1039
917
|
className: wrapperClasses,
|
|
1040
918
|
style: resolvedStyle,
|
|
1041
919
|
"data-state": state,
|
|
1042
|
-
"data-state-transition":
|
|
920
|
+
"data-state-transition": statusTransition,
|
|
1043
921
|
children: [
|
|
1044
|
-
|
|
922
|
+
startAdornment,
|
|
1045
923
|
/* @__PURE__ */ jsx(
|
|
1046
924
|
"input",
|
|
1047
925
|
{
|
|
@@ -1055,31 +933,54 @@ var Input = forwardRef(
|
|
|
1055
933
|
value,
|
|
1056
934
|
defaultValue,
|
|
1057
935
|
onChange: handleChange,
|
|
1058
|
-
|
|
1059
|
-
disabled:
|
|
936
|
+
onBlur: handleBlur,
|
|
937
|
+
disabled: disabled || isLoading,
|
|
1060
938
|
"aria-busy": isLoading || void 0,
|
|
1061
939
|
"aria-invalid": isInvalid || void 0,
|
|
1062
940
|
"aria-describedby": describedBy,
|
|
1063
941
|
"aria-required": isRequired || void 0,
|
|
1064
942
|
className: inputClasses,
|
|
1065
|
-
"data-variant": variant,
|
|
1066
|
-
"data-size": size,
|
|
1067
|
-
"data-success": success || void 0,
|
|
1068
943
|
"data-disabled": disabled || void 0,
|
|
1069
|
-
"data-loading": isLoading || void 0
|
|
944
|
+
"data-loading": isLoading || void 0,
|
|
945
|
+
"data-size": size,
|
|
946
|
+
"data-state": state,
|
|
947
|
+
"data-variant": variant
|
|
1070
948
|
}
|
|
1071
949
|
),
|
|
1072
|
-
|
|
950
|
+
endAdornment
|
|
1073
951
|
]
|
|
1074
|
-
}
|
|
1075
|
-
stateTransition ?? "idle"
|
|
952
|
+
}
|
|
1076
953
|
);
|
|
1077
954
|
}
|
|
1078
955
|
);
|
|
1079
956
|
Input.displayName = "Input";
|
|
957
|
+
|
|
958
|
+
// src/utils/env.ts
|
|
959
|
+
function readProcessEnv() {
|
|
960
|
+
try {
|
|
961
|
+
return typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
|
|
962
|
+
} catch {
|
|
963
|
+
return void 0;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
__name(readProcessEnv, "readProcessEnv");
|
|
967
|
+
function readImportMetaEnv() {
|
|
968
|
+
try {
|
|
969
|
+
return typeof import.meta !== "undefined" ? import.meta.env?.MODE : void 0;
|
|
970
|
+
} catch {
|
|
971
|
+
return void 0;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
__name(readImportMetaEnv, "readImportMetaEnv");
|
|
975
|
+
function isDev() {
|
|
976
|
+
const mode = readProcessEnv() ?? readImportMetaEnv();
|
|
977
|
+
return mode !== void 0 && mode !== "production";
|
|
978
|
+
}
|
|
979
|
+
__name(isDev, "isDev");
|
|
1080
980
|
function FormField({
|
|
1081
981
|
id: externalId,
|
|
1082
|
-
|
|
982
|
+
status = "none",
|
|
983
|
+
message: formMessage,
|
|
1083
984
|
required = false,
|
|
1084
985
|
className,
|
|
1085
986
|
children
|
|
@@ -1089,24 +990,52 @@ function FormField({
|
|
|
1089
990
|
const labelId = `${id}-label`;
|
|
1090
991
|
const descriptionId = `${id}-description`;
|
|
1091
992
|
const messageId = `${id}-message`;
|
|
1092
|
-
const [
|
|
1093
|
-
|
|
1094
|
-
|
|
993
|
+
const [reportedValidity, setReportedValidity] = useState(null);
|
|
994
|
+
const reportValidity = useCallback((result) => {
|
|
995
|
+
setReportedValidity(result);
|
|
996
|
+
}, []);
|
|
997
|
+
const reportedMessage = reportedValidity?.invalid ? reportedValidity.message : void 0;
|
|
1095
998
|
const [labelCount, setLabelCount] = useState(0);
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
999
|
+
function countMessageComponents(children2) {
|
|
1000
|
+
let count = 0;
|
|
1001
|
+
Children.forEach(children2, (child) => {
|
|
1002
|
+
if (!isValidElement(child)) {
|
|
1003
|
+
return;
|
|
1004
|
+
}
|
|
1005
|
+
if (child.type === FormFieldMessage) {
|
|
1006
|
+
count += 1;
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
if (child.props.children) {
|
|
1010
|
+
count += countMessageComponents(child.props.children);
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
return count;
|
|
1014
|
+
}
|
|
1015
|
+
__name(countMessageComponents, "countMessageComponents");
|
|
1103
1016
|
const registerLabel = useCallback(() => {
|
|
1104
|
-
setLabelCount((
|
|
1105
|
-
return () =>
|
|
1017
|
+
setLabelCount((count) => count + 1);
|
|
1018
|
+
return () => {
|
|
1019
|
+
setLabelCount((count) => count - 1);
|
|
1020
|
+
};
|
|
1106
1021
|
}, []);
|
|
1107
1022
|
const hasExternalLabel = labelCount > 0;
|
|
1108
|
-
const displayedMessage =
|
|
1109
|
-
const
|
|
1023
|
+
const displayedMessage = formMessage ?? reportedMessage;
|
|
1024
|
+
const message = displayedMessage;
|
|
1025
|
+
const invalid = status === "error" || Boolean(formMessage) || Boolean(reportedValidity?.invalid);
|
|
1026
|
+
const messageCount = countMessageComponents(children);
|
|
1027
|
+
const hasCustomMessage = messageCount > 0;
|
|
1028
|
+
const describedBy = [descriptionId, message || hasCustomMessage ? messageId : void 0].filter(Boolean).join(" ") || void 0;
|
|
1029
|
+
useEffect(() => {
|
|
1030
|
+
if (!isDev()) {
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
if (messageCount > 1) {
|
|
1034
|
+
console.warn(
|
|
1035
|
+
"[Kreativ UI] Multiple <FormField.Message /> components were detected inside the same <FormField>. Only one custom message should be provided."
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
}, [messageCount]);
|
|
1110
1039
|
return /* @__PURE__ */ jsx(
|
|
1111
1040
|
FormFieldContext.Provider,
|
|
1112
1041
|
{
|
|
@@ -1115,9 +1044,10 @@ function FormField({
|
|
|
1115
1044
|
labelId,
|
|
1116
1045
|
descriptionId,
|
|
1117
1046
|
messageId,
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1047
|
+
message,
|
|
1048
|
+
status,
|
|
1049
|
+
describedBy,
|
|
1050
|
+
invalid,
|
|
1121
1051
|
required,
|
|
1122
1052
|
reportValidity,
|
|
1123
1053
|
registerLabel,
|
|
@@ -1125,7 +1055,7 @@ function FormField({
|
|
|
1125
1055
|
},
|
|
1126
1056
|
children: /* @__PURE__ */ jsxs("div", { className: cn("flex flex-col gap-2", className), children: [
|
|
1127
1057
|
children,
|
|
1128
|
-
|
|
1058
|
+
!hasCustomMessage && /* @__PURE__ */ jsx(FormFieldMessage, {})
|
|
1129
1059
|
] })
|
|
1130
1060
|
}
|
|
1131
1061
|
);
|
|
@@ -1148,7 +1078,7 @@ function FormFieldLabel({
|
|
|
1148
1078
|
{
|
|
1149
1079
|
id: field.labelId,
|
|
1150
1080
|
htmlFor: field.id,
|
|
1151
|
-
className: cn("
|
|
1081
|
+
className: cn("font-medium text-text text-sm", className),
|
|
1152
1082
|
children: [
|
|
1153
1083
|
children,
|
|
1154
1084
|
field.required && /* @__PURE__ */ jsx("span", { "aria-hidden": true, className: "ml-1 text-destructive", children: "*" })
|
|
@@ -1173,15 +1103,30 @@ function FormFieldDescription({
|
|
|
1173
1103
|
);
|
|
1174
1104
|
}
|
|
1175
1105
|
__name(FormFieldDescription, "FormFieldDescription");
|
|
1106
|
+
var statusClasses = {
|
|
1107
|
+
error: "text-destructive animate-kui-shake [animation-delay:500ms]",
|
|
1108
|
+
success: "text-success",
|
|
1109
|
+
warning: "text-warning"
|
|
1110
|
+
};
|
|
1176
1111
|
function FormFieldMessage({ children }) {
|
|
1177
|
-
const { messageId } = useFormField();
|
|
1112
|
+
const { messageId, message, status, invalid } = useFormField();
|
|
1113
|
+
const content = children ?? message;
|
|
1114
|
+
if (!content) {
|
|
1115
|
+
return null;
|
|
1116
|
+
}
|
|
1117
|
+
const effectiveStatus = status !== "none" ? status : invalid ? "error" : "none";
|
|
1178
1118
|
return /* @__PURE__ */ jsx(
|
|
1179
1119
|
"p",
|
|
1180
1120
|
{
|
|
1181
1121
|
id: messageId,
|
|
1182
|
-
role: "alert",
|
|
1183
|
-
|
|
1184
|
-
|
|
1122
|
+
role: effectiveStatus === "error" ? "alert" : void 0,
|
|
1123
|
+
"aria-live": effectiveStatus === "error" ? "assertive" : "polite",
|
|
1124
|
+
"data-status": effectiveStatus,
|
|
1125
|
+
className: cn(
|
|
1126
|
+
"text-sm",
|
|
1127
|
+
effectiveStatus !== "none" && statusClasses[effectiveStatus]
|
|
1128
|
+
),
|
|
1129
|
+
children: content
|
|
1185
1130
|
}
|
|
1186
1131
|
);
|
|
1187
1132
|
}
|
|
@@ -1650,38 +1595,48 @@ Select.Item = SelectItem;
|
|
|
1650
1595
|
Select.Value = SelectValue;
|
|
1651
1596
|
Select.Group = SelectGroup;
|
|
1652
1597
|
Select.Label = SelectLabel;
|
|
1653
|
-
|
|
1654
|
-
// src/components/Textarea/Textarea.styles.ts
|
|
1655
|
-
var textareaBase = cn(
|
|
1656
|
-
"flex w-full min-w-0 bg-transparent font-sans outline-none border-0",
|
|
1657
|
-
"text-text placeholder:text-text-muted",
|
|
1658
|
-
"transition-colors duration-[var(--kui-duration-fast)]",
|
|
1659
|
-
"disabled:opacity-50 disabled:pointer-events-none disabled:cursor-not-allowed"
|
|
1660
|
-
);
|
|
1661
|
-
var textareaResizeVariants = {
|
|
1662
|
-
none: "resize-none",
|
|
1663
|
-
both: "resize",
|
|
1664
|
-
horizontal: "resize-x",
|
|
1665
|
-
vertical: "resize-y"
|
|
1666
|
-
};
|
|
1667
1598
|
function mergeRefs2(...refs) {
|
|
1668
1599
|
return (node) => {
|
|
1669
|
-
refs.forEach((
|
|
1670
|
-
if (!
|
|
1671
|
-
if (typeof
|
|
1672
|
-
|
|
1600
|
+
refs.forEach((ref) => {
|
|
1601
|
+
if (!ref) return;
|
|
1602
|
+
if (typeof ref === "function") {
|
|
1603
|
+
ref(node);
|
|
1604
|
+
} else {
|
|
1605
|
+
ref.current = node;
|
|
1606
|
+
}
|
|
1673
1607
|
});
|
|
1674
1608
|
};
|
|
1675
1609
|
}
|
|
1676
1610
|
__name(mergeRefs2, "mergeRefs");
|
|
1611
|
+
function resolveFieldState({
|
|
1612
|
+
error,
|
|
1613
|
+
success,
|
|
1614
|
+
warning,
|
|
1615
|
+
hasReachedMaxLength,
|
|
1616
|
+
internalInvalid,
|
|
1617
|
+
fieldInvalid
|
|
1618
|
+
}) {
|
|
1619
|
+
const isInvalid = error === true || hasReachedMaxLength || internalInvalid === true || fieldInvalid === true;
|
|
1620
|
+
const isSuccess = !isInvalid && (success ?? internalInvalid === false);
|
|
1621
|
+
const isWarning = !isInvalid && !isSuccess && warning === true;
|
|
1622
|
+
const state = isInvalid ? "error" : isSuccess ? "success" : isWarning ? "warning" : "none";
|
|
1623
|
+
return { isInvalid, isSuccess, isWarning, state };
|
|
1624
|
+
}
|
|
1625
|
+
__name(resolveFieldState, "resolveFieldState");
|
|
1677
1626
|
var TextareaCore = forwardRef(
|
|
1678
1627
|
({
|
|
1679
|
-
className,
|
|
1680
1628
|
value: valueProp,
|
|
1681
1629
|
defaultValue,
|
|
1630
|
+
onValueChange: onValueChangeProp,
|
|
1631
|
+
onChange: onChangeProp,
|
|
1632
|
+
onBlur: onBlurProp,
|
|
1633
|
+
className,
|
|
1634
|
+
style: customStyle,
|
|
1682
1635
|
size = "md",
|
|
1683
|
-
|
|
1636
|
+
variant = "outline",
|
|
1684
1637
|
resize = "vertical",
|
|
1638
|
+
fullWidth = true,
|
|
1639
|
+
embedded = false,
|
|
1685
1640
|
autoResize = false,
|
|
1686
1641
|
minRows,
|
|
1687
1642
|
maxRows,
|
|
@@ -1689,43 +1644,71 @@ var TextareaCore = forwardRef(
|
|
|
1689
1644
|
onClear,
|
|
1690
1645
|
characterCounter = false,
|
|
1691
1646
|
debounceDelay = 0,
|
|
1692
|
-
|
|
1647
|
+
trim = false,
|
|
1693
1648
|
error,
|
|
1694
1649
|
success,
|
|
1695
|
-
|
|
1650
|
+
warning,
|
|
1651
|
+
validate,
|
|
1652
|
+
validateOn = "blur",
|
|
1696
1653
|
disabled,
|
|
1697
1654
|
id: externalId,
|
|
1655
|
+
required,
|
|
1698
1656
|
maxLength,
|
|
1699
|
-
variant = "outline",
|
|
1700
|
-
onValueChange: onValueChangeProp,
|
|
1701
|
-
onChange: onChangeProp,
|
|
1702
|
-
onBlur: onBlurProp,
|
|
1703
1657
|
rows,
|
|
1704
1658
|
...props
|
|
1705
1659
|
}, ref) => {
|
|
1706
1660
|
const autoId = useId();
|
|
1707
1661
|
const field = useOptionalFormField();
|
|
1708
|
-
const id = field?.id ?? externalId ?? autoId;
|
|
1709
1662
|
const { theme } = useTheme();
|
|
1663
|
+
const id = field?.id ?? externalId ?? autoId;
|
|
1710
1664
|
const internalRef = useRef(null);
|
|
1711
1665
|
const debounceTimer = useRef(null);
|
|
1666
|
+
const typography = useTypography("body");
|
|
1667
|
+
const { style: sizeStyle } = useSizeStyle(size, false, "textarea", {
|
|
1668
|
+
includeHeight: false
|
|
1669
|
+
});
|
|
1712
1670
|
const [draft, setDraft] = useState(() => valueProp ?? defaultValue ?? "");
|
|
1713
1671
|
useEffect(() => {
|
|
1714
|
-
if (valueProp !== void 0)
|
|
1672
|
+
if (valueProp !== void 0) {
|
|
1673
|
+
setDraft(valueProp);
|
|
1674
|
+
}
|
|
1715
1675
|
}, [valueProp]);
|
|
1716
1676
|
const [internalValidation, setInternalValidation] = useState({});
|
|
1717
|
-
const
|
|
1718
|
-
const
|
|
1719
|
-
const
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1677
|
+
const maxLengthExceeded = maxLength !== void 0 && draft.length > maxLength;
|
|
1678
|
+
const hasValue = draft.length > 0;
|
|
1679
|
+
const hasMaxLength = typeof maxLength === "number";
|
|
1680
|
+
const hasReachedMaxLength = hasMaxLength && draft.length >= maxLength;
|
|
1681
|
+
const maxLengthMessage = hasReachedMaxLength ? `Maximum length of ${maxLength} characters reached.` : void 0;
|
|
1682
|
+
const { isInvalid, isSuccess, isWarning, state } = useMemo(
|
|
1683
|
+
() => resolveFieldState({
|
|
1684
|
+
error,
|
|
1685
|
+
success,
|
|
1686
|
+
warning,
|
|
1687
|
+
hasReachedMaxLength,
|
|
1688
|
+
internalInvalid: internalValidation.invalid,
|
|
1689
|
+
fieldInvalid: field?.invalid
|
|
1690
|
+
}),
|
|
1691
|
+
[
|
|
1692
|
+
error,
|
|
1693
|
+
success,
|
|
1694
|
+
warning,
|
|
1695
|
+
hasReachedMaxLength,
|
|
1696
|
+
internalValidation.invalid,
|
|
1697
|
+
field?.invalid
|
|
1698
|
+
]
|
|
1725
1699
|
);
|
|
1700
|
+
useEffect(() => {
|
|
1701
|
+
return () => {
|
|
1702
|
+
if (debounceTimer.current) {
|
|
1703
|
+
clearTimeout(debounceTimer.current);
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
}, []);
|
|
1726
1707
|
function commitValue(next, { immediate = false } = {}) {
|
|
1727
1708
|
setDraft(next);
|
|
1728
|
-
if (debounceTimer.current)
|
|
1709
|
+
if (debounceTimer.current) {
|
|
1710
|
+
clearTimeout(debounceTimer.current);
|
|
1711
|
+
}
|
|
1729
1712
|
if (debounceDelay > 0 && !immediate) {
|
|
1730
1713
|
debounceTimer.current = setTimeout(() => {
|
|
1731
1714
|
onValueChangeProp?.(next);
|
|
@@ -1735,84 +1718,137 @@ var TextareaCore = forwardRef(
|
|
|
1735
1718
|
}
|
|
1736
1719
|
}
|
|
1737
1720
|
__name(commitValue, "commitValue");
|
|
1738
|
-
function
|
|
1739
|
-
|
|
1740
|
-
|
|
1721
|
+
function getValidationResult(value) {
|
|
1722
|
+
if (maxLength !== void 0 && value.length >= maxLength) {
|
|
1723
|
+
return {
|
|
1724
|
+
invalid: true,
|
|
1725
|
+
message: maxLengthMessage
|
|
1726
|
+
};
|
|
1727
|
+
}
|
|
1728
|
+
if (!validate) {
|
|
1729
|
+
return null;
|
|
1730
|
+
}
|
|
1731
|
+
const result = validate(value);
|
|
1732
|
+
if (result === true) {
|
|
1733
|
+
return {
|
|
1734
|
+
invalid: false,
|
|
1735
|
+
message: void 0
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
if (result === false) {
|
|
1739
|
+
return {
|
|
1740
|
+
invalid: true,
|
|
1741
|
+
message: void 0
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
return {
|
|
1745
|
+
invalid: true,
|
|
1746
|
+
message: result
|
|
1747
|
+
};
|
|
1741
1748
|
}
|
|
1742
|
-
__name(
|
|
1743
|
-
function runValidation(
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
setInternalValidation(parsed);
|
|
1748
|
-
field?.reportValidity(parsed.invalid ? parsed : null);
|
|
1749
|
+
__name(getValidationResult, "getValidationResult");
|
|
1750
|
+
function runValidation(value) {
|
|
1751
|
+
const result = getValidationResult(value);
|
|
1752
|
+
setInternalValidation(result ?? {});
|
|
1753
|
+
field?.reportValidity(result?.invalid ? result : null);
|
|
1749
1754
|
}
|
|
1750
1755
|
__name(runValidation, "runValidation");
|
|
1751
|
-
function
|
|
1756
|
+
function handleChange(event) {
|
|
1757
|
+
const next = event.target.value;
|
|
1758
|
+
commitValue(next);
|
|
1759
|
+
onChangeProp?.(event);
|
|
1760
|
+
const shouldValidate = validateOn === "change" || validateOn === "both";
|
|
1761
|
+
if (shouldValidate) {
|
|
1762
|
+
runValidation(next);
|
|
1763
|
+
} else if (internalValidation.invalid) {
|
|
1764
|
+
setInternalValidation({});
|
|
1765
|
+
field?.reportValidity(null);
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
__name(handleChange, "handleChange");
|
|
1769
|
+
function handleBlur(event) {
|
|
1752
1770
|
let finalValue = draft;
|
|
1753
|
-
if (
|
|
1771
|
+
if (trim) {
|
|
1754
1772
|
const trimmed = draft.trim();
|
|
1755
1773
|
if (trimmed !== draft) {
|
|
1756
|
-
commitValue(trimmed, {
|
|
1774
|
+
commitValue(trimmed, {
|
|
1775
|
+
immediate: true
|
|
1776
|
+
});
|
|
1757
1777
|
finalValue = trimmed;
|
|
1758
1778
|
}
|
|
1759
1779
|
}
|
|
1760
|
-
|
|
1761
|
-
|
|
1780
|
+
if (validateOn === "blur" || validateOn === "both") {
|
|
1781
|
+
runValidation(finalValue);
|
|
1782
|
+
}
|
|
1783
|
+
onBlurProp?.(event);
|
|
1762
1784
|
}
|
|
1763
1785
|
__name(handleBlur, "handleBlur");
|
|
1764
1786
|
function handleClear() {
|
|
1765
|
-
commitValue("", {
|
|
1766
|
-
|
|
1787
|
+
commitValue("", {
|
|
1788
|
+
immediate: true
|
|
1789
|
+
});
|
|
1767
1790
|
setInternalValidation({});
|
|
1768
1791
|
field?.reportValidity(null);
|
|
1792
|
+
internalRef.current?.focus();
|
|
1769
1793
|
onClear?.();
|
|
1770
1794
|
}
|
|
1771
1795
|
__name(handleClear, "handleClear");
|
|
1772
1796
|
useLayoutEffect(() => {
|
|
1773
1797
|
if (!autoResize) return;
|
|
1774
|
-
const
|
|
1775
|
-
if (!
|
|
1776
|
-
const computed = window.getComputedStyle(
|
|
1798
|
+
const element = internalRef.current;
|
|
1799
|
+
if (!element) return;
|
|
1800
|
+
const computed = window.getComputedStyle(element);
|
|
1777
1801
|
const lineHeight = parseFloat(computed.lineHeight) || parseFloat(computed.fontSize) * 1.2;
|
|
1778
1802
|
const paddingY = parseFloat(computed.paddingTop) + parseFloat(computed.paddingBottom);
|
|
1779
1803
|
const borderY = parseFloat(computed.borderTopWidth) + parseFloat(computed.borderBottomWidth);
|
|
1780
|
-
const minHeight = minRows ? lineHeight * minRows + paddingY + borderY : void 0;
|
|
1781
|
-
const maxHeight = maxRows ? lineHeight * maxRows + paddingY + borderY : void 0;
|
|
1782
|
-
|
|
1783
|
-
let
|
|
1784
|
-
if (minHeight
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1804
|
+
const minHeight = minRows !== void 0 ? lineHeight * minRows + paddingY + borderY : void 0;
|
|
1805
|
+
const maxHeight = maxRows !== void 0 ? lineHeight * maxRows + paddingY + borderY : void 0;
|
|
1806
|
+
element.style.height = "auto";
|
|
1807
|
+
let nextHeight = element.scrollHeight;
|
|
1808
|
+
if (minHeight !== void 0) {
|
|
1809
|
+
nextHeight = Math.max(nextHeight, minHeight);
|
|
1810
|
+
}
|
|
1811
|
+
if (maxHeight !== void 0) {
|
|
1812
|
+
nextHeight = Math.min(nextHeight, maxHeight);
|
|
1813
|
+
}
|
|
1814
|
+
element.style.height = `${nextHeight}px`;
|
|
1815
|
+
element.style.overflowY = maxHeight !== void 0 && element.scrollHeight > maxHeight ? "auto" : "hidden";
|
|
1788
1816
|
}, [autoResize, draft, minRows, maxRows]);
|
|
1789
|
-
const hasValue = draft.length > 0;
|
|
1790
1817
|
const showClear = clearable && hasValue && !disabled;
|
|
1791
1818
|
const showCounter = characterCounter;
|
|
1792
|
-
const nearLimit =
|
|
1819
|
+
const nearLimit = hasMaxLength && draft.length >= Math.max(0, maxLength - 10);
|
|
1793
1820
|
const needsBottomSpace = showClear || showCounter;
|
|
1794
1821
|
const messageId = !field?.describedBy && (isInvalid || isSuccess) ? `${id}-message` : void 0;
|
|
1795
1822
|
const counterId = showCounter ? `${id}-counter` : void 0;
|
|
1796
1823
|
const describedBy = cn(field?.describedBy, messageId, counterId).trim() || void 0;
|
|
1797
|
-
const wrapperClassName =
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
includeHeight: false
|
|
1824
|
+
const wrapperClassName = resolveRecipe(theme.recipes.FormControl, {
|
|
1825
|
+
variant,
|
|
1826
|
+
state,
|
|
1827
|
+
fullWidth,
|
|
1828
|
+
disabled: !!disabled,
|
|
1829
|
+
embedded
|
|
1830
|
+
});
|
|
1831
|
+
const textareaClasses = resolveRecipe(theme.recipes.Textarea, {
|
|
1832
|
+
variant,
|
|
1833
|
+
resize,
|
|
1834
|
+
autoResize
|
|
1809
1835
|
});
|
|
1810
|
-
const textareaStyle = {
|
|
1836
|
+
const textareaStyle = {
|
|
1837
|
+
...typography,
|
|
1838
|
+
...sizeStyle,
|
|
1839
|
+
...customStyle
|
|
1840
|
+
};
|
|
1811
1841
|
if (needsBottomSpace) {
|
|
1812
1842
|
const existingBottom = sizeStyle.paddingBottom;
|
|
1813
1843
|
textareaStyle.paddingBottom = existingBottom ? `calc(${existingBottom} + 1.25rem)` : "1.5rem";
|
|
1814
1844
|
}
|
|
1815
|
-
|
|
1845
|
+
const counterClassName = cn(
|
|
1846
|
+
"pointer-events-none absolute",
|
|
1847
|
+
"bottom-1.5 right-2.5",
|
|
1848
|
+
"font-mono text-[11px]",
|
|
1849
|
+
maxLengthExceeded ? "text-destructive" : hasReachedMaxLength ? "text-warning" : nearLimit ? "text-warning" : "text-text-muted"
|
|
1850
|
+
);
|
|
1851
|
+
return /* @__PURE__ */ jsxs("div", { className: cn(wrapperClassName, "items-start"), children: [
|
|
1816
1852
|
/* @__PURE__ */ jsx(
|
|
1817
1853
|
"textarea",
|
|
1818
1854
|
{
|
|
@@ -1826,17 +1862,17 @@ var TextareaCore = forwardRef(
|
|
|
1826
1862
|
rows: autoResize ? void 0 : rows ?? minRows,
|
|
1827
1863
|
"aria-invalid": isInvalid || void 0,
|
|
1828
1864
|
"aria-describedby": describedBy,
|
|
1865
|
+
"aria-required": required,
|
|
1866
|
+
required,
|
|
1829
1867
|
style: textareaStyle,
|
|
1830
|
-
className: cn(
|
|
1831
|
-
textareaBase,
|
|
1832
|
-
!autoResize && textareaResizeVariants[resize],
|
|
1833
|
-
autoResize && "resize-none overflow-hidden"
|
|
1834
|
-
),
|
|
1868
|
+
className: cn(textareaClasses, "py-3", className),
|
|
1835
1869
|
"data-size": size,
|
|
1836
1870
|
"data-invalid": isInvalid || void 0,
|
|
1837
1871
|
"data-success": isSuccess || void 0,
|
|
1872
|
+
"data-warning": isWarning || void 0,
|
|
1838
1873
|
"data-disabled": disabled || void 0,
|
|
1839
1874
|
"data-autoresize": autoResize || void 0,
|
|
1875
|
+
"data-maxlength-reached": hasReachedMaxLength || void 0,
|
|
1840
1876
|
...props
|
|
1841
1877
|
}
|
|
1842
1878
|
),
|
|
@@ -1846,30 +1882,26 @@ var TextareaCore = forwardRef(
|
|
|
1846
1882
|
type: "button",
|
|
1847
1883
|
"aria-label": "Clear textarea",
|
|
1848
1884
|
onClick: handleClear,
|
|
1849
|
-
className: "absolute right-2 top-2 flex items-center justify-center text-text-muted transition-colors hover:text-text",
|
|
1850
|
-
children: /* @__PURE__ */ jsx(X, { size: 14 })
|
|
1851
|
-
}
|
|
1852
|
-
),
|
|
1853
|
-
showCounter && /* @__PURE__ */ jsxs(
|
|
1854
|
-
"div",
|
|
1855
|
-
{
|
|
1856
|
-
id: counterId,
|
|
1857
1885
|
className: cn(
|
|
1858
|
-
"
|
|
1859
|
-
|
|
1886
|
+
"absolute right-2 top-2",
|
|
1887
|
+
"flex items-center justify-center",
|
|
1888
|
+
"text-text-muted",
|
|
1889
|
+
"transition-colors",
|
|
1890
|
+
"hover:text-text"
|
|
1860
1891
|
),
|
|
1861
|
-
children:
|
|
1862
|
-
draft.length,
|
|
1863
|
-
maxLength ? `/${maxLength}` : ""
|
|
1864
|
-
]
|
|
1892
|
+
children: /* @__PURE__ */ jsx(X, { size: 14 })
|
|
1865
1893
|
}
|
|
1866
1894
|
),
|
|
1895
|
+
showCounter && /* @__PURE__ */ jsxs("div", { id: counterId, className: counterClassName, children: [
|
|
1896
|
+
draft.length,
|
|
1897
|
+
maxLength ? `/${maxLength}` : ""
|
|
1898
|
+
] }),
|
|
1867
1899
|
internalValidation.message && !field && /* @__PURE__ */ jsx(
|
|
1868
1900
|
"p",
|
|
1869
1901
|
{
|
|
1870
1902
|
id: messageId,
|
|
1871
1903
|
role: "alert",
|
|
1872
|
-
className: "mt-1.5 px-0.5 text-xs text-
|
|
1904
|
+
className: cn("mt-1.5 px-0.5", "text-xs text-destructive"),
|
|
1873
1905
|
children: internalValidation.message
|
|
1874
1906
|
}
|
|
1875
1907
|
)
|
|
@@ -1961,29 +1993,6 @@ function insertLink(value, start, end) {
|
|
|
1961
1993
|
return { value: next, selectionStart: urlStart, selectionEnd: urlStart + 3 };
|
|
1962
1994
|
}
|
|
1963
1995
|
__name(insertLink, "insertLink");
|
|
1964
|
-
|
|
1965
|
-
// src/utils/env.ts
|
|
1966
|
-
function readProcessEnv() {
|
|
1967
|
-
try {
|
|
1968
|
-
return typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
|
|
1969
|
-
} catch {
|
|
1970
|
-
return void 0;
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
__name(readProcessEnv, "readProcessEnv");
|
|
1974
|
-
function readImportMetaEnv() {
|
|
1975
|
-
try {
|
|
1976
|
-
return typeof import.meta !== "undefined" ? import.meta.env?.MODE : void 0;
|
|
1977
|
-
} catch {
|
|
1978
|
-
return void 0;
|
|
1979
|
-
}
|
|
1980
|
-
}
|
|
1981
|
-
__name(readImportMetaEnv, "readImportMetaEnv");
|
|
1982
|
-
function isDev() {
|
|
1983
|
-
const mode = readProcessEnv() ?? readImportMetaEnv();
|
|
1984
|
-
return mode !== void 0 && mode !== "production";
|
|
1985
|
-
}
|
|
1986
|
-
__name(isDev, "isDev");
|
|
1987
1996
|
var TOOLBAR = [
|
|
1988
1997
|
{
|
|
1989
1998
|
label: "Heading",
|
|
@@ -2024,6 +2033,13 @@ var MarkdownEditor = forwardRef(
|
|
|
2024
2033
|
defaultValue,
|
|
2025
2034
|
onValueChange,
|
|
2026
2035
|
className,
|
|
2036
|
+
fullWidth,
|
|
2037
|
+
variant,
|
|
2038
|
+
success,
|
|
2039
|
+
error,
|
|
2040
|
+
warning,
|
|
2041
|
+
disabled,
|
|
2042
|
+
maxLength,
|
|
2027
2043
|
...textareaProps
|
|
2028
2044
|
}, ref) => {
|
|
2029
2045
|
const baseId = useId();
|
|
@@ -2032,8 +2048,22 @@ var MarkdownEditor = forwardRef(
|
|
|
2032
2048
|
defaultTab
|
|
2033
2049
|
);
|
|
2034
2050
|
const tab = tabProp ?? uncontrolledTab;
|
|
2051
|
+
const { theme } = useTheme();
|
|
2052
|
+
const field = useOptionalFormField();
|
|
2053
|
+
const footerMessage = hint;
|
|
2035
2054
|
const [draft, setDraft] = useState(() => valueProp ?? defaultValue ?? "");
|
|
2036
2055
|
const value = valueProp ?? draft;
|
|
2056
|
+
const maxLengthReached = typeof maxLength === "number" && value.length >= maxLength;
|
|
2057
|
+
const state = error || maxLengthReached ? "error" : success ? "success" : warning ? "warning" : field?.status ?? "none";
|
|
2058
|
+
const editorClasses = cn(
|
|
2059
|
+
resolveRecipe(theme.recipes.MarkdownEditor, {
|
|
2060
|
+
variant,
|
|
2061
|
+
state,
|
|
2062
|
+
fullWidth,
|
|
2063
|
+
disabled: !!disabled
|
|
2064
|
+
}),
|
|
2065
|
+
className
|
|
2066
|
+
);
|
|
2037
2067
|
function setTab(next) {
|
|
2038
2068
|
if (tabProp === void 0) setUncontrolledTab(next);
|
|
2039
2069
|
onTabChange?.(next);
|
|
@@ -2045,6 +2075,7 @@ var MarkdownEditor = forwardRef(
|
|
|
2045
2075
|
}
|
|
2046
2076
|
__name(commit, "commit");
|
|
2047
2077
|
function runAction(action) {
|
|
2078
|
+
if (disabled) return;
|
|
2048
2079
|
const el = textareaRef.current;
|
|
2049
2080
|
if (!el) return;
|
|
2050
2081
|
const { selectionStart, selectionEnd } = el;
|
|
@@ -2074,94 +2105,91 @@ var MarkdownEditor = forwardRef(
|
|
|
2074
2105
|
);
|
|
2075
2106
|
}
|
|
2076
2107
|
}, [renderMarkdown]);
|
|
2077
|
-
return /* @__PURE__ */ jsxs(
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
"
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2108
|
+
return /* @__PURE__ */ jsxs("div", { className: editorClasses, children: [
|
|
2109
|
+
/* @__PURE__ */ jsxs(
|
|
2110
|
+
"div",
|
|
2111
|
+
{
|
|
2112
|
+
role: "tablist",
|
|
2113
|
+
"aria-label": "Markdown editor mode",
|
|
2114
|
+
id: tablistId,
|
|
2115
|
+
className: "flex items-center gap-4 border-b border-border px-3",
|
|
2116
|
+
children: [
|
|
2117
|
+
["write", "preview"].map((t) => /* @__PURE__ */ jsx(
|
|
2118
|
+
"button",
|
|
2119
|
+
{
|
|
2120
|
+
type: "button",
|
|
2121
|
+
role: "tab",
|
|
2122
|
+
id: `${baseId}-${t}-tab`,
|
|
2123
|
+
"aria-selected": tab === t,
|
|
2124
|
+
"aria-controls": t === "write" ? writePanelId : previewPanelId,
|
|
2125
|
+
onClick: () => setTab(t),
|
|
2126
|
+
disabled,
|
|
2127
|
+
className: cn(
|
|
2128
|
+
"border-b-2 py-2.5 text-sm capitalize transition-colors",
|
|
2129
|
+
"disabled:pointer-events-none disabled:cursor-not-allowed",
|
|
2130
|
+
tab === t ? "border-brand text-text" : "border-transparent text-text-muted hover:text-text"
|
|
2131
|
+
),
|
|
2132
|
+
children: t
|
|
2133
|
+
},
|
|
2134
|
+
t
|
|
2135
|
+
)),
|
|
2136
|
+
tab === "write" && /* @__PURE__ */ jsx("div", { className: "ml-auto flex items-center gap-1 py-1.5", children: TOOLBAR.map(({ label, icon: Icon, action }) => /* @__PURE__ */ jsx(
|
|
2137
|
+
"button",
|
|
2138
|
+
{
|
|
2139
|
+
type: "button",
|
|
2140
|
+
"aria-label": label,
|
|
2141
|
+
onClick: () => runAction(action),
|
|
2142
|
+
disabled,
|
|
2143
|
+
className: "rounded-(--kui-radii-sm) p-1.5 text-text-muted transition-colors hover:bg-surface-raised hover:text-text disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
|
|
2144
|
+
children: /* @__PURE__ */ jsx(Icon, { size: 15 })
|
|
2145
|
+
},
|
|
2146
|
+
label
|
|
2147
|
+
)) })
|
|
2148
|
+
]
|
|
2149
|
+
}
|
|
2150
|
+
),
|
|
2151
|
+
/* @__PURE__ */ jsx(
|
|
2152
|
+
"div",
|
|
2153
|
+
{
|
|
2154
|
+
id: writePanelId,
|
|
2155
|
+
role: "tabpanel",
|
|
2156
|
+
"aria-labelledby": `${baseId}-write-tab`,
|
|
2157
|
+
hidden: tab !== "write",
|
|
2158
|
+
children: /* @__PURE__ */ jsx(
|
|
2159
|
+
TextareaCore,
|
|
2126
2160
|
{
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
{
|
|
2134
|
-
ref: (node) => {
|
|
2135
|
-
textareaRef.current = node;
|
|
2136
|
-
if (typeof ref === "function") ref(node);
|
|
2137
|
-
else if (ref)
|
|
2138
|
-
ref.current = node;
|
|
2139
|
-
},
|
|
2140
|
-
value,
|
|
2141
|
-
onValueChange: commit,
|
|
2142
|
-
resize: "vertical",
|
|
2143
|
-
variant: "ghost",
|
|
2144
|
-
className: "rounded-none border-0",
|
|
2145
|
-
...textareaProps
|
|
2161
|
+
ref: (node) => {
|
|
2162
|
+
textareaRef.current = node;
|
|
2163
|
+
if (typeof ref === "function") {
|
|
2164
|
+
ref(node);
|
|
2165
|
+
} else if (ref) {
|
|
2166
|
+
ref.current = node;
|
|
2146
2167
|
}
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
"aria-labelledby": `${baseId}-preview-tab`,
|
|
2156
|
-
hidden: tab !== "preview",
|
|
2157
|
-
className: "min-h-32 p-3 text-sm text-text",
|
|
2158
|
-
children: renderMarkdown ? renderedPreview : /* @__PURE__ */ jsx("span", { className: "text-text-muted", children: "No renderMarkdown provided \u2014 showing raw text." })
|
|
2168
|
+
},
|
|
2169
|
+
value,
|
|
2170
|
+
onValueChange: commit,
|
|
2171
|
+
embedded: true,
|
|
2172
|
+
resize: "vertical",
|
|
2173
|
+
disabled,
|
|
2174
|
+
maxLength,
|
|
2175
|
+
...textareaProps
|
|
2159
2176
|
}
|
|
2160
|
-
)
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2177
|
+
)
|
|
2178
|
+
}
|
|
2179
|
+
),
|
|
2180
|
+
/* @__PURE__ */ jsx(
|
|
2181
|
+
"div",
|
|
2182
|
+
{
|
|
2183
|
+
id: previewPanelId,
|
|
2184
|
+
role: "tabpanel",
|
|
2185
|
+
"aria-labelledby": `${baseId}-preview-tab`,
|
|
2186
|
+
hidden: tab !== "preview",
|
|
2187
|
+
className: "min-h-32 p-3 text-sm text-text",
|
|
2188
|
+
children: renderMarkdown ? renderedPreview : /* @__PURE__ */ jsx("span", { className: "text-text-muted", children: "No renderMarkdown provided \u2014 showing raw text." })
|
|
2189
|
+
}
|
|
2190
|
+
),
|
|
2191
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 border-t border-border px-3 py-2 text-xs z-1", children: footerMessage })
|
|
2192
|
+
] });
|
|
2165
2193
|
}
|
|
2166
2194
|
);
|
|
2167
2195
|
MarkdownEditor.displayName = "MarkdownEditor";
|
|
@@ -2174,60 +2202,6 @@ var Textarea = forwardRef(
|
|
|
2174
2202
|
}
|
|
2175
2203
|
);
|
|
2176
2204
|
Textarea.displayName = "Textarea";
|
|
2177
|
-
var checkboxBoxVariants = cva(
|
|
2178
|
-
"flex shrink-0 items-center justify-center rounded-[calc(var(--kui-radii-md)-2px)] border transition-colors duration-[var(--kui-duration-fast)]",
|
|
2179
|
-
{
|
|
2180
|
-
variants: {
|
|
2181
|
-
size: {
|
|
2182
|
-
sm: "h-4 w-4",
|
|
2183
|
-
md: "h-5 w-5",
|
|
2184
|
-
lg: "h-6 w-6"
|
|
2185
|
-
},
|
|
2186
|
-
state: {
|
|
2187
|
-
none: "",
|
|
2188
|
-
error: "border-danger",
|
|
2189
|
-
success: "border-success"
|
|
2190
|
-
},
|
|
2191
|
-
checked: {
|
|
2192
|
-
true: "bg-brand border-brand text-brand-fg",
|
|
2193
|
-
false: "border-border bg-transparent"
|
|
2194
|
-
},
|
|
2195
|
-
disabled: {
|
|
2196
|
-
true: "cursor-not-allowed",
|
|
2197
|
-
false: "cursor-pointer"
|
|
2198
|
-
}
|
|
2199
|
-
},
|
|
2200
|
-
defaultVariants: {
|
|
2201
|
-
size: "md",
|
|
2202
|
-
state: "none",
|
|
2203
|
-
checked: false,
|
|
2204
|
-
disabled: false
|
|
2205
|
-
},
|
|
2206
|
-
compoundVariants: [
|
|
2207
|
-
{ checked: false, state: "error", class: "border-danger" },
|
|
2208
|
-
{ checked: false, state: "success", class: "border-success" }
|
|
2209
|
-
]
|
|
2210
|
-
}
|
|
2211
|
-
);
|
|
2212
|
-
var checkboxIconSizes = {
|
|
2213
|
-
sm: 10,
|
|
2214
|
-
md: 12,
|
|
2215
|
-
lg: 14
|
|
2216
|
-
};
|
|
2217
|
-
function DashIcon({ size }) {
|
|
2218
|
-
return /* @__PURE__ */ jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 3, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsx("line", { x1: "5", y1: "12", x2: "19", y2: "12" }) });
|
|
2219
|
-
}
|
|
2220
|
-
__name(DashIcon, "DashIcon");
|
|
2221
|
-
function mergeRefs3(...refs) {
|
|
2222
|
-
return (node) => {
|
|
2223
|
-
refs.forEach((r) => {
|
|
2224
|
-
if (!r) return;
|
|
2225
|
-
if (typeof r === "function") r(node);
|
|
2226
|
-
else r.current = node;
|
|
2227
|
-
});
|
|
2228
|
-
};
|
|
2229
|
-
}
|
|
2230
|
-
__name(mergeRefs3, "mergeRefs");
|
|
2231
2205
|
var Checkbox = forwardRef(
|
|
2232
2206
|
({
|
|
2233
2207
|
className,
|
|
@@ -2235,9 +2209,10 @@ var Checkbox = forwardRef(
|
|
|
2235
2209
|
defaultChecked,
|
|
2236
2210
|
onCheckedChange,
|
|
2237
2211
|
indeterminate = false,
|
|
2238
|
-
size = "
|
|
2212
|
+
size = "sm",
|
|
2239
2213
|
error,
|
|
2240
2214
|
success,
|
|
2215
|
+
status,
|
|
2241
2216
|
disabled,
|
|
2242
2217
|
label,
|
|
2243
2218
|
description,
|
|
@@ -2248,97 +2223,136 @@ var Checkbox = forwardRef(
|
|
|
2248
2223
|
}, ref) => {
|
|
2249
2224
|
const autoId = useId();
|
|
2250
2225
|
const field = useOptionalFormField();
|
|
2226
|
+
const { theme } = useTheme();
|
|
2251
2227
|
const id = field?.id ?? externalId ?? autoId;
|
|
2252
|
-
const
|
|
2228
|
+
const inputRef = useRef(null);
|
|
2253
2229
|
const [internalChecked, setInternalChecked] = useState(
|
|
2254
2230
|
defaultChecked ?? false
|
|
2255
2231
|
);
|
|
2256
|
-
const
|
|
2232
|
+
const isControlled = checkedProp !== void 0;
|
|
2233
|
+
const checked = isControlled ? checkedProp : internalChecked;
|
|
2257
2234
|
const hasWarned = useRef(false);
|
|
2258
2235
|
useEffect(() => {
|
|
2259
|
-
if (
|
|
2260
|
-
if (hasWarned.current) return;
|
|
2236
|
+
if (!isDev() || hasWarned.current) return;
|
|
2261
2237
|
if (label && field?.hasExternalLabel) {
|
|
2262
2238
|
console.warn(
|
|
2263
|
-
"[kreativ-ui/Checkbox] This checkbox has both a `label` prop and a <FormField.Label> ancestor.
|
|
2239
|
+
"[kreativ-ui/Checkbox] This checkbox has both a `label` prop and a <FormField.Label> ancestor. Checkbox owns its label. Use the Checkbox `label` prop instead of <FormField.Label>."
|
|
2264
2240
|
);
|
|
2265
2241
|
hasWarned.current = true;
|
|
2266
2242
|
}
|
|
2267
2243
|
}, [label, field?.hasExternalLabel]);
|
|
2268
2244
|
useEffect(() => {
|
|
2269
|
-
if (
|
|
2270
|
-
|
|
2245
|
+
if (inputRef.current) {
|
|
2246
|
+
inputRef.current.indeterminate = indeterminate;
|
|
2247
|
+
}
|
|
2271
2248
|
}, [indeterminate]);
|
|
2272
2249
|
const isInvalid = error ?? field?.invalid ?? false;
|
|
2273
2250
|
const isSuccess = success ?? false;
|
|
2274
|
-
const state = isInvalid ? "error" : isSuccess ? "success" : "none";
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2251
|
+
const state = status ? status : isInvalid ? "error" : isSuccess ? "success" : "none";
|
|
2252
|
+
const hasLabels = label || description;
|
|
2253
|
+
const {
|
|
2254
|
+
style: sizeStyle,
|
|
2255
|
+
iconSize,
|
|
2256
|
+
fontSize
|
|
2257
|
+
} = useSizeStyle(size, !hasLabels, "checkbox", {
|
|
2258
|
+
widthFromHeight: true,
|
|
2259
|
+
sizeOffset: "7px"
|
|
2260
|
+
});
|
|
2261
|
+
const checkboxClasses = resolveRecipe(theme.recipes.Checkbox, {
|
|
2262
|
+
state,
|
|
2263
|
+
checked: checked || indeterminate,
|
|
2264
|
+
disabled: !!disabled
|
|
2265
|
+
});
|
|
2266
|
+
const statusTransition = useStatusTransition(state);
|
|
2267
|
+
const descriptionId = description ? `${id}-description` : void 0;
|
|
2268
|
+
const describedBy = [field?.describedBy, descriptionId].filter(Boolean).join(" ") || void 0;
|
|
2269
|
+
function handleChange(event) {
|
|
2270
|
+
const nextChecked = event.target.checked;
|
|
2271
|
+
if (!isControlled) {
|
|
2272
|
+
setInternalChecked(nextChecked);
|
|
2273
|
+
}
|
|
2274
|
+
onCheckedChange?.(nextChecked);
|
|
2275
|
+
onChangeProp?.(event);
|
|
2280
2276
|
}
|
|
2281
2277
|
__name(handleChange, "handleChange");
|
|
2282
|
-
const
|
|
2283
|
-
|
|
2278
|
+
const wasInvalidRef = useRef(isInvalid);
|
|
2279
|
+
useEffect(() => {
|
|
2280
|
+
const justBecameInvalid = isInvalid && !wasInvalidRef.current;
|
|
2281
|
+
wasInvalidRef.current = isInvalid;
|
|
2282
|
+
if (!justBecameInvalid) {
|
|
2283
|
+
return;
|
|
2284
|
+
}
|
|
2285
|
+
inputRef.current?.scrollIntoView({
|
|
2286
|
+
behavior: "smooth",
|
|
2287
|
+
block: "center"
|
|
2288
|
+
});
|
|
2289
|
+
}, [isInvalid]);
|
|
2284
2290
|
return /* @__PURE__ */ jsxs(
|
|
2285
2291
|
"div",
|
|
2286
2292
|
{
|
|
2287
2293
|
className: cn(
|
|
2288
|
-
"flex gap-2
|
|
2294
|
+
"inline-flex items-start gap-2",
|
|
2289
2295
|
disabled && "cursor-not-allowed opacity-50",
|
|
2290
2296
|
className
|
|
2291
2297
|
),
|
|
2292
2298
|
children: [
|
|
2293
|
-
/* @__PURE__ */ jsxs("div", { className: "relative
|
|
2299
|
+
/* @__PURE__ */ jsxs("div", { className: "relative inline-flex shrink-0", children: [
|
|
2294
2300
|
/* @__PURE__ */ jsx(
|
|
2295
2301
|
"input",
|
|
2296
2302
|
{
|
|
2297
|
-
|
|
2298
|
-
|
|
2303
|
+
...props,
|
|
2304
|
+
ref: mergeRefs(inputRef, ref),
|
|
2299
2305
|
id,
|
|
2306
|
+
type: "checkbox",
|
|
2300
2307
|
checked,
|
|
2301
2308
|
disabled,
|
|
2302
2309
|
required: required ?? field?.required,
|
|
2303
2310
|
onChange: handleChange,
|
|
2304
2311
|
"aria-invalid": isInvalid || void 0,
|
|
2305
2312
|
"aria-describedby": describedBy,
|
|
2306
|
-
className: "peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
|
|
2307
2313
|
"data-invalid": isInvalid || void 0,
|
|
2308
|
-
|
|
2314
|
+
className: cn(
|
|
2315
|
+
"peer absolute inset-0 z-10 m-0 h-full w-full",
|
|
2316
|
+
"cursor-pointer opacity-0",
|
|
2317
|
+
"disabled:cursor-not-allowed"
|
|
2318
|
+
)
|
|
2309
2319
|
}
|
|
2310
2320
|
),
|
|
2311
2321
|
/* @__PURE__ */ jsx(
|
|
2312
|
-
"
|
|
2322
|
+
"span",
|
|
2313
2323
|
{
|
|
2314
2324
|
"aria-hidden": "true",
|
|
2315
|
-
className:
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
checked: checked || indeterminate,
|
|
2320
|
-
disabled: !!disabled
|
|
2321
|
-
}),
|
|
2322
|
-
"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
|
|
2323
|
-
),
|
|
2324
|
-
children: indeterminate ? /* @__PURE__ */ jsx(DashIcon, { size: checkboxIconSizes[size] }) : checked ? /* @__PURE__ */ jsx(Check, { size: checkboxIconSizes[size] }) : null
|
|
2325
|
+
className: checkboxClasses,
|
|
2326
|
+
style: sizeStyle,
|
|
2327
|
+
"data-state-transition": statusTransition,
|
|
2328
|
+
children: /* @__PURE__ */ jsx("span", { className: "absolute inset-0 flex items-center justify-center shrink-0", children: indeterminate ? /* @__PURE__ */ jsx(Minus, { strokeWidth: 3, size: iconSize }) : checked ? /* @__PURE__ */ jsx(Check, { strokeWidth: 3, size: iconSize }) : null })
|
|
2325
2329
|
}
|
|
2326
2330
|
)
|
|
2327
2331
|
] }),
|
|
2328
|
-
|
|
2329
|
-
label
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
children: label
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2332
|
+
hasLabels && /* @__PURE__ */ jsxs(
|
|
2333
|
+
"label",
|
|
2334
|
+
{
|
|
2335
|
+
htmlFor: id,
|
|
2336
|
+
className: cn(
|
|
2337
|
+
"flex flex-col gap-px",
|
|
2338
|
+
!disabled && "cursor-pointer"
|
|
2339
|
+
),
|
|
2340
|
+
children: [
|
|
2341
|
+
label && /* @__PURE__ */ jsx("span", { className: "text-text", style: { fontSize }, children: label }),
|
|
2342
|
+
description && /* @__PURE__ */ jsx(
|
|
2343
|
+
"span",
|
|
2344
|
+
{
|
|
2345
|
+
id: descriptionId,
|
|
2346
|
+
className: "text-text-muted",
|
|
2347
|
+
style: {
|
|
2348
|
+
fontSize: fontSize ? `calc(${fontSize} - 1px)` : void 0
|
|
2349
|
+
},
|
|
2350
|
+
children: description
|
|
2351
|
+
}
|
|
2352
|
+
)
|
|
2353
|
+
]
|
|
2354
|
+
}
|
|
2355
|
+
)
|
|
2342
2356
|
]
|
|
2343
2357
|
}
|
|
2344
2358
|
);
|
|
@@ -2419,7 +2433,7 @@ var radioBubbleVariants = cva(
|
|
|
2419
2433
|
},
|
|
2420
2434
|
state: {
|
|
2421
2435
|
none: "",
|
|
2422
|
-
error: "border-
|
|
2436
|
+
error: "border-destructive",
|
|
2423
2437
|
success: "border-success"
|
|
2424
2438
|
},
|
|
2425
2439
|
checked: {
|
|
@@ -2431,9 +2445,14 @@ var radioBubbleVariants = cva(
|
|
|
2431
2445
|
false: "cursor-pointer"
|
|
2432
2446
|
}
|
|
2433
2447
|
},
|
|
2434
|
-
defaultVariants: {
|
|
2448
|
+
defaultVariants: {
|
|
2449
|
+
size: "md",
|
|
2450
|
+
state: "none",
|
|
2451
|
+
checked: false,
|
|
2452
|
+
disabled: false
|
|
2453
|
+
},
|
|
2435
2454
|
compoundVariants: [
|
|
2436
|
-
{ checked: false, state: "error", class: "border-
|
|
2455
|
+
{ checked: false, state: "error", class: "border-destructive" },
|
|
2437
2456
|
{ checked: false, state: "success", class: "border-success" }
|
|
2438
2457
|
]
|
|
2439
2458
|
}
|
|
@@ -2515,6 +2534,7 @@ var switchTrackVariants = cva(
|
|
|
2515
2534
|
}
|
|
2516
2535
|
);
|
|
2517
2536
|
var switchThumbConfig = {
|
|
2537
|
+
xs: { thumb: "h-3 w-3", translate: "translate-x-3" },
|
|
2518
2538
|
sm: { thumb: "h-3 w-3", translate: "translate-x-3" },
|
|
2519
2539
|
md: { thumb: "h-4 w-4", translate: "translate-x-4" },
|
|
2520
2540
|
lg: { thumb: "h-5 w-5", translate: "translate-x-5" }
|
|
@@ -2567,7 +2587,7 @@ function Switch({
|
|
|
2567
2587
|
{
|
|
2568
2588
|
"aria-hidden": "true",
|
|
2569
2589
|
className: cn(
|
|
2570
|
-
switchTrackVariants({
|
|
2590
|
+
switchTrackVariants({ checked, disabled: !!disabled }),
|
|
2571
2591
|
"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
|
|
2572
2592
|
),
|
|
2573
2593
|
children: /* @__PURE__ */ jsx(
|
|
@@ -2597,7 +2617,7 @@ function useComboboxContext(componentName) {
|
|
|
2597
2617
|
return ctx;
|
|
2598
2618
|
}
|
|
2599
2619
|
__name(useComboboxContext, "useComboboxContext");
|
|
2600
|
-
var
|
|
2620
|
+
var inputBase = [
|
|
2601
2621
|
"flex",
|
|
2602
2622
|
"items-center",
|
|
2603
2623
|
"font-sans",
|
|
@@ -2620,7 +2640,7 @@ var inputWrapperVariants = cva(
|
|
|
2620
2640
|
},
|
|
2621
2641
|
state: {
|
|
2622
2642
|
none: "focus-within:ring-2 focus-within:ring-brand/20",
|
|
2623
|
-
error: "border-
|
|
2643
|
+
error: "border-destructive focus-within:ring-2 focus-within:ring-destructive/20",
|
|
2624
2644
|
success: "border-success focus-within:ring-2 focus-within:ring-success/20"
|
|
2625
2645
|
},
|
|
2626
2646
|
rounded: {
|
|
@@ -2651,6 +2671,7 @@ var inputWrapperVariants = cva(
|
|
|
2651
2671
|
}
|
|
2652
2672
|
);
|
|
2653
2673
|
var inputSizeVariants = {
|
|
2674
|
+
xs: "h-8 px-2 text-xs",
|
|
2654
2675
|
sm: "h-8 px-2 text-xs",
|
|
2655
2676
|
md: "h-10 px-3 text-sm",
|
|
2656
2677
|
lg: "h-12 px-4 text-base"
|
|
@@ -2756,7 +2777,7 @@ var ComboboxInput = forwardRef(
|
|
|
2756
2777
|
onKeyDown: handleKeyDown,
|
|
2757
2778
|
onBlur: handleBlur,
|
|
2758
2779
|
"data-state": ctx.open ? "open" : "closed",
|
|
2759
|
-
className: cn(
|
|
2780
|
+
className: cn(inputBase, "flex-1 border-0 bg-transparent outline-none", inputSizeVariants[size], "px-0")
|
|
2760
2781
|
}
|
|
2761
2782
|
),
|
|
2762
2783
|
showClear && /* @__PURE__ */ jsx(
|
|
@@ -3101,7 +3122,7 @@ var MultiSelectTrigger = forwardRef(
|
|
|
3101
3122
|
ref: ctx.triggerRef,
|
|
3102
3123
|
className: cn(
|
|
3103
3124
|
inputWrapperVariants({ variant: ctx.variant, state, fullWidth: true, disabled: ctx.disabled, rounded: ctx.rounded }),
|
|
3104
|
-
multiSelectSizeVariants({
|
|
3125
|
+
multiSelectSizeVariants({}),
|
|
3105
3126
|
"flex flex-wrap items-center gap-1",
|
|
3106
3127
|
className
|
|
3107
3128
|
),
|
|
@@ -3131,7 +3152,7 @@ var MultiSelectTrigger = forwardRef(
|
|
|
3131
3152
|
"span",
|
|
3132
3153
|
{
|
|
3133
3154
|
className: cn(
|
|
3134
|
-
chipSizeVariants({
|
|
3155
|
+
chipSizeVariants({}),
|
|
3135
3156
|
"bg-brand/15 text-brand"
|
|
3136
3157
|
),
|
|
3137
3158
|
children: [
|
|
@@ -3371,15 +3392,235 @@ function MultiSelect({
|
|
|
3371
3392
|
}),
|
|
3372
3393
|
[value, toggleValue, removeValue, disabled, variant, size, open, triggerId, contentId, field?.invalid, field?.describedBy, field?.required, required, placeholder, maxVisibleChips, activeValue, registerItem, optionId, error, success, rounded, clearable, handleClear]
|
|
3373
3394
|
);
|
|
3374
|
-
return /* @__PURE__ */ jsx(MultiSelectContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, className: className ?? "relative w-full", children: [
|
|
3375
|
-
children,
|
|
3376
|
-
name && value.map((v) => /* @__PURE__ */ jsx("input", { type: "hidden", name: `${name}[]`, value: v, disabled }, v))
|
|
3377
|
-
] }) });
|
|
3395
|
+
return /* @__PURE__ */ jsx(MultiSelectContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxs("div", { ref: rootRef, className: className ?? "relative w-full", children: [
|
|
3396
|
+
children,
|
|
3397
|
+
name && value.map((v) => /* @__PURE__ */ jsx("input", { type: "hidden", name: `${name}[]`, value: v, disabled }, v))
|
|
3398
|
+
] }) });
|
|
3399
|
+
}
|
|
3400
|
+
__name(MultiSelect, "MultiSelect");
|
|
3401
|
+
MultiSelect.Trigger = MultiSelectTrigger;
|
|
3402
|
+
MultiSelect.Content = MultiSelectContent;
|
|
3403
|
+
MultiSelect.Item = MultiSelectItem;
|
|
3404
|
+
var InputField = forwardRef(
|
|
3405
|
+
({
|
|
3406
|
+
id,
|
|
3407
|
+
label,
|
|
3408
|
+
description,
|
|
3409
|
+
message,
|
|
3410
|
+
required,
|
|
3411
|
+
optional,
|
|
3412
|
+
labelStart,
|
|
3413
|
+
labelEnd,
|
|
3414
|
+
labelClassName,
|
|
3415
|
+
status = "none",
|
|
3416
|
+
...inputProps
|
|
3417
|
+
}, ref) => {
|
|
3418
|
+
const error = status === "error";
|
|
3419
|
+
const success = status === "success";
|
|
3420
|
+
const warning = status === "warning";
|
|
3421
|
+
return /* @__PURE__ */ jsxs(FormField, { id, message, required, children: [
|
|
3422
|
+
label && /* @__PURE__ */ jsxs(FormField.Label, { className: labelClassName, children: [
|
|
3423
|
+
labelStart,
|
|
3424
|
+
label,
|
|
3425
|
+
optional && /* @__PURE__ */ jsx("span", { className: "text-text-muted", children: " (optional)" }),
|
|
3426
|
+
labelEnd
|
|
3427
|
+
] }),
|
|
3428
|
+
/* @__PURE__ */ jsx(FormField.Control, { children: /* @__PURE__ */ jsx(
|
|
3429
|
+
Input,
|
|
3430
|
+
{
|
|
3431
|
+
...inputProps,
|
|
3432
|
+
ref,
|
|
3433
|
+
id,
|
|
3434
|
+
error,
|
|
3435
|
+
success,
|
|
3436
|
+
warning,
|
|
3437
|
+
required
|
|
3438
|
+
}
|
|
3439
|
+
) }),
|
|
3440
|
+
description && /* @__PURE__ */ jsx(FormField.Description, { children: description }),
|
|
3441
|
+
/* @__PURE__ */ jsx(FormField.Message, { children: message })
|
|
3442
|
+
] });
|
|
3443
|
+
}
|
|
3444
|
+
);
|
|
3445
|
+
InputField.displayName = "InputField";
|
|
3446
|
+
|
|
3447
|
+
// src/provider/cssVariables.ts
|
|
3448
|
+
function toKebabCase(str) {
|
|
3449
|
+
return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
3450
|
+
}
|
|
3451
|
+
__name(toKebabCase, "toKebabCase");
|
|
3452
|
+
function colorToRgbChannels(value) {
|
|
3453
|
+
const trimmed = value.trim();
|
|
3454
|
+
const rgbMatch = trimmed.match(
|
|
3455
|
+
/^rgba?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(?:\s*[/,]\s*[\d.]+%?)?\s*\)$/i
|
|
3456
|
+
);
|
|
3457
|
+
if (rgbMatch) {
|
|
3458
|
+
return `${rgbMatch[1]} ${rgbMatch[2]} ${rgbMatch[3]}`;
|
|
3459
|
+
}
|
|
3460
|
+
if (trimmed.startsWith("#")) {
|
|
3461
|
+
const hex = trimmed.slice(1);
|
|
3462
|
+
if (hex.length === 3) {
|
|
3463
|
+
const r = parseInt(hex[0] + hex[0], 16);
|
|
3464
|
+
const g = parseInt(hex[1] + hex[1], 16);
|
|
3465
|
+
const b = parseInt(hex[2] + hex[2], 16);
|
|
3466
|
+
return `${r} ${g} ${b}`;
|
|
3467
|
+
}
|
|
3468
|
+
if (hex.length === 6) {
|
|
3469
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
3470
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
3471
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
3472
|
+
return `${r} ${g} ${b}`;
|
|
3473
|
+
}
|
|
3474
|
+
}
|
|
3475
|
+
if (/^\d+(?:\.\d+)?\s+\d+(?:\.\d+)?\s+\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
3476
|
+
return trimmed;
|
|
3477
|
+
}
|
|
3478
|
+
return value;
|
|
3479
|
+
}
|
|
3480
|
+
__name(colorToRgbChannels, "colorToRgbChannels");
|
|
3481
|
+
function getTokenValue(reference, tokens) {
|
|
3482
|
+
const path = reference.replace(/^\{/, "").replace(/\}$/, "").split(".");
|
|
3483
|
+
let current = tokens;
|
|
3484
|
+
for (const segment of path) {
|
|
3485
|
+
if (typeof current !== "object" || current === null || !(segment in current)) {
|
|
3486
|
+
return void 0;
|
|
3487
|
+
}
|
|
3488
|
+
current = current[segment];
|
|
3489
|
+
}
|
|
3490
|
+
if (typeof current === "object" && current !== null && "value" in current) {
|
|
3491
|
+
const value = current.value;
|
|
3492
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
3493
|
+
return value;
|
|
3494
|
+
}
|
|
3495
|
+
}
|
|
3496
|
+
return void 0;
|
|
3497
|
+
}
|
|
3498
|
+
__name(getTokenValue, "getTokenValue");
|
|
3499
|
+
function resolveReference(reference, tokens, seen = /* @__PURE__ */ new Set()) {
|
|
3500
|
+
if (seen.has(reference)) {
|
|
3501
|
+
console.error(
|
|
3502
|
+
`[kreativ-ui] Circular token reference detected: ${reference}`
|
|
3503
|
+
);
|
|
3504
|
+
return void 0;
|
|
3505
|
+
}
|
|
3506
|
+
const nextSeen = new Set(seen);
|
|
3507
|
+
nextSeen.add(reference);
|
|
3508
|
+
const value = getTokenValue(reference, tokens);
|
|
3509
|
+
if (value === void 0) {
|
|
3510
|
+
console.warn(
|
|
3511
|
+
`[kreativ-ui] Unable to resolve token reference: ${reference}`
|
|
3512
|
+
);
|
|
3513
|
+
return void 0;
|
|
3514
|
+
}
|
|
3515
|
+
if (typeof value === "number") {
|
|
3516
|
+
return String(value);
|
|
3517
|
+
}
|
|
3518
|
+
if (value.startsWith("{") && value.endsWith("}")) {
|
|
3519
|
+
return resolveReference(value, tokens, nextSeen);
|
|
3520
|
+
}
|
|
3521
|
+
return value;
|
|
3522
|
+
}
|
|
3523
|
+
__name(resolveReference, "resolveReference");
|
|
3524
|
+
function resolveValue(value, tokens) {
|
|
3525
|
+
if (typeof value === "number") {
|
|
3526
|
+
return String(value);
|
|
3527
|
+
}
|
|
3528
|
+
if (typeof value !== "string") {
|
|
3529
|
+
return void 0;
|
|
3530
|
+
}
|
|
3531
|
+
if (value.startsWith("{") && value.endsWith("}")) {
|
|
3532
|
+
return resolveReference(value, tokens);
|
|
3533
|
+
}
|
|
3534
|
+
return value;
|
|
3535
|
+
}
|
|
3536
|
+
__name(resolveValue, "resolveValue");
|
|
3537
|
+
function flattenTokens(value, path, result, tokens) {
|
|
3538
|
+
if (typeof value !== "object" || value === null) {
|
|
3539
|
+
return;
|
|
3540
|
+
}
|
|
3541
|
+
if ("value" in value) {
|
|
3542
|
+
const tokenValue = value.value;
|
|
3543
|
+
const resolved = resolveValue(tokenValue, tokens);
|
|
3544
|
+
if (resolved !== void 0) {
|
|
3545
|
+
result[path.join(".")] = resolved;
|
|
3546
|
+
}
|
|
3547
|
+
return;
|
|
3548
|
+
}
|
|
3549
|
+
for (const [key, child] of Object.entries(value)) {
|
|
3550
|
+
flattenTokens(child, [...path, key], result, tokens);
|
|
3551
|
+
}
|
|
3552
|
+
}
|
|
3553
|
+
__name(flattenTokens, "flattenTokens");
|
|
3554
|
+
function resolveSemanticValue(value, mode, tokens) {
|
|
3555
|
+
if (typeof value === "object" && value !== null && "light" in value && "dark" in value) {
|
|
3556
|
+
const modeValue = value[mode];
|
|
3557
|
+
return resolveValue(modeValue, tokens);
|
|
3558
|
+
}
|
|
3559
|
+
return resolveValue(value, tokens);
|
|
3560
|
+
}
|
|
3561
|
+
__name(resolveSemanticValue, "resolveSemanticValue");
|
|
3562
|
+
function resolveSemanticTokens(semanticTokens, tokens, mode) {
|
|
3563
|
+
const result = {};
|
|
3564
|
+
function walk(value, path) {
|
|
3565
|
+
if (typeof value !== "object" || value === null) {
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
if ("value" in value) {
|
|
3569
|
+
const semanticValue = value.value;
|
|
3570
|
+
const resolved = resolveSemanticValue(semanticValue, mode, tokens);
|
|
3571
|
+
if (resolved !== void 0) {
|
|
3572
|
+
result[path.join(".")] = resolved;
|
|
3573
|
+
}
|
|
3574
|
+
return;
|
|
3575
|
+
}
|
|
3576
|
+
for (const [key, child] of Object.entries(
|
|
3577
|
+
value
|
|
3578
|
+
)) {
|
|
3579
|
+
walk(child, [...path, key]);
|
|
3580
|
+
}
|
|
3581
|
+
}
|
|
3582
|
+
__name(walk, "walk");
|
|
3583
|
+
walk(semanticTokens, []);
|
|
3584
|
+
return result;
|
|
3585
|
+
}
|
|
3586
|
+
__name(resolveSemanticTokens, "resolveSemanticTokens");
|
|
3587
|
+
function resolveTokens(tokens, semanticTokens, mode) {
|
|
3588
|
+
const primitiveTokens = {};
|
|
3589
|
+
flattenTokens(tokens, [], primitiveTokens, tokens);
|
|
3590
|
+
const resolvedSemanticTokens = resolveSemanticTokens(
|
|
3591
|
+
semanticTokens,
|
|
3592
|
+
tokens,
|
|
3593
|
+
mode
|
|
3594
|
+
);
|
|
3595
|
+
return {
|
|
3596
|
+
...primitiveTokens,
|
|
3597
|
+
...resolvedSemanticTokens
|
|
3598
|
+
};
|
|
3378
3599
|
}
|
|
3379
|
-
__name(
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3600
|
+
__name(resolveTokens, "resolveTokens");
|
|
3601
|
+
function tokensToCssVars(tokens, mode, intensity) {
|
|
3602
|
+
const cssVars = {};
|
|
3603
|
+
for (const [path, value] of Object.entries(tokens)) {
|
|
3604
|
+
const parts = path.split(".");
|
|
3605
|
+
const isSemanticColor = parts.length === 2 && parts[0] === "colors";
|
|
3606
|
+
const isPrimitiveColor = parts.length >= 3 && parts[0] === "colors";
|
|
3607
|
+
const varName = isSemanticColor ? `--kui-${toKebabCase(parts[1])}` : `--kui-${parts.map(toKebabCase).join("-")}`;
|
|
3608
|
+
const outputValue = isSemanticColor || isPrimitiveColor ? colorToRgbChannels(value) : value;
|
|
3609
|
+
cssVars[varName] = outputValue;
|
|
3610
|
+
}
|
|
3611
|
+
return {
|
|
3612
|
+
...cssVars,
|
|
3613
|
+
"--kui-mode": mode,
|
|
3614
|
+
"--kui-intensity": String(intensity)
|
|
3615
|
+
};
|
|
3616
|
+
}
|
|
3617
|
+
__name(tokensToCssVars, "tokensToCssVars");
|
|
3618
|
+
|
|
3619
|
+
// src/theme/recipes/defineRecipe.ts
|
|
3620
|
+
function defineRecipe(recipe) {
|
|
3621
|
+
return recipe;
|
|
3622
|
+
}
|
|
3623
|
+
__name(defineRecipe, "defineRecipe");
|
|
3383
3624
|
|
|
3384
3625
|
// src/theme/defaults/tokens.ts
|
|
3385
3626
|
var defaultTokens = {
|
|
@@ -3527,17 +3768,38 @@ var defaultSemanticTokens = {
|
|
|
3527
3768
|
}
|
|
3528
3769
|
};
|
|
3529
3770
|
|
|
3771
|
+
// src/theme/typography/defineTypography.ts
|
|
3772
|
+
function defineTypography(typography) {
|
|
3773
|
+
return typography;
|
|
3774
|
+
}
|
|
3775
|
+
__name(defineTypography, "defineTypography");
|
|
3776
|
+
|
|
3777
|
+
// src/theme/typography/extendTypography.ts
|
|
3778
|
+
function extendTypography(override) {
|
|
3779
|
+
if (!override) {
|
|
3780
|
+
return { ...defaultTypography };
|
|
3781
|
+
}
|
|
3782
|
+
const result = { ...defaultTypography };
|
|
3783
|
+
for (const key of Object.keys(override)) {
|
|
3784
|
+
const variant = key;
|
|
3785
|
+
result[variant] = {
|
|
3786
|
+
...defaultTypography[variant],
|
|
3787
|
+
...override[variant]
|
|
3788
|
+
};
|
|
3789
|
+
}
|
|
3790
|
+
return result;
|
|
3791
|
+
}
|
|
3792
|
+
__name(extendTypography, "extendTypography");
|
|
3793
|
+
|
|
3530
3794
|
// src/theme/defaults/typography.ts
|
|
3531
|
-
var defaultTypography = {
|
|
3795
|
+
var defaultTypography = defineTypography({
|
|
3532
3796
|
body: {
|
|
3533
3797
|
fontFamily: "{fonts.body}",
|
|
3534
|
-
fontSize: "{fontSizes.md}",
|
|
3535
3798
|
fontWeight: "{fontWeights.normal}",
|
|
3536
3799
|
lineHeight: "{lineHeights.normal}"
|
|
3537
3800
|
},
|
|
3538
3801
|
bodySmall: {
|
|
3539
3802
|
fontFamily: "{fonts.body}",
|
|
3540
|
-
fontSize: "{fontSizes.sm}",
|
|
3541
3803
|
fontWeight: "{fontWeights.normal}",
|
|
3542
3804
|
lineHeight: "{lineHeights.normal}"
|
|
3543
3805
|
},
|
|
@@ -3553,22 +3815,290 @@ var defaultTypography = {
|
|
|
3553
3815
|
fontWeight: "{fontWeights.semibold}",
|
|
3554
3816
|
lineHeight: "{lineHeights.tight}"
|
|
3555
3817
|
},
|
|
3818
|
+
label: {
|
|
3819
|
+
fontFamily: "{fonts.body}",
|
|
3820
|
+
fontWeight: "{fontWeights.medium}",
|
|
3821
|
+
lineHeight: "{lineHeights.normal}"
|
|
3822
|
+
},
|
|
3556
3823
|
caption: {
|
|
3557
3824
|
fontFamily: "{fonts.body}",
|
|
3558
3825
|
fontSize: "{fontSizes.xs}",
|
|
3559
3826
|
fontWeight: "{fontWeights.normal}",
|
|
3560
3827
|
lineHeight: "{lineHeights.normal}"
|
|
3561
3828
|
},
|
|
3562
|
-
mono: {
|
|
3563
|
-
fontFamily: "{fonts.mono}",
|
|
3564
|
-
fontSize: "{fontSizes.xs}",
|
|
3565
|
-
fontWeight: "{fontWeights.normal}",
|
|
3566
|
-
lineHeight: "{lineHeights.normal}"
|
|
3829
|
+
mono: {
|
|
3830
|
+
fontFamily: "{fonts.mono}",
|
|
3831
|
+
fontSize: "{fontSizes.xs}",
|
|
3832
|
+
fontWeight: "{fontWeights.normal}",
|
|
3833
|
+
lineHeight: "{lineHeights.normal}"
|
|
3834
|
+
}
|
|
3835
|
+
});
|
|
3836
|
+
|
|
3837
|
+
// src/theme/defaults/recipes/button.ts
|
|
3838
|
+
var buttonBase = "inline-flex items-center justify-center rounded-[var(--kui-button-radius,var(--kui-radius))] font-medium transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-2 focus-visible:ring-offset-surface disabled:opacity-60 disabled:pointer-events-none";
|
|
3839
|
+
var buttonVariants = {
|
|
3840
|
+
solid: "",
|
|
3841
|
+
outline: "border bg-transparent",
|
|
3842
|
+
ghost: "bg-transparent",
|
|
3843
|
+
soft: "",
|
|
3844
|
+
link: "bg-transparent p-0 h-auto hover:underline"
|
|
3845
|
+
};
|
|
3846
|
+
var buttonColors = {
|
|
3847
|
+
brand: {
|
|
3848
|
+
solid: "bg-brand text-brand-fg hover:bg-brand-hover",
|
|
3849
|
+
outline: "border-brand text-brand hover:bg-brand/10",
|
|
3850
|
+
ghost: "text-brand hover:bg-brand/10",
|
|
3851
|
+
soft: "bg-brand/10 text-brand hover:bg-brand/20",
|
|
3852
|
+
link: "text-brand"
|
|
3853
|
+
},
|
|
3854
|
+
destructive: {
|
|
3855
|
+
solid: "bg-destructive text-destructive-fg hover:bg-destructive-hover",
|
|
3856
|
+
outline: "border-destructive text-destructive hover:bg-destructive/10",
|
|
3857
|
+
ghost: "text-destructive hover:bg-destructive/10",
|
|
3858
|
+
soft: "bg-destructive/10 text-destructive hover:bg-destructive/20",
|
|
3859
|
+
link: "text-destructive"
|
|
3860
|
+
},
|
|
3861
|
+
success: {
|
|
3862
|
+
solid: "bg-success text-success-fg hover:bg-success-hover",
|
|
3863
|
+
outline: "border-success text-success hover:bg-success/10",
|
|
3864
|
+
ghost: "text-success hover:bg-success/10",
|
|
3865
|
+
soft: "bg-success/10 text-success hover:bg-success/20",
|
|
3866
|
+
link: "text-success"
|
|
3867
|
+
},
|
|
3868
|
+
warning: {
|
|
3869
|
+
solid: "bg-warning text-warning-fg hover:bg-warning-hover",
|
|
3870
|
+
outline: "border-warning text-warning hover:bg-warning/10",
|
|
3871
|
+
ghost: "text-warning hover:bg-warning/10",
|
|
3872
|
+
soft: "bg-warning/10 text-warning hover:bg-warning/20",
|
|
3873
|
+
link: "text-warning"
|
|
3874
|
+
},
|
|
3875
|
+
info: {
|
|
3876
|
+
solid: "bg-info text-info-fg hover:bg-info-hover",
|
|
3877
|
+
outline: "border-info text-info hover:bg-info/10",
|
|
3878
|
+
ghost: "text-info hover:bg-info/10",
|
|
3879
|
+
soft: "bg-info/10 text-info hover:bg-info/20",
|
|
3880
|
+
link: "text-info"
|
|
3881
|
+
},
|
|
3882
|
+
white: {
|
|
3883
|
+
solid: "bg-white text-black hover:bg-gray-50",
|
|
3884
|
+
outline: "border-white/30 text-white hover:bg-white/10",
|
|
3885
|
+
ghost: "text-white hover:bg-white/10",
|
|
3886
|
+
soft: "bg-white/10 text-white hover:bg-white/20",
|
|
3887
|
+
link: "text-white"
|
|
3888
|
+
},
|
|
3889
|
+
neutral: {
|
|
3890
|
+
solid: "bg-surface-raised text-text hover:bg-surface-sunken",
|
|
3891
|
+
outline: "border-border text-text hover:bg-surface-raised",
|
|
3892
|
+
ghost: "text-text hover:bg-surface-raised",
|
|
3893
|
+
soft: "bg-surface-raised text-text hover:bg-surface-sunken",
|
|
3894
|
+
link: "text-text"
|
|
3895
|
+
}
|
|
3896
|
+
};
|
|
3897
|
+
var buildCompoundVariants = /* @__PURE__ */ __name(() => {
|
|
3898
|
+
const compounds = [];
|
|
3899
|
+
for (const [color, variantMap] of Object.entries(buttonColors)) {
|
|
3900
|
+
for (const [variant, className] of Object.entries(variantMap)) {
|
|
3901
|
+
compounds.push({
|
|
3902
|
+
conditions: { color, variant },
|
|
3903
|
+
className
|
|
3904
|
+
});
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3907
|
+
return compounds;
|
|
3908
|
+
}, "buildCompoundVariants");
|
|
3909
|
+
var buttonRecipe = defineRecipe({
|
|
3910
|
+
base: buttonBase,
|
|
3911
|
+
variants: {
|
|
3912
|
+
variant: buttonVariants,
|
|
3913
|
+
color: Object.fromEntries(
|
|
3914
|
+
Object.keys(buttonColors).map((color) => [color, ""])
|
|
3915
|
+
)
|
|
3916
|
+
},
|
|
3917
|
+
defaultVariants: {
|
|
3918
|
+
variant: "solid",
|
|
3919
|
+
color: "brand"
|
|
3920
|
+
},
|
|
3921
|
+
compoundVariants: buildCompoundVariants()
|
|
3922
|
+
});
|
|
3923
|
+
|
|
3924
|
+
// src/theme/defaults/recipes/formControl.ts
|
|
3925
|
+
var formControlBase = "group relative inline-flex items-center rounded-[var(--kui-radii-md)] transition-[border-color,box-shadow] duration-[var(--kui-duration-fast)] focus-within:outline-none focus-within:ring-offset-2 focus-within:ring-offset-surface";
|
|
3926
|
+
var formControlVariants = {
|
|
3927
|
+
outline: "border border-border bg-transparent text-text",
|
|
3928
|
+
filled: "border border-transparent bg-surface-raised text-text",
|
|
3929
|
+
ghost: "border border-transparent bg-transparent text-text"
|
|
3930
|
+
};
|
|
3931
|
+
var standaloneStates = {
|
|
3932
|
+
none: "hover:border-brand focus-within:ring-2 focus-within:ring-brand/20",
|
|
3933
|
+
error: "border-destructive hover:border-destructive focus-within:ring-2 focus-within:ring-destructive/20",
|
|
3934
|
+
success: "border-success hover:border-success focus-within:ring-2 focus-within:ring-success/20",
|
|
3935
|
+
warning: "border-warning hover:border-warning focus-within:ring-2 focus-within:ring-warning/20"
|
|
3936
|
+
};
|
|
3937
|
+
var formControlRecipe = defineRecipe({
|
|
3938
|
+
base: formControlBase,
|
|
3939
|
+
variants: {
|
|
3940
|
+
variant: formControlVariants,
|
|
3941
|
+
embedded: {
|
|
3942
|
+
true: "rounded-none border-0 shadow-none hover:border-0 hover:bg-transparent focus-within:ring-0 focus-within:ring-offset-0",
|
|
3943
|
+
false: ""
|
|
3944
|
+
},
|
|
3945
|
+
state: standaloneStates,
|
|
3946
|
+
rounded: {
|
|
3947
|
+
true: "rounded-full",
|
|
3948
|
+
false: ""
|
|
3949
|
+
},
|
|
3950
|
+
fullWidth: {
|
|
3951
|
+
true: "w-full",
|
|
3952
|
+
false: ""
|
|
3953
|
+
},
|
|
3954
|
+
disabled: {
|
|
3955
|
+
true: "cursor-not-allowed opacity-50 border-border hover:border-border focus-within:ring-0",
|
|
3956
|
+
false: ""
|
|
3957
|
+
},
|
|
3958
|
+
hasAdornment: {
|
|
3959
|
+
true: "px-2",
|
|
3960
|
+
false: ""
|
|
3961
|
+
}
|
|
3962
|
+
},
|
|
3963
|
+
compoundVariants: [
|
|
3964
|
+
{
|
|
3965
|
+
conditions: { embedded: true, state: "none" },
|
|
3966
|
+
className: "border-0! shadow-none! focus-within:ring-0! hover:border-0!"
|
|
3967
|
+
},
|
|
3968
|
+
{
|
|
3969
|
+
conditions: { embedded: true, state: "error" },
|
|
3970
|
+
className: "border-0! shadow-none! focus-within:ring-0! hover:border-0!"
|
|
3971
|
+
},
|
|
3972
|
+
{
|
|
3973
|
+
conditions: { embedded: true, state: "success" },
|
|
3974
|
+
className: "border-0! shadow-none! focus-within:ring-0! hover:border-0!"
|
|
3975
|
+
},
|
|
3976
|
+
{
|
|
3977
|
+
conditions: { embedded: true, state: "warning" },
|
|
3978
|
+
className: "border-0! shadow-none! focus-within:ring-0! hover:border-0!"
|
|
3979
|
+
},
|
|
3980
|
+
{
|
|
3981
|
+
conditions: {
|
|
3982
|
+
disabled: true,
|
|
3983
|
+
state: "error"
|
|
3984
|
+
},
|
|
3985
|
+
className: "border-border hover:border-border focus-within:ring-0"
|
|
3986
|
+
},
|
|
3987
|
+
{
|
|
3988
|
+
conditions: {
|
|
3989
|
+
disabled: true,
|
|
3990
|
+
state: "success"
|
|
3991
|
+
},
|
|
3992
|
+
className: "border-border hover:border-border focus-within:ring-0"
|
|
3993
|
+
},
|
|
3994
|
+
{
|
|
3995
|
+
conditions: {
|
|
3996
|
+
disabled: true,
|
|
3997
|
+
state: "warning"
|
|
3998
|
+
},
|
|
3999
|
+
className: "border-border hover:border-border focus-within:ring-0"
|
|
4000
|
+
},
|
|
4001
|
+
{
|
|
4002
|
+
conditions: {
|
|
4003
|
+
embedded: true,
|
|
4004
|
+
disabled: true
|
|
4005
|
+
},
|
|
4006
|
+
className: "border-0! hover:border-0! focus-within:ring-0! cursor-default"
|
|
4007
|
+
}
|
|
4008
|
+
],
|
|
4009
|
+
defaultVariants: {
|
|
4010
|
+
variant: "outline",
|
|
4011
|
+
state: "none",
|
|
4012
|
+
embedded: false,
|
|
4013
|
+
rounded: false,
|
|
4014
|
+
fullWidth: true,
|
|
4015
|
+
disabled: false,
|
|
4016
|
+
hasAdornment: false
|
|
4017
|
+
}
|
|
4018
|
+
});
|
|
4019
|
+
|
|
4020
|
+
// src/theme/defaults/recipes/input.ts
|
|
4021
|
+
var inputBase2 = "flex min-w-0 flex-1 font-sans bg-transparent border-0 outline-none transition-colors duration-[var(--kui-duration-fast)] placeholder:text-text-muted disabled:cursor-not-allowed";
|
|
4022
|
+
var inputRecipe = defineRecipe({
|
|
4023
|
+
base: inputBase2,
|
|
4024
|
+
variants: {
|
|
4025
|
+
variant: {
|
|
4026
|
+
outline: "",
|
|
4027
|
+
filled: "",
|
|
4028
|
+
ghost: ""
|
|
4029
|
+
}
|
|
4030
|
+
},
|
|
4031
|
+
defaultVariants: {
|
|
4032
|
+
variant: "outline"
|
|
4033
|
+
}
|
|
4034
|
+
});
|
|
4035
|
+
|
|
4036
|
+
// src/theme/defaults/recipes/textarea.ts
|
|
4037
|
+
var textareaRecipe = defineRecipe({
|
|
4038
|
+
base: "flex w-full min-w-0 bg-transparent outline-none border-0 text-text placeholder:text-text-muted transition-colors duration-[var(--kui-duration-fast)] disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 kui-scrollbar",
|
|
4039
|
+
variants: {
|
|
4040
|
+
variant: {
|
|
4041
|
+
outline: "",
|
|
4042
|
+
filled: "",
|
|
4043
|
+
ghost: ""
|
|
4044
|
+
},
|
|
4045
|
+
resize: {
|
|
4046
|
+
none: "resize-none",
|
|
4047
|
+
both: "resize",
|
|
4048
|
+
horizontal: "resize-x",
|
|
4049
|
+
vertical: "resize-y"
|
|
4050
|
+
},
|
|
4051
|
+
autoResize: {
|
|
4052
|
+
true: "resize-none overflow-hidden",
|
|
4053
|
+
false: ""
|
|
4054
|
+
}
|
|
4055
|
+
},
|
|
4056
|
+
defaultVariants: {
|
|
4057
|
+
variant: "outline",
|
|
4058
|
+
resize: "vertical",
|
|
4059
|
+
autoResize: false
|
|
4060
|
+
}
|
|
4061
|
+
});
|
|
4062
|
+
|
|
4063
|
+
// src/theme/defaults/recipes/markdownEditor.ts
|
|
4064
|
+
var markdownEditorRecipe = defineRecipe({
|
|
4065
|
+
base: "group relative w-full overflow-hidden rounded-[var(--kui-radii-md)] transition-[border-color,box-shadow] duration-[var(--kui-duration-fast)]",
|
|
4066
|
+
variants: {
|
|
4067
|
+
variant: {
|
|
4068
|
+
outline: "border border-border bg-transparent",
|
|
4069
|
+
filled: "border border-transparent bg-surface-raised",
|
|
4070
|
+
ghost: "border border-transparent bg-transparent"
|
|
4071
|
+
},
|
|
4072
|
+
state: {
|
|
4073
|
+
none: "hover:border-brand focus-within:ring-2 focus-within:ring-brand/20",
|
|
4074
|
+
error: "border-destructive focus-within:ring-2 focus-within:ring-destructive/20",
|
|
4075
|
+
success: "border-success focus-within:ring-2 focus-within:ring-success/20",
|
|
4076
|
+
warning: "border-warning focus-within:ring-2 focus-within:ring-warning/20"
|
|
4077
|
+
},
|
|
4078
|
+
disabled: {
|
|
4079
|
+
true: "cursor-not-allowed opacity-50 border-border hover:border-border focus-within:ring-0",
|
|
4080
|
+
false: ""
|
|
4081
|
+
},
|
|
4082
|
+
fullWidth: {
|
|
4083
|
+
true: "w-full",
|
|
4084
|
+
false: ""
|
|
4085
|
+
}
|
|
4086
|
+
},
|
|
4087
|
+
defaultVariants: {
|
|
4088
|
+
variant: "outline",
|
|
4089
|
+
state: "none",
|
|
4090
|
+
fullWidth: true
|
|
3567
4091
|
}
|
|
3568
|
-
};
|
|
4092
|
+
});
|
|
3569
4093
|
|
|
3570
|
-
// src/theme/
|
|
3571
|
-
|
|
4094
|
+
// src/theme/size/defineSize.ts
|
|
4095
|
+
function defineSizes(sizes) {
|
|
4096
|
+
return sizes;
|
|
4097
|
+
}
|
|
4098
|
+
__name(defineSizes, "defineSizes");
|
|
4099
|
+
|
|
4100
|
+
// src/theme/defaults/sizes.ts
|
|
4101
|
+
var defaultSizes = defineSizes({
|
|
3572
4102
|
xs: {
|
|
3573
4103
|
height: "1.75rem",
|
|
3574
4104
|
paddingX: "0.5rem",
|
|
@@ -3594,18 +4124,77 @@ var defaultSizes = {
|
|
|
3594
4124
|
radius: "1rem"
|
|
3595
4125
|
},
|
|
3596
4126
|
lg: {
|
|
3597
|
-
height: "
|
|
4127
|
+
height: "3.5rem",
|
|
3598
4128
|
paddingX: "1.5rem",
|
|
3599
4129
|
fontSize: "1rem",
|
|
3600
4130
|
gap: "0.625rem",
|
|
3601
4131
|
iconSize: "1.25rem",
|
|
3602
4132
|
radius: "1.15rem"
|
|
3603
4133
|
}
|
|
3604
|
-
};
|
|
4134
|
+
});
|
|
4135
|
+
|
|
4136
|
+
// src/theme/defaults/recipes/checkbox.ts
|
|
4137
|
+
var checkboxRecipe = defineRecipe({
|
|
4138
|
+
base: "relative inline-flex shrink-0 items-center justify-center border transition-colors duration-[var(--kui-duration-fast)] peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1",
|
|
4139
|
+
variants: {
|
|
4140
|
+
state: {
|
|
4141
|
+
none: "border-border",
|
|
4142
|
+
error: "border-destructive",
|
|
4143
|
+
success: "border-success",
|
|
4144
|
+
warning: "border-warning"
|
|
4145
|
+
},
|
|
4146
|
+
checked: {
|
|
4147
|
+
true: "border-brand bg-brand text-brand-fg",
|
|
4148
|
+
false: "bg-transparent"
|
|
4149
|
+
},
|
|
4150
|
+
disabled: {
|
|
4151
|
+
true: "cursor-not-allowed",
|
|
4152
|
+
false: "cursor-pointer"
|
|
4153
|
+
},
|
|
4154
|
+
rounded: {
|
|
4155
|
+
true: "rounded-full",
|
|
4156
|
+
false: "rounded-[calc(var(--kui-checkbox-radius)-4px)]"
|
|
4157
|
+
}
|
|
4158
|
+
},
|
|
4159
|
+
compoundVariants: [
|
|
4160
|
+
{
|
|
4161
|
+
conditions: {
|
|
4162
|
+
checked: false,
|
|
4163
|
+
state: "error"
|
|
4164
|
+
},
|
|
4165
|
+
className: "border-destructive"
|
|
4166
|
+
},
|
|
4167
|
+
{
|
|
4168
|
+
conditions: {
|
|
4169
|
+
checked: false,
|
|
4170
|
+
state: "success"
|
|
4171
|
+
},
|
|
4172
|
+
className: "border-success"
|
|
4173
|
+
},
|
|
4174
|
+
{
|
|
4175
|
+
conditions: {
|
|
4176
|
+
checked: false,
|
|
4177
|
+
state: "warning"
|
|
4178
|
+
},
|
|
4179
|
+
className: "border-warning"
|
|
4180
|
+
}
|
|
4181
|
+
],
|
|
4182
|
+
defaultVariants: {
|
|
4183
|
+
state: "none",
|
|
4184
|
+
checked: false,
|
|
4185
|
+
disabled: false,
|
|
4186
|
+
rounded: false
|
|
4187
|
+
}
|
|
4188
|
+
});
|
|
4189
|
+
|
|
4190
|
+
// src/theme/defaults/theme.ts
|
|
3605
4191
|
var defaultRecipes = {
|
|
3606
4192
|
Button: buttonRecipe,
|
|
3607
4193
|
FormControl: formControlRecipe,
|
|
3608
|
-
Input: inputRecipe
|
|
4194
|
+
Input: inputRecipe,
|
|
4195
|
+
Textarea: textareaRecipe,
|
|
4196
|
+
MarkdownEditor: markdownEditorRecipe,
|
|
4197
|
+
Checkbox: checkboxRecipe
|
|
3609
4198
|
};
|
|
3610
4199
|
var defaultTheme = {
|
|
3611
4200
|
tokens: defaultTokens,
|
|
@@ -3616,241 +4205,49 @@ var defaultTheme = {
|
|
|
3616
4205
|
sizes: defaultSizes
|
|
3617
4206
|
};
|
|
3618
4207
|
|
|
3619
|
-
// src/
|
|
3620
|
-
function
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
__name(toKebabCase, "toKebabCase");
|
|
3624
|
-
function colorToRgbChannels(value) {
|
|
3625
|
-
const trimmed = value.trim();
|
|
3626
|
-
const rgbMatch = trimmed.match(
|
|
3627
|
-
/^rgba?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(?:\s*[/,]\s*[\d.]+%?)?\s*\)$/i
|
|
3628
|
-
);
|
|
3629
|
-
if (rgbMatch) {
|
|
3630
|
-
return `${rgbMatch[1]} ${rgbMatch[2]} ${rgbMatch[3]}`;
|
|
3631
|
-
}
|
|
3632
|
-
if (trimmed.startsWith("#")) {
|
|
3633
|
-
const hex = trimmed.slice(1);
|
|
3634
|
-
if (hex.length === 3) {
|
|
3635
|
-
const r = parseInt(hex[0] + hex[0], 16);
|
|
3636
|
-
const g = parseInt(hex[1] + hex[1], 16);
|
|
3637
|
-
const b = parseInt(hex[2] + hex[2], 16);
|
|
3638
|
-
return `${r} ${g} ${b}`;
|
|
3639
|
-
}
|
|
3640
|
-
if (hex.length === 6) {
|
|
3641
|
-
const r = parseInt(hex.slice(0, 2), 16);
|
|
3642
|
-
const g = parseInt(hex.slice(2, 4), 16);
|
|
3643
|
-
const b = parseInt(hex.slice(4, 6), 16);
|
|
3644
|
-
return `${r} ${g} ${b}`;
|
|
3645
|
-
}
|
|
3646
|
-
}
|
|
3647
|
-
if (/^\d+(?:\.\d+)?\s+\d+(?:\.\d+)?\s+\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
3648
|
-
return trimmed;
|
|
3649
|
-
}
|
|
3650
|
-
return value;
|
|
3651
|
-
}
|
|
3652
|
-
__name(colorToRgbChannels, "colorToRgbChannels");
|
|
3653
|
-
function getTokenValue(reference, tokens) {
|
|
3654
|
-
const path = reference.replace(/^\{/, "").replace(/\}$/, "").split(".");
|
|
3655
|
-
let current = tokens;
|
|
3656
|
-
for (const segment of path) {
|
|
3657
|
-
if (typeof current !== "object" || current === null || !(segment in current)) {
|
|
3658
|
-
return void 0;
|
|
3659
|
-
}
|
|
3660
|
-
current = current[segment];
|
|
3661
|
-
}
|
|
3662
|
-
if (typeof current === "object" && current !== null && "value" in current) {
|
|
3663
|
-
const value = current.value;
|
|
3664
|
-
if (typeof value === "string" || typeof value === "number") {
|
|
3665
|
-
return value;
|
|
3666
|
-
}
|
|
3667
|
-
}
|
|
3668
|
-
return void 0;
|
|
3669
|
-
}
|
|
3670
|
-
__name(getTokenValue, "getTokenValue");
|
|
3671
|
-
function resolveReference(reference, tokens, seen = /* @__PURE__ */ new Set()) {
|
|
3672
|
-
if (seen.has(reference)) {
|
|
3673
|
-
console.error(
|
|
3674
|
-
`[kreativ-ui] Circular token reference detected: ${reference}`
|
|
3675
|
-
);
|
|
3676
|
-
return void 0;
|
|
3677
|
-
}
|
|
3678
|
-
const nextSeen = new Set(seen);
|
|
3679
|
-
nextSeen.add(reference);
|
|
3680
|
-
const value = getTokenValue(reference, tokens);
|
|
3681
|
-
if (value === void 0) {
|
|
3682
|
-
console.warn(
|
|
3683
|
-
`[kreativ-ui] Unable to resolve token reference: ${reference}`
|
|
3684
|
-
);
|
|
3685
|
-
return void 0;
|
|
3686
|
-
}
|
|
3687
|
-
if (typeof value === "number") {
|
|
3688
|
-
return String(value);
|
|
3689
|
-
}
|
|
3690
|
-
if (value.startsWith("{") && value.endsWith("}")) {
|
|
3691
|
-
return resolveReference(value, tokens, nextSeen);
|
|
3692
|
-
}
|
|
3693
|
-
return value;
|
|
3694
|
-
}
|
|
3695
|
-
__name(resolveReference, "resolveReference");
|
|
3696
|
-
function resolveValue(value, tokens) {
|
|
3697
|
-
if (typeof value === "number") {
|
|
3698
|
-
return String(value);
|
|
3699
|
-
}
|
|
3700
|
-
if (typeof value !== "string") {
|
|
3701
|
-
return void 0;
|
|
3702
|
-
}
|
|
3703
|
-
if (value.startsWith("{") && value.endsWith("}")) {
|
|
3704
|
-
return resolveReference(value, tokens);
|
|
3705
|
-
}
|
|
3706
|
-
return value;
|
|
3707
|
-
}
|
|
3708
|
-
__name(resolveValue, "resolveValue");
|
|
3709
|
-
function flattenTokens(value, path, result, tokens) {
|
|
3710
|
-
if (typeof value !== "object" || value === null) {
|
|
3711
|
-
return;
|
|
3712
|
-
}
|
|
3713
|
-
if ("value" in value) {
|
|
3714
|
-
const tokenValue = value.value;
|
|
3715
|
-
const resolved = resolveValue(tokenValue, tokens);
|
|
3716
|
-
if (resolved !== void 0) {
|
|
3717
|
-
result[path.join(".")] = resolved;
|
|
3718
|
-
}
|
|
3719
|
-
return;
|
|
3720
|
-
}
|
|
3721
|
-
for (const [key, child] of Object.entries(value)) {
|
|
3722
|
-
flattenTokens(child, [...path, key], result, tokens);
|
|
3723
|
-
}
|
|
3724
|
-
}
|
|
3725
|
-
__name(flattenTokens, "flattenTokens");
|
|
3726
|
-
function resolveSemanticValue(value, mode, tokens) {
|
|
3727
|
-
if (typeof value === "object" && value !== null && "light" in value && "dark" in value) {
|
|
3728
|
-
const modeValue = value[mode];
|
|
3729
|
-
return resolveValue(modeValue, tokens);
|
|
4208
|
+
// src/theme/recipes/extendRecipe.ts
|
|
4209
|
+
function extendRecipes(override) {
|
|
4210
|
+
if (!override) {
|
|
4211
|
+
return defaultRecipes;
|
|
3730
4212
|
}
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
walk(child, [...path, key]);
|
|
3752
|
-
}
|
|
4213
|
+
const result = { ...defaultRecipes };
|
|
4214
|
+
for (const [name, recipeOverride] of Object.entries(override)) {
|
|
4215
|
+
const key = name;
|
|
4216
|
+
const base = defaultRecipes[key];
|
|
4217
|
+
result[key] = {
|
|
4218
|
+
...base,
|
|
4219
|
+
...recipeOverride,
|
|
4220
|
+
...base?.compoundVariants || recipeOverride?.compoundVariants ? {
|
|
4221
|
+
compoundVariants: [
|
|
4222
|
+
...base?.compoundVariants ?? [],
|
|
4223
|
+
...recipeOverride?.compoundVariants ?? []
|
|
4224
|
+
]
|
|
4225
|
+
} : {},
|
|
4226
|
+
...base?.variants || recipeOverride?.variants ? {
|
|
4227
|
+
variants: {
|
|
4228
|
+
...base?.variants,
|
|
4229
|
+
...recipeOverride?.variants
|
|
4230
|
+
}
|
|
4231
|
+
} : {}
|
|
4232
|
+
};
|
|
3753
4233
|
}
|
|
3754
|
-
__name(walk, "walk");
|
|
3755
|
-
walk(semanticTokens, []);
|
|
3756
4234
|
return result;
|
|
3757
4235
|
}
|
|
3758
|
-
__name(
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
const resolvedSemanticTokens = resolveSemanticTokens(
|
|
3763
|
-
semanticTokens,
|
|
3764
|
-
tokens,
|
|
3765
|
-
mode
|
|
3766
|
-
);
|
|
4236
|
+
__name(extendRecipes, "extendRecipes");
|
|
4237
|
+
|
|
4238
|
+
// src/theme/token/defineToken.ts
|
|
4239
|
+
function defineToken(value) {
|
|
3767
4240
|
return {
|
|
3768
|
-
|
|
3769
|
-
...resolvedSemanticTokens
|
|
4241
|
+
value
|
|
3770
4242
|
};
|
|
3771
4243
|
}
|
|
3772
|
-
__name(
|
|
3773
|
-
function
|
|
3774
|
-
|
|
3775
|
-
for (const [path, value] of Object.entries(tokens)) {
|
|
3776
|
-
const parts = path.split(".");
|
|
3777
|
-
const isSemanticColor = parts.length === 2 && parts[0] === "colors";
|
|
3778
|
-
const isPrimitiveColor = parts.length >= 3 && parts[0] === "colors";
|
|
3779
|
-
const varName = isSemanticColor ? `--kui-${toKebabCase(parts[1])}` : `--kui-${parts.map(toKebabCase).join("-")}`;
|
|
3780
|
-
const outputValue = isSemanticColor || isPrimitiveColor ? colorToRgbChannels(value) : value;
|
|
3781
|
-
cssVars[varName] = outputValue;
|
|
3782
|
-
}
|
|
3783
|
-
return {
|
|
3784
|
-
...cssVars,
|
|
3785
|
-
"--kui-mode": mode,
|
|
3786
|
-
"--kui-intensity": String(intensity)
|
|
3787
|
-
};
|
|
4244
|
+
__name(defineToken, "defineToken");
|
|
4245
|
+
function defineSemanticToken(light, dark) {
|
|
4246
|
+
return { value: { light, dark } };
|
|
3788
4247
|
}
|
|
3789
|
-
__name(
|
|
4248
|
+
__name(defineSemanticToken, "defineSemanticToken");
|
|
3790
4249
|
|
|
3791
|
-
// src/
|
|
3792
|
-
var CSS_SIZE = /^-?\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|fr)$|^(auto|min-content|max-content|fit-content)$/;
|
|
3793
|
-
var CSS_KEYWORDS = /* @__PURE__ */ new Set([
|
|
3794
|
-
"auto",
|
|
3795
|
-
"min-content",
|
|
3796
|
-
"max-content",
|
|
3797
|
-
"fit-content"
|
|
3798
|
-
]);
|
|
3799
|
-
var SIZE_FIELDS = [
|
|
3800
|
-
"height",
|
|
3801
|
-
"width",
|
|
3802
|
-
"paddingX",
|
|
3803
|
-
"paddingY",
|
|
3804
|
-
"fontSize",
|
|
3805
|
-
"gap",
|
|
3806
|
-
"iconSize",
|
|
3807
|
-
"radius"
|
|
3808
|
-
];
|
|
3809
|
-
function isCssKeyword(value) {
|
|
3810
|
-
return CSS_KEYWORDS.has(value);
|
|
3811
|
-
}
|
|
3812
|
-
__name(isCssKeyword, "isCssKeyword");
|
|
3813
|
-
function toPx(value) {
|
|
3814
|
-
if (isCssKeyword(value)) return void 0;
|
|
3815
|
-
const num = parseFloat(value);
|
|
3816
|
-
if (Number.isNaN(num)) return void 0;
|
|
3817
|
-
if (value.endsWith("px")) return num;
|
|
3818
|
-
if (value.endsWith("rem") || value.endsWith("em")) {
|
|
3819
|
-
return num * 16;
|
|
3820
|
-
}
|
|
3821
|
-
return void 0;
|
|
3822
|
-
}
|
|
3823
|
-
__name(toPx, "toPx");
|
|
3824
|
-
function validateSizeToken(key, token) {
|
|
3825
|
-
SIZE_FIELDS.forEach((field) => {
|
|
3826
|
-
const value = token[field];
|
|
3827
|
-
if (value === void 0) return;
|
|
3828
|
-
if (!CSS_SIZE.test(value)) {
|
|
3829
|
-
console.error(
|
|
3830
|
-
`[kreativ-ui] Invalid size "${key}.${field}": "${value}" is not a valid CSS size.`
|
|
3831
|
-
);
|
|
3832
|
-
return;
|
|
3833
|
-
}
|
|
3834
|
-
if (isCssKeyword(value)) return;
|
|
3835
|
-
const num = parseFloat(value);
|
|
3836
|
-
if (num < 0) {
|
|
3837
|
-
console.error(
|
|
3838
|
-
`[kreativ-ui] Invalid size "${key}.${field}": "${value}" is negative.`
|
|
3839
|
-
);
|
|
3840
|
-
}
|
|
3841
|
-
});
|
|
3842
|
-
if (token.height && token.fontSize) {
|
|
3843
|
-
const heightPx = toPx(token.height);
|
|
3844
|
-
const fontSizePx = toPx(token.fontSize);
|
|
3845
|
-
if (heightPx !== void 0 && fontSizePx !== void 0 && fontSizePx >= heightPx) {
|
|
3846
|
-
console.warn(
|
|
3847
|
-
`[kreativ-ui] Size "${key}" has conflicting dimensions: height=${token.height} (${heightPx}px), fontSize=${token.fontSize} (${fontSizePx}px).
|
|
3848
|
-
Font size meets or exceeds the box height \u2014 text may clip or overflow.`
|
|
3849
|
-
);
|
|
3850
|
-
}
|
|
3851
|
-
}
|
|
3852
|
-
}
|
|
3853
|
-
__name(validateSizeToken, "validateSizeToken");
|
|
4250
|
+
// src/utils/deepMerge.ts
|
|
3854
4251
|
function isPlainObject(value) {
|
|
3855
4252
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3856
4253
|
}
|
|
@@ -3876,53 +4273,49 @@ function deepMerge(base, override) {
|
|
|
3876
4273
|
return result;
|
|
3877
4274
|
}
|
|
3878
4275
|
__name(deepMerge, "deepMerge");
|
|
3879
|
-
|
|
3880
|
-
|
|
3881
|
-
|
|
3882
|
-
|
|
3883
|
-
function mergeSemanticTokens(base, override) {
|
|
3884
|
-
return deepMerge(base, override);
|
|
4276
|
+
|
|
4277
|
+
// src/theme/token/extendTokens.ts
|
|
4278
|
+
function extendTokens(override) {
|
|
4279
|
+
return deepMerge(defaultTokens, override);
|
|
3885
4280
|
}
|
|
3886
|
-
__name(
|
|
3887
|
-
function
|
|
3888
|
-
return deepMerge(
|
|
4281
|
+
__name(extendTokens, "extendTokens");
|
|
4282
|
+
function extendSemanticTokens(override) {
|
|
4283
|
+
return deepMerge(defaultSemanticTokens, override);
|
|
3889
4284
|
}
|
|
3890
|
-
__name(
|
|
3891
|
-
|
|
4285
|
+
__name(extendSemanticTokens, "extendSemanticTokens");
|
|
4286
|
+
|
|
4287
|
+
// src/theme/size/extendSize.ts
|
|
4288
|
+
function extendSizes(override) {
|
|
4289
|
+
const result = {
|
|
4290
|
+
...defaultSizes
|
|
4291
|
+
};
|
|
3892
4292
|
if (!override) {
|
|
3893
|
-
return
|
|
4293
|
+
return result;
|
|
3894
4294
|
}
|
|
3895
|
-
const
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
const next = {
|
|
3900
|
-
...merged[key],
|
|
3901
|
-
...overrideToken
|
|
4295
|
+
for (const [key, value] of Object.entries(override)) {
|
|
4296
|
+
result[key] = {
|
|
4297
|
+
...defaultSizes[key] ?? {},
|
|
4298
|
+
...value
|
|
3902
4299
|
};
|
|
3903
|
-
validateSizeToken(key, next);
|
|
3904
|
-
merged[key] = next;
|
|
3905
4300
|
}
|
|
3906
|
-
return
|
|
4301
|
+
return result;
|
|
3907
4302
|
}
|
|
3908
|
-
__name(
|
|
3909
|
-
|
|
4303
|
+
__name(extendSizes, "extendSizes");
|
|
4304
|
+
|
|
4305
|
+
// src/theme/extendTheme.ts
|
|
4306
|
+
function extendTheme(override) {
|
|
3910
4307
|
if (!override) {
|
|
3911
|
-
return
|
|
4308
|
+
return defaultTheme;
|
|
3912
4309
|
}
|
|
3913
4310
|
return {
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
)
|
|
3919
|
-
typography: mergeTypography(base.typography, override.typography),
|
|
3920
|
-
recipes: mergeRecipes(base.recipes, override.recipes),
|
|
3921
|
-
intensity: override.intensity ?? base.intensity,
|
|
3922
|
-
sizes: mergeSizes(base.sizes, override.sizes)
|
|
4311
|
+
...defaultTheme,
|
|
4312
|
+
...override,
|
|
4313
|
+
sizes: extendSizes(override.sizes),
|
|
4314
|
+
typography: extendTypography(override.typography),
|
|
4315
|
+
recipes: extendRecipes(override.recipes)
|
|
3923
4316
|
};
|
|
3924
4317
|
}
|
|
3925
|
-
__name(
|
|
4318
|
+
__name(extendTheme, "extendTheme");
|
|
3926
4319
|
function useSystemPrefersDark() {
|
|
3927
4320
|
const [prefersDark, setPrefersDark] = useState(false);
|
|
3928
4321
|
useEffect(() => {
|
|
@@ -3949,10 +4342,7 @@ function UIProvider({
|
|
|
3949
4342
|
const [mode, setMode] = useState(defaultMode);
|
|
3950
4343
|
const systemPrefersDark = useSystemPrefersDark();
|
|
3951
4344
|
const resolvedMode = mode === "system" ? systemPrefersDark ? "dark" : "light" : mode;
|
|
3952
|
-
const theme = useMemo(
|
|
3953
|
-
() => mergeTheme(defaultTheme, themeOverride),
|
|
3954
|
-
[themeOverride]
|
|
3955
|
-
);
|
|
4345
|
+
const theme = useMemo(() => extendTheme(themeOverride), [themeOverride]);
|
|
3956
4346
|
const resolvedTokens = useMemo(
|
|
3957
4347
|
() => resolveTokens(theme.tokens, theme.semanticTokens, resolvedMode),
|
|
3958
4348
|
[theme.tokens, theme.semanticTokens, resolvedMode]
|
|
@@ -3992,6 +4382,6 @@ function UIProvider({
|
|
|
3992
4382
|
}
|
|
3993
4383
|
__name(UIProvider, "UIProvider");
|
|
3994
4384
|
|
|
3995
|
-
export { Button, Checkbox, Combobox, ComboboxContent, ComboboxInput, ComboboxItem, FormField, FormFieldControl, FormFieldDescription, FormFieldLabel, FormFieldMessage, Input, MarkdownEditor, MultiSelect, MultiSelectContent,
|
|
4385
|
+
export { Button, Checkbox, Combobox, ComboboxContent, ComboboxInput, ComboboxItem, FormField, FormFieldControl, FormFieldDescription, FormFieldLabel, FormFieldMessage, Input, InputField, MarkdownEditor, MultiSelect, MultiSelectContent, MultiSelectItem, MultiSelectTrigger, Radio, RadioGroup, Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, Switch, Textarea, ThemeContext, ThemeToggler, UIProvider, cn, defineRecipe, defineSemanticToken, defineToken, defineTypography, extendRecipes, extendSemanticTokens, extendTheme, extendTokens, extendTypography, hexToRgbString, rgbToHex, useBreakpoint, useClearableField, useFloatingSide, useSizeStyle, useStatusTransition, useTheme, useTypography };
|
|
3996
4386
|
//# sourceMappingURL=index.js.map
|
|
3997
4387
|
//# sourceMappingURL=index.js.map
|