@vvedantb/ui 0.30.2 → 0.31.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.
@@ -44,6 +44,7 @@ export function Fixture() {
44
44
  <Button onClick={fire}>Show toast</Button>
45
45
  </div>
46
46
  </main>
47
+ {/* No `position`: the package default, top-right. */}
47
48
  <SonnerToaster
48
49
  theme={dark ? "dark" : "light"}
49
50
  toastRadius={compact ? "control" : "surface"}
@@ -1,11 +1,12 @@
1
1
  # toaster fixture
2
2
 
3
- Renders `SonnerToaster` with every opt-in prop on (`toastRadius="surface"`, `toastIcons="filled24"`, `closeButtonStyle="hoverChip"`, `sonnerVars`, `descriptionMuted`). It fires one sample toast with a title and a description on load. The toast stays open. Use "Show toast" to fire another.
3
+ Renders `SonnerToaster` with every opt-in prop on (`toastRadius="surface"`, `toastIcons="filled24"`, `closeButtonStyle="hoverChip"`, `sonnerVars`, `descriptionMuted`). It passes no `position`, so toasts show at the top right, the package default from 0.31.1. It fires one sample toast with a title and a description on load. The toast stays open. Use "Show toast" to fire another.
4
4
 
5
5
  | Page | Stylesheet |
6
6
  | --- | --- |
7
7
  | `/tokens.html` | `tokens.css` plus `utilities.css` (`styles-tokens.css`) |
8
8
  | `/compat.html` | `compat-shadcn-rgb.css` plus `utilities.css`, with sample `R G B` variables (`styles-compat.css`) |
9
+ | `/update.html` | `tokens.css` plus `utilities.css` (`styles-tokens.css`). Fires the update toast from `showUpdateAvailableToast` on load, at the top right: title, description and a Refresh action that reloads the page. The Refresh button uses the package default (28px tall, `rounded-control`). "Show update toast" fires it again. |
9
10
 
10
11
  Each stylesheet declares `glass-panel-strong` (tokens page only) and `smooth-shadow-ring-md`. The app owns those toast classes. The compat page also defines `--success` and `--warning` and maps them to `--color-success` and `--color-warning`.
11
12
 
@@ -15,4 +16,4 @@ Run it from this folder (it is not a workspace member, and React resolves from t
15
16
  pnpm install --ignore-workspace && pnpm dev
16
17
  ```
17
18
 
18
- Open the printed URL plus `/tokens.html` or `/compat.html`. Add `?variant=compact` for the compact density with `toastRadius="control"`. Add `?theme=dark` for dark mode (combine with `&`), or use "Toggle theme". Hover the toast to see the close chip. `Fixture.tsx` is not part of the package typecheck.
19
+ Open the printed URL plus `/tokens.html`, `/compat.html` or `/update.html`. Add `?variant=compact` for the compact density with `toastRadius="control"`. Add `?theme=dark` for dark mode (combine with `&`), or use "Toggle theme". `?variant=compact` applies to the first two pages only. Hover the toast to see the close chip. `Fixture.tsx` and `UpdateToastFixture.tsx` are not part of the package typecheck.
@@ -0,0 +1,53 @@
1
+ import { useEffect, useState } from "react";
2
+ import { toast } from "sonner";
3
+ import { showUpdateAvailableToast } from "../../../app/src/update/updateWatcher";
4
+ import { Button } from "../../../src/ui/button";
5
+ import { SonnerToaster } from "../../../src/ui/sonner";
6
+
7
+ function initialDark(): boolean {
8
+ return new URLSearchParams(window.location.search).get("theme") === "dark";
9
+ }
10
+
11
+ // The toast `startUpdateAvailableWatcher` shows. Refresh reloads this page,
12
+ // which fires the toast again.
13
+ function fireUpdateToast() {
14
+ showUpdateAvailableToast({ toast });
15
+ }
16
+
17
+ /** The update toast with its Refresh action, for screenshots. */
18
+ export function UpdateToastFixture() {
19
+ const [dark, setDark] = useState(initialDark);
20
+
21
+ // Sonner portals toasts onto `document.body`, so `.dark` must live on `<html>`.
22
+ useEffect(() => {
23
+ document.documentElement.classList.toggle("dark", dark);
24
+ return () => {
25
+ document.documentElement.classList.remove("dark");
26
+ };
27
+ }, [dark]);
28
+
29
+ useEffect(() => {
30
+ const id = window.setTimeout(fireUpdateToast, 150);
31
+ return () => window.clearTimeout(id);
32
+ }, []);
33
+
34
+ return (
35
+ <>
36
+ <main className="min-h-screen bg-background p-8 text-foreground">
37
+ <div className="flex gap-3">
38
+ <Button onClick={() => setDark((d) => !d)}>Toggle theme</Button>
39
+ <Button onClick={fireUpdateToast}>Show update toast</Button>
40
+ </div>
41
+ </main>
42
+ {/* No `position`: the package default, top-right, as Eva mounts it. */}
43
+ <SonnerToaster
44
+ theme={dark ? "dark" : "light"}
45
+ toastRadius="surface"
46
+ toastIcons="filled24"
47
+ closeButtonStyle="hoverChip"
48
+ sonnerVars
49
+ descriptionMuted
50
+ />
51
+ </>
52
+ );
53
+ }
@@ -0,0 +1,5 @@
1
+ import { createRoot } from "react-dom/client";
2
+ import { UpdateToastFixture } from "./UpdateToastFixture";
3
+ import "./styles-tokens.css";
4
+
5
+ createRoot(document.getElementById("root")!).render(<UpdateToastFixture />);
@@ -0,0 +1,12 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Update toast fixture</title>
7
+ </head>
8
+ <body>
9
+ <div id="root"></div>
10
+ <script type="module" src="./main-update.tsx"></script>
11
+ </body>
12
+ </html>
@@ -7,6 +7,6 @@ export default defineConfig({
7
7
  plugins: [tailwindcss()],
8
8
  esbuild: { jsx: "automatic" },
9
9
  resolve: { dedupe: ["react", "react-dom"] },
10
- build: { rollupOptions: { input: ["tokens.html", "compat.html"] } },
10
+ build: { rollupOptions: { input: ["tokens.html", "compat.html", "update.html"] } },
11
11
  server: { fs: { allow: ["../../.."] } },
12
12
  });