@vvedantb/ui 0.59.2 → 0.59.3
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.
|
@@ -17,7 +17,12 @@ export type ThemeProviderProps = {
|
|
|
17
17
|
attribute?: ThemeAttribute | ThemeAttribute[];
|
|
18
18
|
/** Theme names. Default `["light", "dark"]`. */
|
|
19
19
|
themes?: string[];
|
|
20
|
-
/**
|
|
20
|
+
/**
|
|
21
|
+
* Theme name to the class or attribute value written. With `attribute="class"`
|
|
22
|
+
* a value can hold more than one class, for example
|
|
23
|
+
* `{ neutral: "dark neutral" }`; such a theme counts as dark when one of its
|
|
24
|
+
* classes is `dark`.
|
|
25
|
+
*/
|
|
21
26
|
value?: Record<string, string>;
|
|
22
27
|
/** Shown on `<html>` instead of the stored theme, which is left unchanged. */
|
|
23
28
|
forcedTheme?: string;
|
|
@@ -41,7 +46,7 @@ export type ThemeState = {
|
|
|
41
46
|
systemTheme: string | undefined;
|
|
42
47
|
/** `false` until the provider's first effect has run. */
|
|
43
48
|
mounted: boolean;
|
|
44
|
-
/** `mounted
|
|
49
|
+
/** `mounted` and `resolvedTheme` is `"dark"`, or its `value` has the `dark` class. */
|
|
45
50
|
isDark: boolean;
|
|
46
51
|
/** `setTheme(resolvedTheme === "dark" ? "light" : "dark")`. */
|
|
47
52
|
toggleTheme: () => void;
|
|
@@ -89,6 +94,17 @@ export function applyThemeClass(theme: string): void {
|
|
|
89
94
|
document.documentElement.classList.add(theme);
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
/** The classes in a `value` entry. */
|
|
98
|
+
function classesOf(written: string): string[] {
|
|
99
|
+
return written.split(" ").filter((name) => name !== "");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** `light` or `dark` for a theme whose `value` has more than one class, from those classes. */
|
|
103
|
+
function schemeOf(written: string | undefined): string | undefined {
|
|
104
|
+
if (!written || !written.includes(" ")) return undefined;
|
|
105
|
+
return classesOf(written).find((name) => COLOR_SCHEMES.includes(name));
|
|
106
|
+
}
|
|
107
|
+
|
|
92
108
|
function systemThemeOf(media: { matches: boolean }): "light" | "dark" {
|
|
93
109
|
return media.matches ? "dark" : "light";
|
|
94
110
|
}
|
|
@@ -129,11 +145,11 @@ function applyTheme(theme: string | undefined, options: DomOptions): void {
|
|
|
129
145
|
const written = options.value ? options.value[resolved] : resolved;
|
|
130
146
|
const restoreTransitions = options.disableTransitionOnChange ? disableTransitions(options.nonce) : null;
|
|
131
147
|
const root = document.documentElement;
|
|
132
|
-
const removable = options.value ? Object.values(options.value) : options.themes;
|
|
148
|
+
const removable = options.value ? Object.values(options.value).flatMap(classesOf) : options.themes;
|
|
133
149
|
for (const attribute of Array.isArray(options.attribute) ? options.attribute : [options.attribute]) {
|
|
134
150
|
if (attribute === "class") {
|
|
135
151
|
root.classList.remove(...removable);
|
|
136
|
-
if (written) root.classList.add(written);
|
|
152
|
+
if (written) root.classList.add(...classesOf(written));
|
|
137
153
|
} else if (attribute.startsWith("data-")) {
|
|
138
154
|
if (written) root.setAttribute(attribute, written);
|
|
139
155
|
else root.removeAttribute(attribute);
|
|
@@ -142,7 +158,8 @@ function applyTheme(theme: string | undefined, options: DomOptions): void {
|
|
|
142
158
|
if (options.enableColorScheme) {
|
|
143
159
|
const fallback = COLOR_SCHEMES.includes(options.defaultTheme) ? options.defaultTheme : null;
|
|
144
160
|
// `null` clears the property in browsers; assigned as-is, as next-themes does.
|
|
145
|
-
|
|
161
|
+
const scheme = COLOR_SCHEMES.includes(resolved) ? resolved : (schemeOf(written) ?? fallback);
|
|
162
|
+
Reflect.set(root.style, "colorScheme", scheme);
|
|
146
163
|
}
|
|
147
164
|
restoreTransitions?.();
|
|
148
165
|
}
|
|
@@ -253,7 +270,9 @@ export function createThemeProvider(options: ThemeProviderOptions = {}): ThemePr
|
|
|
253
270
|
themes: enableSystem ? [...themes, "system"] : themes,
|
|
254
271
|
systemTheme: enableSystem ? systemTheme : undefined,
|
|
255
272
|
mounted,
|
|
256
|
-
isDark:
|
|
273
|
+
isDark:
|
|
274
|
+
mounted &&
|
|
275
|
+
(resolvedTheme === "dark" || (resolvedTheme !== undefined && schemeOf(domOptions.value?.[resolvedTheme]) === "dark")),
|
|
257
276
|
toggleTheme: () => setTheme(resolvedTheme === "dark" ? "light" : "dark"),
|
|
258
277
|
};
|
|
259
278
|
return <Context value={state}>{children}</Context>;
|
|
@@ -31,6 +31,17 @@ export function applyThemeClass(theme) {
|
|
|
31
31
|
document.documentElement.classList.remove("light", "dark");
|
|
32
32
|
document.documentElement.classList.add(theme);
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
/** The classes in a `value` entry. */
|
|
36
|
+
function classesOf(written) {
|
|
37
|
+
return written.split(" ").filter(name => name !== "");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** `light` or `dark` for a theme whose `value` has more than one class, from those classes. */
|
|
41
|
+
function schemeOf(written) {
|
|
42
|
+
if (!written || !written.includes(" ")) return undefined;
|
|
43
|
+
return classesOf(written).find(name => COLOR_SCHEMES.includes(name));
|
|
44
|
+
}
|
|
34
45
|
function systemThemeOf(media) {
|
|
35
46
|
return media.matches ? "dark" : "light";
|
|
36
47
|
}
|
|
@@ -63,11 +74,11 @@ function applyTheme(theme, options) {
|
|
|
63
74
|
const written = options.value ? options.value[resolved] : resolved;
|
|
64
75
|
const restoreTransitions = options.disableTransitionOnChange ? disableTransitions(options.nonce) : null;
|
|
65
76
|
const root = document.documentElement;
|
|
66
|
-
const removable = options.value ? Object.values(options.value) : options.themes;
|
|
77
|
+
const removable = options.value ? Object.values(options.value).flatMap(classesOf) : options.themes;
|
|
67
78
|
for (const attribute of Array.isArray(options.attribute) ? options.attribute : [options.attribute]) {
|
|
68
79
|
if (attribute === "class") {
|
|
69
80
|
root.classList.remove(...removable);
|
|
70
|
-
if (written) root.classList.add(written);
|
|
81
|
+
if (written) root.classList.add(...classesOf(written));
|
|
71
82
|
} else if (attribute.startsWith("data-")) {
|
|
72
83
|
if (written) root.setAttribute(attribute, written);else root.removeAttribute(attribute);
|
|
73
84
|
}
|
|
@@ -75,7 +86,8 @@ function applyTheme(theme, options) {
|
|
|
75
86
|
if (options.enableColorScheme) {
|
|
76
87
|
const fallback = COLOR_SCHEMES.includes(options.defaultTheme) ? options.defaultTheme : null;
|
|
77
88
|
// `null` clears the property in browsers; assigned as-is, as next-themes does.
|
|
78
|
-
|
|
89
|
+
const scheme = COLOR_SCHEMES.includes(resolved) ? resolved : schemeOf(written) ?? fallback;
|
|
90
|
+
Reflect.set(root.style, "colorScheme", scheme);
|
|
79
91
|
}
|
|
80
92
|
restoreTransitions?.();
|
|
81
93
|
}
|
|
@@ -159,7 +171,7 @@ export function createThemeProvider(options = {}) {
|
|
|
159
171
|
return next_0.setTheme;
|
|
160
172
|
}
|
|
161
173
|
function Provider(t0) {
|
|
162
|
-
const $ = _c(
|
|
174
|
+
const $ = _c(60);
|
|
163
175
|
const {
|
|
164
176
|
forcedTheme,
|
|
165
177
|
disableTransitionOnChange: t1,
|
|
@@ -335,18 +347,27 @@ export function createThemeProvider(options = {}) {
|
|
|
335
347
|
t19 = $[39];
|
|
336
348
|
}
|
|
337
349
|
const t20 = enableSystem ? systemTheme : undefined;
|
|
338
|
-
|
|
350
|
+
let t21;
|
|
351
|
+
if ($[40] !== domOptions || $[41] !== mounted || $[42] !== resolvedTheme) {
|
|
352
|
+
t21 = mounted && (resolvedTheme === "dark" || resolvedTheme !== undefined && schemeOf(domOptions.value?.[resolvedTheme]) === "dark");
|
|
353
|
+
$[40] = domOptions;
|
|
354
|
+
$[41] = mounted;
|
|
355
|
+
$[42] = resolvedTheme;
|
|
356
|
+
$[43] = t21;
|
|
357
|
+
} else {
|
|
358
|
+
t21 = $[43];
|
|
359
|
+
}
|
|
339
360
|
let t22;
|
|
340
|
-
if ($[
|
|
361
|
+
if ($[44] !== resolvedTheme || $[45] !== setTheme) {
|
|
341
362
|
t22 = () => setTheme(resolvedTheme === "dark" ? "light" : "dark");
|
|
342
|
-
$[
|
|
343
|
-
$[
|
|
344
|
-
$[
|
|
363
|
+
$[44] = resolvedTheme;
|
|
364
|
+
$[45] = setTheme;
|
|
365
|
+
$[46] = t22;
|
|
345
366
|
} else {
|
|
346
|
-
t22 = $[
|
|
367
|
+
t22 = $[46];
|
|
347
368
|
}
|
|
348
369
|
let t23;
|
|
349
|
-
if ($[
|
|
370
|
+
if ($[47] !== forcedTheme || $[48] !== mounted || $[49] !== resolvedTheme || $[50] !== setTheme || $[51] !== t19 || $[52] !== t20 || $[53] !== t21 || $[54] !== t22 || $[55] !== theme) {
|
|
350
371
|
t23 = {
|
|
351
372
|
theme,
|
|
352
373
|
setTheme,
|
|
@@ -358,31 +379,31 @@ export function createThemeProvider(options = {}) {
|
|
|
358
379
|
isDark: t21,
|
|
359
380
|
toggleTheme: t22
|
|
360
381
|
};
|
|
361
|
-
$[
|
|
362
|
-
$[
|
|
363
|
-
$[
|
|
364
|
-
$[
|
|
365
|
-
$[
|
|
366
|
-
$[
|
|
367
|
-
$[
|
|
368
|
-
$[
|
|
369
|
-
$[
|
|
370
|
-
$[
|
|
382
|
+
$[47] = forcedTheme;
|
|
383
|
+
$[48] = mounted;
|
|
384
|
+
$[49] = resolvedTheme;
|
|
385
|
+
$[50] = setTheme;
|
|
386
|
+
$[51] = t19;
|
|
387
|
+
$[52] = t20;
|
|
388
|
+
$[53] = t21;
|
|
389
|
+
$[54] = t22;
|
|
390
|
+
$[55] = theme;
|
|
391
|
+
$[56] = t23;
|
|
371
392
|
} else {
|
|
372
|
-
t23 = $[
|
|
393
|
+
t23 = $[56];
|
|
373
394
|
}
|
|
374
395
|
const state = t23;
|
|
375
396
|
let t24;
|
|
376
|
-
if ($[
|
|
397
|
+
if ($[57] !== children || $[58] !== state) {
|
|
377
398
|
t24 = /*#__PURE__*/_jsx(Context, {
|
|
378
399
|
value: state,
|
|
379
400
|
children: children
|
|
380
401
|
});
|
|
381
|
-
$[
|
|
382
|
-
$[
|
|
383
|
-
$[
|
|
402
|
+
$[57] = children;
|
|
403
|
+
$[58] = state;
|
|
404
|
+
$[59] = t24;
|
|
384
405
|
} else {
|
|
385
|
-
t24 = $[
|
|
406
|
+
t24 = $[59];
|
|
386
407
|
}
|
|
387
408
|
return t24;
|
|
388
409
|
}
|
|
@@ -19,11 +19,12 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
19
19
|
* `.RailFooter` instead.
|
|
20
20
|
*
|
|
21
21
|
* In an `AppShell variant="rail"` each of `top`, the body and `footer` sits on
|
|
22
|
-
* its own `RailGroup` trough,
|
|
22
|
+
* its own `RailGroup` trough, the body trough is centred vertically, and
|
|
23
|
+
* `showDivider` and `RailDivider` draw nothing.
|
|
23
24
|
* A `bodyAsChild` body is left as it is.
|
|
24
25
|
*/
|
|
25
26
|
export function SidebarRail(t0) {
|
|
26
|
-
const $ = _c(
|
|
27
|
+
const $ = _c(41);
|
|
27
28
|
let bodyClassName;
|
|
28
29
|
let children;
|
|
29
30
|
let className;
|
|
@@ -104,64 +105,74 @@ export function SidebarRail(t0) {
|
|
|
104
105
|
} else {
|
|
105
106
|
t6 = $[17];
|
|
106
107
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
$[
|
|
112
|
-
$[
|
|
113
|
-
$[
|
|
108
|
+
const t7 = rail && "justify-center-safe";
|
|
109
|
+
let t8;
|
|
110
|
+
if ($[18] !== bodyClassName || $[19] !== t7) {
|
|
111
|
+
t8 = cn(t7, bodyClassName);
|
|
112
|
+
$[18] = bodyClassName;
|
|
113
|
+
$[19] = t7;
|
|
114
|
+
$[20] = t8;
|
|
114
115
|
} else {
|
|
115
|
-
|
|
116
|
+
t8 = $[20];
|
|
116
117
|
}
|
|
117
|
-
let
|
|
118
|
-
if ($[
|
|
119
|
-
|
|
118
|
+
let t9;
|
|
119
|
+
if ($[21] !== bodyAsChild || $[22] !== children || $[23] !== slot) {
|
|
120
|
+
t9 = bodyAsChild ? children : slot(children);
|
|
121
|
+
$[21] = bodyAsChild;
|
|
122
|
+
$[22] = children;
|
|
123
|
+
$[23] = slot;
|
|
124
|
+
$[24] = t9;
|
|
125
|
+
} else {
|
|
126
|
+
t9 = $[24];
|
|
127
|
+
}
|
|
128
|
+
let t10;
|
|
129
|
+
if ($[25] !== bodyAsChild || $[26] !== t8 || $[27] !== t9 || $[28] !== tabs) {
|
|
130
|
+
t10 = /*#__PURE__*/_jsx(RailBody, {
|
|
120
131
|
asChild: bodyAsChild,
|
|
121
132
|
tabs: tabs,
|
|
122
|
-
className:
|
|
123
|
-
children:
|
|
133
|
+
className: t8,
|
|
134
|
+
children: t9
|
|
124
135
|
});
|
|
125
|
-
$[
|
|
126
|
-
$[23] = bodyClassName;
|
|
127
|
-
$[24] = t7;
|
|
128
|
-
$[25] = tabs;
|
|
136
|
+
$[25] = bodyAsChild;
|
|
129
137
|
$[26] = t8;
|
|
138
|
+
$[27] = t9;
|
|
139
|
+
$[28] = tabs;
|
|
140
|
+
$[29] = t10;
|
|
130
141
|
} else {
|
|
131
|
-
|
|
142
|
+
t10 = $[29];
|
|
132
143
|
}
|
|
133
|
-
let
|
|
134
|
-
if ($[
|
|
135
|
-
|
|
144
|
+
let t11;
|
|
145
|
+
if ($[30] !== footer || $[31] !== footerClassName || $[32] !== slot) {
|
|
146
|
+
t11 = footer == null ? null : /*#__PURE__*/_jsx(RailFooter, {
|
|
136
147
|
className: footerClassName,
|
|
137
148
|
children: slot(footer)
|
|
138
149
|
});
|
|
139
|
-
$[
|
|
140
|
-
$[
|
|
141
|
-
$[
|
|
142
|
-
$[
|
|
150
|
+
$[30] = footer;
|
|
151
|
+
$[31] = footerClassName;
|
|
152
|
+
$[32] = slot;
|
|
153
|
+
$[33] = t11;
|
|
143
154
|
} else {
|
|
144
|
-
|
|
155
|
+
t11 = $[33];
|
|
145
156
|
}
|
|
146
|
-
let
|
|
147
|
-
if ($[
|
|
148
|
-
|
|
157
|
+
let t12;
|
|
158
|
+
if ($[34] !== className || $[35] !== props || $[36] !== t10 || $[37] !== t11 || $[38] !== t5 || $[39] !== t6) {
|
|
159
|
+
t12 = /*#__PURE__*/_jsxs(Rail, {
|
|
149
160
|
...props,
|
|
150
161
|
showDivider: t5,
|
|
151
162
|
className: className,
|
|
152
|
-
children: [t6,
|
|
163
|
+
children: [t6, t10, t11]
|
|
153
164
|
});
|
|
154
|
-
$[
|
|
155
|
-
$[
|
|
156
|
-
$[
|
|
157
|
-
$[
|
|
158
|
-
$[
|
|
159
|
-
$[
|
|
160
|
-
$[
|
|
165
|
+
$[34] = className;
|
|
166
|
+
$[35] = props;
|
|
167
|
+
$[36] = t10;
|
|
168
|
+
$[37] = t11;
|
|
169
|
+
$[38] = t5;
|
|
170
|
+
$[39] = t6;
|
|
171
|
+
$[40] = t12;
|
|
161
172
|
} else {
|
|
162
|
-
|
|
173
|
+
t12 = $[40];
|
|
163
174
|
}
|
|
164
|
-
return
|
|
175
|
+
return t12;
|
|
165
176
|
}
|
|
166
177
|
|
|
167
178
|
/** A slot's trough hides while the slot renders nothing (the pill is then its only child). */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.59.
|
|
3
|
+
"version": "0.59.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React 19 UI for web apps: one main JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, artifact viewers over the @vvedantb/server artifacts core, native tokens), third-party brand logos (also @vvedantb/ui/logos), motion-driven animated SVG icons (@vvedantb/ui/icons/animated), a client entry without @vvedantb/server, convex or Clerk for Chrome extensions, design-token CSS, shared Tailwind v4 CSS, a Tailwind preset and packaged Instrument Sans fonts.",
|
|
6
6
|
"type": "module",
|
|
@@ -42,7 +42,8 @@ export type SidebarRailProps = Omit<ComponentPropsWithoutRef<"div">, "children"
|
|
|
42
42
|
* `.RailFooter` instead.
|
|
43
43
|
*
|
|
44
44
|
* In an `AppShell variant="rail"` each of `top`, the body and `footer` sits on
|
|
45
|
-
* its own `RailGroup` trough,
|
|
45
|
+
* its own `RailGroup` trough, the body trough is centred vertically, and
|
|
46
|
+
* `showDivider` and `RailDivider` draw nothing.
|
|
46
47
|
* A `bodyAsChild` body is left as it is.
|
|
47
48
|
*/
|
|
48
49
|
export function SidebarRail({
|
|
@@ -63,7 +64,7 @@ export function SidebarRail({
|
|
|
63
64
|
return (
|
|
64
65
|
<Rail {...props} showDivider={showDivider && !rail} className={className}>
|
|
65
66
|
{top == null ? null : <RailHeader className={topClassName}>{slot(top)}</RailHeader>}
|
|
66
|
-
<RailBody asChild={bodyAsChild} tabs={tabs} className={bodyClassName}>
|
|
67
|
+
<RailBody asChild={bodyAsChild} tabs={tabs} className={cn(rail && "justify-center-safe", bodyClassName)}>
|
|
67
68
|
{bodyAsChild ? children : slot(children)}
|
|
68
69
|
</RailBody>
|
|
69
70
|
{footer == null ? null : <RailFooter className={footerClassName}>{slot(footer)}</RailFooter>}
|