Skip to content

Commit 7f54f7d

Browse files
authored
feat: adopt shadcn theme tokens and motion foundation (#65)
1 parent 0f2e44c commit 7f54f7d

10 files changed

Lines changed: 207 additions & 18 deletions

File tree

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!-- BEGIN:nextjs-agent-rules -->
22

3-
# This is NOT the Next.js you know
3+
## This is NOT the Next.js you know
44

55
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.
66

‎ARCHITECTURE.md‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,30 @@ not stylistic — the tests and the public API depend on them.
8989
4. **Shared types come from `./types`.** Do not declare a local `Locale`. Two
9090
divergent copies previously hid behind a `NavBarLocale` alias.
9191
92-
Also: `"use client"` at the top, Tailwind utility classes only (no CSS-variable
93-
design tokens), dark mode via `dark:` variants, and TSDoc on every prop.
94-
95-
**No framework dependencies.** The package's only runtime deps are `clsx` and
96-
`tailwind-merge`. `NavBar` needs link rendering, so it takes a `linkComponent`
97-
prop defaulting to `"a"` rather than importing `next/link` — that keeps the
98-
library usable in Vite, Remix, or plain React.
92+
Also: `"use client"` at the top, Tailwind utility classes only, and TSDoc on every
93+
prop.
94+
95+
**Styling: shadcn semantic tokens.** Components use `bg-popover`, `text-muted-foreground`,
96+
`border-input`, `ring-ring/50`, `bg-accent` and friends — never raw palette colours
97+
like `zinc-*` or `emerald-*` — so they inherit the consumer's shadcn theme. Dark mode
98+
comes from the tokens; reach for `dark:` only where shadcn itself does
99+
(`dark:bg-input/30`). The docs site defines the tokens in `src/app/globals.css`.
100+
101+
**Customisation surface.** Every visual component takes a `classNames` prop (one key
102+
per part, merged last with `cn`) plus `size` / `variant` where they make sense, and
103+
exports its `*ClassNames` interface from the barrel.
104+
105+
**Motion.** Animations use `motion/react`, wrapped in
106+
`<MotionConfig reducedMotion="user">`. Popups render inside `AnimatePresence` and mark
107+
themselves `aria-hidden` while exiting (`useIsPresent`), so a closing menu leaves the
108+
accessibility tree immediately. Tests set `MotionGlobalConfig.skipAnimations`.
109+
110+
**Dependencies.** Runtime deps are `clsx`, `tailwind-merge`, `motion` and
111+
`lucide-react` — keep them in sync across `package.json`, the `external` list in
112+
`tsup.config.ts`, and each item's `dependencies` in `registry.ts`. No framework
113+
dependencies: `NavBar` needs link rendering, so it takes a `linkComponent` prop
114+
defaulting to `"a"` rather than importing `next/link` — that keeps the library usable
115+
in Vite, Remix, or plain React.
99116
100117
## Adding a component
101118

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ the components render unstyled:
5858
content: ["./src/**/*.{ts,tsx}", "./node_modules/@babelize/elements/dist/**/*.js"],
5959
```
6060

61+
Components are styled with shadcn/ui theme tokens. In a shadcn project they pick up
62+
your theme automatically; otherwise add the tokens once — see
63+
[Theme tokens](https://elements.babelize.co/docs/getting-started/install#theme-tokens).
64+
6165
Components installed with the CLI below live in your own source tree, so they need
6266
no extra Tailwind config.
6367

‎bun.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎content/docs/getting-started/install.mdx‎

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ icon: Download
77
import { Tabs, Tab } from "fumadocs-ui/components/tabs";
88

99
Babelize Elements drops into any React + Tailwind CSS project — Next.js, Vite, Remix,
10-
or anything else that bundles React. The package ships TypeScript types, both ESM and
11-
CJS builds, and no runtime dependencies beyond React and Tailwind CSS.
10+
or anything else that bundles React. The package ships TypeScript types and both ESM and
11+
CJS builds. Runtime dependencies are small and standard in the shadcn ecosystem:
12+
`motion` for animation and `lucide-react` for icons.
1213

1314
## Package Manager
1415

@@ -57,6 +58,99 @@ This step is only for the npm package. Components installed with the
5758
[shadcn CLI](/docs/getting-started/shadcn-cli) live in your own source tree, which
5859
Tailwind already scans.
5960

61+
## Theme tokens
62+
63+
Components are styled with [shadcn/ui](https://ui.shadcn.com/docs/theming) semantic
64+
tokens — `bg-popover`, `text-muted-foreground`, `ring-ring`, and so on — so they
65+
pick up your app's theme, radius, and dark mode automatically.
66+
67+
**Already using shadcn/ui?** Nothing to do: `shadcn init` defined the tokens.
68+
69+
**Not using shadcn/ui?** Add the tokens once to the CSS file that imports Tailwind.
70+
This is the shadcn neutral theme; change any value to match your brand.
71+
72+
```css title="app/globals.css"
73+
/* Make `dark:` follow the `.dark` class, as the tokens below do. */
74+
@custom-variant dark (&:is(.dark *));
75+
76+
:root {
77+
--radius: 0.625rem;
78+
--background: oklch(1 0 0);
79+
--foreground: oklch(0.145 0 0);
80+
--card: oklch(1 0 0);
81+
--card-foreground: oklch(0.145 0 0);
82+
--popover: oklch(1 0 0);
83+
--popover-foreground: oklch(0.145 0 0);
84+
--primary: oklch(0.205 0 0);
85+
--primary-foreground: oklch(0.985 0 0);
86+
--secondary: oklch(0.97 0 0);
87+
--secondary-foreground: oklch(0.205 0 0);
88+
--muted: oklch(0.97 0 0);
89+
--muted-foreground: oklch(0.556 0 0);
90+
--accent: oklch(0.97 0 0);
91+
--accent-foreground: oklch(0.205 0 0);
92+
--destructive: oklch(0.577 0.245 27.325);
93+
--border: oklch(0.922 0 0);
94+
--input: oklch(0.922 0 0);
95+
--ring: oklch(0.708 0 0);
96+
}
97+
98+
.dark {
99+
--background: oklch(0.145 0 0);
100+
--foreground: oklch(0.985 0 0);
101+
--card: oklch(0.205 0 0);
102+
--card-foreground: oklch(0.985 0 0);
103+
--popover: oklch(0.205 0 0);
104+
--popover-foreground: oklch(0.985 0 0);
105+
--primary: oklch(0.922 0 0);
106+
--primary-foreground: oklch(0.205 0 0);
107+
--secondary: oklch(0.269 0 0);
108+
--secondary-foreground: oklch(0.985 0 0);
109+
--muted: oklch(0.269 0 0);
110+
--muted-foreground: oklch(0.708 0 0);
111+
--accent: oklch(0.269 0 0);
112+
--accent-foreground: oklch(0.985 0 0);
113+
--destructive: oklch(0.704 0.191 22.216);
114+
--border: oklch(1 0 0 / 10%);
115+
--input: oklch(1 0 0 / 15%);
116+
--ring: oklch(0.556 0 0);
117+
}
118+
119+
@theme inline {
120+
--radius-sm: calc(var(--radius) - 4px);
121+
--radius-md: calc(var(--radius) - 2px);
122+
--radius-lg: var(--radius);
123+
--radius-xl: calc(var(--radius) + 4px);
124+
--color-background: var(--background);
125+
--color-foreground: var(--foreground);
126+
--color-card: var(--card);
127+
--color-card-foreground: var(--card-foreground);
128+
--color-popover: var(--popover);
129+
--color-popover-foreground: var(--popover-foreground);
130+
--color-primary: var(--primary);
131+
--color-primary-foreground: var(--primary-foreground);
132+
--color-secondary: var(--secondary);
133+
--color-secondary-foreground: var(--secondary-foreground);
134+
--color-muted: var(--muted);
135+
--color-muted-foreground: var(--muted-foreground);
136+
--color-accent: var(--accent);
137+
--color-accent-foreground: var(--accent-foreground);
138+
--color-destructive: var(--destructive);
139+
--color-border: var(--border);
140+
--color-input: var(--input);
141+
--color-ring: var(--ring);
142+
}
143+
```
144+
145+
On Tailwind v3, map the same variables under `theme.extend.colors` in
146+
`tailwind.config.js`, as in the
147+
[shadcn v3 guide](https://v3.shadcn.com/docs/theming). Components are designed for
148+
Tailwind v4; on v3 they work, but some v4-only utilities (such as `shadow-xs`) fall
149+
back to no effect.
150+
151+
Every component also takes a `classNames` prop for per-part overrides, so you can
152+
restyle any slot without forking the source.
153+
60154
## Install individual components
61155

62156
Prefer installing components one at a time, straight into your codebase? Use the [shadcn CLI](/docs/getting-started/shadcn-cli):

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
},
8181
"dependencies": {
8282
"clsx": "^2.1.1",
83+
"lucide-react": "^1.28.0",
84+
"motion": "^12.43.0",
8385
"tailwind-merge": "^3.6.0"
8486
},
8587
"devDependencies": {
@@ -97,8 +99,6 @@
9799
"fumadocs-mdx": "^15.2.2",
98100
"fumadocs-ui": "^16.14.0",
99101
"jsdom": "^30.0.1",
100-
"lucide-react": "^1.28.0",
101-
"motion": "^12.43.0",
102102
"next": "16.4.0",
103103
"next-themes": "^0.4.6",
104104
"prettier": "^3.9.6",

‎src/app/globals.css‎

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,86 @@
1515
--font-mono: var(--font-geist-mono);
1616
}
1717

18-
/* ── Site chrome tokens (light/dark) ── */
19-
:root {
18+
/*
19+
* ── shadcn/ui theme tokens ──
20+
* The registry components are styled with shadcn's semantic tokens, so they take
21+
* on whatever theme the consuming app defines. These are the docs site's values:
22+
* shadcn neutral, with the Babelize emerald as `primary` and `ring`.
23+
*
24+
* `.light` comes last so the docs preview stage can render a light island inside
25+
* the dark site shell — see the `@variant dark` above.
26+
*/
27+
:root,
28+
.light {
29+
--radius: 0.625rem;
2030
--background: #ffffff;
2131
--foreground: #111111;
32+
--card: #ffffff;
33+
--card-foreground: #111111;
34+
--popover: #ffffff;
35+
--popover-foreground: #111111;
36+
--primary: #00bd7d;
37+
--primary-foreground: #ffffff;
38+
--secondary: #f4f4f5;
39+
--secondary-foreground: #18181b;
2240
--muted: #f4f4f5;
41+
--muted-foreground: #71717a;
42+
--accent: #f4f4f5;
43+
--accent-foreground: #18181b;
44+
--destructive: #e7000b;
45+
--border: #e4e4e7;
46+
--input: #e4e4e7;
47+
--ring: #00bd7d;
2348
}
2449

2550
.dark {
2651
--background: #0a0a0a;
2752
--foreground: #ededed;
53+
--card: #111111;
54+
--card-foreground: #ededed;
55+
--popover: #111111;
56+
--popover-foreground: #ededed;
57+
--primary: #26d996;
58+
--primary-foreground: #00120c;
59+
--secondary: #1c1c1e;
60+
--secondary-foreground: #ededed;
2861
--muted: #131313;
62+
--muted-foreground: #8a8a8a;
63+
--accent: #1f1f22;
64+
--accent-foreground: #ededed;
65+
--destructive: #ff6467;
66+
--border: rgba(255, 255, 255, 0.1);
67+
--input: rgba(255, 255, 255, 0.14);
68+
--ring: #26d996;
69+
}
70+
71+
.light {
72+
color-scheme: light;
73+
}
74+
75+
@theme inline {
76+
--radius-sm: calc(var(--radius) - 4px);
77+
--radius-md: calc(var(--radius) - 2px);
78+
--radius-lg: var(--radius);
79+
--radius-xl: calc(var(--radius) + 4px);
80+
--color-background: var(--background);
81+
--color-foreground: var(--foreground);
82+
--color-card: var(--card);
83+
--color-card-foreground: var(--card-foreground);
84+
--color-popover: var(--popover);
85+
--color-popover-foreground: var(--popover-foreground);
86+
--color-primary: var(--primary);
87+
--color-primary-foreground: var(--primary-foreground);
88+
--color-secondary: var(--secondary);
89+
--color-secondary-foreground: var(--secondary-foreground);
90+
--color-muted: var(--muted);
91+
--color-muted-foreground: var(--muted-foreground);
92+
--color-accent: var(--accent);
93+
--color-accent-foreground: var(--accent-foreground);
94+
--color-destructive: var(--destructive);
95+
--color-border: var(--border);
96+
--color-input: var(--input);
97+
--color-ring: var(--ring);
2998
}
3099

31100
/* ── Babelize brand: emerald accent ── */

‎src/components/docs/preview-shell.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function PreviewShell({ code, highlighted, fullBleed, children }: Preview
6363
// `light` is what turns the stage back off inside the dark site shell —
6464
// the absence of `dark` is not enough, see the `@variant` in globals.css.
6565
previewDark ? "dark" : "light",
66-
"bg-white text-zinc-900 dark:bg-zinc-950 dark:text-zinc-50",
66+
"bg-background text-foreground",
6767
)}
6868
>
6969
{fullBleed ? (

‎test/setup.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import "@testing-library/jest-dom/vitest";
2+
import { MotionGlobalConfig } from "motion/react";
23

34
class ResizeObserverMock {
45
observe() {}
@@ -7,3 +8,7 @@ class ResizeObserverMock {
78
}
89

910
globalThis.ResizeObserver = ResizeObserverMock;
11+
12+
// Animations would hold closed popups in the DOM while they fade out; tests
13+
// assert on the settled state.
14+
MotionGlobalConfig.skipAnimations = true;

‎tsup.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default defineConfig([
1414
entry: { index: "src/registry/components/index.ts" },
1515
format: ["esm", "cjs"],
1616
dts: true,
17-
external: ["react", "react-dom", "next", "clsx", "tailwind-merge"],
17+
external: ["react", "react-dom", "next", "clsx", "tailwind-merge", "lucide-react", "motion"],
1818
// Every component in this entry is stateful, and bundling strips the
1919
// per-file directives. Without this the package throws
2020
// "useState is not a function" the moment a React Server Component

0 commit comments

Comments
 (0)