@skriv/ads 0.1.0 → 0.2.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 +5 -3
- package/bin/ads.mjs +1 -1
- package/dist/manifest.json +22 -5
- package/dist/skills/ads-init/SKILL.md +2 -0
- package/dist/skills/ads-init/profile.md +1 -1
- package/dist/skills/heroui-theming/LICENSE.txt +199 -0
- package/dist/skills/heroui-theming/SKILL.md +268 -0
- package/dist/skills/heroui-theming/references/any-framework.md +219 -0
- package/dist/skills/heroui-theming/references/components.md +237 -0
- package/dist/skills/heroui-theming/references/theme-recipe.md +701 -0
- package/dist/skills/heroui-theming/references/tokens.md +258 -0
- package/dist/skills/heroui-theming/scripts/_styles_dir.mjs +112 -0
- package/dist/skills/heroui-theming/scripts/list_component_classes.mjs +319 -0
- package/dist/skills/heroui-theming/scripts/list_tokens.mjs +157 -0
- package/dist/templates/routing.md +2 -0
- package/dist/templates/theming.md +26 -0
- package/package.json +21 -6
- package/src/install.mjs +3 -2
|
@@ -0,0 +1,701 @@
|
|
|
1
|
+
# Theme Recipe: Authoring a Complete HeroUI Theme
|
|
2
|
+
|
|
3
|
+
A HeroUI theme is a small folder of CSS: token values for a light and a dark mode, plus per-component BEM overrides for whatever tokens cannot express. No JavaScript, no changes to `@heroui/react`, nothing in `node_modules`.
|
|
4
|
+
|
|
5
|
+
## Anatomy
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
src/themes/<name>/
|
|
9
|
+
├── index.css # entry: imports the two files below into the right layers
|
|
10
|
+
├── variables.css # token values for <name>-light and <name>-dark
|
|
11
|
+
└── components/
|
|
12
|
+
├── index.css # imports each component override
|
|
13
|
+
├── button.css # one file per component, named like the HeroUI stylesheet
|
|
14
|
+
└── …
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Optional: `utilities.css` (theme `@utility` / `@theme` definitions) and font loading, both imported **before** the layered imports and **without** `layer()`.
|
|
18
|
+
|
|
19
|
+
## Step 0 — Turn the brief into decisions
|
|
20
|
+
|
|
21
|
+
Write these down before touching CSS. Every answer maps to tokens.
|
|
22
|
+
|
|
23
|
+
| Decision | Question | Tokens |
|
|
24
|
+
| --------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------- |
|
|
25
|
+
| Neutrals | Tinted or pure gray? What hue? | `--background`, `--surface*`, `--overlay`, `--default`, `--muted`, `--border`, `--separator`, `--snow`, `--eclipse` |
|
|
26
|
+
| Brand | Accent color; is text on it light or dark? | `--accent`, `--accent-foreground`, `--focus`, `--link` |
|
|
27
|
+
| Status | Keep defaults or re-tune to the palette? | `--success`, `--warning`, `--danger` (+ `-foreground`) |
|
|
28
|
+
| Shape | Sharp, soft, or pill? | `--radius`, `--field-radius` |
|
|
29
|
+
| Elevation | Soft shadows, hard shadows, borders, or flat? | `--surface-shadow`, `--overlay-shadow`, `--field-shadow` |
|
|
30
|
+
| Material | How do "on" states feel: flat, raised, pressed-in, outlined? | `--<name>-raised`, `--<name>-pressed` on every "on" selector ([Material](#material-one-look-for-every-on-state)) |
|
|
31
|
+
| Fields | Filled or outlined? | `--field-background`, `--field-border`, `--field-border-width` |
|
|
32
|
+
| Type | Custom font? | `--font-sans` (Tailwind's token) |
|
|
33
|
+
| Signature | The one or two details that make it recognizable | theme tokens `--<name>-*` + component overrides |
|
|
34
|
+
|
|
35
|
+
Work **tokens first**. Most of a theme is `variables.css`; add a component file only when a token cannot do it.
|
|
36
|
+
|
|
37
|
+
**Tinted neutrals.** Pick one hue for every neutral and let chroma do the tinting: roughly `0.008–0.012` for the page and surfaces, `0.015–0.02` for borders and field outlines, `0.03` for `--muted`. Status colors stay untinted. Point the derived neutrals at a few base ones (`--overlay: var(--surface)`), so whoever brands the theme later changes three values instead of twelve.
|
|
38
|
+
|
|
39
|
+
## Step 1 — Scaffold
|
|
40
|
+
|
|
41
|
+
`index.css`:
|
|
42
|
+
|
|
43
|
+
```css
|
|
44
|
+
/* <Name> theme for HeroUI */
|
|
45
|
+
|
|
46
|
+
/* Theme variables (palette, radius, shadows, theme tokens) */
|
|
47
|
+
@import "./variables.css" layer(theme);
|
|
48
|
+
|
|
49
|
+
/* Component overrides (BEM classes) */
|
|
50
|
+
@import "./components/index.css" layer(components);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`variables.css`:
|
|
54
|
+
|
|
55
|
+
```css
|
|
56
|
+
.<name>-light,
|
|
57
|
+
[data-theme="<name>-light"] {
|
|
58
|
+
color-scheme: light;
|
|
59
|
+
/* tokens */
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.<name>-dark,
|
|
63
|
+
[data-theme="<name>-dark"] {
|
|
64
|
+
color-scheme: dark;
|
|
65
|
+
/* tokens */
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`components/index.css`:
|
|
70
|
+
|
|
71
|
+
```css
|
|
72
|
+
/* <Name> Theme - Component Overrides */
|
|
73
|
+
@import "./button.css";
|
|
74
|
+
@import "./card.css";
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Why this shape:
|
|
78
|
+
|
|
79
|
+
- `layer(theme)` puts your tokens in HeroUI's `theme` layer, above the default theme, so they win without `!important` or extra specificity.
|
|
80
|
+
- `layer(components)` appends your overrides after HeroUI's component CSS in the same layer, and keeps them below `utilities`, so `className` overrides on a single element still work.
|
|
81
|
+
- The class + attribute selector pair lets the app activate the theme with either `class` or `data-theme` (theme switchers differ).
|
|
82
|
+
|
|
83
|
+
## Step 2 — Fill `variables.css`
|
|
84
|
+
|
|
85
|
+
1. List the tokens of the installed version: `node scripts/list_tokens.mjs` (reference: [tokens.md](tokens.md)).
|
|
86
|
+
2. In **each** mode, set the whole base palette — do not rely on the default theme for the dark mode: `<name>-dark` does not match HeroUI's `.dark` / `[data-theme="dark"]` selector, so anything you leave out falls back to the **light** defaults.
|
|
87
|
+
3. Set `color-scheme` in each block (native controls, scrollbars, and `light-dark()` follow it).
|
|
88
|
+
4. Use `oklch()` for every color. Keep hue constant across a neutral ramp; move lightness.
|
|
89
|
+
5. Change colors in pairs: `--x` and `--x-foreground` must stay readable together (aim for WCAG AA: 4.5:1 for text).
|
|
90
|
+
6. Leave calculated tokens (`--accent-hover`, `--accent-soft`, `--field-hover`, `--border-secondary`…) alone; they recompute from your base tokens. Re-declare one only when the result is wrong for your palette.
|
|
91
|
+
7. Put theme-specific values in `--<name>-*` tokens (one value per mode) and read them from component overrides.
|
|
92
|
+
8. Shadow tokens must always be a shadow: use `0 0 0 0 transparent`, never `none` (a `none` breaks focus rings).
|
|
93
|
+
|
|
94
|
+
## Step 3 — Component overrides
|
|
95
|
+
|
|
96
|
+
For each override:
|
|
97
|
+
|
|
98
|
+
1. `node scripts/list_component_classes.mjs <component> --css` — read the real selectors, states, and custom properties ([components.md](components.md)).
|
|
99
|
+
2. Create `components/<component>.css`, add it to `components/index.css`.
|
|
100
|
+
3. Write the smallest rule that works. In order of preference: re-assign the component's custom properties → `@apply` utilities → raw declarations.
|
|
101
|
+
4. For state styles, copy the base selector list (pseudo-class **and** data attribute).
|
|
102
|
+
5. Match the specificity of the rule you are replacing, and re-assert modifiers that your block rule would clobber.
|
|
103
|
+
6. Read colors from tokens. A hardcoded color in a component file will be wrong in the other mode.
|
|
104
|
+
|
|
105
|
+
Overrides are **not** scoped to the theme selector: once the file is imported, they apply to the whole app. That is the intended model — one theme stylesheet per app, with the light/dark split handled by tokens. If several themes must be switchable at runtime, see "Several themes in one app" below.
|
|
106
|
+
|
|
107
|
+
## Step 4 — Import it
|
|
108
|
+
|
|
109
|
+
```css
|
|
110
|
+
/* app/globals.css */
|
|
111
|
+
@import "tailwindcss";
|
|
112
|
+
@import "@heroui/styles";
|
|
113
|
+
@import "../themes/<name>/index.css";
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Order matters: Tailwind, then HeroUI, then the theme. The theme import itself has no `layer()` (its children already do).
|
|
117
|
+
|
|
118
|
+
## Step 5 — Activate it
|
|
119
|
+
|
|
120
|
+
Importing is not enough; one mode must be active on `<html>`:
|
|
121
|
+
|
|
122
|
+
```html
|
|
123
|
+
<html data-theme="<name>-light">
|
|
124
|
+
<body class="bg-background text-foreground">
|
|
125
|
+
…
|
|
126
|
+
</body>
|
|
127
|
+
</html>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
- Switch modes by changing the attribute to `<name>-dark`. A class works too: `<html class="<name>-dark">`.
|
|
131
|
+
- Always on `<html>`: overlays render in a portal under `<body>`, and calculated tokens only recompute on the root.
|
|
132
|
+
- With `next-themes`: `<ThemeProvider attribute="data-theme" value={{light: "<name>-light", dark: "<name>-dark"}} enableSystem>`.
|
|
133
|
+
- If app code uses Tailwind's `dark:` variant: HeroUI's `dark:` matches `.dark` / `[data-theme="dark"]` only. Either keep `class="dark"` on `<html>` next to `data-theme="<name>-dark"`, or redefine the variant after the HeroUI import:
|
|
134
|
+
|
|
135
|
+
```css
|
|
136
|
+
@custom-variant dark (&:where(.dark, .dark *, [data-theme="dark"], [data-theme="dark"] *, .<name>-dark, .<name>-dark *, [data-theme="<name>-dark"], [data-theme="<name>-dark"] *));
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
This covers both the attribute and the class form of `<name>-dark` and keeps the default `.dark` / `[data-theme="dark"]` matches. It replaces HeroUI's definition, which also falls back to `prefers-color-scheme: dark` and styles `::before` / `::after`; `dark:` now follows only the explicit theme.
|
|
140
|
+
|
|
141
|
+
To make the theme the app's only look (no attribute needed), add the root to the selectors: `:root, .<name>-light, [data-theme="<name>-light"]` for light and `.dark, .<name>-dark, [data-theme="<name>-dark"]` for dark.
|
|
142
|
+
|
|
143
|
+
## Step 6 — Verify
|
|
144
|
+
|
|
145
|
+
Build the app's CSS (a wrong utility name in `@apply` fails the build), then check both modes. Minimum pass:
|
|
146
|
+
|
|
147
|
+
- [ ] Page canvas and text: `bg-background` / `text-foreground` on `<body>`
|
|
148
|
+
- [ ] Buttons: every variant, hover, pressed, **keyboard focus ring**, disabled
|
|
149
|
+
- [ ] Fields: Input, Select, Checkbox, Radio, Switch — rest, hover, focus, invalid, disabled; placeholder contrast
|
|
150
|
+
- [ ] Surfaces: Card (all variants), Accordion, Table, Tabs (selected indicator)
|
|
151
|
+
- [ ] Overlays: Popover/Dropdown/Select list, Tooltip (and its arrow), Modal + backdrop, Toast — background, shadow/outline, radius
|
|
152
|
+
- [ ] Soft colors: Chip/Badge/Alert in accent, success, warning, danger — text contrast on the soft fill
|
|
153
|
+
- [ ] Reduced motion: new transitions stop with `prefers-reduced-motion`
|
|
154
|
+
- [ ] No leftover unlayered `:root { --token }` overrides fighting the theme
|
|
155
|
+
|
|
156
|
+
## Material: one look for every "on" state
|
|
157
|
+
|
|
158
|
+
A theme feels designed when everything that is **on** looks made of the same stuff: the primary button, a checked switch, a selected day, a slider's fill, a progress bar. Pick the treatment once, as tokens, and apply it to every "on" selector.
|
|
159
|
+
|
|
160
|
+
**1. Define the material per mode.** Shadows that read in light vanish in dark, so dark needs a different structure, not just darker values: a light inner edge on top and a black ring around, instead of a soft drop.
|
|
161
|
+
|
|
162
|
+
```css
|
|
163
|
+
/* variables.css */
|
|
164
|
+
.<name>-light,
|
|
165
|
+
[data-theme="<name>-light"] {
|
|
166
|
+
/* raised: a lit top edge plus a short drop */
|
|
167
|
+
--<name>-raised: inset 0 1px 0 0 oklch(100% 0 0 / 0.2), 0 1px 2px oklch(0% 0 0 / 0.08), 0 3px 6px -2px oklch(0% 0 0 / 0.06);
|
|
168
|
+
/* pressed: pushed into the surface */
|
|
169
|
+
--<name>-pressed: inset 0 1px 2px oklch(0% 0 0 / 0.08), inset 0 0 4px oklch(0% 0 0 / 0.06);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.<name>-dark,
|
|
173
|
+
[data-theme="<name>-dark"] {
|
|
174
|
+
--<name>-raised: inset 0 1px 0 0 oklch(100% 0 0 / 0.2), 0 0 0 1px oklch(0% 0 0 / 0.4), 0 3px 6px -2px oklch(0% 0 0 / 0.3);
|
|
175
|
+
--<name>-pressed: inset 0 1px 1px oklch(100% 0 0 / 0.08);
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**2. Apply it to every "on" selector.** These are the ones in `@heroui/styles` 3.2.x (re-run `list_component_classes.mjs` for your version):
|
|
180
|
+
|
|
181
|
+
| "On" state | Selector | Watch out for |
|
|
182
|
+
| ------------------------- | ------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------- |
|
|
183
|
+
| Filled buttons | `.button--primary`, `.button--danger` | Focusable: use shadow utilities |
|
|
184
|
+
| Switch on | `.switch[data-selected="true"] .switch__control` (+ `[aria-checked="true"]`) | Focusable |
|
|
185
|
+
| Checkbox on | `.checkbox[data-selected="true"] .checkbox__control` (+ `[aria-checked="true"]`) | The control draws its fill with `::before` |
|
|
186
|
+
| Radio on | `.radio[data-selected] .radio__control` | The indicator draws its dot with `::before` |
|
|
187
|
+
| Toggle button on | `.toggle-button[data-selected="true"]` | Focusable |
|
|
188
|
+
| Selected tab | `.tabs__indicator` | Line-style tabs reuse it as an underline |
|
|
189
|
+
| Slider | `.slider__fill`, `.slider__thumb` | The thumb draws its knob with `::after`: style the `::after` |
|
|
190
|
+
| Progress and meter | `.progress-bar__fill`, `.meter__fill` | The track clips: set `overflow: visible` on the track for shadow |
|
|
191
|
+
| Progress circle | `.progress-circle__fill-circle` | SVG: use `stroke`, not `box-shadow` |
|
|
192
|
+
| Selected day | `.calendar__cell[data-selected="true"]` | Focusable |
|
|
193
|
+
| Range ends | `.range-calendar__cell[data-selection-start="true"] .range-calendar__cell-button` (and `data-selection-end`) | Skip `[data-outside-month="true"]` |
|
|
194
|
+
| Pressed (not filled) | `.button--secondary`, `--tertiary`, `--ghost` with `:active, [data-pressed="true"]` | Not inside `.button-group`, whose buttons share edges |
|
|
195
|
+
|
|
196
|
+
```css
|
|
197
|
+
/* components/button.css */
|
|
198
|
+
.button--primary,
|
|
199
|
+
.button--danger {
|
|
200
|
+
@apply shadow-(--<name>-raised);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.button--secondary,
|
|
204
|
+
.button--tertiary,
|
|
205
|
+
.button--ghost {
|
|
206
|
+
&:active,
|
|
207
|
+
&[data-pressed="true"] {
|
|
208
|
+
@apply shadow-(--<name>-pressed);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
.button-group .button {
|
|
213
|
+
&:active,
|
|
214
|
+
&[data-pressed="true"] {
|
|
215
|
+
@apply shadow-none;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
**3. Light the fill with a gradient, not a pseudo-element.** `background-image: linear-gradient(oklch(1 0 0 / 0.14), transparent)` sits on top of `background-color` without adding a `::before`, which the checkbox, radio indicator and slider thumb already use. Keep the gradient in a token (`--<name>-light`) so dark can dim it. Inside a track that clips (progress, meter, slider fill), use only the inset half of the material: the outer drop is cut off.
|
|
221
|
+
|
|
222
|
+
**4. Check the list in both modes.** A material applied to buttons only looks like a bug on the switch next to them.
|
|
223
|
+
|
|
224
|
+
## Restyling a theme you didn't write
|
|
225
|
+
|
|
226
|
+
Presets (HeroUI Pro's themes, a design team's package) give you the **material**; your product supplies the **palette**. Keep them in two files and let the palette load last:
|
|
227
|
+
|
|
228
|
+
```css
|
|
229
|
+
/* app/globals.css */
|
|
230
|
+
@import "tailwindcss";
|
|
231
|
+
@import "@heroui/styles";
|
|
232
|
+
@import "<preset>/index.css"; /* tokens in layer(theme), overrides in layer(components) */
|
|
233
|
+
@import "./brand.css" layer(theme); /* your palette, after the preset in the same layer */
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
1. **Use the preset's selectors.** Same layer and same specificity means the later file wins. If the preset keys its tokens on `[data-theme="<preset>-light"]`, so does `brand.css`. A bare `:root` block only wins by accident.
|
|
237
|
+
2. **Replace the palette, keep the material.** Override the colors (`--background`, `--surface*`, `--default`, `--accent`, `--muted`, `--border`, `--separator`, `--radius`) and leave the preset's `--<preset>-*` material tokens alone. To tune the material, redefine those tokens; don't copy the component overrides.
|
|
238
|
+
3. **Find every token the preset tints.** A purple preset tints more than the obvious ones: `--overlay`, `--surface-tertiary`, `--field-background`, `--field-border`, `--backdrop`, `--scrollbar-thumb`, `--chart-*`. Run `list_tokens.mjs` and diff it against the preset's file. Point them at your palette instead of giving each a value:
|
|
239
|
+
|
|
240
|
+
```css
|
|
241
|
+
[data-theme="<preset>-light"],
|
|
242
|
+
[data-theme="<preset>-dark"] {
|
|
243
|
+
--overlay: var(--surface);
|
|
244
|
+
--surface-tertiary: var(--default);
|
|
245
|
+
--field-background: var(--surface);
|
|
246
|
+
--field-border: var(--border);
|
|
247
|
+
--scrollbar-thumb: color-mix(in oklch, var(--foreground) 15%, transparent);
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
One block covers both modes because the `var()`s resolve on the element that holds the mode. Declare it on the theme's own selectors, not on `:root` (see "Calculated tokens resolve where they are declared" in [tokens.md](tokens.md)).
|
|
252
|
+
|
|
253
|
+
4. **Unlayered works, at a price.** Importing `brand.css` without `layer()` also beats the preset, since unlayered CSS beats every layer. Nothing in a layer can adjust those tokens afterwards, and a later named theme silently loses to them.
|
|
254
|
+
|
|
255
|
+
## Optional pieces
|
|
256
|
+
|
|
257
|
+
### Fonts
|
|
258
|
+
|
|
259
|
+
Set Tailwind's `--font-sans` in both theme blocks: `--font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;`. Load the font the way the framework prefers (`next/font`, a `<link>`, or `@font-face`). If you use `@import url(…)`, it must be the first import in `index.css`.
|
|
260
|
+
|
|
261
|
+
### Theme utilities and Tailwind tokens
|
|
262
|
+
|
|
263
|
+
`@utility` cannot be nested in a layer, so keep these in a file imported without `layer()`:
|
|
264
|
+
|
|
265
|
+
```css
|
|
266
|
+
/* themes/<name>/utilities.css */
|
|
267
|
+
@theme inline {
|
|
268
|
+
--color-<name>-edge: var(--<name>-edge); /* enables border-<name>-edge, bg-<name>-edge… */
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
@utility <name>-keycap {
|
|
272
|
+
@apply shadow-[0_var(--<name>-depth)_0_0_var(--<name>-edge)];
|
|
273
|
+
}
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
```css
|
|
277
|
+
/* themes/<name>/index.css */
|
|
278
|
+
@import "./utilities.css";
|
|
279
|
+
@import "./variables.css" layer(theme);
|
|
280
|
+
@import "./components/index.css" layer(components);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Text that scales, corners that don't
|
|
284
|
+
|
|
285
|
+
For a text-size setting (Small / Default / Large), change the root `font-size` and keep **text in rem, shape in px**. HeroUI's defaults are rem, so set `--radius` and `--spacing` in px to keep corners and padding fixed while the text grows:
|
|
286
|
+
|
|
287
|
+
```css
|
|
288
|
+
@theme {
|
|
289
|
+
--spacing: 4px;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
[data-theme="<name>-light"],
|
|
293
|
+
[data-theme="<name>-dark"] {
|
|
294
|
+
--radius: 8px;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
html[data-text-size="large"] {
|
|
298
|
+
font-size: 17px;
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Line heights follow the spacing unit (`leading-5` is `5 × --spacing`), so pin the ones you use in rem in the same `@theme` block (`--leading-5: 1.25rem`).
|
|
303
|
+
|
|
304
|
+
### More text steps and status text
|
|
305
|
+
|
|
306
|
+
HeroUI has `--foreground` and `--muted`. Dense UIs often need one or two more steps, and status colors that are readable as **text**, not only as fills:
|
|
307
|
+
|
|
308
|
+
```css
|
|
309
|
+
[data-theme="<name>-light"] {
|
|
310
|
+
--subtle: oklch(52% 0.01 285); /* ≥ 4.5:1 on --surface and --background */
|
|
311
|
+
--faint: oklch(72% 0.01 285); /* placeholders and disabled only: may fall below 4.5:1 */
|
|
312
|
+
--danger-text: oklch(55% 0.2 25); /* --danger darkened until it passes as text */
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Give dark its own values (status text usually lightens there), write the measured ratio in a comment next to each, and map them once with `@theme inline` (`--color-subtle: var(--subtle);`) to get `text-subtle`.
|
|
317
|
+
|
|
318
|
+
**Name custom tokens so `tailwind-merge` understands them.** HeroUI merges a `className` with its own classes, and `tailwind-merge` sorts classes by name. A custom font size called `text-caption` reads as a color, so `text-caption text-muted` keeps only one of them. Use t-shirt names for sizes (`--text-2xs`, `--text-2sm`, `--text-md`), and write custom shadows and radii as variables (`shadow-(--menu-shadow)`, `rounded-(--radius-panel)`) so they are recognized as shadows and radii.
|
|
319
|
+
|
|
320
|
+
### Several themes in one app
|
|
321
|
+
|
|
322
|
+
Tokens are already scoped by selector. Component overrides are not, so wrap each file's rules in the theme selector (CSS nesting):
|
|
323
|
+
|
|
324
|
+
```css
|
|
325
|
+
:is(.arcade-light, .arcade-dark, [data-theme="arcade-light"], [data-theme="arcade-dark"]) {
|
|
326
|
+
.button {
|
|
327
|
+
@apply font-semibold;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
This also raises specificity, so scoped overrides reliably beat the base rule.
|
|
333
|
+
|
|
334
|
+
### Without Tailwind (prebuilt CSS)
|
|
335
|
+
|
|
336
|
+
When the page loads `heroui.min.css` instead of compiling with Tailwind, `@apply`, `@utility`, and `@import … layer()` through a bundler are unavailable. Write plain CSS inside the same layers: `@layer theme { [data-theme="x-light"] { … } }` and `@layer components { .button { … } }`. See [any-framework.md](any-framework.md).
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Worked example: "Arcade"
|
|
341
|
+
|
|
342
|
+
Brief: _chunky and tactile — ink outlines, generous radius, warm paper neutrals, and a hard "key cap" shadow that buttons press into._
|
|
343
|
+
|
|
344
|
+
Decisions:
|
|
345
|
+
|
|
346
|
+
| Decision | Choice |
|
|
347
|
+
| --------- | --------------------------------------------------------------------------------------------- |
|
|
348
|
+
| Neutrals | Warm paper (hue 95) in light, deep ink (hue 285) in dark; primitives tinted to match |
|
|
349
|
+
| Brand | Tangerine accent with **ink** text on it; violet focus ring so focus never blends with accent |
|
|
350
|
+
| Shape | `--radius: 0.75rem` (pill buttons, soft cards) |
|
|
351
|
+
| Elevation | No blur anywhere: hard offset shadows; overlays get their outline from the shadow token |
|
|
352
|
+
| Fields | Outlined (2px ink), flat |
|
|
353
|
+
| Signature | `--arcade-outline`, `--arcade-depth`, `--arcade-edge` + key-cap buttons |
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
src/themes/arcade/
|
|
357
|
+
├── index.css
|
|
358
|
+
├── variables.css
|
|
359
|
+
└── components/
|
|
360
|
+
├── index.css
|
|
361
|
+
├── button.css
|
|
362
|
+
├── card.css
|
|
363
|
+
├── chip.css
|
|
364
|
+
├── switch.css
|
|
365
|
+
└── tooltip.css
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
**`themes/arcade/index.css`**
|
|
369
|
+
|
|
370
|
+
```css
|
|
371
|
+
/* Arcade theme for HeroUI
|
|
372
|
+
Chunky and tactile: ink outlines, generous radius, and a hard "key cap"
|
|
373
|
+
shadow that buttons press into. */
|
|
374
|
+
|
|
375
|
+
/* Theme variables (palette, radius, shadows, arcade tokens) */
|
|
376
|
+
@import "./variables.css" layer(theme);
|
|
377
|
+
|
|
378
|
+
/* Component overrides (BEM classes) */
|
|
379
|
+
@import "./components/index.css" layer(components);
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
**`themes/arcade/variables.css`**
|
|
383
|
+
|
|
384
|
+
```css
|
|
385
|
+
/* Arcade Theme Variables */
|
|
386
|
+
|
|
387
|
+
.arcade-light,
|
|
388
|
+
[data-theme="arcade-light"] {
|
|
389
|
+
color-scheme: light;
|
|
390
|
+
|
|
391
|
+
/* Primitives: tinted ink and paper instead of neutral black and white */
|
|
392
|
+
--snow: oklch(0.985 0.012 95);
|
|
393
|
+
--eclipse: oklch(0.24 0.03 285);
|
|
394
|
+
|
|
395
|
+
/* Arcade tokens (theme-specific, read by the component overrides) */
|
|
396
|
+
--arcade-outline: 2px;
|
|
397
|
+
--arcade-depth: 3px;
|
|
398
|
+
--arcade-edge: var(--eclipse);
|
|
399
|
+
|
|
400
|
+
/* Base */
|
|
401
|
+
--background: oklch(0.972 0.02 95);
|
|
402
|
+
--foreground: var(--eclipse);
|
|
403
|
+
|
|
404
|
+
/* Surfaces */
|
|
405
|
+
--surface: oklch(0.995 0.008 95);
|
|
406
|
+
--surface-foreground: var(--foreground);
|
|
407
|
+
--surface-secondary: oklch(0.955 0.022 95);
|
|
408
|
+
--surface-secondary-foreground: var(--foreground);
|
|
409
|
+
--surface-tertiary: oklch(0.935 0.026 95);
|
|
410
|
+
--surface-tertiary-foreground: var(--foreground);
|
|
411
|
+
|
|
412
|
+
/* Overlays */
|
|
413
|
+
--overlay: oklch(0.995 0.008 95);
|
|
414
|
+
--overlay-foreground: var(--foreground);
|
|
415
|
+
--backdrop: oklch(0.24 0.03 285 / 0.45);
|
|
416
|
+
|
|
417
|
+
/* Neutrals */
|
|
418
|
+
--muted: oklch(0.5 0.03 285);
|
|
419
|
+
--default: oklch(0.925 0.028 95);
|
|
420
|
+
--default-foreground: var(--eclipse);
|
|
421
|
+
--segment: var(--surface);
|
|
422
|
+
--segment-foreground: var(--foreground);
|
|
423
|
+
|
|
424
|
+
/* Accent and status */
|
|
425
|
+
--accent: oklch(0.74 0.17 55);
|
|
426
|
+
--accent-foreground: var(--eclipse);
|
|
427
|
+
--success: oklch(0.78 0.17 150);
|
|
428
|
+
--success-foreground: var(--eclipse);
|
|
429
|
+
--warning: oklch(0.85 0.16 90);
|
|
430
|
+
--warning-foreground: var(--eclipse);
|
|
431
|
+
--danger: oklch(0.65 0.22 25);
|
|
432
|
+
--danger-foreground: var(--snow);
|
|
433
|
+
|
|
434
|
+
/* Calculated token, re-declared: the default mix is too pale on cream */
|
|
435
|
+
--accent-soft-foreground: color-mix(in oklab, var(--accent) 45%, var(--foreground) 55%);
|
|
436
|
+
|
|
437
|
+
/* Fields: flat wells with an ink outline */
|
|
438
|
+
--field-background: var(--surface);
|
|
439
|
+
--field-foreground: var(--foreground);
|
|
440
|
+
--field-placeholder: var(--muted);
|
|
441
|
+
--field-border: var(--arcade-edge);
|
|
442
|
+
--field-border-width: var(--arcade-outline);
|
|
443
|
+
--field-border-hover: var(--arcade-edge);
|
|
444
|
+
--field-border-focus: var(--focus);
|
|
445
|
+
|
|
446
|
+
/* Lines and focus */
|
|
447
|
+
--border: var(--arcade-edge);
|
|
448
|
+
--separator: oklch(0.24 0.03 285 / 0.16);
|
|
449
|
+
--focus: oklch(0.55 0.22 285);
|
|
450
|
+
--link: var(--foreground);
|
|
451
|
+
|
|
452
|
+
/* Shape */
|
|
453
|
+
--radius: 0.75rem;
|
|
454
|
+
--field-radius: 0.875rem;
|
|
455
|
+
|
|
456
|
+
/* Elevation: hard offsets, never blurred. Every shadow token stays a real
|
|
457
|
+
shadow value (never `none`) so focus rings can still compose with it. */
|
|
458
|
+
--surface-shadow: 0 var(--arcade-depth) 0 0 var(--arcade-edge);
|
|
459
|
+
--overlay-shadow:
|
|
460
|
+
0 0 0 var(--arcade-outline) var(--arcade-edge),
|
|
461
|
+
0 calc(var(--arcade-depth) * 2) 0 var(--arcade-outline) var(--arcade-edge);
|
|
462
|
+
--field-shadow: 0 0 0 0 transparent;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
.arcade-dark,
|
|
466
|
+
[data-theme="arcade-dark"] {
|
|
467
|
+
color-scheme: dark;
|
|
468
|
+
|
|
469
|
+
--snow: oklch(0.985 0.012 95);
|
|
470
|
+
--eclipse: oklch(0.24 0.03 285);
|
|
471
|
+
|
|
472
|
+
--arcade-outline: 2px;
|
|
473
|
+
--arcade-depth: 3px;
|
|
474
|
+
--arcade-edge: oklch(0.11 0.02 285);
|
|
475
|
+
|
|
476
|
+
--background: oklch(0.2 0.03 285);
|
|
477
|
+
--foreground: var(--snow);
|
|
478
|
+
|
|
479
|
+
--surface: oklch(0.26 0.035 285);
|
|
480
|
+
--surface-foreground: var(--foreground);
|
|
481
|
+
--surface-secondary: oklch(0.3 0.035 285);
|
|
482
|
+
--surface-secondary-foreground: var(--foreground);
|
|
483
|
+
--surface-tertiary: oklch(0.34 0.035 285);
|
|
484
|
+
--surface-tertiary-foreground: var(--foreground);
|
|
485
|
+
|
|
486
|
+
--overlay: oklch(0.28 0.035 285);
|
|
487
|
+
--overlay-foreground: var(--foreground);
|
|
488
|
+
--backdrop: oklch(0.11 0.02 285 / 0.6);
|
|
489
|
+
|
|
490
|
+
--muted: oklch(0.74 0.03 285);
|
|
491
|
+
--default: oklch(0.33 0.04 285);
|
|
492
|
+
--default-foreground: var(--snow);
|
|
493
|
+
--segment: oklch(0.4 0.04 285);
|
|
494
|
+
--segment-foreground: var(--foreground);
|
|
495
|
+
|
|
496
|
+
--accent: oklch(0.8 0.16 60);
|
|
497
|
+
--accent-foreground: var(--eclipse);
|
|
498
|
+
--success: oklch(0.8 0.17 150);
|
|
499
|
+
--success-foreground: var(--eclipse);
|
|
500
|
+
--warning: oklch(0.86 0.15 90);
|
|
501
|
+
--warning-foreground: var(--eclipse);
|
|
502
|
+
--danger: oklch(0.66 0.21 25);
|
|
503
|
+
--danger-foreground: var(--snow);
|
|
504
|
+
|
|
505
|
+
--field-background: oklch(0.24 0.03 285);
|
|
506
|
+
--field-foreground: var(--foreground);
|
|
507
|
+
--field-placeholder: var(--muted);
|
|
508
|
+
--field-border: var(--arcade-edge);
|
|
509
|
+
--field-border-width: var(--arcade-outline);
|
|
510
|
+
--field-border-hover: var(--arcade-edge);
|
|
511
|
+
--field-border-focus: var(--focus);
|
|
512
|
+
|
|
513
|
+
--border: var(--arcade-edge);
|
|
514
|
+
--separator: oklch(0.985 0.012 95 / 0.14);
|
|
515
|
+
--focus: oklch(0.82 0.13 285);
|
|
516
|
+
--link: var(--foreground);
|
|
517
|
+
|
|
518
|
+
--radius: 0.75rem;
|
|
519
|
+
--field-radius: 0.875rem;
|
|
520
|
+
|
|
521
|
+
--surface-shadow: 0 var(--arcade-depth) 0 0 var(--arcade-edge);
|
|
522
|
+
--overlay-shadow:
|
|
523
|
+
0 0 0 var(--arcade-outline) var(--arcade-edge),
|
|
524
|
+
0 calc(var(--arcade-depth) * 2) 0 var(--arcade-outline) var(--arcade-edge);
|
|
525
|
+
--field-shadow: 0 0 0 0 transparent;
|
|
526
|
+
}
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
What the tokens alone already did: every field is outlined, every overlay (popover, dropdown, select list, modal) has an ink outline and a hard drop, cards sit on a key-cap shadow, focus rings are violet, the whole radius scale is rounder. The component files below only add what tokens cannot.
|
|
530
|
+
|
|
531
|
+
**`themes/arcade/components/index.css`**
|
|
532
|
+
|
|
533
|
+
```css
|
|
534
|
+
/* Arcade Theme - Component Overrides */
|
|
535
|
+
|
|
536
|
+
/* Buttons */
|
|
537
|
+
@import "./button.css";
|
|
538
|
+
|
|
539
|
+
/* Controls */
|
|
540
|
+
@import "./switch.css";
|
|
541
|
+
|
|
542
|
+
/* Data display */
|
|
543
|
+
@import "./chip.css";
|
|
544
|
+
|
|
545
|
+
/* Layout */
|
|
546
|
+
@import "./card.css";
|
|
547
|
+
|
|
548
|
+
/* Overlays */
|
|
549
|
+
@import "./tooltip.css";
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
**`themes/arcade/components/button.css`**
|
|
553
|
+
|
|
554
|
+
```css
|
|
555
|
+
/* Arcade Theme - Button */
|
|
556
|
+
/* Every button is an outlined key cap: a hard bottom shadow that the button
|
|
557
|
+
travels into while it is pressed. */
|
|
558
|
+
|
|
559
|
+
.button {
|
|
560
|
+
/* A shadow utility (not raw box-shadow) so the focus ring still composes with it */
|
|
561
|
+
@apply font-semibold shadow-[0_var(--arcade-depth)_0_0_var(--arcade-edge)];
|
|
562
|
+
border: var(--arcade-outline) solid var(--border);
|
|
563
|
+
|
|
564
|
+
transition:
|
|
565
|
+
translate 80ms var(--ease-out),
|
|
566
|
+
box-shadow 80ms var(--ease-out),
|
|
567
|
+
background-color 100ms var(--ease-out);
|
|
568
|
+
@apply motion-reduce:transition-none;
|
|
569
|
+
|
|
570
|
+
/* Replace the default scale with key travel. Both selectors, always. */
|
|
571
|
+
&:active,
|
|
572
|
+
&[data-pressed="true"] {
|
|
573
|
+
@apply shadow-[0_0_0_0_var(--arcade-edge)];
|
|
574
|
+
transform: none;
|
|
575
|
+
translate: 0 var(--arcade-depth);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
/* Ghost stays flat: no outline, no key cap, no travel */
|
|
580
|
+
.button--ghost {
|
|
581
|
+
@apply border-transparent shadow-none;
|
|
582
|
+
|
|
583
|
+
&:active,
|
|
584
|
+
&[data-pressed="true"] {
|
|
585
|
+
@apply shadow-none;
|
|
586
|
+
translate: none;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
**`themes/arcade/components/card.css`**
|
|
592
|
+
|
|
593
|
+
```css
|
|
594
|
+
/* Arcade Theme - Card */
|
|
595
|
+
/* The key-cap shadow comes from --surface-shadow; the card only adds the outline. */
|
|
596
|
+
|
|
597
|
+
.card {
|
|
598
|
+
border: var(--arcade-outline) solid var(--border);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/* `.card` now sets a border, so re-assert the modifier it would otherwise clobber */
|
|
602
|
+
.card--transparent {
|
|
603
|
+
@apply border-none;
|
|
604
|
+
}
|
|
605
|
+
```
|
|
606
|
+
|
|
607
|
+
**`themes/arcade/components/chip.css`**
|
|
608
|
+
|
|
609
|
+
```css
|
|
610
|
+
/* Arcade Theme - Chip */
|
|
611
|
+
|
|
612
|
+
.chip {
|
|
613
|
+
@apply font-semibold;
|
|
614
|
+
border: var(--arcade-outline) solid var(--border);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/* Tertiary chips have no fill, so drop the outline to keep them quiet */
|
|
618
|
+
.chip--tertiary {
|
|
619
|
+
@apply border-transparent;
|
|
620
|
+
}
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
**`themes/arcade/components/switch.css`**
|
|
624
|
+
|
|
625
|
+
```css
|
|
626
|
+
/* Arcade Theme - Switch */
|
|
627
|
+
/* Outlines are drawn with shadows, not borders: no layout shift, and the track's
|
|
628
|
+
shadow utility still composes with the focus ring. */
|
|
629
|
+
|
|
630
|
+
.switch__control {
|
|
631
|
+
@apply shadow-[inset_0_0_0_var(--arcade-outline)_var(--border)];
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
.switch__thumb {
|
|
635
|
+
background-color: var(--snow);
|
|
636
|
+
box-shadow: 0 0 0 var(--arcade-outline) var(--border);
|
|
637
|
+
|
|
638
|
+
/* @heroui/styles restyles the thumb when selected, with a more specific selector.
|
|
639
|
+
Repeat that selector (both the ARIA and the data attribute) to win. */
|
|
640
|
+
.switch[aria-checked="true"] &,
|
|
641
|
+
.switch[data-selected="true"] & {
|
|
642
|
+
background-color: var(--snow);
|
|
643
|
+
box-shadow: 0 0 0 var(--arcade-outline) var(--border);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
**`themes/arcade/components/tooltip.css`**
|
|
649
|
+
|
|
650
|
+
```css
|
|
651
|
+
/* Arcade Theme - Tooltip */
|
|
652
|
+
/* Inverted label: ink background, paper text, no key cap */
|
|
653
|
+
|
|
654
|
+
.tooltip {
|
|
655
|
+
@apply font-medium;
|
|
656
|
+
background-color: var(--foreground);
|
|
657
|
+
color: var(--background);
|
|
658
|
+
box-shadow: none;
|
|
659
|
+
|
|
660
|
+
/* Parts without a BEM class are reached through their data-slot */
|
|
661
|
+
& [data-slot="overlay-arrow"] {
|
|
662
|
+
fill: var(--foreground);
|
|
663
|
+
stroke: none;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
**`app/globals.css`**
|
|
669
|
+
|
|
670
|
+
```css
|
|
671
|
+
@import "tailwindcss";
|
|
672
|
+
@import "@heroui/styles";
|
|
673
|
+
@import "../themes/arcade/index.css";
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
**Activate**
|
|
677
|
+
|
|
678
|
+
```html
|
|
679
|
+
<html data-theme="arcade-light">
|
|
680
|
+
<body class="bg-background text-foreground">
|
|
681
|
+
…
|
|
682
|
+
</body>
|
|
683
|
+
</html>
|
|
684
|
+
```
|
|
685
|
+
|
|
686
|
+
### Patterns this example demonstrates
|
|
687
|
+
|
|
688
|
+
| Pattern | Where |
|
|
689
|
+
| ------------------------------------------------- | ----------------------------------------------------------------------------------- |
|
|
690
|
+
| Tokens do most of the work | Fields, overlays, focus, radius: no component file needed |
|
|
691
|
+
| Theme tokens with a `--<name>-*` prefix | `--arcade-outline`, `--arcade-depth`, `--arcade-edge` |
|
|
692
|
+
| Mode differences live in tokens, not in overrides | `--arcade-edge` is ink in light and near-black in dark; overrides are mode-agnostic |
|
|
693
|
+
| Re-declaring one calculated token | `--accent-soft-foreground` |
|
|
694
|
+
| Pseudo-class + data attribute for every state | `&:active, &[data-pressed="true"]` |
|
|
695
|
+
| Shadow utilities that compose with the focus ring | `button.css`, `switch.css` (`@apply shadow-[…]`) |
|
|
696
|
+
| Re-asserting a clobbered modifier | `.card--transparent` |
|
|
697
|
+
| Matching the base rule's specificity | `.switch[data-selected="true"] .switch__thumb` |
|
|
698
|
+
| Styling an unclassed part through `data-slot` | Tooltip arrow |
|
|
699
|
+
| Reduced motion after a custom `transition` | `button.css` |
|
|
700
|
+
|
|
701
|
+
Raw `box-shadow: none` on `.tooltip` is safe because the tooltip panel is never focused. On a focusable element, use `@apply shadow-none` instead.
|