@vvedantb/ui 0.30.2 → 0.31.1

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 CHANGED
@@ -260,6 +260,17 @@ import {
260
260
  <FadePresence show={visible} variants={fadeUpSpring}>…</FadePresence>
261
261
  ```
262
262
 
263
+ - `Button` `shape` (0.31.0, a default change): `"pill"` (default) is `rounded-full` for every variant and size, so the icon sizes are circles. `"rounded"` keeps the radius from before 0.31.0: `rounded-lg`, and `rounded-md` on `xs` and `icon-xs`. Use `shape="rounded"` for buttons that join other edges (inside a `ButtonGroup`) or sit in square chrome. A `className` radius still wins over both. `InputGroupButton`, the message branch arrows and the sidebar `AccountTrigger`, `MobileMenuButton` and `PanelClose` already use `"rounded"`. With the default `--radius` (1rem), buttons 32px tall or less were already fully round, so the visible change is on `default`, `lg` and `icon`.
264
+
265
+ ```tsx
266
+ <Button>Save</Button> {/* pill */}
267
+ <Button size="icon" aria-label="Add"><IconPlus /></Button> {/* circle */}
268
+ <ButtonGroup>
269
+ <Button variant="outline" shape="rounded">Day</Button>
270
+ <Button variant="outline" shape="rounded">Week</Button>
271
+ </ButtonGroup>
272
+ ```
273
+
263
274
  - `Button`: variants `flat`, `success` and `warning` (each is `ghost` plus an override). `loading` disables the button, sets `data-loading="true"` and shows a spinner in place of `startContent`; without `loading` there is no `data-loading` attribute. `endContent` renders after the children. Both are ignored with `asChild` (`loading` still disables).
264
275
  - `DropdownMenuContent`: `fitViewport` caps the height on small screens and scrolls. It reads the optional `--vv-height` CSS variable, which the app may set to the visual viewport height (falls back to `70dvh`). `suppressAltKey` stops a bare Alt press from moving focus. `restoreScrollLockOnClose` calls `restoreModalScrollLock` on close (now and on the next tick). `ContextMenuContent` takes `suppressAltKey` too.
265
276
  - `DropdownMenuItem` `endContent` and `ContextMenuItem` `startContent`, `description` and `endContent`: the label moves into a growing column (`min-w-0 flex-1`), the description sits under it and `endContent` sits at the end. `DropdownMenuSubTrigger` and `ContextMenuSubTrigger` take `startContent`.
@@ -438,7 +449,7 @@ Convention: compound parts are static members of a namespace object, `<Namespace
438
449
  | --- | --- |
439
450
  | `Root` | No DOM. Holds `isDesktop`, `mobileOpen`, `onMobileOpenChange`, `collapsed`, `panelHidden` and the drawer `id`. Closes the drawer at the desktop breakpoint. The chrome parts need it. |
440
451
  | `MobileHeader` | Fixed header below `md`, a three-column grid (menu button, title, actions). Escape closes the drawer. Keep all three children so the columns line up. |
441
- | `MobileMenuButton` | Opens the drawer. `label`, `icon` (`(open) => node`). |
452
+ | `MobileMenuButton` | Opens the drawer. `label`, `icon` (`(open) => node`). Keeps `rounded-lg` (`Button` `shape="rounded"`); change it with `className`. |
442
453
  | `MobileTitle` | Centred `<h1>` that truncates. Without children, an empty `<span>` keeps the middle column. |
443
454
  | `MobileActions` | Trailing header actions. Without children, a spacer that keeps the title centred. |
444
455
  | `Backdrop` | Drawer backdrop; a click closes the drawer. `label` (`"Close navigation"`). |
@@ -452,11 +463,11 @@ Convention: compound parts are static members of a namespace object, `<Namespace
452
463
  | `Panel` | Panel column. `collapsed` (`md:hidden`) and `panelHidden` (renders nothing) default to the Root values. |
453
464
  | `PanelHeader` | Padded header row for `PanelTitle` and `PanelActions`. |
454
465
  | `PanelTitle` / `PanelActions` | The `<h2>` and the trailing actions. |
455
- | `PanelClose` | Ghost close button. `label` (`"Close navigation"`). Without `onClick` it closes the drawer. |
466
+ | `PanelClose` | Ghost close button. `label` (`"Close navigation"`). Without `onClick` it closes the drawer. Keeps `rounded-lg` (`Button` `shape="rounded"`); change it with `className`. |
456
467
  | `NavItem` | Panel nav row (`sidebarNavItemClass`). `active` (fill, `font-medium`, `aria-current="page"`), `iconOnly`, `icon` (element; gets `sidebarNavIconClass`), `asChild` for a router link. A `<button type="button">` without `asChild`. 0.7.2: `selected`, `indent`, `dragging`, `dropTarget`; see [Sidebar nav row parts (0.7.2)](#sidebar-nav-row-parts-072). |
457
468
  | `NavItemLeading` / `NavItemLabel` / `NavItemTrailing` / `NavItemActions` | Row parts (0.7.2): leading slot, truncated label, always-visible trailing content and hover-revealed actions. `<span>`, or the child with `asChild`. |
458
469
  | `AccountMenu` | Dropdown root. `badge` adds the unread dot (`AccountBadge`) in a `relative` wrapper. |
459
- | `AccountTrigger` | Rail-tile-sized avatar button. `userName` (default `title` and `aria-label`, and the initials), `imageUrl`, plus `Button` props; native `name` goes to the button. |
470
+ | `AccountTrigger` | Rail-tile-sized avatar button. `userName` (default `title` and `aria-label`, and the initials), `imageUrl`, plus `Button` props except `asChild` and `shape` (it keeps the rail tile `rounded-lg`); native `name` goes to the button. |
460
471
  | `AccountAvatar` | Avatar image or initials. `userName`, `imageUrl`. |
461
472
  | `AccountContent` | Menu content. Defaults `align="center"`, `side="right"`, `sideOffset={8}`, `w-56`. |
462
473
  | `AccountLabel` | Identity label: avatar, `userName`, optional `email`, `stacked`. |
@@ -882,9 +893,11 @@ links under a separator.
882
893
  ### `Icon*` app icons
883
894
 
884
895
  Tabler-style plain app glyphs: `IconVibot`, `IconVhub`, `IconVmem`, `IconVerve`,
885
- `IconVelth` and `IconProjectV`. No background. Each sits on an equalised square viewBox, so all apps look the same size. `APP_ICONS[app]`
896
+ `IconVelth`, `IconProjectV`, `IconEva` and `IconBee`. No background. Each sits on an equalised square viewBox, so all apps look the same size. `APP_ICONS[app]`
886
897
  looks one up by `AppName`.
887
898
 
899
+ `IconEva` (a filled four-point star) and `IconBee` (an orb with eyes, stripes and antennae) are icons only. `eva` and `bee` are in `APP_NAMES`, `APP_MARKS` and `APP_ICONS`, but not in `FAMILY_APPS` or `V_PRO_APP_BENEFITS`, and `AppWordmark` and `PricingModal` do not take them.
900
+
888
901
  ```tsx
889
902
  import { IconVerve } from "@vvedantb/ui"
890
903
 
@@ -940,13 +953,14 @@ import { AppWordmark } from "@vvedantb/ui"
940
953
  ### `AppMark` (deprecated)
941
954
 
942
955
  Deprecated in favour of the `Icon*` components for plain marks. Tiles stay here.
943
- Family app icons: `app` (`projectv`, `vibot`, `vhub`, `vmem`, `verve`, `velth`),
956
+ Family app icons: `app` (`projectv`, `vibot`, `vhub`, `vmem`, `verve`, `velth`, and the icon-only `eva` and `bee`),
944
957
  `variant`, `size`, `title`.
945
958
 
946
959
  - `variant="mark"` (default) is the plain logo in `currentColor`. It sits
947
960
  on a square viewBox. The five apps (`vibot`, `vhub`, `vmem`, `verve`, `velth`) keep one
948
961
  frame size, 629 x 629 (`APP_MARK_CROP_VIEWBOX` is the historical `173 197 629 629`), so relative
949
- glyph sizes match the tiles. Each viewBox origin is centred on that glyph's `markBBox`, so no
962
+ glyph sizes match the tiles. `eva` and `bee` use the same 629 side, but the historical crop does not
963
+ include them. Each viewBox origin is centred on that glyph's `markBBox`, so no
950
964
  glyph sits off-centre in its square. `projectv` is a brand mark, so it keeps its own 687 frame,
951
965
  centred on its bbox (`PROJECTV_MARK_VIEWBOX`, `171.5 181 687 687`). `size` sets both width and
952
966
  height; a string `size` (for example `"2rem"`) is any CSS length. `APP_MARK_VIEWBOX` holds the
@@ -971,7 +985,7 @@ default) and `renderCheckout`.
971
985
 
972
986
  #### Multi-plan (0.22.0)
973
987
 
974
- Header: `apps` (an `AppName[]`, shown as plain `Icon*` logos at the top left; each links to the app's site in a new tab and shows its display name in a tooltip, from `FAMILY_APPS`),
988
+ Header: `apps` (a `FamilyAppName[]`, shown as plain `Icon*` logos at the top left; each links to the app's site in a new tab and shows its display name in a tooltip, from `FAMILY_APPS`),
975
989
  `headline` (centre), a Monthly / Annual switch and a close button (top right).
976
990
  Then one card per entry of `plans` (2 to 4 fit) and one `finePrint` line. Cards
977
991
  stack on narrow screens.
@@ -986,7 +1000,7 @@ outlined "Current plan" button and does not call `renderCheckout`.
986
1000
 
987
1001
  `appBenefits` (`{ app, items }[]`, type `PricingPlanAppBenefit`) groups benefits per app, each under a small heading with that app's icon and display name. It renders after `benefits` and scrolls inside the card when long. Set `currentApp` on the modal to put that app's group first; the other groups keep the array order. The `featured` / `highlighted` plan uses `V_PRO_APP_BENEFITS` (the approved V Pro copy, in the order vibot, vmem, vhub, velth, verve) when it omits `appBenefits`, so apps usually pass only `currentApp`. Other plans show app benefits only when set.
988
1002
 
989
- `FAMILY_APPS` (and `familyApp(app)`), exported from the root and `@vvedantb/ui/brand`, is the single list of app display names and sites (`vibot`, `Verve`, `Velth`, `vmem`, `vhub`, `Project V`; URLs without a trailing slash). App names live only under `src/brand/`.
1003
+ `FAMILY_APPS` (and `familyApp(app)`), exported from the root and `@vvedantb/ui/brand`, is the single list of app display names and sites (`vibot`, `Verve`, `Velth`, `vmem`, `vhub`, `Project V`; URLs without a trailing slash). Its app type is `FamilyAppName`: `AppName` without the icon-only `eva` and `bee`. App names live only under `src/brand/`.
990
1004
 
991
1005
  The `featured` plan's button is a solid primary button (`Button` `variant="default"`). Other plans use `secondary`.
992
1006
 
@@ -1297,7 +1311,13 @@ import { SonnerToaster, toast } from "@vvedantb/ui";
1297
1311
  />;
1298
1312
  ```
1299
1313
 
1300
- With no new props and no `UiConfig.SonnerToaster` entry the toaster looks as it did in 0.2.1. An entry sets app defaults for any prop (see "App config: AI chat" below). Caller props merge with the package defaults instead of replacing them:
1314
+ With no new props and no `UiConfig.SonnerToaster` entry the toaster looks as it did in 0.2.1, except for three changes from 0.31.1:
1315
+
1316
+ - Toasts sit at the top right (`position="top-right"`). Sonner's own default is bottom-right. Pass `position`, or set `UiConfig.SonnerToaster.position`, to move them.
1317
+ - The text column grows (`content`: `flex min-w-0 grow flex-col`). `unstyled` drops sonner's own grow, so without it the action button left a gap at the right edge. Apps no longer need to set `classes.content` for this.
1318
+ - The action and cancel buttons are 28px tall (`h-7 shrink-0 rounded-control px-2.5 text-xs`), up from 24px. The action button presses with `motion-press active:scale-[0.96]` (`motion-press` is an app utility) and hovers with `hover:bg-primary/90`. `classes.actionButton` replaces the string, and `toastOptions.classNames.actionButton` appends to it.
1319
+
1320
+ A `UiConfig.SonnerToaster` entry sets app defaults for any prop (see "App config: AI chat" below). Caller props merge with the package defaults instead of replacing them:
1301
1321
 
1302
1322
  - `toastOptions.classNames`: per key, the package classes come first and the caller classes follow, so callers can override utilities. Other `toastOptions` fields (such as `duration`) take the caller value.
1303
1323
  - `icons`: merged per key. With `toastIcons="filled24"` the caller overrides single icons and keeps the rest.
@@ -1319,7 +1339,9 @@ Opt-in props (all default to the current look):
1319
1339
 
1320
1340
  With `closeButtonStyle="hoverChip"`, hover changes the text colour, and sonner may still change the background. The border stays `border-border` (pinned with `hover:border-border!` over sonner's dark hover border), so the ring does not brighten in dark mode.
1321
1341
 
1322
- Helpers: `createToasterClassNames`, `mergeToastClassNames`, `mergeToastOptions`, `mergeToasterStyle`, `filledToastIcons`. Fixture: `tokens/examples/toaster/`.
1342
+ Helpers: `createToasterClassNames`, `mergeToastClassNames`, `mergeToastOptions`, `mergeToasterStyle`, `filledToastIcons`. Fixture: `tokens/examples/toaster/` (`update.html` shows the update toast).
1343
+
1344
+ For the "Update available" toast, call `showUpdateAvailableToast({ toast, closeConvex })` or let `startUpdateAvailableWatcher` call it. See `app/README.md`.
1323
1345
 
1324
1346
  ## App config
1325
1347
 
@@ -1354,7 +1376,7 @@ const config = {
1354
1376
  } satisfies UiConfig;
1355
1377
  ```
1356
1378
 
1357
- - `Button`: `classes.base`, `classes.variant.<variant>`, `classes.size.<size>`. New size `xs` (`h-7 rounded-md px-2 text-xs hit-target`, 14px icons).
1379
+ - `Button`: `classes.base`, `classes.variant.<variant>`, `classes.size.<size>`, `classes.shape.<pill|rounded>` (0.31.0). New size `xs` (`h-7 px-2 text-xs hit-target`, 14px icons). Since 0.31.0 the radius is not in `base` or the size strings: `classes.shape` sets it, one string per shape for every size (built in: `pill` `rounded-full`; `rounded` `rounded-lg`, or `rounded-md` on `xs` and `icon-xs`).
1358
1380
  - `Badge`: `classes.base`, `classes.variant.<variant>`.
1359
1381
  - `Input`, `Textarea`: `classes.base`.
1360
1382
  - `Checkbox`: `classes.root`, `classes.indicator`, `icon`. New prop `icon`: the indicator content (default a 14px check). The `CheckboxProps` type is exported.
package/app/README.md ADDED
@@ -0,0 +1,269 @@
1
+ # App helpers (`@vvedantb/ui`)
2
+
3
+ Shared web React helpers that were duplicated across apps. Source-exported as the `./app` subpath of `@vvedantb/ui`.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @vvedantb/ui
9
+ ```
10
+
11
+ ## Peers
12
+
13
+ Required: `react` and `react-dom` (>=19). Optional peers of `@vvedantb/ui` used by the app helpers: `@clerk/clerk-react` (`useStableAuth`, `ConvexClerkProvider`), `convex` (`ConvexClerkProvider`, `useEnsureUser`), `@tanstack/react-hotkeys` and `zod` (your `z` for `parseClientEnv`). The root imports Clerk and `convex/react` statically, so they must be installed even if you do not use these helpers; see the package README.
14
+
15
+ `sonner` is not a dependency. The update watcher takes the toast API as an option. The app source uses a local class join, which the root does not export (the root `cn` is the clsx and tailwind-merge one). Tailwind must scan `node_modules/@vvedantb/ui/app/src/**/*.{ts,tsx}` so the class names are generated, and the app needs the `@vvedantb/ui/tokens` names (`bg-surface-card`, `divide-separator`, `text-muted-foreground` and so on).
16
+
17
+ ```css
18
+ @source "../node_modules/@vvedantb/ui/app/src/**/*.{ts,tsx}";
19
+ ```
20
+
21
+ ## Confirm skip (Alt-click)
22
+
23
+ ```tsx
24
+ import { ConfirmSkipHint, skipConfirmTitle, useRequestConfirm } from "@vvedantb/ui";
25
+
26
+ const { request } = useRequestConfirm();
27
+
28
+ <DropdownMenuItem
29
+ title={skipConfirmTitle("Delete")}
30
+ onSelect={(event) => request(() => setOpen(true), () => remove(), event)}
31
+ >
32
+ Delete <ConfirmSkipHint />
33
+ </DropdownMenuItem>
34
+ ```
35
+
36
+ - `useRequestConfirm` does not subscribe to Alt. It reads `getAltHeld()` when the request happens, so the menu owner does not re-render when Alt goes down. It returns `{ request }` only.
37
+ - `ConfirmSkipHint` stays mounted and gains a `hidden` class when Alt is not held, so an open Radix menu keeps a stable child tree.
38
+ - The Alt store resets when the last subscriber leaves, clears on blur and tab hide, and cancels a bare Alt keydown only inside `[role='menu']` or `[data-radix-menu-content]`.
39
+ - Also exported: `useAltHeld`, `getAltHeld`, `createAltHeldStore`, `bindToWindow`, `shouldSkipConfirm`, `requestConfirm`.
40
+
41
+ ## Update available watcher
42
+
43
+ ```ts
44
+ import { toast } from "sonner";
45
+ import { startUpdateAvailableWatcher } from "@vvedantb/ui";
46
+
47
+ useEffect(
48
+ () =>
49
+ startUpdateAvailableWatcher({
50
+ origin: window.location.origin,
51
+ toast,
52
+ closeConvex: () => void convex.close(),
53
+ enabled: !import.meta.env.DEV,
54
+ }),
55
+ [],
56
+ );
57
+ ```
58
+
59
+ Options: `origin`, `toast`, `closeConvex?`, `pollMs?` (default 60000), `toastId?` (default `app-update-available`), `enabled?` (default true), `reload?` (default `window.location.reload`). On a changed asset fingerprint it calls `showUpdateAvailableToast` once. `fingerprintFromHtml` and `fetchDeployFingerprint` are exported too. The fingerprint looks for Vite `/assets/*.js` URLs in the index HTML.
60
+
61
+ `showUpdateAvailableToast({ toast, closeConvex?, toastId?, reload? })` (from 0.31.1) shows the toast on its own, for an app with its own update signal:
62
+
63
+ ```ts
64
+ import { showUpdateAvailableToast, toast } from "@vvedantb/ui";
65
+
66
+ showUpdateAvailableToast({ toast, closeConvex: () => void convex.close() });
67
+ ```
68
+
69
+ It shows a sticky "Update available" toast, "Refresh to load the latest version.", with a Refresh action. Refresh calls `closeConvex` (errors ignored), then reloads. The same `toastId` replaces an open toast instead of adding a second one. Mount `SonnerToaster`: from 0.31.1 its default `content` class grows the text column, so Refresh sits at the right edge without app classes.
70
+
71
+ ## Settings chrome
72
+
73
+ ```tsx
74
+ import { SettingsPage, SettingsSection, SettingsToggleRow } from "@vvedantb/ui";
75
+
76
+ <SettingsPage
77
+ title="Notifications"
78
+ layout={({ title, headerRight, toolbar, tabs, fillHeight, children }) => (
79
+ <PageContainer title={title} rightSection={headerRight} toolbar={toolbar} tabs={tabs} noScroll={fillHeight}>
80
+ {children}
81
+ </PageContainer>
82
+ )}
83
+ >
84
+ <SettingsSection title="Email" bodyVariant="list">
85
+ <SettingsToggleRow title="Weekly digest" action={<Switch />} />
86
+ </SettingsSection>
87
+ </SettingsPage>
88
+ ```
89
+
90
+ Exports: `SettingsSection`, `SettingsField`, `SettingsStack`, `SettingsToggleRow`, `SettingsEmptyState` (icon is `ComponentType<{ size?: number; className?: string }>`), `SettingsPage`. `SettingsField` `layout`: `"stacked"` (default) puts the label above the control. `"horizontal"` renders one row with the label and description on the left and the control on the right. Without `layout`, `SettingsPage` renders a plain `div` with a heading and the optional slots.
91
+
92
+ ## useStableAuth
93
+
94
+ ```ts
95
+ import { useStableAuth } from "@vvedantb/ui"; // 2000 ms debounce, wraps Clerk useAuth
96
+ import { createUseStableAuth } from "@vvedantb/ui";
97
+
98
+ const useAuth = createUseStableAuth(useClerkAuth, { debounceMs: 3000 });
99
+ ```
100
+
101
+ After a signed-in session, a drop to signed-out reports `isLoaded: false` for the debounce window so Convex does not cascade. State is module-level. `resetStableAuthSession()` clears it and is for tests only.
102
+
103
+ ## Develop
104
+
105
+ ```sh
106
+ pnpm --filter @vvedantb/ui typecheck
107
+ pnpm --filter @vvedantb/ui test
108
+ ```
109
+
110
+ Source is in `app/src` and tests in `app/tests`. Publish steps are in the root `README.md`.
111
+
112
+ ## Theme
113
+
114
+ ```tsx
115
+ import { createThemeProvider } from "@vvedantb/ui";
116
+
117
+ // One kit per app, at module level.
118
+ export const { ThemeProvider, useTheme } = createThemeProvider();
119
+
120
+ <ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
121
+ <App />
122
+ </ThemeProvider>;
123
+
124
+ const { theme, resolvedTheme, setTheme, isDark, toggleTheme, mounted } = useTheme();
125
+ ```
126
+
127
+ `createThemeProvider` is a port of next-themes 0.4.6. An app that uses next-themes can switch without a change in behaviour: the same localStorage writes, `<html>` classes and attributes, `style.colorScheme`, `prefers-color-scheme` listener, cross-tab `storage` sync and transition blocking. Parity tests run both side by side.
128
+
129
+ - Props, as in next-themes: `storageKey` (`"theme"`), `defaultTheme` (`"system"` with `enableSystem`, else `"light"`), `enableSystem` (`true`), `enableColorScheme` (`true`), `attribute` (`"data-theme"`; `"class"`, any `data-*`, or an array), `themes` (`["light", "dark"]`), `value` (theme name to written value), `forcedTheme`, `disableTransitionOnChange` (`false`) and `nonce`.
130
+ - State: `theme`, `setTheme` (a value or a function of the current theme), `resolvedTheme`, `systemTheme`, `forcedTheme` and `themes`, as in next-themes. Added: `mounted` (after the provider's first effect), `isDark` (`mounted && resolvedTheme === "dark"`) and `toggleTheme` (from `resolvedTheme`).
131
+ - `setTheme` is a new function each time `theme` changes and stable otherwise, as in next-themes, so effects that list it re-run at the same times.
132
+ - next-themes reads the DOM options (`attribute`, `themes`, `value`, `enableSystem`, `enableColorScheme`, `defaultTheme`, `disableTransitionOnChange`, `nonce`) once, on the first render, and so does this port. If `enableSystem` starts `false` and later turns `true`, a stored `"system"` is written as the class `system`. `forcedTheme` follows props.
133
+ - A nested `ThemeProvider` from the same kit renders only its children.
134
+ - `createThemeProvider({ missingProviderMessage })`: `useTheme()` outside the provider throws that message. Without it, `useTheme()` returns an empty state with no-op setters, as next-themes does.
135
+ - No inline script is rendered. next-themes renders one for server rendering; React does not run it in a client-rendered app. Keep a pre-paint script in `index.html` if the app has one.
136
+
137
+ For an app with its own theme state (for example a theme synced from the server), two helpers:
138
+
139
+ - `getSystemTheme()`: `"dark"` or `"light"` from `prefers-color-scheme`; `"light"` without `window`.
140
+ - `applyThemeClass(theme)`: removes `light` and `dark` from `<html>`, then adds `theme`. No-op without `document`.
141
+
142
+ ## Page title
143
+
144
+ ```tsx
145
+ import { createPageTitleContext } from "@vvedantb/ui";
146
+
147
+ export const { PageTitleProvider, usePageTitle, usePageTitleSync } = createPageTitleContext({
148
+ missingProviderMessage: "usePageTitle must be used within a PageTitleProvider",
149
+ });
150
+
151
+ // The shell reads it:
152
+ const { pageTitle } = usePageTitle();
153
+ // A page publishes it while mounted:
154
+ usePageTitleSync(title);
155
+ ```
156
+
157
+ - `usePageTitle()` returns `{ pageTitle, setPageTitle, mobileActionsSlot, setMobileActionsSlot }`. `mobileActionsSlot` is an element a mobile top bar registers (pass `setMobileActionsSlot` as its `ref`) so pages can portal actions into it.
158
+ - `usePageTitleSync(title)` sets the title while the caller is mounted and clears it on unmount. Titles that are not strings publish `""`.
159
+ - `missingProviderMessage`: `usePageTitle()` outside the provider throws it. Without it, `usePageTitle()` returns an empty title and no-op setters.
160
+ - `documentTitle` (off by default; without it `document.title` is never touched): `{ suffix?, separator? = " · ", fallback? }`. While a page title is set, `document.title` is `` `${pageTitle}${separator}${suffix}` `` (just the page title without a suffix). While it is empty, `fallback`, else the title at mount. The mount-time title comes back on unmount.
161
+
162
+ ## Page motion
163
+
164
+ ```tsx
165
+ import { MotionConfig } from "motion/react";
166
+ import { PageMotionProvider, useDisablePageMotion } from "@vvedantb/ui";
167
+
168
+ <PageMotionProvider disabled={flags?.disablePageMotion === true} motionConfig={MotionConfig}>
169
+ <App />
170
+ </PageMotionProvider>;
171
+ ```
172
+
173
+ - Sets `html[data-page-motion]` to `"off"` or `"on"` in a layout effect. The attribute stays after unmount. From 0.15.0 `tokens.css` (through `tokens/css/motion.css`) ships the `"off"` rules: `.ui-page-enter`, `.ui-enter`, `.ui-enter-up` and `.ui-stagger` fade only, `animate-in` / `animate-out`, `.t-modal` and `.t-tabs-pill` stop transitioning, and view transitions stop.
174
+ - Renders `motionConfig` with `reducedMotion` `"always"` when disabled, else `"never"`.
175
+ - `useDisablePageMotion()`: the `disabled` value, `false` outside the provider.
176
+ - This module does not import `motion`. Pass `MotionConfig`, or an app component that wraps it, defined at module level, for example with `LazyMotion`:
177
+
178
+ ```tsx
179
+ function LazyMotionConfig({ reducedMotion, children }: PageMotionConfigProps) {
180
+ return (
181
+ <LazyMotion features={domAnimation}>
182
+ <MotionConfig reducedMotion={reducedMotion}>{children}</MotionConfig>
183
+ </LazyMotion>
184
+ );
185
+ }
186
+ ```
187
+
188
+ ## Compact relative time
189
+
190
+ ```ts
191
+ import { formatCompactRelativeTime } from "@vvedantb/ui";
192
+
193
+ formatCompactRelativeTime(createdAt, { justNow: "now" }); // "now", "5m", "3h", "2d", "4mo", "1y"
194
+ formatCompactRelativeTime(updatedAt, { calendar: true }); // "42s", ..., calendar months and years
195
+ ```
196
+
197
+ Pure TypeScript, no dependencies. Options:
198
+
199
+ - `now`: clock in ms, default `Date.now()`.
200
+ - `justNow`: returned for anything under a minute old, future times included. Without it the result is whole seconds (`"42s"`), and a future time gives `"0s"` or a negative count.
201
+ - `calendar`: `false` (default) counts elapsed time: a day is 24 hours, a month 30 days, a year 12 such months. `true` counts as `dayjs().diff(date, unit)` does: days by the local calendar across DST changes, and calendar months and years.
202
+
203
+ Strings are parsed with `new Date(string)`. dayjs parses a date-only string such as `"2026-03-01"` as local midnight, `new Date` as UTC midnight; numbers, `Date` objects and ISO strings with a time give the same result either way. An invalid date gives `"NaNy"` (`"0mo"` with `calendar`).
204
+
205
+ ## Convex provider, VITE env and ensure-user (0.10.0)
206
+
207
+ React and VITE env helpers for Convex apps. The non-React Convex helpers (`mapLoadedQuery`, `forEachLoadedQuery`, `updateAllCachedQueries`, `patchLoadedQuery`, `OptimisticStore`, `tempId`, `createMemoryOptimisticStore`) live in `@vvedantb/server`, so backend packages, tests and React Native can use them without loading this package.
208
+
209
+ ### `ConvexClerkProvider`
210
+
211
+ ```tsx
212
+ import { ConvexClerkProvider, useStableAuth } from "@vvedantb/ui";
213
+ import { ConvexReactClient } from "convex/react";
214
+
215
+ const convex = new ConvexReactClient(env.VITE_CONVEX_URL);
216
+
217
+ <ClerkProvider publishableKey={env.VITE_CLERK_PUBLISHABLE_KEY}>
218
+ <ConvexClerkProvider client={convex} useAuth={useStableAuth}>
219
+ <App />
220
+ </ConvexClerkProvider>
221
+ </ClerkProvider>;
222
+ ```
223
+
224
+ | Props | Renders |
225
+ | --- | --- |
226
+ | `client` is `null` or `undefined` | `children` alone (no provider). |
227
+ | `clerk={false}` | `<ConvexProvider client={client}>`. |
228
+ | otherwise | `<ConvexProviderWithClerk client={client} useAuth={useAuth}>`; `useAuth` defaults to `@clerk/clerk-react`'s. |
229
+
230
+ `clerk` defaults to `true`. Render it inside `ClerkProvider` unless `clerk` is `false`. Types: `ConvexClerkProviderProps`, `ConvexClerkUseAuth`.
231
+
232
+ ### `parseClientEnv`
233
+
234
+ ```ts
235
+ import { z } from "zod";
236
+ import { parseClientEnv } from "@vvedantb/ui";
237
+
238
+ export const clientEnv = parseClientEnv(import.meta.env, { z, viteEnv: "fallback" });
239
+ // { VITE_CONVEX_URL: string; VITE_CLERK_PUBLISHABLE_KEY: string; VITE_ENV: "development" | "staging" | "production" }
240
+
241
+ export const extensionEnv = parseClientEnv(import.meta.env, {
242
+ z,
243
+ viteEnv: false,
244
+ extend: { VITE_CLERK_SYNC_HOST: z.string().url() },
245
+ });
246
+ ```
247
+
248
+ The schema is `z.object({ VITE_CONVEX_URL: z.string().min(1), VITE_CLERK_PUBLISHABLE_KEY: z.string().min(1), VITE_ENV: z.enum(["development", "staging", "production"]), ...extend })`, built with your `z` (zod 3.25+ or 4; the package never imports zod at runtime). Only the schema's keys are read from `rawEnv`. Failure throws the `ZodError` from `.parse`.
249
+
250
+ | `viteEnv` | `VITE_ENV` |
251
+ | --- | --- |
252
+ | `"strict"` (default) | Must be one of `VITE_ENV_NAMES`. |
253
+ | `"fallback"` | Any other value, or none, becomes `"development"` before parsing. |
254
+ | `false` | Not in the schema or the result. |
255
+
256
+ Types: `ClientEnv`, `ClientEnvWithoutViteEnv`, `ClientEnvOptions`, `ClientEnvSource`, `ViteEnvMode`, `ViteEnvName`.
257
+
258
+ ### `useEnsureUser`
259
+
260
+ ```tsx
261
+ function EnsureUser() {
262
+ useEnsureUser(api.users.ensureUserExists);
263
+ return null;
264
+ }
265
+ ```
266
+
267
+ Calls `mutation({})` every time `useConvexAuth().isAuthenticated` becomes `true` (once on mount if already signed in), and logs a rejection with `console.error`. Needs a Convex auth provider above it (`ConvexClerkProvider` with Clerk on). Pair it with `ensureUser` from `@vvedantb/server`. Type: `EnsureUserMutation`.
268
+
269
+ Tests: `app/tests/convex/` ports each app's copy and runs it beside the helper (env with zod 4 and zod 3.25; provider variants; ensure-user calls over auth sequences). `app/tests-node/convex-esm.test.mjs` loads the helpers in plain Node.
package/app/src/index.ts CHANGED
@@ -17,7 +17,9 @@ export {
17
17
  fingerprintFromHtml,
18
18
  } from "./update/deployFingerprint.js";
19
19
  export {
20
+ showUpdateAvailableToast,
20
21
  startUpdateAvailableWatcher,
22
+ type ShowUpdateAvailableToastOptions,
21
23
  type UpdateAvailableWatcherOptions,
22
24
  type UpdateToastOptions,
23
25
  } from "./update/updateWatcher.js";
@@ -16,6 +16,7 @@ export type UpdateAvailableWatcherOptions = {
16
16
  closeConvex?: () => void;
17
17
  /** Poll interval in ms. Default 60000. */
18
18
  pollMs?: number;
19
+ /** Default `app-update-available`. */
19
20
  toastId?: string;
20
21
  /** Pass `!import.meta.env.DEV`. When false, nothing starts. Default true. */
21
22
  enabled?: boolean;
@@ -23,13 +24,47 @@ export type UpdateAvailableWatcherOptions = {
23
24
  reload?: () => void;
24
25
  };
25
26
 
27
+ export type ShowUpdateAvailableToastOptions = Pick<
28
+ UpdateAvailableWatcherOptions,
29
+ "toast" | "closeConvex" | "toastId" | "reload"
30
+ >;
31
+
26
32
  const DEFAULT_POLL_MS = 60_000;
27
33
  const DEFAULT_TOAST_ID = "app-update-available";
28
34
 
35
+ /**
36
+ * Show the sticky "Update available" toast with a Refresh action. Refresh
37
+ * calls `closeConvex` (errors ignored), then reloads. The same `toastId`
38
+ * replaces an open toast instead of stacking a second one.
39
+ */
40
+ export function showUpdateAvailableToast({
41
+ toast,
42
+ closeConvex,
43
+ toastId = DEFAULT_TOAST_ID,
44
+ reload = () => window.location.reload(),
45
+ }: ShowUpdateAvailableToastOptions): void {
46
+ toast.message("Update available", {
47
+ id: toastId,
48
+ description: "Refresh to load the latest version.",
49
+ duration: Number.POSITIVE_INFINITY,
50
+ action: {
51
+ label: "Refresh",
52
+ onClick: () => {
53
+ try {
54
+ closeConvex?.();
55
+ } catch {
56
+ // socket may already be closed during teardown
57
+ }
58
+ reload();
59
+ },
60
+ },
61
+ });
62
+ }
63
+
29
64
  /**
30
65
  * Poll the live index HTML for a new Vite asset fingerprint (and re-check when
31
- * the tab becomes visible). Shows a sticky "Update available" toast with a
32
- * Refresh action when a newer deploy is serving. Returns a stop function.
66
+ * the tab becomes visible). Calls `showUpdateAvailableToast` once when a newer
67
+ * deploy is serving. Returns a stop function.
33
68
  */
34
69
  export function startUpdateAvailableWatcher(
35
70
  options: UpdateAvailableWatcherOptions,
@@ -39,9 +74,9 @@ export function startUpdateAvailableWatcher(
39
74
  toast,
40
75
  closeConvex,
41
76
  pollMs = DEFAULT_POLL_MS,
42
- toastId = DEFAULT_TOAST_ID,
77
+ toastId,
43
78
  enabled = true,
44
- reload = () => window.location.reload(),
79
+ reload,
45
80
  } = options;
46
81
  if (!enabled) return () => {};
47
82
 
@@ -52,22 +87,7 @@ export function startUpdateAvailableWatcher(
52
87
  const showToast = (): void => {
53
88
  if (shown) return;
54
89
  shown = true;
55
- toast.message("Update available", {
56
- id: toastId,
57
- description: "Refresh to load the latest version.",
58
- duration: Number.POSITIVE_INFINITY,
59
- action: {
60
- label: "Refresh",
61
- onClick: () => {
62
- try {
63
- closeConvex?.();
64
- } catch {
65
- // socket may already be closed during teardown
66
- }
67
- reload();
68
- },
69
- },
70
- });
90
+ showUpdateAvailableToast({ toast, closeConvex, toastId, reload });
71
91
  };
72
92
 
73
93
  const check = async (): Promise<void> => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/ui",
3
- "version": "0.30.2",
3
+ "version": "0.31.1",
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), 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",
@@ -72,6 +72,17 @@
72
72
  "./src/marketing/landing.css",
73
73
  "./fonts/instrument-sans.css"
74
74
  ],
75
+ "scripts": {
76
+ "check:tokens": "node tokens/scripts/check-component-tokens.mjs",
77
+ "build": "node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsc -p tsconfig.json",
78
+ "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.consumer.json && tsc -p tsconfig.consumer-speech.json && tsc -p tokens/tsconfig.json",
79
+ "test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
80
+ "verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
81
+ "analyze": "node tokens/verify/analyze.mjs",
82
+ "brand:assets": "node scripts/build-brand-assets.mjs",
83
+ "brand:sheet": "node scripts/build-brand-sheet.mjs",
84
+ "prepack": "node tokens/scripts/check-exports.mjs"
85
+ },
75
86
  "dependencies": {
76
87
  "@dnd-kit/core": "^6.3.1",
77
88
  "@dnd-kit/modifiers": "^9.0.0",
@@ -161,6 +172,7 @@
161
172
  "@tanstack/react-hotkeys": "^0.13.0",
162
173
  "@types/react": "^19.1.0",
163
174
  "@types/react-dom": "^19.1.0",
175
+ "@vvedantb/server": "workspace:*",
164
176
  "ai": "^5.0.0",
165
177
  "class-variance-authority": "^0.7.1",
166
178
  "clsx": "^2.1.1",
@@ -184,8 +196,7 @@
184
196
  "vaul": "^1.1.0",
185
197
  "vitest": "^3.2.0",
186
198
  "zod": "^4.0.0",
187
- "zod3": "npm:zod@^3.25.76",
188
- "@vvedantb/server": "0.10.0"
199
+ "zod3": "npm:zod@^3.25.76"
189
200
  },
190
201
  "peerDependenciesMeta": {
191
202
  "@clerk/clerk-react": {
@@ -206,15 +217,5 @@
206
217
  "@vvedantb/server": {
207
218
  "optional": true
208
219
  }
209
- },
210
- "scripts": {
211
- "check:tokens": "node tokens/scripts/check-component-tokens.mjs",
212
- "build": "node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsc -p tsconfig.json",
213
- "typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.consumer.json && tsc -p tsconfig.consumer-speech.json && tsc -p tokens/tsconfig.json",
214
- "test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
215
- "verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
216
- "analyze": "node tokens/verify/analyze.mjs",
217
- "brand:assets": "node scripts/build-brand-assets.mjs",
218
- "brand:sheet": "node scripts/build-brand-sheet.mjs"
219
220
  }
220
- }
221
+ }
@@ -238,19 +238,23 @@ export function AccountAvatar({ imageUrl, userName, className }: SidebarAccountA
238
238
  );
239
239
  }
240
240
 
241
- export type SidebarAccountTriggerProps = Omit<ButtonProps, "asChild"> & {
241
+ export type SidebarAccountTriggerProps = Omit<ButtonProps, "asChild" | "shape"> & {
242
242
  /** Default `title` and `aria-label`, and the avatar initials. Native `name` goes to the button. */
243
243
  userName: string;
244
244
  imageUrl?: string;
245
245
  };
246
246
 
247
- /** Rail-tile-sized avatar button that opens the menu. Children replace the avatar. */
247
+ /**
248
+ * Rail-tile-sized avatar button that opens the menu. Children replace the avatar.
249
+ * A rail tile (`rounded-lg`), so `shape="rounded"`; change the radius with `className`.
250
+ */
248
251
  export function AccountTrigger({ userName, imageUrl, className, children, ...props }: SidebarAccountTriggerProps) {
249
252
  return (
250
253
  <DropdownMenuTrigger asChild>
251
254
  <Button
252
255
  type="button"
253
256
  variant="ghost"
257
+ shape="rounded"
254
258
  title={userName}
255
259
  aria-label={`Account menu for ${userName}`}
256
260
  {...props}
@@ -110,14 +110,14 @@ function MobileHeader({ className, onKeyDown, ...props }: SidebarMobileHeaderPro
110
110
 
111
111
  const defaultMobileMenuIcon = () => <IconMenu2 size={20} />;
112
112
 
113
- export type SidebarMobileMenuButtonProps = Omit<ButtonProps, "children"> & {
113
+ export type SidebarMobileMenuButtonProps = Omit<ButtonProps, "children" | "shape"> & {
114
114
  /** `aria-label`. Default `"Open navigation menu"`. */
115
115
  label?: string;
116
116
  /** Icon for the drawer state. Default a 20px menu icon. */
117
117
  icon?: (open: boolean) => ReactNode;
118
118
  };
119
119
 
120
- /** Opens the drawer. */
120
+ /** Opens the drawer. `shape="rounded"` (`rounded-lg`); change the radius with `className`. */
121
121
  function MobileMenuButton({
122
122
  label = "Open navigation menu",
123
123
  icon = defaultMobileMenuIcon,
@@ -131,6 +131,7 @@ function MobileMenuButton({
131
131
  type="button"
132
132
  variant="ghost"
133
133
  size="icon"
134
+ shape="rounded"
134
135
  {...props}
135
136
  onClick={(event) => {
136
137
  onClick?.(event);
@@ -120,12 +120,15 @@ export function PanelActions({ className, ...props }: SidebarPanelActionsProps)
120
120
  return <div {...props} className={cn("flex items-center justify-end gap-0.5", className)} />;
121
121
  }
122
122
 
123
- export type SidebarPanelCloseProps = ButtonProps & {
123
+ export type SidebarPanelCloseProps = Omit<ButtonProps, "shape"> & {
124
124
  /** `aria-label`. Default `"Close navigation"`. */
125
125
  label?: string;
126
126
  };
127
127
 
128
- /** Ghost close button. Without `onClick` it closes the `Sidebar.Root` drawer. */
128
+ /**
129
+ * Ghost close button. Without `onClick` it closes the `Sidebar.Root` drawer.
130
+ * `shape="rounded"` (`rounded-lg`); change the radius with `className`.
131
+ */
129
132
  export function PanelClose({ label = "Close navigation", onClick, className, children, ...props }: SidebarPanelCloseProps) {
130
133
  const sidebar = useOptionalSidebar();
131
134
  return (
@@ -133,6 +136,7 @@ export function PanelClose({ label = "Close navigation", onClick, className, chi
133
136
  type="button"
134
137
  variant="ghost"
135
138
  size="icon-sm"
139
+ shape="rounded"
136
140
  {...props}
137
141
  onClick={onClick ?? (() => sidebar?.onMobileOpenChange(false))}
138
142
  aria-label={label}