@vvedantb/ui 0.8.0 → 0.9.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 +89 -1
- package/app/README.md +193 -0
- package/package.json +14 -11
- package/shell/src/SidebarAccountMenu.tsx +78 -2
- package/shell/src/SidebarRail.tsx +20 -0
- package/shell/src/index.ts +2 -2
- package/src/index.ts +52 -2
- package/src/marketing/PricingModal.tsx +126 -0
- package/src/marketing/SiteFooter.tsx +135 -0
- package/src/marketing/createLandingKit.tsx +214 -0
- package/src/marketing/landing.css +271 -0
- package/src/marketing/landing.tsx +217 -0
- package/src/marketing/marketing-classes.ts +115 -0
- package/tokens/README.md +98 -0
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
|
package/app/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
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`, needed only for the app helpers: `@clerk/clerk-react` (`useStableAuth`), `@tanstack/react-hotkeys` and `zod`.
|
|
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`).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
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.",
|
|
6
6
|
"type": "module",
|
|
@@ -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",
|
|
@@ -164,13 +175,5 @@
|
|
|
164
175
|
"zod": {
|
|
165
176
|
"optional": true
|
|
166
177
|
}
|
|
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
178
|
}
|
|
176
|
-
}
|
|
179
|
+
}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { useState, type ComponentPropsWithoutRef, type ReactNode } from "react";
|
|
2
|
+
import { IconLogout, IconMoon, IconSun } from "@tabler/icons-react";
|
|
3
|
+
import { ConfirmSkipHint, skipConfirmTitle } from "../../app/src/confirm/ConfirmSkipHint";
|
|
4
|
+
import { useRequestConfirm } from "../../app/src/confirm/useRequestConfirm";
|
|
2
5
|
import { Button, type ButtonProps } from "../../src/ui/button";
|
|
3
6
|
import {
|
|
4
7
|
DropdownMenu,
|
|
5
8
|
DropdownMenuContent,
|
|
9
|
+
DropdownMenuItem,
|
|
6
10
|
DropdownMenuLabel,
|
|
7
11
|
DropdownMenuSeparator,
|
|
8
12
|
DropdownMenuTrigger,
|
|
9
13
|
} from "../../src/ui/dropdown-menu";
|
|
10
14
|
import { cn } from "../../src/utils/cn";
|
|
11
15
|
import { accountEmailClass, railTileClass, railTileStateClass } from "./app-shell-classes";
|
|
16
|
+
import { SignOutDialog } from "./SignOutDialog";
|
|
12
17
|
|
|
13
18
|
type ContentProps = ComponentPropsWithoutRef<typeof DropdownMenuContent>;
|
|
14
19
|
|
|
@@ -45,6 +50,20 @@ export type SidebarAccountMenuProps = {
|
|
|
45
50
|
>;
|
|
46
51
|
/** Menu items after the label and separator. */
|
|
47
52
|
children?: ReactNode;
|
|
53
|
+
/** Adds a "Light mode" / "Dark mode" item after `children`. */
|
|
54
|
+
themeToggle?: { isDark: boolean; onToggle: () => void };
|
|
55
|
+
/**
|
|
56
|
+
* Adds a separator and a danger "Sign out" item last. Selecting it opens
|
|
57
|
+
* `SignOutDialog` (Alt-click skips it, with `ConfirmSkipHint`). The menu owns
|
|
58
|
+
* the dialog state; `onSignOut` failing re-enables the dialog.
|
|
59
|
+
*/
|
|
60
|
+
signOut?: {
|
|
61
|
+
onSignOut: () => Promise<void>;
|
|
62
|
+
/** Second line of the dialog. */
|
|
63
|
+
description?: string;
|
|
64
|
+
};
|
|
65
|
+
/** `size` of the theme and sign-out item icons. Default: the icon's own size (24). */
|
|
66
|
+
itemIconSize?: number;
|
|
48
67
|
};
|
|
49
68
|
|
|
50
69
|
/** Account menu on a rail tile: avatar trigger, identity label, then the app's items. Composed from `Sidebar.Account*` parts. */
|
|
@@ -62,8 +81,25 @@ export function SidebarAccountMenu({
|
|
|
62
81
|
triggerProps,
|
|
63
82
|
contentProps,
|
|
64
83
|
children,
|
|
84
|
+
themeToggle,
|
|
85
|
+
signOut,
|
|
86
|
+
itemIconSize,
|
|
65
87
|
}: SidebarAccountMenuProps) {
|
|
66
|
-
|
|
88
|
+
const [signOutOpen, setSignOutOpen] = useState(false);
|
|
89
|
+
const [signingOut, setSigningOut] = useState(false);
|
|
90
|
+
const { request } = useRequestConfirm();
|
|
91
|
+
|
|
92
|
+
const handleSignOut = async () => {
|
|
93
|
+
if (!signOut) return;
|
|
94
|
+
setSigningOut(true);
|
|
95
|
+
try {
|
|
96
|
+
await signOut.onSignOut();
|
|
97
|
+
} catch {
|
|
98
|
+
setSigningOut(false);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const menu = (
|
|
67
103
|
<AccountMenu badge={badge}>
|
|
68
104
|
<AccountTrigger {...triggerProps} userName={name} imageUrl={imageUrl} />
|
|
69
105
|
<AccountContent
|
|
@@ -77,9 +113,49 @@ export function SidebarAccountMenu({
|
|
|
77
113
|
<AccountLabel userName={name} email={email} imageUrl={imageUrl} stacked={stackedLabel} />
|
|
78
114
|
<AccountSeparator />
|
|
79
115
|
{children}
|
|
116
|
+
{themeToggle ? (
|
|
117
|
+
<DropdownMenuItem onSelect={() => themeToggle.onToggle()}>
|
|
118
|
+
{themeToggle.isDark ? <IconSun size={itemIconSize} /> : <IconMoon size={itemIconSize} />}
|
|
119
|
+
{themeToggle.isDark ? "Light mode" : "Dark mode"}
|
|
120
|
+
</DropdownMenuItem>
|
|
121
|
+
) : null}
|
|
122
|
+
{signOut ? (
|
|
123
|
+
<>
|
|
124
|
+
<DropdownMenuSeparator />
|
|
125
|
+
<DropdownMenuItem
|
|
126
|
+
onSelect={() =>
|
|
127
|
+
request(
|
|
128
|
+
() => setSignOutOpen(true),
|
|
129
|
+
() => {
|
|
130
|
+
void handleSignOut();
|
|
131
|
+
},
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
className="text-danger focus:text-danger data-[highlighted]:text-danger"
|
|
135
|
+
title={skipConfirmTitle("Sign out")}
|
|
136
|
+
>
|
|
137
|
+
<IconLogout size={itemIconSize} />
|
|
138
|
+
Sign out
|
|
139
|
+
<ConfirmSkipHint />
|
|
140
|
+
</DropdownMenuItem>
|
|
141
|
+
</>
|
|
142
|
+
) : null}
|
|
80
143
|
</AccountContent>
|
|
81
144
|
</AccountMenu>
|
|
82
145
|
);
|
|
146
|
+
if (!signOut) return menu;
|
|
147
|
+
return (
|
|
148
|
+
<>
|
|
149
|
+
{menu}
|
|
150
|
+
<SignOutDialog
|
|
151
|
+
open={signOutOpen}
|
|
152
|
+
onOpenChange={setSignOutOpen}
|
|
153
|
+
pending={signingOut}
|
|
154
|
+
onConfirm={handleSignOut}
|
|
155
|
+
description={signOut.description}
|
|
156
|
+
/>
|
|
157
|
+
</>
|
|
158
|
+
);
|
|
83
159
|
}
|
|
84
160
|
|
|
85
161
|
export type SidebarAccountMenuRootProps = ComponentPropsWithoutRef<typeof DropdownMenu> & {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ComponentPropsWithoutRef, ReactNode } from "react";
|
|
2
2
|
import { Slot, Slottable } from "@radix-ui/react-slot";
|
|
3
3
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
4
|
+
import { IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpandFilled } from "@tabler/icons-react";
|
|
4
5
|
import { cn } from "../../src/utils/cn";
|
|
5
6
|
import { railTileClass, railTileStateClass } from "./app-shell-classes";
|
|
6
7
|
import { SidebarIconTooltip } from "./SidebarIconTooltip";
|
|
@@ -199,3 +200,22 @@ export type RailDividerProps = { className?: string };
|
|
|
199
200
|
export function RailDivider({ className }: RailDividerProps) {
|
|
200
201
|
return <RailSeparator className={className} />;
|
|
201
202
|
}
|
|
203
|
+
|
|
204
|
+
export type RailCollapseTileProps = {
|
|
205
|
+
/** Panel is collapsed: shows the expand icon and "Show sidebar". */
|
|
206
|
+
collapsed: boolean;
|
|
207
|
+
onToggle: () => void;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/** Rail tile that shows or hides the sidebar panel. */
|
|
211
|
+
export function RailCollapseTile({ collapsed, onToggle }: RailCollapseTileProps) {
|
|
212
|
+
return (
|
|
213
|
+
<RailItem label={collapsed ? "Show sidebar" : "Hide sidebar"} onClick={onToggle}>
|
|
214
|
+
{collapsed ? (
|
|
215
|
+
<IconLayoutSidebarLeftExpandFilled className="size-[22px]" />
|
|
216
|
+
) : (
|
|
217
|
+
<IconLayoutSidebarLeftCollapse className="size-[22px]" />
|
|
218
|
+
)}
|
|
219
|
+
</RailItem>
|
|
220
|
+
);
|
|
221
|
+
}
|
package/shell/src/index.ts
CHANGED
|
@@ -22,8 +22,8 @@ export { AppSidebar } from "./AppSidebar.js";
|
|
|
22
22
|
export type { AppSidebarProps } from "./AppSidebar.js";
|
|
23
23
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
24
24
|
export * from "./Sidebar.js";
|
|
25
|
-
export { SidebarRail, RailTile, RailDivider } from "./SidebarRail.js";
|
|
26
|
-
export type { SidebarRailProps, RailTileProps, RailDividerProps } from "./SidebarRail.js";
|
|
25
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile } from "./SidebarRail.js";
|
|
26
|
+
export type { SidebarRailProps, RailTileProps, RailDividerProps, RailCollapseTileProps } from "./SidebarRail.js";
|
|
27
27
|
export { SidebarResizeHandle, useAppShellResize } from "./SidebarResize.js";
|
|
28
28
|
export type {
|
|
29
29
|
AppShellResize,
|
package/src/index.ts
CHANGED
|
@@ -135,8 +135,13 @@ export { AppSidebar } from "../shell/src/AppSidebar";
|
|
|
135
135
|
export type { AppSidebarProps } from "../shell/src/AppSidebar";
|
|
136
136
|
// Composable sidebar parts (`Sidebar.Root`, `Sidebar.Rail`, ...) and their prop types.
|
|
137
137
|
export * from "../shell/src/Sidebar";
|
|
138
|
-
export { SidebarRail, RailTile, RailDivider } from "../shell/src/SidebarRail";
|
|
139
|
-
export type {
|
|
138
|
+
export { SidebarRail, RailTile, RailDivider, RailCollapseTile } from "../shell/src/SidebarRail";
|
|
139
|
+
export type {
|
|
140
|
+
SidebarRailProps,
|
|
141
|
+
RailTileProps,
|
|
142
|
+
RailDividerProps,
|
|
143
|
+
RailCollapseTileProps,
|
|
144
|
+
} from "../shell/src/SidebarRail";
|
|
140
145
|
export { SidebarResizeHandle, useAppShellResize } from "../shell/src/SidebarResize";
|
|
141
146
|
export type {
|
|
142
147
|
AppShellResize,
|
|
@@ -172,6 +177,51 @@ export {
|
|
|
172
177
|
} from "../shell/src/app-shell-classes";
|
|
173
178
|
export type { SidebarNavItemClassOptions } from "../shell/src/app-shell-classes";
|
|
174
179
|
|
|
180
|
+
// Marketing: landing kit, site footer and pricing dialog. Router- and Motion-free;
|
|
181
|
+
// `createLandingKit` takes the app's `motion`. Styles: `@vvedantb/ui/landing.css`.
|
|
182
|
+
export {
|
|
183
|
+
LandingFeatureCard,
|
|
184
|
+
LandingFooter,
|
|
185
|
+
LandingLattice,
|
|
186
|
+
LandingNavMenu,
|
|
187
|
+
LandingPageLayout,
|
|
188
|
+
LandingSection,
|
|
189
|
+
LandingSectionHeading,
|
|
190
|
+
landingItemVariants,
|
|
191
|
+
} from "./marketing/landing";
|
|
192
|
+
export type {
|
|
193
|
+
LandingFeature,
|
|
194
|
+
LandingFooterProps,
|
|
195
|
+
LandingLatticeProps,
|
|
196
|
+
LandingLink,
|
|
197
|
+
LandingNavMenuProps,
|
|
198
|
+
LandingPageLayoutProps,
|
|
199
|
+
LandingSectionHeadingProps,
|
|
200
|
+
LandingSectionProps,
|
|
201
|
+
} from "./marketing/landing";
|
|
202
|
+
export { createLandingKit } from "./marketing/createLandingKit";
|
|
203
|
+
export type {
|
|
204
|
+
LandingCtaProps,
|
|
205
|
+
LandingHeroProps,
|
|
206
|
+
LandingKit,
|
|
207
|
+
LandingKitOptions,
|
|
208
|
+
LandingMotion,
|
|
209
|
+
LandingNavProps,
|
|
210
|
+
LandingRevealItemProps,
|
|
211
|
+
LandingRevealProps,
|
|
212
|
+
} from "./marketing/createLandingKit";
|
|
213
|
+
export {
|
|
214
|
+
landingFooterButtonClass,
|
|
215
|
+
landingFooterLinkClass,
|
|
216
|
+
landingPanelClass,
|
|
217
|
+
landingShellClass,
|
|
218
|
+
} from "./marketing/marketing-classes";
|
|
219
|
+
export type { PricingModalTone, SiteFooterVariant } from "./marketing/marketing-classes";
|
|
220
|
+
export { SiteFooter } from "./marketing/SiteFooter";
|
|
221
|
+
export type { SiteFooterLink, SiteFooterProps, SiteFooterSocial } from "./marketing/SiteFooter";
|
|
222
|
+
export { PricingModal } from "./marketing/PricingModal";
|
|
223
|
+
export type { PricingModalProps } from "./marketing/PricingModal";
|
|
224
|
+
|
|
175
225
|
// App helpers: confirm skip, update watcher, settings chrome, stable auth.
|
|
176
226
|
export * from "../app/src/index";
|
|
177
227
|
|