@vvedantb/ui 0.19.1 → 0.22.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 +99 -8
- package/app/README.md +259 -0
- package/package.json +20 -12
- package/scripts/build-brand-assets.mjs +126 -0
- package/src/brand/AppMark.tsx +55 -0
- package/src/brand/index.ts +16 -0
- package/src/brand/svg.ts +119 -0
- package/src/index.ts +12 -2
- package/src/marketing/PricingModal.tsx +284 -11
- package/src/marketing/marketing-classes.ts +12 -0
- package/tokens/README.md +120 -0
package/README.md
CHANGED
|
@@ -867,14 +867,105 @@ links under a separator.
|
|
|
867
867
|
|
|
868
868
|
### `PricingModal`
|
|
869
869
|
|
|
870
|
-
|
|
871
|
-
`
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
`
|
|
876
|
-
|
|
877
|
-
|
|
870
|
+
Upgrade dialog with two layouts. Without `plans` it is the single-plan dialog
|
|
871
|
+
below. With `plans` (0.22.0) it is the wide multi-plan dialog.
|
|
872
|
+
|
|
873
|
+
Shared props: `open`, `onClose`, `title` (accessible, hidden), `description`
|
|
874
|
+
(hidden), `tone` (`"muted"` default or `"muted-foreground"`),
|
|
875
|
+
`billingPeriod`, `onBillingPeriodChange`, `defaultBillingPeriod` (`"month"`
|
|
876
|
+
default) and `renderCheckout`.
|
|
877
|
+
|
|
878
|
+
#### Multi-plan (0.22.0)
|
|
879
|
+
|
|
880
|
+
Header: `apps` (an `AppName[]`, shown as `AppMark` tiles at the top left),
|
|
881
|
+
`headline` (centre), a Monthly / Annual switch and a close button (top right).
|
|
882
|
+
Then one card per entry of `plans` (2 to 4 fit) and one `finePrint` line. Cards
|
|
883
|
+
stack on narrow screens.
|
|
884
|
+
|
|
885
|
+
A `PricingPlan` is `{ id, name, price: { month, year }, ctaLabel?, intro?,
|
|
886
|
+
highlight?: { title, description }, benefits?: { label, icon?: "check" |
|
|
887
|
+
AppName, muted? }[], current?, featured?, periodSuffix? }`. Prices are display
|
|
888
|
+
strings and always per month (`periodSuffix` default `"/month"`; the yearly
|
|
889
|
+
price is the per-month price). `ctaLabel` defaults to "Get started". `featured`
|
|
890
|
+
(or `highlighted`) adds a subtle ring. A `current` plan shows a disabled,
|
|
891
|
+
outlined "Current plan" button and does not call `renderCheckout`.
|
|
892
|
+
|
|
893
|
+
The `featured` plan's button is a solid primary button (`Button` `variant="default"`). Other plans use `secondary`.
|
|
894
|
+
|
|
895
|
+
`renderCheckout(button, plan, period)` wraps each plan's button.
|
|
896
|
+
|
|
897
|
+
Each app passes its own plan names, prices and copy. The example and the screenshots use placeholder text only.
|
|
898
|
+
|
|
899
|
+
```tsx
|
|
900
|
+
<PricingModal
|
|
901
|
+
open={open}
|
|
902
|
+
onClose={close}
|
|
903
|
+
title="Plans"
|
|
904
|
+
apps={["vibot", "verve", "velth", "vmem", "vhub"]}
|
|
905
|
+
headline="One plan. Every V app."
|
|
906
|
+
finePrint="Cancel anytime. $120 billed yearly. Save 33%."
|
|
907
|
+
plans={[
|
|
908
|
+
{ id: "free", name: "Free", price: { month: "$0", year: "$0" }, current: true },
|
|
909
|
+
{
|
|
910
|
+
id: "pro",
|
|
911
|
+
name: "V Pro",
|
|
912
|
+
price: { month: "$15", year: "$10" },
|
|
913
|
+
featured: true,
|
|
914
|
+
intro: "Everything in Free, and:",
|
|
915
|
+
highlight: { title: "Shared", description: "usage across every V app" },
|
|
916
|
+
benefits: [
|
|
917
|
+
{ label: "Higher limits", icon: "vibot" },
|
|
918
|
+
{ label: "Pro features", icon: "verve" },
|
|
919
|
+
{ label: "Pro features", icon: "velth" },
|
|
920
|
+
{ label: "More memory", icon: "vmem" },
|
|
921
|
+
{ label: "More storage", icon: "vhub" },
|
|
922
|
+
],
|
|
923
|
+
},
|
|
924
|
+
]}
|
|
925
|
+
renderCheckout={(button, plan, period) => (
|
|
926
|
+
<CheckoutButton planId={plan.id} planPeriod={period}>{button}</CheckoutButton>
|
|
927
|
+
)}
|
|
928
|
+
/>
|
|
929
|
+
```
|
|
930
|
+
|
|
931
|
+
In the example, V Pro costs $15/month, or $10/month billed yearly ($120/year,
|
|
932
|
+
a 33% saving). The cards show the per-month price only, so the yearly total and
|
|
933
|
+
the saving go in `finePrint`. Screenshots: `brand/pricing-modal/` (regenerate with
|
|
934
|
+
`node scripts/build-pricing-screenshots.mjs`).
|
|
935
|
+
|
|
936
|
+
#### Single plan
|
|
937
|
+
|
|
938
|
+
Props: `logo` (`dark` and `light` image URLs, shown in that colour mode),
|
|
939
|
+
`wordmark`, `price`, `tagline`, `taglineFontClassName`, `features`, `ctaLabel`
|
|
940
|
+
(default "Get Pro"), `renderCheckout(button, period)` (wrap the button in the
|
|
941
|
+
billing provider's checkout), `closeButton` (an extra compact close button,
|
|
942
|
+
default `false`) and, when `description` is set, the title is an `sr-only`
|
|
943
|
+
`DialogTitle`, otherwise it sits in `VisuallyHidden`.
|
|
944
|
+
|
|
945
|
+
From 0.20.0, `yearly={{ pricePerMonth, total?, saveLabel? }}` adds a
|
|
946
|
+
monthly/yearly toggle; `price` stays the monthly price. `renderCheckout` gets the
|
|
947
|
+
selected `period` (`"month"` or `"year"`) as its second argument, for Clerk's
|
|
948
|
+
`planPeriod`. Without `yearly` the DOM is unchanged.
|
|
949
|
+
|
|
950
|
+
```tsx
|
|
951
|
+
<PricingModal
|
|
952
|
+
price="$10"
|
|
953
|
+
yearly={{ pricePerMonth: "$8.33", total: "$100" }}
|
|
954
|
+
renderCheckout={(button, period) => (
|
|
955
|
+
<CheckoutButton planId={planId} planPeriod={period}>{button}</CheckoutButton>
|
|
956
|
+
)}
|
|
957
|
+
/* ... */
|
|
958
|
+
/>
|
|
959
|
+
```
|
|
960
|
+
|
|
961
|
+
#### Migration
|
|
962
|
+
|
|
963
|
+
Single-plan callers need no change. To move to the multi-plan layout, replace
|
|
964
|
+
`logo`, `wordmark`, `price`, `tagline`, `features` and `yearly` with `plans`,
|
|
965
|
+
`apps` and `headline`, and change `renderCheckout` to
|
|
966
|
+
`(button, plan, period)`. Type helpers: use `PricingModalLegacyProps` or
|
|
967
|
+
`PricingModalMultiProps` when you need one layout's props;
|
|
968
|
+
`PricingModalProps` is their union.
|
|
878
969
|
|
|
879
970
|
### Account menu items and rail collapse tile
|
|
880
971
|
|
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. 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.
|
|
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
|
+
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.
|
|
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"license": "MIT",
|
|
5
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, artifact viewers over the @vvedantb/server artifacts core, native tokens), design-token CSS, shared Tailwind v4 CSS and a Tailwind preset.",
|
|
6
6
|
"type": "module",
|
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"types": "./tokens/src/tailwind-preset.d.mts",
|
|
41
41
|
"default": "./tokens/src/tailwind-preset.mjs"
|
|
42
42
|
},
|
|
43
|
+
"./brand": {
|
|
44
|
+
"types": "./src/brand/index.ts",
|
|
45
|
+
"default": "./src/brand/index.ts"
|
|
46
|
+
},
|
|
43
47
|
"./landing.css": "./src/marketing/landing.css",
|
|
44
48
|
"./package.json": "./package.json"
|
|
45
49
|
},
|
|
@@ -50,6 +54,7 @@
|
|
|
50
54
|
"app/src",
|
|
51
55
|
"tokens/src",
|
|
52
56
|
"tokens/examples",
|
|
57
|
+
"scripts/build-brand-assets.mjs",
|
|
53
58
|
"README.md",
|
|
54
59
|
"LICENSE",
|
|
55
60
|
"!**/*.test.ts",
|
|
@@ -59,6 +64,17 @@
|
|
|
59
64
|
"./src/ui/sonner.css",
|
|
60
65
|
"./src/marketing/landing.css"
|
|
61
66
|
],
|
|
67
|
+
"scripts": {
|
|
68
|
+
"check:tokens": "node tokens/scripts/check-component-tokens.mjs",
|
|
69
|
+
"build": "node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsc -p tsconfig.json",
|
|
70
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.consumer.json && tsc -p tsconfig.consumer-speech.json && tsc -p tokens/tsconfig.json",
|
|
71
|
+
"test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
|
|
72
|
+
"verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
|
|
73
|
+
"analyze": "node tokens/verify/analyze.mjs",
|
|
74
|
+
"brand:assets": "node scripts/build-brand-assets.mjs",
|
|
75
|
+
"brand:sheet": "node scripts/build-brand-sheet.mjs",
|
|
76
|
+
"prepack": "node tokens/scripts/check-exports.mjs"
|
|
77
|
+
},
|
|
62
78
|
"dependencies": {
|
|
63
79
|
"@dnd-kit/core": "^6.3.1",
|
|
64
80
|
"@dnd-kit/modifiers": "^9.0.0",
|
|
@@ -148,6 +164,7 @@
|
|
|
148
164
|
"@tanstack/react-hotkeys": "^0.13.0",
|
|
149
165
|
"@types/react": "^19.1.0",
|
|
150
166
|
"@types/react-dom": "^19.1.0",
|
|
167
|
+
"@vvedantb/server": "workspace:*",
|
|
151
168
|
"ai": "^5.0.0",
|
|
152
169
|
"class-variance-authority": "^0.7.1",
|
|
153
170
|
"clsx": "^2.1.1",
|
|
@@ -171,8 +188,7 @@
|
|
|
171
188
|
"vaul": "^1.1.0",
|
|
172
189
|
"vitest": "^3.2.0",
|
|
173
190
|
"zod": "^4.0.0",
|
|
174
|
-
"zod3": "npm:zod@^3.25.76"
|
|
175
|
-
"@vvedantb/server": "0.8.1"
|
|
191
|
+
"zod3": "npm:zod@^3.25.76"
|
|
176
192
|
},
|
|
177
193
|
"peerDependenciesMeta": {
|
|
178
194
|
"@clerk/clerk-react": {
|
|
@@ -193,13 +209,5 @@
|
|
|
193
209
|
"@vvedantb/server": {
|
|
194
210
|
"optional": true
|
|
195
211
|
}
|
|
196
|
-
},
|
|
197
|
-
"scripts": {
|
|
198
|
-
"check:tokens": "node tokens/scripts/check-component-tokens.mjs",
|
|
199
|
-
"build": "node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsc -p tsconfig.json",
|
|
200
|
-
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.consumer.json && tsc -p tsconfig.consumer-speech.json && tsc -p tokens/tsconfig.json",
|
|
201
|
-
"test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
|
|
202
|
-
"verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
|
|
203
|
-
"analyze": "node tokens/verify/analyze.mjs"
|
|
204
212
|
}
|
|
205
|
-
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// Writes the favicon, PWA, extension and Android icon sets for the family apps.
|
|
2
|
+
//
|
|
3
|
+
// node scripts/build-brand-assets.mjs --out <dir> [--app <name>] [--no-png] [--dry-run]
|
|
4
|
+
//
|
|
5
|
+
// SVGs are always written. PNGs and favicon.ico need `rsvg-convert`; without it they are skipped
|
|
6
|
+
// with a message. Layout: <dir>/<app>/{mark,icon,favicon,icon-light}.svg, PNGs, extension/, android/.
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { APP_NAMES, appAdaptiveSvg, appExtension128Svg, appMarkSvg, appTileSvg } from "../src/brand/svg.ts";
|
|
12
|
+
|
|
13
|
+
/** Whether `rsvg-convert` can be run. */
|
|
14
|
+
export function hasRsvg() {
|
|
15
|
+
return spawnSync("rsvg-convert", ["--version"], { stdio: "ignore" }).status === 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Renders `svg` to a square PNG buffer of `px` pixels. */
|
|
19
|
+
export function renderPng(svg, px) {
|
|
20
|
+
const result = spawnSync("rsvg-convert", ["-w", String(px), "-h", String(px), "-f", "png"], { input: svg, maxBuffer: 64 * 1024 * 1024 });
|
|
21
|
+
if (result.status !== 0) throw new Error(`rsvg-convert failed: ${String(result.stderr)}`);
|
|
22
|
+
return result.stdout;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** An ICO file that embeds each PNG (sizes in pixels, same order). */
|
|
26
|
+
export function icoFromPngs(pngs, sizes) {
|
|
27
|
+
const header = Buffer.alloc(6 + 16 * pngs.length);
|
|
28
|
+
header.writeUInt16LE(1, 2);
|
|
29
|
+
header.writeUInt16LE(pngs.length, 4);
|
|
30
|
+
let offset = header.length;
|
|
31
|
+
pngs.forEach((png, i) => {
|
|
32
|
+
const at = 6 + 16 * i;
|
|
33
|
+
header.writeUInt8(sizes[i] % 256, at);
|
|
34
|
+
header.writeUInt8(sizes[i] % 256, at + 1);
|
|
35
|
+
header.writeUInt16LE(1, at + 4);
|
|
36
|
+
header.writeUInt16LE(32, at + 6);
|
|
37
|
+
header.writeUInt32LE(png.length, at + 8);
|
|
38
|
+
header.writeUInt32LE(offset, at + 12);
|
|
39
|
+
offset += png.length;
|
|
40
|
+
});
|
|
41
|
+
return Buffer.concat([header, ...pngs]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** SVG files for one app, as `[relative path, content]`. */
|
|
45
|
+
export function svgFiles(app) {
|
|
46
|
+
const tile = appTileSvg(app);
|
|
47
|
+
return [
|
|
48
|
+
["mark.svg", appMarkSvg(app)],
|
|
49
|
+
["icon.svg", tile],
|
|
50
|
+
["favicon.svg", tile],
|
|
51
|
+
["icon-light.svg", appTileSvg(app, "light")],
|
|
52
|
+
["android/adaptive-foreground.svg", appAdaptiveSvg(app, "#fff")],
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** PNG files for one app, as `[relative path, svg source, pixels]`. */
|
|
57
|
+
export function pngSpecs(app) {
|
|
58
|
+
const tile = appTileSvg(app);
|
|
59
|
+
const square = appTileSvg(app, "dark", 0);
|
|
60
|
+
return [
|
|
61
|
+
["favicon-16.png", tile, 16],
|
|
62
|
+
["favicon-32.png", tile, 32],
|
|
63
|
+
["apple-touch-icon.png", square, 180],
|
|
64
|
+
["icon-192.png", tile, 192],
|
|
65
|
+
["icon-512.png", tile, 512],
|
|
66
|
+
["icon-1024.png", tile, 1024],
|
|
67
|
+
["icon-light.png", appTileSvg(app, "light"), 512],
|
|
68
|
+
["maskable-512.png", square, 512],
|
|
69
|
+
["extension/icon-16.png", tile, 16],
|
|
70
|
+
["extension/icon-32.png", tile, 32],
|
|
71
|
+
["extension/icon-48.png", tile, 48],
|
|
72
|
+
["extension/icon-128.png", appExtension128Svg(app), 128],
|
|
73
|
+
["android/adaptive-foreground-432.png", appAdaptiveSvg(app, "#fff"), 432],
|
|
74
|
+
["android/adaptive-monochrome-432.png", appAdaptiveSvg(app, "#000"), 432],
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Writes (or, with `dryRun`, lists) the set for each app. Returns the relative file paths per app and any skip notes. */
|
|
79
|
+
export function buildBrandAssets({ out, apps = APP_NAMES, png = true, dryRun = false }) {
|
|
80
|
+
const written = [];
|
|
81
|
+
const notes = [];
|
|
82
|
+
const withPng = png && hasRsvg();
|
|
83
|
+
if (png && !withPng) notes.push("rsvg-convert not found: PNGs and favicon.ico skipped (SVGs written).");
|
|
84
|
+
const put = (file, data) => {
|
|
85
|
+
written.push(file);
|
|
86
|
+
if (dryRun) return;
|
|
87
|
+
mkdirSync(dirname(join(out, file)), { recursive: true });
|
|
88
|
+
writeFileSync(join(out, file), data);
|
|
89
|
+
};
|
|
90
|
+
for (const app of apps) {
|
|
91
|
+
for (const [name, svg] of svgFiles(app)) put(join(app, name), svg);
|
|
92
|
+
if (!withPng) continue;
|
|
93
|
+
for (const [name, svg, px] of pngSpecs(app)) put(join(app, name), dryRun ? "" : renderPng(svg, px));
|
|
94
|
+
const sizes = [16, 32, 48];
|
|
95
|
+
const tile = appTileSvg(app);
|
|
96
|
+
put(join(app, "favicon.ico"), dryRun ? "" : icoFromPngs(sizes.map((px) => renderPng(tile, px)), sizes));
|
|
97
|
+
}
|
|
98
|
+
return { written, notes };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function parseArgs(argv) {
|
|
102
|
+
const args = { out: "", app: "", png: true, dryRun: false };
|
|
103
|
+
for (let i = 0; i < argv.length; i++) {
|
|
104
|
+
const arg = argv[i];
|
|
105
|
+
if (arg === "--out") args.out = argv[++i] ?? "";
|
|
106
|
+
else if (arg === "--app") args.app = argv[++i] ?? "";
|
|
107
|
+
else if (arg === "--no-png") args.png = false;
|
|
108
|
+
else if (arg === "--dry-run") args.dryRun = true;
|
|
109
|
+
else throw new Error(`unknown argument: ${arg}`);
|
|
110
|
+
}
|
|
111
|
+
if (!args.out) throw new Error("--out <dir> is required");
|
|
112
|
+
if (args.app && !APP_NAMES.includes(args.app)) throw new Error(`--app must be one of ${APP_NAMES.join(", ")}`);
|
|
113
|
+
return args;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
117
|
+
try {
|
|
118
|
+
const args = parseArgs(process.argv.slice(2));
|
|
119
|
+
const { written, notes } = buildBrandAssets({ out: args.out, apps: args.app ? [args.app] : APP_NAMES, png: args.png, dryRun: args.dryRun });
|
|
120
|
+
for (const file of written) console.log(`${args.dryRun ? "would write" : "wrote"} ${join(args.out, file)}`);
|
|
121
|
+
for (const note of notes) console.warn(note);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.error(error instanceof Error ? error.message : error);
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useId, type SVGProps } from "react";
|
|
2
|
+
import { APP_MARKS, MARK_VIEWBOX, TILE_RADIUS, markLinecap, markStrokeWidth, type AppMarkVariant, type AppName } from "./svg";
|
|
3
|
+
|
|
4
|
+
export type AppMarkProps = Omit<SVGProps<SVGSVGElement>, "children" | "height" | "width" | "viewBox"> & {
|
|
5
|
+
/** Which family app's mark to draw. */
|
|
6
|
+
app: AppName;
|
|
7
|
+
/** `"mark"` (default): glyph in `currentColor`. `"tile"`: white glyph on a black rounded tile. `"tile-light"`: black glyph on a white tile. */
|
|
8
|
+
variant?: AppMarkVariant;
|
|
9
|
+
/** Width and height. Default 24. */
|
|
10
|
+
size?: number | string;
|
|
11
|
+
/** Accessible name. Without it the mark is `aria-hidden`. */
|
|
12
|
+
title?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const TILE_TONES = {
|
|
16
|
+
tile: { bg: "#000", fg: "#fff" },
|
|
17
|
+
"tile-light": { bg: "#fff", fg: "#000" },
|
|
18
|
+
} as const;
|
|
19
|
+
|
|
20
|
+
/** One of the six family app marks on the 1024 grid. */
|
|
21
|
+
export function AppMark({ app, variant = "mark", size = 24, title, ...rest }: AppMarkProps) {
|
|
22
|
+
const titleId = useId();
|
|
23
|
+
const { kind, paths } = APP_MARKS[app];
|
|
24
|
+
const tone = variant === "mark" ? undefined : TILE_TONES[variant];
|
|
25
|
+
const color = tone?.fg ?? "currentColor";
|
|
26
|
+
const glyphProps =
|
|
27
|
+
kind === "fill"
|
|
28
|
+
? { fill: color }
|
|
29
|
+
: { fill: "none", stroke: color, strokeWidth: markStrokeWidth(app), strokeLinecap: markLinecap(app), strokeLinejoin: "round" };
|
|
30
|
+
const glyph = (
|
|
31
|
+
<g {...(glyphProps as SVGProps<SVGGElement>)} data-glyph={app}>
|
|
32
|
+
{paths.map((d) => (
|
|
33
|
+
<path key={d} d={d} />
|
|
34
|
+
))}
|
|
35
|
+
</g>
|
|
36
|
+
);
|
|
37
|
+
return (
|
|
38
|
+
<svg
|
|
39
|
+
{...rest}
|
|
40
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
41
|
+
width={size}
|
|
42
|
+
height={size}
|
|
43
|
+
viewBox={MARK_VIEWBOX}
|
|
44
|
+
data-app={app}
|
|
45
|
+
data-variant={variant}
|
|
46
|
+
role={title ? "img" : undefined}
|
|
47
|
+
aria-hidden={title ? undefined : true}
|
|
48
|
+
aria-labelledby={title ? titleId : undefined}
|
|
49
|
+
>
|
|
50
|
+
{title ? <title id={titleId}>{title}</title> : null}
|
|
51
|
+
{tone ? <rect width={1024} height={1024} rx={TILE_RADIUS} fill={tone.bg} /> : null}
|
|
52
|
+
{glyph}
|
|
53
|
+
</svg>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { AppMark } from "./AppMark";
|
|
2
|
+
export type { AppMarkProps } from "./AppMark";
|
|
3
|
+
export {
|
|
4
|
+
APP_MARKS,
|
|
5
|
+
APP_MARK_SVG,
|
|
6
|
+
APP_NAMES,
|
|
7
|
+
APP_TILE_LIGHT_SVG,
|
|
8
|
+
APP_TILE_SVG,
|
|
9
|
+
appAdaptiveSvg,
|
|
10
|
+
appExtension128Svg,
|
|
11
|
+
appMarkSvg,
|
|
12
|
+
appTileSvg,
|
|
13
|
+
markLinecap,
|
|
14
|
+
markStrokeWidth,
|
|
15
|
+
} from "./svg";
|
|
16
|
+
export type { AppMarkVariant, AppName, MarkShape } from "./svg";
|
package/src/brand/svg.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Geometry and raw SVG strings for the family app marks. No imports, so the
|
|
2
|
+
// asset script can load this file directly with Node.
|
|
3
|
+
|
|
4
|
+
export const APP_NAMES = ["projectv", "vibot", "vhub", "vmem", "verve", "velth"] as const;
|
|
5
|
+
|
|
6
|
+
export type AppName = (typeof APP_NAMES)[number];
|
|
7
|
+
|
|
8
|
+
/** `mark`: glyph only, follows `currentColor`. `tile`: white glyph on a black tile. `tile-light`: black glyph on a white tile. */
|
|
9
|
+
export type AppMarkVariant = "mark" | "tile" | "tile-light";
|
|
10
|
+
|
|
11
|
+
export const MARK_VIEWBOX = "0 0 1024 1024";
|
|
12
|
+
export const MARK_STROKE_WIDTH = 50;
|
|
13
|
+
export const TILE_RADIUS = 224;
|
|
14
|
+
|
|
15
|
+
export type MarkShape = {
|
|
16
|
+
/** Filled shapes (no stroke) versus lines (50 wide, round caps by default). */
|
|
17
|
+
kind: "fill" | "stroke";
|
|
18
|
+
/** Path data on the 1024 grid. */
|
|
19
|
+
paths: readonly string[];
|
|
20
|
+
/** Stroke width override on the 1024 grid. Defaults to `MARK_STROKE_WIDTH`. */
|
|
21
|
+
strokeWidth?: number;
|
|
22
|
+
/** Line cap override. Defaults to `"round"`. */
|
|
23
|
+
linecap?: "butt" | "round";
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Stroke width of a mark on the 1024 grid. */
|
|
27
|
+
export function markStrokeWidth(app: AppName): number {
|
|
28
|
+
return APP_MARKS[app].strokeWidth ?? MARK_STROKE_WIDTH;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Line cap of a mark. */
|
|
32
|
+
export function markLinecap(app: AppName): "butt" | "round" {
|
|
33
|
+
return APP_MARKS[app].linecap ?? "round";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Glyphs sized by one rule: longest side = 512 * min(1.2, aspect^0.25), centred halfway between
|
|
38
|
+
* the bounding-box centre and the centre of mass. `verve` and `velth` are the final vectors.
|
|
39
|
+
* The others are traced from the approved 1024px renders.
|
|
40
|
+
*/
|
|
41
|
+
export const APP_MARKS: Record<AppName, MarkShape> = {
|
|
42
|
+
projectv: {
|
|
43
|
+
kind: "fill",
|
|
44
|
+
paths: ["M172 398L260 397L418 558L580 377L858 378L824 415L604 415L452 598L466 611L622 433L808 433L773 471L658 471L491 671L442 672Z"],
|
|
45
|
+
},
|
|
46
|
+
vibot: {
|
|
47
|
+
kind: "fill",
|
|
48
|
+
paths: [
|
|
49
|
+
"M295 314L396 314L396 574C520 540 620 440 655 314L711 314C680 470 560 590 396 627L390 627L390 651L396 651C560 610 700 480 734 314L789 314C740 540 560 712 295 712Z",
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
vhub: {
|
|
53
|
+
kind: "stroke",
|
|
54
|
+
paths: ["M211 512L743 512", "M415 512C500 512 540 363 743 363", "M415 512C500 512 540 661 743 661"],
|
|
55
|
+
},
|
|
56
|
+
vmem: {
|
|
57
|
+
kind: "stroke",
|
|
58
|
+
strokeWidth: 58,
|
|
59
|
+
linecap: "butt",
|
|
60
|
+
paths: [
|
|
61
|
+
"M693.2 379.5A227.25 227.25 0 0 1 581.0 732.7",
|
|
62
|
+
"M442.5 732.7A227.25 227.25 0 0 1 330.9 378.7",
|
|
63
|
+
"M397.3 319.9A227.25 227.25 0 0 1 627.1 320.4",
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
verve: {
|
|
67
|
+
kind: "stroke",
|
|
68
|
+
paths: [
|
|
69
|
+
"M285.4 344.1Q428.6 344.1 512 552.6Q595.4 344.1 738.6 344.1",
|
|
70
|
+
"M285.4 344.1L285.4 579.8Q428.6 579.8 512 706.7Q595.4 579.8 738.6 579.8L738.6 344.1",
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
velth: {
|
|
74
|
+
kind: "stroke",
|
|
75
|
+
paths: [
|
|
76
|
+
"M512 732.3C379.8 652.1 289.7 471.9 299.7 301.6C419.9 371.7 500 552 512 732.3Z",
|
|
77
|
+
"M512 732.3C644.2 652.1 734.3 471.9 724.3 301.6C604.1 371.7 524 552 512 732.3Z",
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const NS = 'xmlns="http://www.w3.org/2000/svg"';
|
|
83
|
+
|
|
84
|
+
/** Attributes that paint the glyph in `color`. */
|
|
85
|
+
export function markPaintAttrs(app: AppName, color: string): string {
|
|
86
|
+
return APP_MARKS[app].kind === "fill" ? `fill="${color}"` : `fill="none" stroke="${color}" stroke-width="${markStrokeWidth(app)}" stroke-linecap="${markLinecap(app)}" stroke-linejoin="round"`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function pathElements(app: AppName): string {
|
|
90
|
+
return APP_MARKS[app].paths.map((d) => `<path d="${d}"/>`).join("");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Glyph only, painted with `color` (default `currentColor`). */
|
|
94
|
+
export function appMarkSvg(app: AppName, color = "currentColor"): string {
|
|
95
|
+
return `<svg ${NS} viewBox="${MARK_VIEWBOX}" ${markPaintAttrs(app, color)}>${pathElements(app)}</svg>\n`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Tile with a glyph. `radius` 0 gives a full-bleed square (apple-touch, maskable). */
|
|
99
|
+
export function appTileSvg(app: AppName, tone: "dark" | "light" = "dark", radius = TILE_RADIUS): string {
|
|
100
|
+
const [bg, fg] = tone === "dark" ? ["#000", "#fff"] : ["#fff", "#000"];
|
|
101
|
+
const rx = radius > 0 ? ` rx="${radius}"` : "";
|
|
102
|
+
return `<svg ${NS} viewBox="${MARK_VIEWBOX}"><rect width="1024" height="1024"${rx} fill="${bg}"/><g ${markPaintAttrs(app, fg)}>${pathElements(app)}</g></svg>\n`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Android adaptive-icon layer: 432 canvas, glyph scaled into the 288 inner square. */
|
|
106
|
+
export function appAdaptiveSvg(app: AppName, color: string): string {
|
|
107
|
+
const scale = 288 / 1024;
|
|
108
|
+
return `<svg ${NS} viewBox="0 0 432 432"><g transform="translate(216 216) scale(${scale}) translate(-512 -512)" ${markPaintAttrs(app, color)}>${pathElements(app)}</g></svg>\n`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Chrome extension 128px icon: 96px tile plus 16px transparent padding. */
|
|
112
|
+
export function appExtension128Svg(app: AppName): string {
|
|
113
|
+
const inner = appTileSvg(app).replace(`<svg ${NS} viewBox="${MARK_VIEWBOX}">`, `<svg ${NS} x="16" y="16" width="96" height="96" viewBox="${MARK_VIEWBOX}">`);
|
|
114
|
+
return `<svg ${NS} viewBox="0 0 128 128">${inner.trim()}</svg>\n`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const APP_MARK_SVG = Object.fromEntries(APP_NAMES.map((app) => [app, appMarkSvg(app)])) as Record<AppName, string>;
|
|
118
|
+
export const APP_TILE_SVG = Object.fromEntries(APP_NAMES.map((app) => [app, appTileSvg(app)])) as Record<AppName, string>;
|
|
119
|
+
export const APP_TILE_LIGHT_SVG = Object.fromEntries(APP_NAMES.map((app) => [app, appTileSvg(app, "light")])) as Record<AppName, string>;
|
package/src/index.ts
CHANGED
|
@@ -143,7 +143,7 @@ export * from "./ai-elements/sources";
|
|
|
143
143
|
export * from "./ai-elements/speech-input";
|
|
144
144
|
export * from "./ai-elements/suggestion";
|
|
145
145
|
|
|
146
|
-
// Agent activity and run surfaces (moved from
|
|
146
|
+
// Agent activity and run surfaces (moved from an app): the activity timeline and
|
|
147
147
|
// its step model, Trace lines, plan, test results, web preview, context usage
|
|
148
148
|
// and the model picker.
|
|
149
149
|
export * from "./ai-elements/activity-shared";
|
|
@@ -289,11 +289,21 @@ export type { PricingModalTone, SiteFooterVariant } from "./marketing/marketing-
|
|
|
289
289
|
export { SiteFooter } from "./marketing/SiteFooter";
|
|
290
290
|
export type { SiteFooterLink, SiteFooterProps, SiteFooterSocial } from "./marketing/SiteFooter";
|
|
291
291
|
export { PricingModal } from "./marketing/PricingModal";
|
|
292
|
-
export type {
|
|
292
|
+
export type {
|
|
293
|
+
PricingModalLegacyProps,
|
|
294
|
+
PricingModalMultiProps,
|
|
295
|
+
PricingModalPeriod,
|
|
296
|
+
PricingModalProps,
|
|
297
|
+
PricingPlan,
|
|
298
|
+
PricingPlanBenefit,
|
|
299
|
+
} from "./marketing/PricingModal";
|
|
293
300
|
|
|
294
301
|
// App helpers: confirm skip, update watcher, settings chrome, stable auth, Convex provider, VITE env and ensure-user.
|
|
295
302
|
export * from "../app/src/index";
|
|
296
303
|
|
|
304
|
+
// Family app marks (AppMark and raw SVG strings for favicons).
|
|
305
|
+
export * from "./brand";
|
|
306
|
+
|
|
297
307
|
// Native tokens (JS values that match tokens.css).
|
|
298
308
|
export { tokens } from "../tokens/src/native";
|
|
299
309
|
export type { Tokens } from "../tokens/src/native";
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { useRef, useState, type ReactElement, type ReactNode } from "react";
|
|
2
2
|
import { IconCheck, IconX } from "@tabler/icons-react";
|
|
3
|
+
import { AppMark } from "../brand/AppMark";
|
|
4
|
+
import type { AppName } from "../brand/svg";
|
|
3
5
|
import { Button } from "../ui/button";
|
|
4
6
|
import { Dialog, DialogContent, DialogDescription, DialogTitle } from "../ui/dialog";
|
|
5
7
|
import { VisuallyHidden } from "../ui/visually-hidden";
|
|
6
|
-
import { pricingModalClasses, type PricingModalTone } from "./marketing-classes";
|
|
8
|
+
import { pricingModalClasses, pricingMultiClasses, type PricingModalTone } from "./marketing-classes";
|
|
7
9
|
|
|
8
|
-
export type
|
|
10
|
+
export type PricingModalPeriod = "month" | "year";
|
|
11
|
+
|
|
12
|
+
export type PricingModalLegacyProps = {
|
|
13
|
+
/** Absent in the single-plan layout. Set `plans` for the multi-plan layout. */
|
|
14
|
+
plans?: undefined;
|
|
9
15
|
open: boolean;
|
|
10
16
|
/** Called when the dialog asks to close and by the `closeButton`. */
|
|
11
17
|
onClose: () => void;
|
|
@@ -19,6 +25,21 @@ export type PricingModalProps = {
|
|
|
19
25
|
wordmark: string;
|
|
20
26
|
/** For example "$9". */
|
|
21
27
|
price: string;
|
|
28
|
+
/** Adds a monthly/yearly toggle. Without it the modal is monthly only and `price` is the only price. */
|
|
29
|
+
yearly?: {
|
|
30
|
+
/** Yearly price per month, for example "$8.33". */
|
|
31
|
+
pricePerMonth: string;
|
|
32
|
+
/** Yearly total shown in the note, for example "$100". */
|
|
33
|
+
total?: string;
|
|
34
|
+
/** Badge on the yearly option. Default "Save 2 months". */
|
|
35
|
+
saveLabel?: string;
|
|
36
|
+
};
|
|
37
|
+
/** Selected period, when the parent controls it. Needs `yearly`. */
|
|
38
|
+
billingPeriod?: PricingModalPeriod;
|
|
39
|
+
/** Called with the period the user picks. */
|
|
40
|
+
onBillingPeriodChange?: (period: PricingModalPeriod) => void;
|
|
41
|
+
/** Initial period when `billingPeriod` is not set. Default `"month"`. */
|
|
42
|
+
defaultBillingPeriod?: PricingModalPeriod;
|
|
22
43
|
tagline: ReactNode;
|
|
23
44
|
/** Extra font class on the tagline, placed after `max-w-[28ch]`. */
|
|
24
45
|
taglineFontClassName?: string;
|
|
@@ -26,16 +47,75 @@ export type PricingModalProps = {
|
|
|
26
47
|
features: readonly string[];
|
|
27
48
|
/** Label of the full-width checkout button. Default "Get Pro". */
|
|
28
49
|
ctaLabel?: string;
|
|
29
|
-
/** Wraps the checkout button, for example in the billing provider's checkout and signed-in gates. */
|
|
30
|
-
renderCheckout: (button: ReactElement) => ReactNode;
|
|
50
|
+
/** Wraps the checkout button, for example in the billing provider's checkout and signed-in gates. `period` is the selected period, for `planPeriod`; it is always `"month"` without `yearly`. */
|
|
51
|
+
renderCheckout: (button: ReactElement, period: PricingModalPeriod) => ReactNode;
|
|
31
52
|
/** Second, compact close button in the top-right corner. Default `false`. */
|
|
32
53
|
closeButton?: boolean;
|
|
33
54
|
/** Secondary text colour class. Default `"muted"`. */
|
|
34
55
|
tone?: PricingModalTone;
|
|
35
56
|
};
|
|
36
57
|
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
export type PricingPlanBenefit = {
|
|
59
|
+
label: ReactNode;
|
|
60
|
+
/** `"check"` (default) or an app mark. */
|
|
61
|
+
icon?: "check" | AppName;
|
|
62
|
+
/** Dimmed row. */
|
|
63
|
+
muted?: boolean;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type PricingPlan = {
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
/** Display strings per month, for example `{ month: "$10", year: "$8" }`. The yearly price is still per month. */
|
|
70
|
+
price: { month: string; year: string };
|
|
71
|
+
/** Default "Get started". */
|
|
72
|
+
ctaLabel?: string;
|
|
73
|
+
/** Line above the highlight, for example "Everything in Free, and:". */
|
|
74
|
+
intro?: ReactNode;
|
|
75
|
+
/** Large title with small text under it. */
|
|
76
|
+
highlight?: { title: string; description: string };
|
|
77
|
+
benefits?: readonly PricingPlanBenefit[];
|
|
78
|
+
/** The plan the user is on: the button reads "Current plan" and is disabled. */
|
|
79
|
+
current?: boolean;
|
|
80
|
+
/** Subtle ring on the card. `highlighted` is an alias. */
|
|
81
|
+
featured?: boolean;
|
|
82
|
+
highlighted?: boolean;
|
|
83
|
+
/** Text after the price. Default "/month". */
|
|
84
|
+
periodSuffix?: string;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type PricingModalMultiProps = {
|
|
88
|
+
open: boolean;
|
|
89
|
+
onClose: () => void;
|
|
90
|
+
/** Accessible dialog title. Not visible. */
|
|
91
|
+
title: string;
|
|
92
|
+
/** Accessible description. Not visible. */
|
|
93
|
+
description?: string;
|
|
94
|
+
/** Cards, left to right. Sized for 1 to 4. */
|
|
95
|
+
plans: readonly PricingPlan[];
|
|
96
|
+
/** App marks at the top left. */
|
|
97
|
+
apps?: readonly AppName[];
|
|
98
|
+
/** Centred headline, for example "One plan. Every V app." */
|
|
99
|
+
headline?: ReactNode;
|
|
100
|
+
/** Small print under the cards. */
|
|
101
|
+
finePrint?: ReactNode;
|
|
102
|
+
billingPeriod?: PricingModalPeriod;
|
|
103
|
+
onBillingPeriodChange?: (period: PricingModalPeriod) => void;
|
|
104
|
+
/** Default `"month"`. */
|
|
105
|
+
defaultBillingPeriod?: PricingModalPeriod;
|
|
106
|
+
/** Wraps each plan's button, for example in the billing provider's checkout. Not called for the `current` plan. */
|
|
107
|
+
renderCheckout: (button: ReactElement, plan: PricingPlan, period: PricingModalPeriod) => ReactNode;
|
|
108
|
+
tone?: PricingModalTone;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export type PricingModalProps = PricingModalLegacyProps | PricingModalMultiProps;
|
|
112
|
+
|
|
113
|
+
/** Upgrade dialog. With `plans`: wide multi-plan layout. Without: the single-plan layout. */
|
|
114
|
+
export function PricingModal(props: PricingModalProps) {
|
|
115
|
+
return props.plans ? <PricingModalMulti {...props} /> : <PricingModalSingle {...props} />;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function PricingModalSingle({
|
|
39
119
|
open,
|
|
40
120
|
onClose,
|
|
41
121
|
title,
|
|
@@ -43,6 +123,10 @@ export function PricingModal({
|
|
|
43
123
|
logo,
|
|
44
124
|
wordmark,
|
|
45
125
|
price,
|
|
126
|
+
yearly,
|
|
127
|
+
billingPeriod,
|
|
128
|
+
onBillingPeriodChange,
|
|
129
|
+
defaultBillingPeriod = "month",
|
|
46
130
|
tagline,
|
|
47
131
|
taglineFontClassName,
|
|
48
132
|
features,
|
|
@@ -50,8 +134,14 @@ export function PricingModal({
|
|
|
50
134
|
renderCheckout,
|
|
51
135
|
closeButton = false,
|
|
52
136
|
tone = "muted",
|
|
53
|
-
}:
|
|
137
|
+
}: PricingModalLegacyProps) {
|
|
54
138
|
const c = pricingModalClasses[tone];
|
|
139
|
+
const [localPeriod, setLocalPeriod] = useState<PricingModalPeriod>(defaultBillingPeriod);
|
|
140
|
+
const period: PricingModalPeriod = yearly ? (billingPeriod ?? localPeriod) : "month";
|
|
141
|
+
const selectPeriod = (next: PricingModalPeriod) => {
|
|
142
|
+
setLocalPeriod(next);
|
|
143
|
+
onBillingPeriodChange?.(next);
|
|
144
|
+
};
|
|
55
145
|
const taglineClass = ["mt-4 max-w-[28ch]", taglineFontClassName, c.tagline].filter(Boolean).join(" ");
|
|
56
146
|
return (
|
|
57
147
|
<Dialog open={open} onOpenChange={(next) => !next && onClose()}>
|
|
@@ -87,9 +177,27 @@ export function PricingModal({
|
|
|
87
177
|
</span>
|
|
88
178
|
</div>
|
|
89
179
|
|
|
90
|
-
|
|
180
|
+
{yearly ? (
|
|
181
|
+
<div role="group" aria-label="Billing period" className="mt-8 inline-flex rounded-lg bg-surface-tertiary p-0.5">
|
|
182
|
+
{(["month", "year"] as const).map((value) => (
|
|
183
|
+
<button
|
|
184
|
+
key={value}
|
|
185
|
+
type="button"
|
|
186
|
+
aria-pressed={period === value}
|
|
187
|
+
onClick={() => selectPeriod(value)}
|
|
188
|
+
className={`rounded-md px-3 py-1 text-xs font-medium transition-colors duration-100 ${
|
|
189
|
+
period === value ? "bg-segment text-segment-foreground" : "text-muted-foreground hover:text-foreground"
|
|
190
|
+
}`}
|
|
191
|
+
>
|
|
192
|
+
{value === "month" ? "Monthly" : `Yearly · ${yearly.saveLabel ?? "Save 2 months"}`}
|
|
193
|
+
</button>
|
|
194
|
+
))}
|
|
195
|
+
</div>
|
|
196
|
+
) : null}
|
|
197
|
+
|
|
198
|
+
<div className={yearly ? "mt-5 flex items-end gap-2" : "mt-8 flex items-end gap-2"}>
|
|
91
199
|
<span className="text-5xl font-medium tabular-nums leading-none tracking-tight text-foreground">
|
|
92
|
-
{price}
|
|
200
|
+
{yearly && period === "year" ? yearly.pricePerMonth : price}
|
|
93
201
|
</span>
|
|
94
202
|
<span className={c.period}>/ month</span>
|
|
95
203
|
</div>
|
|
@@ -102,9 +210,14 @@ export function PricingModal({
|
|
|
102
210
|
<Button size="lg" className="h-11 w-full rounded-xl">
|
|
103
211
|
{ctaLabel}
|
|
104
212
|
</Button>,
|
|
213
|
+
period,
|
|
105
214
|
)}
|
|
106
215
|
|
|
107
|
-
<p className={c.note}>
|
|
216
|
+
<p className={c.note}>
|
|
217
|
+
{period === "year"
|
|
218
|
+
? `Cancel anytime. ${yearly?.total ? `${yearly.total} billed yearly.` : "Billed yearly."}`
|
|
219
|
+
: "Cancel anytime. Billed monthly."}
|
|
220
|
+
</p>
|
|
108
221
|
|
|
109
222
|
<div className="mt-8">
|
|
110
223
|
<p className={c.featuresHeading}>What you get</p>
|
|
@@ -124,3 +237,163 @@ export function PricingModal({
|
|
|
124
237
|
</Dialog>
|
|
125
238
|
);
|
|
126
239
|
}
|
|
240
|
+
|
|
241
|
+
const multiWidth = {
|
|
242
|
+
1: "sm:max-w-md",
|
|
243
|
+
2: "sm:max-w-3xl",
|
|
244
|
+
3: "sm:max-w-5xl",
|
|
245
|
+
4: "sm:max-w-6xl",
|
|
246
|
+
} as const;
|
|
247
|
+
|
|
248
|
+
const multiColumns = {
|
|
249
|
+
1: "",
|
|
250
|
+
2: "sm:grid-cols-2",
|
|
251
|
+
3: "md:grid-cols-3",
|
|
252
|
+
4: "sm:grid-cols-2 lg:grid-cols-4",
|
|
253
|
+
} as const;
|
|
254
|
+
|
|
255
|
+
function PricingModalMulti({
|
|
256
|
+
open,
|
|
257
|
+
onClose,
|
|
258
|
+
title,
|
|
259
|
+
description,
|
|
260
|
+
plans,
|
|
261
|
+
apps,
|
|
262
|
+
headline,
|
|
263
|
+
finePrint,
|
|
264
|
+
billingPeriod,
|
|
265
|
+
onBillingPeriodChange,
|
|
266
|
+
defaultBillingPeriod = "month",
|
|
267
|
+
renderCheckout,
|
|
268
|
+
tone = "muted",
|
|
269
|
+
}: PricingModalMultiProps) {
|
|
270
|
+
const c = pricingMultiClasses[tone];
|
|
271
|
+
const [localPeriod, setLocalPeriod] = useState<PricingModalPeriod>(defaultBillingPeriod);
|
|
272
|
+
const period = billingPeriod ?? localPeriod;
|
|
273
|
+
const selectPeriod = (next: PricingModalPeriod) => {
|
|
274
|
+
setLocalPeriod(next);
|
|
275
|
+
onBillingPeriodChange?.(next);
|
|
276
|
+
};
|
|
277
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
278
|
+
const count = Math.min(Math.max(plans.length, 1), 4) as 1 | 2 | 3 | 4;
|
|
279
|
+
return (
|
|
280
|
+
<Dialog open={open} onOpenChange={(next) => !next && onClose()}>
|
|
281
|
+
<DialogContent
|
|
282
|
+
ref={contentRef}
|
|
283
|
+
hideCloseButton
|
|
284
|
+
// Focus the dialog, not the first segment button, so no ring shows on open.
|
|
285
|
+
onOpenAutoFocus={(event) => {
|
|
286
|
+
event.preventDefault();
|
|
287
|
+
contentRef.current?.focus();
|
|
288
|
+
}}
|
|
289
|
+
className={`max-h-[calc(100dvh-2rem)] gap-0 overflow-y-auto p-0 font-sans sm:w-[calc(100vw-2rem)] ${multiWidth[count]}`}
|
|
290
|
+
>
|
|
291
|
+
<DialogTitle className="sr-only">{title}</DialogTitle>
|
|
292
|
+
{description ? <DialogDescription className="sr-only">{description}</DialogDescription> : null}
|
|
293
|
+
|
|
294
|
+
<div className="grid grid-cols-[1fr_auto] items-center gap-x-4 gap-y-3 px-4 pb-4 pt-5 sm:grid-cols-[1fr_auto_1fr] sm:px-6">
|
|
295
|
+
<div className="flex items-center gap-2 text-foreground" data-testid="pricing-apps">
|
|
296
|
+
{apps?.map((app) => <AppMark key={app} app={app} variant="tile" size={24} className="rounded-md" />)}
|
|
297
|
+
</div>
|
|
298
|
+
<div className="flex items-center justify-end gap-2 sm:order-last">
|
|
299
|
+
<div role="group" aria-label="Billing period" className="inline-flex rounded-full bg-surface-tertiary p-0.5">
|
|
300
|
+
{(["month", "year"] as const).map((value) => (
|
|
301
|
+
<button
|
|
302
|
+
key={value}
|
|
303
|
+
type="button"
|
|
304
|
+
aria-pressed={period === value}
|
|
305
|
+
onClick={() => selectPeriod(value)}
|
|
306
|
+
className={`rounded-full px-3 py-1 text-xs font-medium transition-colors duration-150 motion-reduce:transition-none ${
|
|
307
|
+
period === value ? "bg-segment text-segment-foreground" : `${c.switchIdle} hover:text-foreground`
|
|
308
|
+
}`}
|
|
309
|
+
>
|
|
310
|
+
{value === "month" ? "Monthly" : "Annual"}
|
|
311
|
+
</button>
|
|
312
|
+
))}
|
|
313
|
+
</div>
|
|
314
|
+
<button
|
|
315
|
+
type="button"
|
|
316
|
+
onClick={onClose}
|
|
317
|
+
className="flex size-8 items-center justify-center rounded-full text-muted-foreground transition-[background-color,transform] duration-100 ease-out hover:bg-surface-tertiary hover:text-foreground active:scale-[0.96] motion-reduce:transition-none"
|
|
318
|
+
>
|
|
319
|
+
<IconX className="size-4" />
|
|
320
|
+
<span className="sr-only">Close</span>
|
|
321
|
+
</button>
|
|
322
|
+
</div>
|
|
323
|
+
{headline ? (
|
|
324
|
+
<p className="col-span-2 text-balance text-center text-xl font-medium tracking-tight text-foreground sm:order-none sm:col-span-1 sm:text-2xl">
|
|
325
|
+
{headline}
|
|
326
|
+
</p>
|
|
327
|
+
) : (
|
|
328
|
+
<span className="hidden sm:block" />
|
|
329
|
+
)}
|
|
330
|
+
</div>
|
|
331
|
+
|
|
332
|
+
<div className={`grid grid-cols-1 gap-3 px-4 sm:px-6 ${multiColumns[count]}`}>
|
|
333
|
+
{plans.map((plan) => {
|
|
334
|
+
const emphasised = plan.featured ?? plan.highlighted;
|
|
335
|
+
const button = (
|
|
336
|
+
<Button
|
|
337
|
+
size="lg"
|
|
338
|
+
variant={plan.current ? "outline" : emphasised ? "default" : "secondary"}
|
|
339
|
+
disabled={plan.current}
|
|
340
|
+
className="h-12 w-full rounded-full"
|
|
341
|
+
>
|
|
342
|
+
{plan.current ? "Current plan" : (plan.ctaLabel ?? "Get started")}
|
|
343
|
+
</Button>
|
|
344
|
+
);
|
|
345
|
+
return (
|
|
346
|
+
<section
|
|
347
|
+
key={plan.id}
|
|
348
|
+
data-plan={plan.id}
|
|
349
|
+
aria-label={plan.name}
|
|
350
|
+
className={`flex flex-col rounded-3xl bg-surface-secondary p-5 ${
|
|
351
|
+
emphasised ? "ring-1 ring-foreground/25" : "ring-1 ring-separator"
|
|
352
|
+
}`}
|
|
353
|
+
>
|
|
354
|
+
<h3 className="text-base text-foreground">{plan.name}</h3>
|
|
355
|
+
<p className="mt-4 flex items-baseline gap-1">
|
|
356
|
+
<span className="text-5xl font-medium tabular-nums leading-none tracking-tight text-foreground">
|
|
357
|
+
{plan.price[period]}
|
|
358
|
+
</span>
|
|
359
|
+
<span className={c.suffix}>{plan.periodSuffix ?? "/month"}</span>
|
|
360
|
+
</p>
|
|
361
|
+
<div className="mt-5">{plan.current ? button : renderCheckout(button, plan, period)}</div>
|
|
362
|
+
{plan.intro ? <p className={`mt-6 text-sm ${c.suffix}`}>{plan.intro}</p> : null}
|
|
363
|
+
{plan.highlight ? (
|
|
364
|
+
<div className="mt-3">
|
|
365
|
+
<p className="text-2xl font-medium leading-tight text-foreground">{plan.highlight.title}</p>
|
|
366
|
+
<p className="text-sm text-foreground">{plan.highlight.description}</p>
|
|
367
|
+
</div>
|
|
368
|
+
) : null}
|
|
369
|
+
{plan.benefits?.length ? (
|
|
370
|
+
<ul className="mt-5 space-y-2.5 border-t border-separator pt-4">
|
|
371
|
+
{plan.benefits.map((benefit, index) => (
|
|
372
|
+
<li
|
|
373
|
+
key={index}
|
|
374
|
+
className={`flex items-start gap-2.5 text-sm leading-snug ${
|
|
375
|
+
benefit.muted ? c.suffix : "text-foreground"
|
|
376
|
+
}`}
|
|
377
|
+
>
|
|
378
|
+
<span className="mt-0.5 flex size-4 shrink-0 items-center justify-center">
|
|
379
|
+
{benefit.icon && benefit.icon !== "check" ? (
|
|
380
|
+
<AppMark app={benefit.icon} size={16} />
|
|
381
|
+
) : (
|
|
382
|
+
<IconCheck className="size-4" strokeWidth={2} />
|
|
383
|
+
)}
|
|
384
|
+
</span>
|
|
385
|
+
<span>{benefit.label}</span>
|
|
386
|
+
</li>
|
|
387
|
+
))}
|
|
388
|
+
</ul>
|
|
389
|
+
) : null}
|
|
390
|
+
</section>
|
|
391
|
+
);
|
|
392
|
+
})}
|
|
393
|
+
</div>
|
|
394
|
+
|
|
395
|
+
{finePrint ? <p className={`px-4 pb-5 pt-4 text-xs sm:px-6 ${c.suffix}`}>{finePrint}</p> : <div className="pb-4" />}
|
|
396
|
+
</DialogContent>
|
|
397
|
+
</Dialog>
|
|
398
|
+
);
|
|
399
|
+
}
|
|
@@ -113,3 +113,15 @@ export const pricingModalClasses = {
|
|
|
113
113
|
} as const;
|
|
114
114
|
|
|
115
115
|
export type PricingModalTone = keyof typeof pricingModalClasses;
|
|
116
|
+
|
|
117
|
+
/** Multi-plan `PricingModal` secondary text classes for the two tones. */
|
|
118
|
+
export const pricingMultiClasses = {
|
|
119
|
+
muted: {
|
|
120
|
+
suffix: "text-muted", // check-tokens-allow: text-muted
|
|
121
|
+
switchIdle: "text-muted", // check-tokens-allow: text-muted
|
|
122
|
+
},
|
|
123
|
+
"muted-foreground": {
|
|
124
|
+
suffix: "text-muted-foreground",
|
|
125
|
+
switchIdle: "text-muted-foreground",
|
|
126
|
+
},
|
|
127
|
+
} as const;
|
package/tokens/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# `@vvedantb/ui/tokens`
|
|
2
|
+
|
|
3
|
+
Design tokens and shared Tailwind v4 CSS for the vvedantb web apps. The CSS and Tailwind preset are subpaths of `@vvedantb/ui`; the native JS tokens are named exports of the root (`tokens`, `Tokens`). Source-exported: no build step. Paths in the `File` column are relative to `packages/ui/tokens/`.
|
|
4
|
+
|
|
5
|
+
## Exports
|
|
6
|
+
|
|
7
|
+
| Export | File | What it is |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `@vvedantb/ui/tokens`, `@vvedantb/ui/tokens/tokens.css` | `src/tokens.css` | Colour, radius, shadow, ease and font tokens (`@theme`), light/dark variables, `dark` variant, the radius utilities `rounded-surface` (`clamp(0.75rem, var(--radius), 1rem)`), `rounded-menu-item` (`min(var(--radius), 0.5rem)`) and `rounded-control` (`min(var(--radius), 0.625rem)`) (0.7.1; `rounded-surface` was in `utilities.css` before), `*` border and `body` defaults. From 0.16.3 `--field-radius` (`rounded-field`) is `min(var(--radius), 0.625rem)`, the same cap as `rounded-control` (was `1.25rem`). 0.7.2 adds `--sidebar-accent` / `sidebar-accent` (sidebar nav row fill: light `var(--surface-tertiary)`, dark `oklch(22.64% 0 0)`). In 0.2.1 it also defines shadcn-style aliases (`primary`, `muted-foreground`, `secondary`, `destructive`, `card`, `popover`, `input`, `ring`) that point at the same tokens. From 0.15.0 it imports `clear-input.css`, `scrollbar-thin.css` and `motion.css`, sets the `--modal-*` and `--tabs-*` motion variables on `:root`, and defines `.glass-panel-strong` (`var(--overlay)`) and `.sidebar-section-label`. |
|
|
10
|
+
| `tokens` and `Tokens` from `@vvedantb/ui` | `src/native.ts` | JS colours, radii and spacing for React Native. `@vvedantb/native-ui` keeps its own copy in `src/tokens.ts`; a test keeps the two equal. |
|
|
11
|
+
| `@vvedantb/ui/tokens/css/base.css` | `src/css/base.css` | `html` touch/accent, `::selection`, control transitions, pointer cursor, range accent (`@layer base`). |
|
|
12
|
+
| `@vvedantb/ui/tokens/css/dialog.css` | `src/css/dialog.css` | Unlayered `max-width: none` for `@vvedantb/ui` compact (bottom-sheet) dialogs. |
|
|
13
|
+
| `@vvedantb/ui/tokens/css/modal.css` | `src/css/modal.css` | `.t-modal`, `.is-open`, `.is-closing` and `t-modal-presence-wait` (`@layer components`). |
|
|
14
|
+
| `@vvedantb/ui/tokens/css/tabs.css` | `src/css/tabs.css` | `.t-tabs` container (0.15.0), `.t-tab` with its press scale, active colour, `.t-tabs-pill`, small-screen `.t-tabs` scrolling. |
|
|
15
|
+
| `@vvedantb/ui/tokens/css/tabs-pills.css` | `src/css/tabs-pills.css` | `--tabs-*` colour variables, `.t-tabs--segmented`, `.t-tabs--pills` and pill hover / active fills. |
|
|
16
|
+
| `@vvedantb/ui/tokens/css/utilities.css` | `src/css/utilities.css` | `@utility hit-target` and `@utility reveal-on-hover`. `rounded-surface` moved to `tokens.css` in 0.7.1. |
|
|
17
|
+
| `@vvedantb/ui/tokens/css/scrollbar-thin.css` | `src/css/scrollbar-thin.css` | `.scrollbar-thin` (`@layer utilities`, always emitted). Imported by `tokens.css` from 0.15.0. |
|
|
18
|
+
| `@vvedantb/ui/tokens/css/clear-input.css` | `src/css/clear-input.css` | `ClearInput` layers (`.t-clear*`) and the `--clear-*` / `--glow-*` timings. Imported by `tokens.css`. From 0.15.1 the layers clip in `.t-clear-clip`, so `.t-clear` keeps the focus ring, and the placeholder layer only shows during `.is-clearing`. |
|
|
19
|
+
| `@vvedantb/ui/tokens/css/motion.css` | `src/css/motion.css` | `.ui-page-enter`, `.ui-enter`, `.ui-enter-up`, `.ui-stagger`, their keyframes and reduced-motion rules, and the `html[data-page-motion="off"]` overrides for `PageMotionProvider`. Imported by `tokens.css`. |
|
|
20
|
+
| `@vvedantb/ui/tokens/css/animations.css` | `src/css/animations.css` | `animate-aurora`, `animate-fade-in-up`, `animate-indeterminate` as `@theme` (CSS-first apps). |
|
|
21
|
+
| `@vvedantb/ui/tokens/css/compat-shadcn-rgb.css`, `@vvedantb/ui/tokens/compat/shadcn-rgb.css` | `src/css/compat-shadcn-rgb.css` | Replaces `tokens.css` for apps with shadcn-style `R G B` channel variables. Defines only the UI-only `--color-*` names as `rgb(var(--x) / alpha)` references, `--radius-field`, `--scrollbar`, `--field-radius` (both `min(var(--radius), 0.625rem)` from 0.16.3), the same three radius utilities as `tokens.css` and `.glass-panel-strong` (solid `--popover` from 0.15.0). Import it **or** `tokens.css`, never both. |
|
|
22
|
+
| `@vvedantb/ui/tokens/css/index.css` | `src/css/index.css` | base + dialog + modal + tabs + tabs-pills + utilities + animations + nav-icons, for new CSS-first apps (`tokens.css` brings scrollbar-thin). |
|
|
23
|
+
| `@vvedantb/ui/tokens/tailwind-preset` | `src/tailwind-preset.mjs` (+ `.d.mts`) | Tailwind preset for apps that load a JS config with `@config`. |
|
|
24
|
+
|
|
25
|
+
Every file was extracted because the same rule (same at-rule context, selector and body) sits in 3 or more of the five apps. The measured duplication is in `verify/ANALYSIS.md`, and the proof that each app compiles to the same CSS after migrating is in `verify/RESULTS.md`. Blocks that only 2 apps share, or that drift in a way that would change an app's CSS, stay in the apps; `verify/ANALYSIS.md` lists them.
|
|
26
|
+
|
|
27
|
+
## Use
|
|
28
|
+
|
|
29
|
+
CSS-first app (no `tailwind.config`):
|
|
30
|
+
|
|
31
|
+
```css
|
|
32
|
+
@import "tailwindcss";
|
|
33
|
+
@import "@vvedantb/ui/tokens";
|
|
34
|
+
@import "@vvedantb/ui/tokens/css/animations.css";
|
|
35
|
+
@import "@vvedantb/ui/tokens/css/base.css";
|
|
36
|
+
/* ...app @layer base rules... */
|
|
37
|
+
@import "@vvedantb/ui/tokens/css/modal.css";
|
|
38
|
+
@import "@vvedantb/ui/tokens/css/tabs.css";
|
|
39
|
+
/* ...app @layer components rules... */
|
|
40
|
+
/* no --modal-* / --tabs-* needed: tokens.css sets them */
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
App with a JS config (`@config "../tailwind.config.ts"`):
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { tokensPreset } from "@vvedantb/ui/tokens/tailwind-preset";
|
|
47
|
+
|
|
48
|
+
export default {
|
|
49
|
+
presets: [tokensPreset()],
|
|
50
|
+
// or tokensPreset({ color: (name) => `color-mix(in oklch, var(--${name}) calc(<alpha-value> * 100%), transparent)` })
|
|
51
|
+
content: ["./src/**/*.{ts,tsx}"],
|
|
52
|
+
theme: { extend: { /* app-only colours, fonts, animations */ } },
|
|
53
|
+
plugins: [tailwindcssAnimate],
|
|
54
|
+
};
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The preset holds `darkMode: "class"`, the shared colour map (`border`, `surface.*`, `danger.*`, `field.*`, shadcn aliases `primary`/`secondary`/`destructive`/`card`/`popover`/`input` ...), `borderRadius` lg/md/sm/field, `boxShadow` soft/panel/insetSoft, `ease-smooth`, `screens` xs to 2xl in px, and the aurora / fade-in-up / indeterminate / accordion keyframes. It does not hold plugins, `content`, fonts, `accent`/`muted`/`ring`/`sidebar` (they differ per app) or accordion timings.
|
|
58
|
+
|
|
59
|
+
Do not import `css/animations.css` in an app that uses the preset: the preset already defines the same keyframes and animations.
|
|
60
|
+
|
|
61
|
+
### Where to put the imports
|
|
62
|
+
|
|
63
|
+
Tailwind inlines an `@import` where it sits, even in the middle of a file (it must be at top level, not inside an `@layer` block). Put each import where the app's own copy of the rules was. Within one layer, later rules win at equal specificity, so moving shared rules above or below app rules can flip the result for elements matched by both. `examples/migration.md` gives the exact position for each app, and `pnpm --filter @vvedantb/ui verify` checks it.
|
|
64
|
+
|
|
65
|
+
### Variables each file needs
|
|
66
|
+
|
|
67
|
+
| File | Needs | Provided by |
|
|
68
|
+
| --- | --- | --- |
|
|
69
|
+
| `base.css` | `--accent`, `--foreground` | tokens.css or the app theme |
|
|
70
|
+
| `dialog.css` | none | |
|
|
71
|
+
| `modal.css` | `--modal-open-dur`, `--modal-close-dur`, `--modal-scale`, `--modal-scale-close`, `--modal-ease` | tokens.css (0.15.0), or app `:root` with the compat file |
|
|
72
|
+
| `tabs.css` | `--tabs-dur`, `--tabs-ease` (tokens.css, or app `:root` with the compat file); `--tabs-text-muted`, `--tabs-text-active`, `--tabs-pill-bg` | colours: tabs-pills.css or the app theme |
|
|
73
|
+
| `tabs-pills.css` | `--muted`, `--segment`, `--segment-foreground`, `--default` | tokens.css or the app theme |
|
|
74
|
+
| `utilities.css` | `--breakpoint-sm` (Tailwind default or app theme) | Tailwind |
|
|
75
|
+
| `scrollbar-thin.css` | `--scrollbar` | tokens.css or the app theme |
|
|
76
|
+
| `clear-input.css`, `motion.css` | none (own `:root` defaults) | |
|
|
77
|
+
| `animations.css` | none | |
|
|
78
|
+
| `tailwind-preset` | the CSS variables named in its colour map, `--radius`, `--field-radius` | tokens.css or the app theme |
|
|
79
|
+
|
|
80
|
+
### Using an existing shadcn RGB theme
|
|
81
|
+
|
|
82
|
+
See the package `README.md`. With the compat file, `base.css`, `scrollbar-thin.css`, `clear-input.css`, `motion.css`, `utilities.css`, `dialog.css`, `modal.css` and `tabs.css` need no `tokens.css` (`modal.css` and `tabs.css` then need the `--modal-*` / `--tabs-*` values on the app `:root`). `base.css` reads `--accent` and `--foreground` and `tabs-pills.css` reads `--muted`, `--segment` and `--default`. Those are not channel-compatible, so skip `tabs-pills.css` and `index.css` (which includes `base.css`) unless the app defines those variables as full colours.
|
|
83
|
+
|
|
84
|
+
### Parameters
|
|
85
|
+
|
|
86
|
+
Where apps share a rule but drifted in one value, the value is a custom property whose fallback is the most common value. Set it on `:root` to keep a different value.
|
|
87
|
+
|
|
88
|
+
| File | Property | Default | Set by |
|
|
89
|
+
| --- | --- | --- | --- |
|
|
90
|
+
| `base.css` | `--tokens-control-transition-property` | `background-color, border-color, color, box-shadow, transform, opacity` | app-c: `background-color, color, transform, opacity` |
|
|
91
|
+
| `base.css` | `--tokens-control-transition-duration` | `240ms` | app-c: `100ms` |
|
|
92
|
+
|
|
93
|
+
From 0.15.0 the files that moved out of the apps take `:root` variables too. Every rule is in a Tailwind layer, so an app rule for the same selector (unlayered, or later in the same layer) also wins.
|
|
94
|
+
|
|
95
|
+
| File | Property | Default |
|
|
96
|
+
| --- | --- | --- |
|
|
97
|
+
| `tokens.css` | `--modal-open-dur`, `--modal-close-dur` | `180ms`, `120ms` |
|
|
98
|
+
| `tokens.css` | `--modal-scale`, `--modal-scale-close` | `0.96`, `0.96` |
|
|
99
|
+
| `tokens.css` | `--modal-ease`, `--tabs-ease` | `cubic-bezier(0.22, 1, 0.36, 1)` |
|
|
100
|
+
| `tokens.css` | `--tabs-dur` | `200ms` |
|
|
101
|
+
| `tokens.css` | `--sidebar-section-label-mix`, `--sidebar-section-label-hover-mix` | `55%`, `80%` (share of `--muted`) |
|
|
102
|
+
| `scrollbar-thin.css` | `--scrollbar-thin-rest`, `--scrollbar-thin-hover` | `40%`, `80%` (share of `--scrollbar`) |
|
|
103
|
+
| `clear-input.css` | `--clear-dur`, `--clear-out-dur`, `--clear-in-dur` | `1000ms`, `400ms`, `400ms` |
|
|
104
|
+
| `clear-input.css` | `--clear-out-fly`, `--clear-in-fly` | `12px`, `12px` |
|
|
105
|
+
| `clear-input.css` | `--clear-out-ease`, `--clear-in-ease` | `cubic-bezier(0.22, 1, 0.36, 1)` |
|
|
106
|
+
| `clear-input.css` | `--glow-delay`, `--glow-peak-at`, `--glow-opacity`, `--glow-spread` | `50ms`, `0.15`, `0.85`, `1.5` |
|
|
107
|
+
| `motion.css` | `--ui-enter-ease` | `cubic-bezier(0.22, 1, 0.36, 1)` |
|
|
108
|
+
| `motion.css` | `--ui-page-enter-dur`, `--ui-enter-dur`, `--ui-enter-up-dur` | `160ms`, `200ms`, `220ms` |
|
|
109
|
+
| `motion.css` | `--ui-stagger-step` | `40ms` (children 1 to 8) |
|
|
110
|
+
|
|
111
|
+
## Develop
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
pnpm --filter @vvedantb/ui build # export targets exist + tsc (primitives, shell, app)
|
|
115
|
+
pnpm --filter @vvedantb/ui test # vitest (app helpers) + offline node --test: exports, CSS structure, Tailwind compile, preset
|
|
116
|
+
pnpm --filter @vvedantb/ui analyze # rule-level duplication across the app clones -> verify/ANALYSIS.tables.md
|
|
117
|
+
pnpm --filter @vvedantb/ui verify # before/after compile of every app -> verify/RESULTS.md, examples/migration.md
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
`analyze` and `verify` need the app clones (`APPS_DIR`, default `/workspace/cvx`; name or symlink the clones `app-a` to `app-e` inside it) and network access the first time: they install Tailwind 4.3.3, the plugins, postcss and jiti into a scratch directory (`VERIFY_DIR`, default `/workspace/pk-tokens-verify`, outside the repo). The migration for each app is data in `verify/migrations/<app>.json`. Each removed block must equal the shared file's block with the same context and selector, or the run fails.
|