@vvedantb/ui 0.59.1 → 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
- /** Theme name to the class or attribute value written. */
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 && resolvedTheme === "dark"`. */
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
- Reflect.set(root.style, "colorScheme", COLOR_SCHEMES.includes(resolved) ? resolved : fallback);
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: mounted && resolvedTheme === "dark",
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
- Reflect.set(root.style, "colorScheme", COLOR_SCHEMES.includes(resolved) ? resolved : fallback);
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(56);
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
- const t21 = mounted && resolvedTheme === "dark";
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 ($[40] !== resolvedTheme || $[41] !== setTheme) {
361
+ if ($[44] !== resolvedTheme || $[45] !== setTheme) {
341
362
  t22 = () => setTheme(resolvedTheme === "dark" ? "light" : "dark");
342
- $[40] = resolvedTheme;
343
- $[41] = setTheme;
344
- $[42] = t22;
363
+ $[44] = resolvedTheme;
364
+ $[45] = setTheme;
365
+ $[46] = t22;
345
366
  } else {
346
- t22 = $[42];
367
+ t22 = $[46];
347
368
  }
348
369
  let t23;
349
- if ($[43] !== forcedTheme || $[44] !== mounted || $[45] !== resolvedTheme || $[46] !== setTheme || $[47] !== t19 || $[48] !== t20 || $[49] !== t21 || $[50] !== t22 || $[51] !== theme) {
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
- $[43] = forcedTheme;
362
- $[44] = mounted;
363
- $[45] = resolvedTheme;
364
- $[46] = setTheme;
365
- $[47] = t19;
366
- $[48] = t20;
367
- $[49] = t21;
368
- $[50] = t22;
369
- $[51] = theme;
370
- $[52] = t23;
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 = $[52];
393
+ t23 = $[56];
373
394
  }
374
395
  const state = t23;
375
396
  let t24;
376
- if ($[53] !== children || $[54] !== state) {
397
+ if ($[57] !== children || $[58] !== state) {
377
398
  t24 = /*#__PURE__*/_jsx(Context, {
378
399
  value: state,
379
400
  children: children
380
401
  });
381
- $[53] = children;
382
- $[54] = state;
383
- $[55] = t24;
402
+ $[57] = children;
403
+ $[58] = state;
404
+ $[59] = t24;
384
405
  } else {
385
- t24 = $[55];
406
+ t24 = $[59];
386
407
  }
387
408
  return t24;
388
409
  }
@@ -138,7 +138,7 @@ function MobileHeader(t0) {
138
138
  }
139
139
  let t2;
140
140
  if ($[7] !== className) {
141
- t2 = cn("fixed inset-x-0 top-0 z-30 grid h-[var(--app-shell-mobile-header-height)] grid-cols-[minmax(max-content,1fr)_minmax(0,auto)_minmax(max-content,1fr)] items-center gap-2 bg-surface px-3 pt-[env(safe-area-inset-top,0px)] pl-[max(0.75rem,env(safe-area-inset-left))] pr-[max(0.75rem,env(safe-area-inset-right))] md:hidden", className);
141
+ t2 = cn("fixed inset-x-0 top-0 z-30 grid h-[var(--app-shell-mobile-header-height)] grid-cols-[minmax(max-content,1fr)_minmax(0,auto)_minmax(max-content,1fr)] items-center gap-2 bg-background px-3 pt-[env(safe-area-inset-top,0px)] pl-[max(0.75rem,env(safe-area-inset-left))] pr-[max(0.75rem,env(safe-area-inset-right))] md:hidden", className);
142
142
  $[7] = className;
143
143
  $[8] = t2;
144
144
  } else {
@@ -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, and `showDivider` and `RailDivider` draw nothing.
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(38);
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
- let t7;
108
- if ($[18] !== bodyAsChild || $[19] !== children || $[20] !== slot) {
109
- t7 = bodyAsChild ? children : slot(children);
110
- $[18] = bodyAsChild;
111
- $[19] = children;
112
- $[20] = slot;
113
- $[21] = t7;
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
- t7 = $[21];
116
+ t8 = $[20];
116
117
  }
117
- let t8;
118
- if ($[22] !== bodyAsChild || $[23] !== bodyClassName || $[24] !== t7 || $[25] !== tabs) {
119
- t8 = /*#__PURE__*/_jsx(RailBody, {
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: bodyClassName,
123
- children: t7
133
+ className: t8,
134
+ children: t9
124
135
  });
125
- $[22] = bodyAsChild;
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
- t8 = $[26];
142
+ t10 = $[29];
132
143
  }
133
- let t9;
134
- if ($[27] !== footer || $[28] !== footerClassName || $[29] !== slot) {
135
- t9 = footer == null ? null : /*#__PURE__*/_jsx(RailFooter, {
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
- $[27] = footer;
140
- $[28] = footerClassName;
141
- $[29] = slot;
142
- $[30] = t9;
150
+ $[30] = footer;
151
+ $[31] = footerClassName;
152
+ $[32] = slot;
153
+ $[33] = t11;
143
154
  } else {
144
- t9 = $[30];
155
+ t11 = $[33];
145
156
  }
146
- let t10;
147
- if ($[31] !== className || $[32] !== props || $[33] !== t5 || $[34] !== t6 || $[35] !== t8 || $[36] !== t9) {
148
- t10 = /*#__PURE__*/_jsxs(Rail, {
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, t8, t9]
163
+ children: [t6, t10, t11]
153
164
  });
154
- $[31] = className;
155
- $[32] = props;
156
- $[33] = t5;
157
- $[34] = t6;
158
- $[35] = t8;
159
- $[36] = t9;
160
- $[37] = t10;
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
- t10 = $[37];
173
+ t12 = $[40];
163
174
  }
164
- return t10;
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.1",
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",
@@ -101,7 +101,7 @@ function MobileHeader({ className, onKeyDown, ...props }: SidebarMobileHeaderPro
101
101
  closeOnEscape(sidebar, event);
102
102
  }}
103
103
  className={cn(
104
- "fixed inset-x-0 top-0 z-30 grid h-[var(--app-shell-mobile-header-height)] grid-cols-[minmax(max-content,1fr)_minmax(0,auto)_minmax(max-content,1fr)] items-center gap-2 bg-surface px-3 pt-[env(safe-area-inset-top,0px)] pl-[max(0.75rem,env(safe-area-inset-left))] pr-[max(0.75rem,env(safe-area-inset-right))] md:hidden",
104
+ "fixed inset-x-0 top-0 z-30 grid h-[var(--app-shell-mobile-header-height)] grid-cols-[minmax(max-content,1fr)_minmax(0,auto)_minmax(max-content,1fr)] items-center gap-2 bg-background px-3 pt-[env(safe-area-inset-top,0px)] pl-[max(0.75rem,env(safe-area-inset-left))] pr-[max(0.75rem,env(safe-area-inset-right))] md:hidden",
105
105
  className,
106
106
  )}
107
107
  />
@@ -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, and `showDivider` and `RailDivider` draw nothing.
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>}