@vvedantb/ui 0.8.0 → 0.10.0

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
@@ -4,12 +4,13 @@ Shared React 19 web UI. Source-exported: no build step.
4
4
 
5
5
  | Import | What it is |
6
6
  | --- | --- |
7
- | `@vvedantb/ui` | The only JavaScript entry. Primitives (Radix-based), AI elements, audio (`playChime`, `useReplyChime`, `playTone`), `toast` and `SonnerToaster`, the composer (`InputArea`, deprecated 0.3 `Composer`), shell (`SidebarHeader`, `PillTabs`, `SessionsHoverCard`, and the app shell: `AppShell`, `AppSidebar`, `SidebarRail`, `RailTile`, `SidebarPanel`, `SidebarAccountMenu`, `SignOutDialog` and related helpers), app helpers (confirm skip, update watcher, settings chrome, `useStableAuth`, and from 0.8.0 `createThemeProvider`, `createPageTitleContext`, `PageMotionProvider` and `formatCompactRelativeTime`), `cn`, and the native tokens `tokens` and `Tokens`. See `app/README.md` in the repository for the app helpers. |
7
+ | `@vvedantb/ui` | The only JavaScript entry. Primitives (Radix-based), AI elements, audio (`playChime`, `useReplyChime`, `playTone`), `toast` and `SonnerToaster`, the composer (`InputArea`, deprecated 0.3 `Composer`), shell (`SidebarHeader`, `PillTabs`, `SessionsHoverCard`, and the app shell: `AppShell`, `AppSidebar`, `SidebarRail`, `RailTile`, `SidebarPanel`, `SidebarAccountMenu`, `SignOutDialog` and related helpers), app helpers (confirm skip, update watcher, settings chrome, `useStableAuth`, and from 0.8.0 `createThemeProvider`, `createPageTitleContext`, `PageMotionProvider` and `formatCompactRelativeTime`), marketing pieces from 0.9.0 (`createLandingKit` and the `Landing*` parts, `SiteFooter`, `PricingModal`), `cn`, and the native tokens `tokens` and `Tokens`. See `app/README.md` in the repository for the app helpers. |
8
8
  | `@vvedantb/ui/tokens` | `tokens.css`: colour, radius, shadow, ease and font tokens for Tailwind v4. CSS. |
9
9
  | `@vvedantb/ui/tokens/tokens.css` | Same file as `@vvedantb/ui/tokens`. CSS. |
10
10
  | `@vvedantb/ui/tokens/css/*.css` | `index`, `base`, `dialog`, `modal`, `tabs`, `tabs-pills`, `utilities`, `scrollbar-thin`, `animations`, `compat-shadcn-rgb`. CSS. |
11
11
  | `@vvedantb/ui/tokens/compat/shadcn-rgb.css` | Same file as `tokens/css/compat-shadcn-rgb.css`. CSS. |
12
12
  | `@vvedantb/ui/tokens/tailwind-preset` | Tailwind preset (`.mjs`) for `@config "@vvedantb/ui/tokens/tailwind-preset"`. Kept as a build-tool entry: Tailwind needs a resolvable package path, and it is not a React API. |
13
+ | `@vvedantb/ui/landing.css` | Landing page classes (`landing-atmosphere`, `landing-grain`, `landing-pulse-dot`, ambient graph and preview animations, smooth `#top` scrolling). CSS. |
13
14
  | `@vvedantb/ui/package.json` | Package metadata. |
14
15
 
15
16
  Removed in 0.4.0-rc.1: the `/cn`, `/sonner`, `/audio`, `/shell`, `/app`, `/composer` and `/tokens/native` subpaths. Import from `@vvedantb/ui`. See [`MIGRATION.md`](MIGRATION.md).
@@ -792,6 +793,93 @@ Rows (hover, active, selected, drop target) use `bg-sidebar-accent` instead of `
792
793
 
793
794
  Rail tiles keep `surface-tertiary`, so in dark mode the active rail tile is a step lighter than the active row. An app that imports `tokens.css` and defines its own `--sidebar-accent` overrides the fill; it must be a full colour value there (use `compat-shadcn-rgb.css` for `R G B` channels).
794
795
 
796
+ ## Landing kit, site footer and pricing dialog (0.9.0)
797
+
798
+ Marketing pieces the apps copied between each other. Each one renders the same
799
+ DOM and class strings as the app copies it replaces. Copy, links, logos, prices
800
+ and auth buttons come from the app; the package imports no router, no Clerk and
801
+ no Motion.
802
+
803
+ Import the stylesheet once (from CSS or TypeScript):
804
+
805
+ ```css
806
+ @import "@vvedantb/ui/landing.css";
807
+ ```
808
+
809
+ The components live under `src/`, which the usual `@source` line already scans.
810
+
811
+ ### Landing kit
812
+
813
+ `createLandingKit({ motion })` takes `motion` from `motion/react` and returns
814
+ the animated parts. Call it once at module scope.
815
+
816
+ ```tsx
817
+ import { motion } from "motion/react";
818
+ import { createLandingKit } from "@vvedantb/ui";
819
+
820
+ export const { LandingReveal, LandingRevealItem, LandingHero, LandingNav, LandingCta } =
821
+ createLandingKit({ motion });
822
+ ```
823
+
824
+ | Part | Props |
825
+ | --- | --- |
826
+ | `LandingReveal` | `className`, `delay` (seconds, default `0`). Staggers its children in once, when 20% is in view. |
827
+ | `LandingRevealItem` | `className`. One revealed child (`landingItemVariants`). |
828
+ | `LandingHero` | `eyebrow`, `title`, `description` (nodes), `actions` (the button row; it renders even when empty), `capabilities` (strings). |
829
+ | `LandingNav` | `brand`, `homeLabel` (home link `aria-label`), `links`, `github` (`href`, `label`, `icon`), `actions`, `menu`. |
830
+ | `LandingCta` | `title`, `description`, `action`. |
831
+
832
+ Plain parts, no Motion:
833
+
834
+ | Part | Props |
835
+ | --- | --- |
836
+ | `LandingPageLayout` | `nav`, `heroBackdrop` (before the hero, inside the atmosphere block), `hero`, `children` (sections), `footer`. Root is `#top`. |
837
+ | `LandingSection` | `id`, `className`. |
838
+ | `LandingSectionHeading` | `eyebrow`, `heading`, `intro`, `className`. |
839
+ | `LandingLattice` | `className` (grid columns). Cells share 1px borders. |
840
+ | `LandingFeatureCard` | `icon` (a component, rendered `size={18} stroke={1.5}`), `title`, `description`. |
841
+ | `LandingNavMenu` | `links`, `github` (`href`, `icon`). Overflow menu below `md`. |
842
+ | `LandingFooter` | `brand`, `tagline`, `links`, `actions` (after the links), `github` (`href`, `label`, `icon`). |
843
+
844
+ Constants: `landingShellClass`, `landingPanelClass`, `landingItemVariants`, and
845
+ for the footer's `actions` slot `landingFooterLinkClass` (a text link) and
846
+ `landingFooterButtonClass` (a `Button variant="link"`).
847
+
848
+ ### `SiteFooter`
849
+
850
+ Brand, tagline and social icon buttons; link columns; then copyright and legal
851
+ links under a separator.
852
+
853
+ | Prop | |
854
+ | --- | --- |
855
+ | `brand`, `tagline` | Nodes. |
856
+ | `socials` | `{ href, icon, label? }[]`. `icon` is a component that takes `className`. Links open in a new tab. |
857
+ | `columns` | `{ heading, links }[]`. A link is `{ href, label, external?, image?: { src, alt } }`. |
858
+ | `name`, `year` | "Copyright © {year} {name}". `year` defaults to the current year. |
859
+ | `legalLinks` | `{ href, label }[]`, open in a new tab. |
860
+ | `variant` | `"muted"` (default, `text-muted`), `"muted-foreground"`, or `"touch"` (`text-muted-foreground`, `max-sm:hit-target` links, safe-area bottom padding). |
861
+
862
+ ### `PricingModal`
863
+
864
+ One-plan upgrade dialog. Props: `open`, `onClose`, `title` (accessible, hidden),
865
+ `description` (hidden; when set the title is an `sr-only` `DialogTitle`,
866
+ otherwise it sits in `VisuallyHidden`), `logo` (`dark` and `light` image URLs,
867
+ shown in that colour mode), `wordmark`, `price`, `tagline`,
868
+ `taglineFontClassName`, `features`, `ctaLabel` (default "Get Pro"),
869
+ `renderCheckout(button)` (wrap the button in the billing provider's checkout),
870
+ `closeButton` (an extra compact close button, default `false`) and `tone`
871
+ (`"muted"` default or `"muted-foreground"`).
872
+
873
+ ### Account menu items and rail collapse tile
874
+
875
+ `SidebarAccountMenu` takes three optional props. Without them it renders as before.
876
+
877
+ - `themeToggle={{ isDark, onToggle }}`: a "Light mode" / "Dark mode" item after `children`.
878
+ - `signOut={{ onSignOut, description? }}`: a separator and a danger "Sign out" item, last. It opens `SignOutDialog`; Alt-click skips the dialog and `ConfirmSkipHint` shows while Alt is held. The menu owns the dialog state. If `onSignOut` rejects, the dialog buttons enable again.
879
+ - `itemIconSize`: `size` of those two items' icons. Default: the icon's own size.
880
+
881
+ `RailCollapseTile({ collapsed, onToggle })`: the rail tile that shows or hides the sidebar panel ("Show sidebar" with the expand icon, or "Hide sidebar").
882
+
795
883
  ## Toaster
796
884
 
797
885
  ```tsx
@@ -855,6 +943,6 @@ The compat file includes a fallback `glass-panel-strong` (`rgb(var(--card) / 0.9
855
943
 
856
944
  A fixture that renders the main components against sample light and dark RGB variables is in `tokens/examples/compat-shadcn-rgb/`.
857
945
 
858
- `@clerk/clerk-react`, `@tanstack/react-hotkeys`, `motion` and `zod` are optional peers (`peerDependenciesMeta`). Install `@clerk/clerk-react` only to use `useStableAuth`, `@tanstack/react-hotkeys` and `zod` only for the features that use them, and `motion` only to use the motion presets, `InputArea`, the 0.3 `Composer` or the AI elements and primitives that animate.
946
+ `@clerk/clerk-react`, `convex`, `@tanstack/react-hotkeys`, `motion` and `zod` are optional peers (`peerDependenciesMeta`), so the package manager does not install or warn about them. The root still imports each of them statically from some module (`useStableAuth` and `ConvexClerkProvider` import Clerk; `ConvexClerkProvider` and `useEnsureUser` import `convex/react`; the motion presets, `ConfirmSkipHint` and others import the rest). So an app that imports `@vvedantb/ui` must have all five resolvable, even if it uses none of those exports: a bundler resolves every import before it tree-shakes. `app/tests-node/convex-esm.test.mjs` pins which root modules import `convex` and Clerk.
859
947
 
860
948
  Full documentation: the repository `README.md`. Upgrading from `@vvedantb/tokens`, `@vvedantb/shell` or `@vvedantb/app-kit`: `MIGRATION.md`.
package/app/README.md ADDED
@@ -0,0 +1,259 @@
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 shows a sticky "Update available" toast. Refresh calls `closeConvex` (errors ignored), then reloads. `fingerprintFromHtml` and `fetchDeployFingerprint` are exported too. The fingerprint looks for Vite `/assets/*.js` URLs in the index HTML.
60
+
61
+ ## Settings chrome
62
+
63
+ ```tsx
64
+ import { SettingsPage, SettingsSection, SettingsToggleRow } from "@vvedantb/ui";
65
+
66
+ <SettingsPage
67
+ title="Notifications"
68
+ layout={({ title, headerRight, toolbar, tabs, fillHeight, children }) => (
69
+ <PageContainer title={title} rightSection={headerRight} toolbar={toolbar} tabs={tabs} noScroll={fillHeight}>
70
+ {children}
71
+ </PageContainer>
72
+ )}
73
+ >
74
+ <SettingsSection title="Email" bodyVariant="list">
75
+ <SettingsToggleRow title="Weekly digest" action={<Switch />} />
76
+ </SettingsSection>
77
+ </SettingsPage>
78
+ ```
79
+
80
+ 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.
81
+
82
+ ## useStableAuth
83
+
84
+ ```ts
85
+ import { useStableAuth } from "@vvedantb/ui"; // 2000 ms debounce, wraps Clerk useAuth
86
+ import { createUseStableAuth } from "@vvedantb/ui";
87
+
88
+ const useAuth = createUseStableAuth(useClerkAuth, { debounceMs: 3000 });
89
+ ```
90
+
91
+ 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.
92
+
93
+ ## Develop
94
+
95
+ ```sh
96
+ pnpm --filter @vvedantb/ui typecheck
97
+ pnpm --filter @vvedantb/ui test
98
+ ```
99
+
100
+ Source is in `app/src` and tests in `app/tests`. Publish steps are in the root `README.md`.
101
+
102
+ ## Theme
103
+
104
+ ```tsx
105
+ import { createThemeProvider } from "@vvedantb/ui";
106
+
107
+ // One kit per app, at module level.
108
+ export const { ThemeProvider, useTheme } = createThemeProvider();
109
+
110
+ <ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
111
+ <App />
112
+ </ThemeProvider>;
113
+
114
+ const { theme, resolvedTheme, setTheme, isDark, toggleTheme, mounted } = useTheme();
115
+ ```
116
+
117
+ `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.
118
+
119
+ - 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`.
120
+ - 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`).
121
+ - `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.
122
+ - 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.
123
+ - A nested `ThemeProvider` from the same kit renders only its children.
124
+ - `createThemeProvider({ missingProviderMessage })`: `useTheme()` outside the provider throws that message. Without it, `useTheme()` returns an empty state with no-op setters, as next-themes does.
125
+ - 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.
126
+
127
+ For an app with its own theme state (for example a theme synced from the server), two helpers:
128
+
129
+ - `getSystemTheme()`: `"dark"` or `"light"` from `prefers-color-scheme`; `"light"` without `window`.
130
+ - `applyThemeClass(theme)`: removes `light` and `dark` from `<html>`, then adds `theme`. No-op without `document`.
131
+
132
+ ## Page title
133
+
134
+ ```tsx
135
+ import { createPageTitleContext } from "@vvedantb/ui";
136
+
137
+ export const { PageTitleProvider, usePageTitle, usePageTitleSync } = createPageTitleContext({
138
+ missingProviderMessage: "usePageTitle must be used within a PageTitleProvider",
139
+ });
140
+
141
+ // The shell reads it:
142
+ const { pageTitle } = usePageTitle();
143
+ // A page publishes it while mounted:
144
+ usePageTitleSync(title);
145
+ ```
146
+
147
+ - `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.
148
+ - `usePageTitleSync(title)` sets the title while the caller is mounted and clears it on unmount. Titles that are not strings publish `""`.
149
+ - `missingProviderMessage`: `usePageTitle()` outside the provider throws it. Without it, `usePageTitle()` returns an empty title and no-op setters.
150
+ - `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.
151
+
152
+ ## Page motion
153
+
154
+ ```tsx
155
+ import { MotionConfig } from "motion/react";
156
+ import { PageMotionProvider, useDisablePageMotion } from "@vvedantb/ui";
157
+
158
+ <PageMotionProvider disabled={flags?.disablePageMotion === true} motionConfig={MotionConfig}>
159
+ <App />
160
+ </PageMotionProvider>;
161
+ ```
162
+
163
+ - Sets `html[data-page-motion]` to `"off"` or `"on"` in a layout effect (CSS can skip page and route transitions on `"off"`). The attribute stays after unmount.
164
+ - Renders `motionConfig` with `reducedMotion` `"always"` when disabled, else `"never"`.
165
+ - `useDisablePageMotion()`: the `disabled` value, `false` outside the provider.
166
+ - This module does not import `motion`. Pass `MotionConfig`, or an app component that wraps it, defined at module level, for example with `LazyMotion`:
167
+
168
+ ```tsx
169
+ function LazyMotionConfig({ reducedMotion, children }: PageMotionConfigProps) {
170
+ return (
171
+ <LazyMotion features={domAnimation}>
172
+ <MotionConfig reducedMotion={reducedMotion}>{children}</MotionConfig>
173
+ </LazyMotion>
174
+ );
175
+ }
176
+ ```
177
+
178
+ ## Compact relative time
179
+
180
+ ```ts
181
+ import { formatCompactRelativeTime } from "@vvedantb/ui";
182
+
183
+ formatCompactRelativeTime(createdAt, { justNow: "now" }); // "now", "5m", "3h", "2d", "4mo", "1y"
184
+ formatCompactRelativeTime(updatedAt, { calendar: true }); // "42s", ..., calendar months and years
185
+ ```
186
+
187
+ Pure TypeScript, no dependencies. Options:
188
+
189
+ - `now`: clock in ms, default `Date.now()`.
190
+ - `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.
191
+ - `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.
192
+
193
+ 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`).
194
+
195
+ ## Convex provider, VITE env and ensure-user (0.10.0)
196
+
197
+ Moved from `@vvedantb/convex-client` 0.1.0 with the same names and behaviour. Its non-React helpers (`mapLoadedQuery`, `forEachLoadedQuery`, `updateAllCachedQueries`, `patchLoadedQuery`, `OptimisticStore`, `tempId`, `createMemoryOptimisticStore`) moved to `@vvedantb/server` instead, so backend packages, tests and React Native can use them without loading this package.
198
+
199
+ ### `ConvexClerkProvider`
200
+
201
+ ```tsx
202
+ import { ConvexClerkProvider, useStableAuth } from "@vvedantb/ui";
203
+ import { ConvexReactClient } from "convex/react";
204
+
205
+ const convex = new ConvexReactClient(env.VITE_CONVEX_URL);
206
+
207
+ <ClerkProvider publishableKey={env.VITE_CLERK_PUBLISHABLE_KEY}>
208
+ <ConvexClerkProvider client={convex} useAuth={useStableAuth}>
209
+ <App />
210
+ </ConvexClerkProvider>
211
+ </ClerkProvider>;
212
+ ```
213
+
214
+ | Props | Renders |
215
+ | --- | --- |
216
+ | `client` is `null` or `undefined` | `children` alone (no provider). |
217
+ | `clerk={false}` | `<ConvexProvider client={client}>`. |
218
+ | otherwise | `<ConvexProviderWithClerk client={client} useAuth={useAuth}>`; `useAuth` defaults to `@clerk/clerk-react`'s. |
219
+
220
+ `clerk` defaults to `true`. Render it inside `ClerkProvider` unless `clerk` is `false`. Types: `ConvexClerkProviderProps`, `ConvexClerkUseAuth`.
221
+
222
+ ### `parseClientEnv`
223
+
224
+ ```ts
225
+ import { z } from "zod";
226
+ import { parseClientEnv } from "@vvedantb/ui";
227
+
228
+ export const clientEnv = parseClientEnv(import.meta.env, { z, viteEnv: "fallback" });
229
+ // { VITE_CONVEX_URL: string; VITE_CLERK_PUBLISHABLE_KEY: string; VITE_ENV: "development" | "staging" | "production" }
230
+
231
+ export const extensionEnv = parseClientEnv(import.meta.env, {
232
+ z,
233
+ viteEnv: false,
234
+ extend: { VITE_CLERK_SYNC_HOST: z.string().url() },
235
+ });
236
+ ```
237
+
238
+ 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`.
239
+
240
+ | `viteEnv` | `VITE_ENV` |
241
+ | --- | --- |
242
+ | `"strict"` (default) | Must be one of `VITE_ENV_NAMES`. |
243
+ | `"fallback"` | Any other value, or none, becomes `"development"` before parsing. |
244
+ | `false` | Not in the schema or the result. |
245
+
246
+ Types: `ClientEnv`, `ClientEnvWithoutViteEnv`, `ClientEnvOptions`, `ClientEnvSource`, `ViteEnvMode`, `ViteEnvName`.
247
+
248
+ ### `useEnsureUser`
249
+
250
+ ```tsx
251
+ function EnsureUser() {
252
+ useEnsureUser(api.users.ensureUserExists);
253
+ return null;
254
+ }
255
+ ```
256
+
257
+ 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`.
258
+
259
+ 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.
@@ -0,0 +1,37 @@
1
+ import { useAuth as useClerkAuth } from "@clerk/clerk-react";
2
+ import { ConvexProvider, type ConvexReactClient } from "convex/react";
3
+ import { ConvexProviderWithClerk } from "convex/react-clerk";
4
+ import type { ComponentProps, ReactNode } from "react";
5
+
6
+ /** The `useAuth` hook `ConvexProviderWithClerk` takes (Clerk's, or a wrapper such as `useStableAuth`). */
7
+ export type ConvexClerkUseAuth = ComponentProps<typeof ConvexProviderWithClerk>["useAuth"];
8
+
9
+ export type ConvexClerkProviderProps = {
10
+ /** No client (for example no Convex URL configured): children render without a provider. */
11
+ client: ConvexReactClient | null | undefined;
12
+ /** Default: `useAuth` from `@clerk/clerk-react`. */
13
+ useAuth?: ConvexClerkUseAuth;
14
+ /** `false` renders a plain `ConvexProvider` (no Clerk auth). Default `true`. */
15
+ clerk?: boolean;
16
+ children: ReactNode;
17
+ };
18
+
19
+ /**
20
+ * The Convex provider for a Clerk app: `ConvexProviderWithClerk`, a plain
21
+ * `ConvexProvider` when `clerk` is `false`, or just the children when there is
22
+ * no client. Render it inside `ClerkProvider` unless `clerk` is `false`.
23
+ */
24
+ export function ConvexClerkProvider({
25
+ client,
26
+ useAuth = useClerkAuth,
27
+ clerk = true,
28
+ children,
29
+ }: ConvexClerkProviderProps) {
30
+ if (!client) return children;
31
+ if (!clerk) return <ConvexProvider client={client}>{children}</ConvexProvider>;
32
+ return (
33
+ <ConvexProviderWithClerk client={client} useAuth={useAuth}>
34
+ {children}
35
+ </ConvexProviderWithClerk>
36
+ );
37
+ }
@@ -0,0 +1,76 @@
1
+ // Type-only: the app passes its own `z`, so zod stays an optional peer and the
2
+ // thrown ZodError comes from the app's zod version (3.25+ or 4), as today.
3
+ import type { z } from "zod";
4
+
5
+ export type ViteEnvName = "development" | "staging" | "production";
6
+
7
+ export const VITE_ENV_NAMES: readonly ["development", "staging", "production"] = ["development", "staging", "production"];
8
+
9
+ /** `import.meta.env`, or any record of raw env values. */
10
+ export type ClientEnvSource = Readonly<Record<string, string | boolean | undefined>>;
11
+
12
+ type BaseShape = {
13
+ VITE_CONVEX_URL: z.ZodType<string>;
14
+ VITE_CLERK_PUBLISHABLE_KEY: z.ZodType<string>;
15
+ };
16
+
17
+ type ViteEnvShape = BaseShape & { VITE_ENV: z.ZodType<ViteEnvName> };
18
+
19
+ /**
20
+ * - `"strict"` (default): `VITE_ENV` must be one of `VITE_ENV_NAMES`.
21
+ * - `"fallback"`: any other value (or none) is read as `"development"`.
22
+ * - `false`: no `VITE_ENV` key.
23
+ */
24
+ export type ViteEnvMode = "strict" | "fallback" | false;
25
+
26
+ export type ClientEnvOptions<Extra extends z.ZodRawShape> = {
27
+ /** The app's `z` from `"zod"`. */
28
+ z: typeof z;
29
+ viteEnv?: ViteEnvMode;
30
+ /** Extra keys, parsed after the base keys in the same `z.object`. A key here replaces a base key. */
31
+ extend?: Extra;
32
+ };
33
+
34
+ /** Parsed env with `VITE_ENV`. */
35
+ export type ClientEnv<Extra extends z.ZodRawShape = Record<never, never>> = z.output<z.ZodObject<ViteEnvShape & Extra>>;
36
+
37
+ /** Parsed env without `VITE_ENV` (`viteEnv: false`). */
38
+ export type ClientEnvWithoutViteEnv<Extra extends z.ZodRawShape = Record<never, never>> = z.output<
39
+ z.ZodObject<BaseShape & Extra>
40
+ >;
41
+
42
+ /**
43
+ * Parse VITE env with zod: `VITE_CONVEX_URL` and `VITE_CLERK_PUBLISHABLE_KEY`
44
+ * are `z.string().min(1)`, `VITE_ENV` is `z.enum(VITE_ENV_NAMES)`, then any
45
+ * `extend` keys. Only those keys are read from `rawEnv`. Throws the ZodError
46
+ * from `z.object(shape).parse`.
47
+ */
48
+ export function parseClientEnv<Extra extends z.ZodRawShape = Record<never, never>>(
49
+ rawEnv: ClientEnvSource,
50
+ options: ClientEnvOptions<Extra> & { viteEnv: false },
51
+ ): ClientEnvWithoutViteEnv<Extra>;
52
+ export function parseClientEnv<Extra extends z.ZodRawShape = Record<never, never>>(
53
+ rawEnv: ClientEnvSource,
54
+ options: ClientEnvOptions<Extra> & { viteEnv?: "strict" | "fallback" },
55
+ ): ClientEnv<Extra>;
56
+ export function parseClientEnv(
57
+ rawEnv: ClientEnvSource,
58
+ options: ClientEnvOptions<z.ZodRawShape>,
59
+ ): z.output<z.ZodObject<z.ZodRawShape>> {
60
+ const zod = options.z;
61
+ const viteEnv = options.viteEnv ?? "strict";
62
+ const shape: z.ZodRawShape = {
63
+ VITE_CONVEX_URL: zod.string().min(1),
64
+ VITE_CLERK_PUBLISHABLE_KEY: zod.string().min(1),
65
+ ...(viteEnv === false ? {} : { VITE_ENV: zod.enum(VITE_ENV_NAMES) }),
66
+ ...options.extend,
67
+ };
68
+ const input: Record<string, string | boolean | undefined> = {};
69
+ for (const key of Object.keys(shape)) input[key] = rawEnv[key];
70
+ if (viteEnv === "fallback") input.VITE_ENV = viteEnvOrDevelopment(rawEnv.VITE_ENV);
71
+ return zod.object(shape).parse(input);
72
+ }
73
+
74
+ function viteEnvOrDevelopment(value: string | boolean | undefined): ViteEnvName {
75
+ return value === "production" || value === "staging" || value === "development" ? value : "development";
76
+ }
@@ -0,0 +1,24 @@
1
+ import { useConvexAuth, useMutation } from "convex/react";
2
+ import type { FunctionReference } from "convex/server";
3
+ import { useEffect } from "react";
4
+
5
+ /** A public mutation that takes no args, such as `api.users.ensureUserExists`. */
6
+ export type EnsureUserMutation = FunctionReference<"mutation", "public", Record<string, never>>;
7
+
8
+ /**
9
+ * Call `mutation({})` each time Convex auth becomes authenticated, logging a
10
+ * failure with `console.error`. Needs a Convex auth provider above it
11
+ * (`ConvexClerkProvider` with Clerk on). Kept as an effect: it syncs the
12
+ * server's users row with the sign-in state, and there is no render-time
13
+ * alternative.
14
+ */
15
+ export function useEnsureUser(mutation: EnsureUserMutation): void {
16
+ const { isAuthenticated } = useConvexAuth();
17
+ const ensureUser = useMutation(mutation);
18
+
19
+ useEffect(() => {
20
+ if (isAuthenticated) {
21
+ ensureUser({}).catch(console.error);
22
+ }
23
+ }, [isAuthenticated, ensureUser]);
24
+ }
package/app/src/index.ts CHANGED
@@ -72,3 +72,20 @@ export {
72
72
  formatCompactRelativeTime,
73
73
  type CompactRelativeTimeOptions,
74
74
  } from "./time/compactRelativeTime.js";
75
+
76
+ export {
77
+ ConvexClerkProvider,
78
+ type ConvexClerkProviderProps,
79
+ type ConvexClerkUseAuth,
80
+ } from "./convex/ConvexClerkProvider.js";
81
+ export {
82
+ parseClientEnv,
83
+ VITE_ENV_NAMES,
84
+ type ClientEnv,
85
+ type ClientEnvOptions,
86
+ type ClientEnvSource,
87
+ type ClientEnvWithoutViteEnv,
88
+ type ViteEnvMode,
89
+ type ViteEnvName,
90
+ } from "./convex/env.js";
91
+ export { useEnsureUser, type EnsureUserMutation } from "./convex/useEnsureUser.js";
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@vvedantb/ui",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "license": "MIT",
5
- "description": "Shared React 19 UI for web apps: one JavaScript entry (primitives, shell pieces, app helpers, native tokens), design-token CSS, shared Tailwind v4 CSS and a Tailwind preset.",
5
+ "description": "Shared React 19 UI for web apps: one JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, native tokens), design-token CSS, shared Tailwind v4 CSS and a Tailwind preset.",
6
6
  "type": "module",
7
7
  "publishConfig": {
8
8
  "access": "public"
@@ -35,6 +35,7 @@
35
35
  "types": "./tokens/src/tailwind-preset.d.mts",
36
36
  "default": "./tokens/src/tailwind-preset.mjs"
37
37
  },
38
+ "./landing.css": "./src/marketing/landing.css",
38
39
  "./package.json": "./package.json"
39
40
  },
40
41
  "types": "./src/index.ts",
@@ -50,8 +51,18 @@
50
51
  "!**/*.test.tsx"
51
52
  ],
52
53
  "sideEffects": [
53
- "./src/ui/sonner.css"
54
+ "./src/ui/sonner.css",
55
+ "./src/marketing/landing.css"
54
56
  ],
57
+ "scripts": {
58
+ "check:tokens": "node tokens/scripts/check-component-tokens.mjs",
59
+ "build": "node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsc -p tsconfig.json",
60
+ "typecheck": "tsc -p tsconfig.json && tsc -p tokens/tsconfig.json",
61
+ "test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
62
+ "verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
63
+ "analyze": "node tokens/verify/analyze.mjs",
64
+ "prepack": "node tokens/scripts/check-exports.mjs"
65
+ },
55
66
  "peerDependencies": {
56
67
  "@clerk/clerk-react": ">=5",
57
68
  "@radix-ui/react-accordion": "^1.2.12",
@@ -83,6 +94,7 @@
83
94
  "class-variance-authority": "^0.7.1",
84
95
  "clsx": "^2.1.1",
85
96
  "cmdk": "^1.1.1",
97
+ "convex": "^1.24.0",
86
98
  "embla-carousel-react": "^8.6.0",
87
99
  "motion": ">=12.0.0",
88
100
  "nanoid": "^5.1.0",
@@ -131,6 +143,7 @@
131
143
  "class-variance-authority": "^0.7.1",
132
144
  "clsx": "^2.1.1",
133
145
  "cmdk": "^1.1.1",
146
+ "convex": "^1.47.0",
134
147
  "dayjs": "1.11.19",
135
148
  "embla-carousel-react": "^8.6.0",
136
149
  "happy-dom": "^18.0.0",
@@ -149,12 +162,16 @@
149
162
  "use-stick-to-bottom": "^1.1.0",
150
163
  "vaul": "^1.1.0",
151
164
  "vitest": "^3.2.0",
152
- "zod": "^4.0.0"
165
+ "zod": "^4.0.0",
166
+ "zod3": "npm:zod@^3.25.76"
153
167
  },
154
168
  "peerDependenciesMeta": {
155
169
  "@clerk/clerk-react": {
156
170
  "optional": true
157
171
  },
172
+ "convex": {
173
+ "optional": true
174
+ },
158
175
  "@tanstack/react-hotkeys": {
159
176
  "optional": true
160
177
  },
@@ -164,13 +181,5 @@
164
181
  "zod": {
165
182
  "optional": true
166
183
  }
167
- },
168
- "scripts": {
169
- "check:tokens": "node tokens/scripts/check-component-tokens.mjs",
170
- "build": "node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsc -p tsconfig.json",
171
- "typecheck": "tsc -p tsconfig.json && tsc -p tokens/tsconfig.json",
172
- "test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
173
- "verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
174
- "analyze": "node tokens/verify/analyze.mjs"
175
184
  }
176
- }
185
+ }