@ttoss/fsl-theme 1.1.11
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/LICENSE +21 -0
- package/README.md +390 -0
- package/dist/Types-6tR0_2Ss.d.ts +1452 -0
- package/dist/css.d.ts +164 -0
- package/dist/dataviz/index.d.ts +62 -0
- package/dist/dtcg.d.ts +49 -0
- package/dist/esm/chunk-4Q4P3JBB.js +185 -0
- package/dist/esm/chunk-5PWPAQMC.js +9 -0
- package/dist/esm/chunk-BXKVVQEP.js +29 -0
- package/dist/esm/chunk-DU4QDQUC.js +29 -0
- package/dist/esm/chunk-FBVUI2PK.js +147 -0
- package/dist/esm/chunk-HRNXVRS3.js +54 -0
- package/dist/esm/chunk-IJGA42O6.js +141 -0
- package/dist/esm/chunk-PQPQNZ73.js +262 -0
- package/dist/esm/chunk-SE5Z52RE.js +1898 -0
- package/dist/esm/chunk-TPMN75JM.js +29 -0
- package/dist/esm/chunk-UMRQ4OTX.js +11 -0
- package/dist/esm/chunk-VL6EGE6Z.js +222 -0
- package/dist/esm/chunk-WVQSTQD5.js +192 -0
- package/dist/esm/css.js +6 -0
- package/dist/esm/dataviz/index.js +19 -0
- package/dist/esm/dtcg.js +65 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/react.js +8 -0
- package/dist/esm/runtime-entry.js +4 -0
- package/dist/esm/themes/bruttal.js +6 -0
- package/dist/esm/themes/corporate.js +6 -0
- package/dist/esm/themes/oca.js +6 -0
- package/dist/esm/themes/ventures.js +6 -0
- package/dist/esm/vars.js +28 -0
- package/dist/index.d.ts +86 -0
- package/dist/react.d.ts +346 -0
- package/dist/runtime-entry.d.ts +95 -0
- package/dist/themes/bruttal.d.ts +5 -0
- package/dist/themes/corporate.d.ts +5 -0
- package/dist/themes/oca.d.ts +5 -0
- package/dist/themes/ventures.d.ts +5 -0
- package/dist/vars.d.ts +127 -0
- package/llms.txt +731 -0
- package/package.json +88 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024, Terezinha Tech Operations (ttoss)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
# @ttoss/fsl-theme
|
|
2
|
+
|
|
3
|
+
Design token system for the ttoss ecosystem. Separates raw values (`core`) from stable design meaning (`semantic`) so components never break when themes change or modes switch. The semantic layer is the public contract — type-safe, mode-agnostic, and consumed directly as CSS custom properties with zero runtime overhead.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @ttoss/fsl-theme
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Entry points
|
|
12
|
+
|
|
13
|
+
| Import | Exports |
|
|
14
|
+
| -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
15
|
+
| `@ttoss/fsl-theme` | `createTheme`, `darkAlternate`, built-in themes (`bruttal`, `corporate`, `oca`, `ventures`), types (`ThemeTokens`, `ThemeBundle`, `SemanticTokens`, `ModeOverride`, `DeepPartial`, `ThemeMode`) |
|
|
16
|
+
| `@ttoss/fsl-theme/react` | `ThemeProvider`, `ThemeHead`, `ThemeScript`, `ThemeStyles`, `useColorMode`, `useTokens`, `useResolvedTokens` |
|
|
17
|
+
| `@ttoss/fsl-theme/dataviz` | `withDataviz`, `useDatavizTokens` |
|
|
18
|
+
| `@ttoss/fsl-theme/css` | `getThemeStylesContent`, `toCssVars`, `toCssVarName`, `toFlatTokens` |
|
|
19
|
+
| `@ttoss/fsl-theme/vars` | `vars`, `buildVarsMap`, type `CssVarsMap` |
|
|
20
|
+
| `@ttoss/fsl-theme/dtcg` | `toDTCG` (W3C Design Tokens format) |
|
|
21
|
+
| `@ttoss/fsl-theme/runtime` | `createThemeRuntime`, `getThemeScriptContent` |
|
|
22
|
+
|
|
23
|
+
## Token architecture
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
ThemeTokens
|
|
27
|
+
├── core — raw primitives (immutable across modes)
|
|
28
|
+
└── semantic — {core.*} references (the public contract; remapped per mode)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Components consume only semantic tokens. Core tokens never change between light and dark — only semantic references remap.
|
|
32
|
+
|
|
33
|
+
## Token grammar
|
|
34
|
+
|
|
35
|
+
One entry per semantic family. Use `vars.*` for typed CSS variable references; use the `semantic.*` path shape below when naming tokens in TypeScript or in discussion.
|
|
36
|
+
|
|
37
|
+
| Family | Path shape | Leaf value |
|
|
38
|
+
| --------- | ------------------------------------------------------------------- | ----------------------- |
|
|
39
|
+
| colors | `semantic.colors.{ux}.{role}.{dimension}.{state}` | CSS color |
|
|
40
|
+
| spacing | `semantic.spacing.inset.{control,surface}.{sm,md,lg}` | CSS length |
|
|
41
|
+
| | `semantic.spacing.gap.{stack,inline}.{xs,sm,md,lg,xl}` | CSS length |
|
|
42
|
+
| | `semantic.spacing.gutter.{page,section}` | CSS length / `clamp()` |
|
|
43
|
+
| | `semantic.spacing.separation.interactive.min` | CSS length |
|
|
44
|
+
| text | `semantic.text.{display,headline,title,body,label,code}.{lg,md,sm}` | TextStyle object |
|
|
45
|
+
| sizing | `semantic.sizing.hit.{min,base,prominent}` | CSS length |
|
|
46
|
+
| | `semantic.sizing.icon.{sm,md,lg}` | CSS length |
|
|
47
|
+
| | `semantic.sizing.identity.{sm,md,lg,xl}` | CSS length |
|
|
48
|
+
| | `semantic.sizing.measure.reading` | CSS `ch` / `clamp()` |
|
|
49
|
+
| | `semantic.sizing.surface.maxWidth` | CSS length |
|
|
50
|
+
| | `semantic.sizing.viewport.{height,width}.full` | CSS dvh/dvw |
|
|
51
|
+
| radii | `semantic.radii.{control,surface,round}` | CSS length |
|
|
52
|
+
| border | `semantic.border.divider` | `{width, style}` |
|
|
53
|
+
| | `semantic.border.outline.{surface,control,selected}` | `{width, style}` |
|
|
54
|
+
| focus | `semantic.focus.ring` | `{width, style, color}` |
|
|
55
|
+
| elevation | `semantic.elevation.surface.{flat,raised,overlay,blocking}` | CSS box-shadow |
|
|
56
|
+
| | `semantic.elevation.tonal.{flat,raised,overlay,blocking}` | CSS color (optional) |
|
|
57
|
+
| opacity | `semantic.opacity.{scrim,loading,disabled}` | number in (0, 1) |
|
|
58
|
+
| overlay | `semantic.overlay.scrim` | CSS color with alpha |
|
|
59
|
+
| motion | `semantic.motion.{feedback,emphasis,decorative}` | `{duration, easing}` |
|
|
60
|
+
| | `semantic.motion.transition.{enter,exit}` | `{duration, easing}` |
|
|
61
|
+
| zIndex | `semantic.zIndex.layer.{base,sticky,overlay,blocking,transient}` | integer |
|
|
62
|
+
|
|
63
|
+
**Colors axes** (`semantic.colors.{ux}.{role}.{dimension}.{state}`):
|
|
64
|
+
|
|
65
|
+
- `ux` — FSL Entity Kind: `action` · `input` · `navigation` · `feedback` · `informational`
|
|
66
|
+
- `role` — Evaluation: `primary` · `secondary` · `accent` · `muted` · `positive` · `caution` · `negative`
|
|
67
|
+
- `dimension` — `background` · `border` · `text`
|
|
68
|
+
- `state` — `default` · `hover` · `active` · `focused` · `disabled` · `selected` · `pressed`
|
|
69
|
+
|
|
70
|
+
## Pick a token in 60s
|
|
71
|
+
|
|
72
|
+
Find the CSS property you are setting, then follow the branch to the leaf.
|
|
73
|
+
|
|
74
|
+
**`color` / `background` / `border-color` / `fill`** → `colors`
|
|
75
|
+
|
|
76
|
+
1. What does the element _do_? → `{ux}`: `action` (button, link, CTA) · `input` (field, toggle, checkbox) · `navigation` (tab, menu item, breadcrumb) · `feedback` (alert, banner, toast, progress) · `informational` (card, badge, chip, stat)
|
|
77
|
+
2. What is its _emphasis_? → `{role}`: `primary` (default for the context) · `secondary` (supporting) · `accent` (brand pop) · `muted` (subdued) · `positive` / `caution` / `negative` (outcome valence)
|
|
78
|
+
3. What is being colored? → `background` · `border` · `text`
|
|
79
|
+
4. What is the interaction state? → `default` · `hover` · `active` · `focused` · `disabled` · `selected` · `pressed`
|
|
80
|
+
|
|
81
|
+
**`padding`** → `spacing.inset`
|
|
82
|
+
|
|
83
|
+
- Element is interactive (button, input, toggle) → `spacing.inset.control.{sm|md|lg}`
|
|
84
|
+
- Element is a container (card, panel, dialog, section) → `spacing.inset.surface.{sm|md|lg}`
|
|
85
|
+
- Default step at any level → `md`
|
|
86
|
+
|
|
87
|
+
**`gap`** → `spacing.gap`
|
|
88
|
+
|
|
89
|
+
- Siblings flow vertically (list, form fields, stacked sections) → `spacing.gap.stack.{xs|sm|md|lg|xl}`
|
|
90
|
+
- Siblings flow horizontally (icon + label, toolbar, chip row) → `spacing.gap.inline.{xs|sm|md|lg|xl}`
|
|
91
|
+
- Adjacent independently focusable targets → `spacing.separation.interactive.min`
|
|
92
|
+
|
|
93
|
+
**`padding` on a page or section wrapper** → `spacing.gutter.{page|section}`
|
|
94
|
+
|
|
95
|
+
**`font-size` / `font-family` / `font-weight` / `line-height`** → `text`
|
|
96
|
+
|
|
97
|
+
| Element's text function | Token |
|
|
98
|
+
| ------------------------------------- | -------------------------- |
|
|
99
|
+
| Hero / landing emphasis | `text.display.{lg,md,sm}` |
|
|
100
|
+
| Page or section heading | `text.headline.{lg,md,sm}` |
|
|
101
|
+
| Surface heading (card, panel, dialog) | `text.title.{lg,md,sm}` |
|
|
102
|
+
| Reading prose / description | `text.body.{lg,md,sm}` |
|
|
103
|
+
| UI label / button text / badge | `text.label.{lg,md,sm}` |
|
|
104
|
+
| Code / identifiers / monospace | `text.code.{md,sm}` |
|
|
105
|
+
|
|
106
|
+
**`width` / `height` / `min-width` / `min-height`** → `sizing`
|
|
107
|
+
|
|
108
|
+
- Interactive area (hit target) → `sizing.hit.{min|base|prominent}`
|
|
109
|
+
- Icon glyph dimension → `sizing.icon.{sm|md|lg}`
|
|
110
|
+
- Avatar / identity object → `sizing.identity.{sm|md|lg|xl}`
|
|
111
|
+
- Reading line length (`max-width` in `ch`) → `sizing.measure.reading`
|
|
112
|
+
- Surface max-width (page shell, card, dialog) → `sizing.surface.maxWidth`
|
|
113
|
+
- Full viewport dimension → `sizing.viewport.{height|width}.full`
|
|
114
|
+
|
|
115
|
+
**`border-radius`** → `radii`
|
|
116
|
+
|
|
117
|
+
- Interactive control (button, input, toggle) → `radii.control`
|
|
118
|
+
- Containing surface (card, panel, dialog, menu) → `radii.surface`
|
|
119
|
+
- Pill, capsule, or avatar → `radii.round`
|
|
120
|
+
|
|
121
|
+
**`border-width` / `border-style`** → `border` (pair with a `colors` token for the color)
|
|
122
|
+
|
|
123
|
+
- Separator between content groups → `border.divider`
|
|
124
|
+
- Enclosing edge of a surface → `border.outline.surface`
|
|
125
|
+
- Enclosing edge of an interactive control → `border.outline.control`
|
|
126
|
+
- Selection / current-item line weight → `border.outline.selected`
|
|
127
|
+
|
|
128
|
+
**`outline` (keyboard focus)** → `focus`
|
|
129
|
+
|
|
130
|
+
- Component has a clear FSL Entity Kind → `{ux}.{role}.border.focused` (from `colors`)
|
|
131
|
+
- No clear Entity Kind (focusable card, custom widget) → `focus.ring`
|
|
132
|
+
|
|
133
|
+
**`box-shadow`** → `elevation.surface`
|
|
134
|
+
|
|
135
|
+
- Flush with page → `elevation.surface.flat`
|
|
136
|
+
- Card or panel → `elevation.surface.raised`
|
|
137
|
+
- Dropdown, popover → `elevation.surface.overlay`
|
|
138
|
+
- Dialog, sheet → `elevation.surface.blocking`
|
|
139
|
+
|
|
140
|
+
**`z-index`** → `zIndex.layer`
|
|
141
|
+
|
|
142
|
+
- Normal page content → `zIndex.layer.base`
|
|
143
|
+
- Sticky header / nav → `zIndex.layer.sticky`
|
|
144
|
+
- Dropdown, popover → `zIndex.layer.overlay`
|
|
145
|
+
- Dialog with scrim → `zIndex.layer.blocking`
|
|
146
|
+
- Toast / transient notification → `zIndex.layer.transient`
|
|
147
|
+
|
|
148
|
+
**`opacity` (whole element)** → `opacity`
|
|
149
|
+
|
|
150
|
+
- Modal backdrop dimming → `opacity.scrim`
|
|
151
|
+
- Content visible during async work → `opacity.loading`
|
|
152
|
+
- Disabled visual asset (image, avatar) → `opacity.disabled`
|
|
153
|
+
- _For disabled controls or text: use `{ux}.{role}.{dimension}.disabled` from `colors` — opacity cannot carry contrast guarantees._
|
|
154
|
+
|
|
155
|
+
**`transition` / `animation`** → `motion`
|
|
156
|
+
|
|
157
|
+
- User input response on a single element → `motion.feedback`
|
|
158
|
+
- Element entering the layout → `motion.transition.enter`
|
|
159
|
+
- Element leaving the layout → `motion.transition.exit`
|
|
160
|
+
- Must-notice in-place change → `motion.emphasis`
|
|
161
|
+
- Ambient / decorative loop → `motion.decorative`
|
|
162
|
+
|
|
163
|
+
**Modal backdrop color** → `overlay.scrim`
|
|
164
|
+
|
|
165
|
+
## Per-family specs
|
|
166
|
+
|
|
167
|
+
Full grammar rules, decision matrices, and anti-patterns live in the family specs. Each file follows the pattern `02-families/{family}.md`:
|
|
168
|
+
|
|
169
|
+
[colors](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/colors.md) · [spacing](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/spacing.md) · [typography](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/typography.md) · [sizing](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/sizing.md) · [radii](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/radii.md) · [borders](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/borders.md) · [elevation](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/elevation.md) · [opacity](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/opacity.md) · [motion](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/motion.md) · [z-index](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/z-index.md) · [breakpoints](https://github.com/ttoss/ttoss/blob/main/docs/website/docs/design/01-design-system/02-design-tokens/02-families/breakpoints.md)
|
|
170
|
+
|
|
171
|
+
## createTheme
|
|
172
|
+
|
|
173
|
+
```ts
|
|
174
|
+
import { createTheme } from '@ttoss/fsl-theme';
|
|
175
|
+
|
|
176
|
+
// Default — light base + built-in dark alternate included
|
|
177
|
+
const myTheme = createTheme();
|
|
178
|
+
|
|
179
|
+
// With brand overrides (dark mode still included)
|
|
180
|
+
const myTheme = createTheme({
|
|
181
|
+
overrides: { core: { colors: { brand: { 500: '#FF0000' } } } },
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// Custom semantic dark alternate
|
|
185
|
+
const myTheme = createTheme({
|
|
186
|
+
overrides: { core: { colors: { brand: { 500: '#FF0000' } } } },
|
|
187
|
+
alternate: {
|
|
188
|
+
semantic: {
|
|
189
|
+
colors: {
|
|
190
|
+
informational: {
|
|
191
|
+
primary: { background: { default: '{core.colors.neutral.900}' } },
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// Single-mode theme (opt out of dark alternate)
|
|
199
|
+
const myTheme = createTheme({ alternate: null });
|
|
200
|
+
|
|
201
|
+
// Inherit from an existing bundle (inherits base + alternate)
|
|
202
|
+
const childTheme = createTheme({ extends: myTheme });
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**`alternate`** is typed `ModeOverride = { semantic: DeepPartial<ThemeTokens['semantic']> }`. Pass `alternate: null` for single-mode.
|
|
206
|
+
|
|
207
|
+
**`darkAlternate`** is also exported for direct composition. `createTheme()` includes it by default.
|
|
208
|
+
|
|
209
|
+
## React (Vite / CRA)
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
// main.tsx
|
|
213
|
+
import { ThemeProvider } from '@ttoss/fsl-theme/react';
|
|
214
|
+
import { myTheme } from './theme';
|
|
215
|
+
|
|
216
|
+
export const App = () => (
|
|
217
|
+
<ThemeProvider theme={myTheme} defaultMode="system">
|
|
218
|
+
<YourApp />
|
|
219
|
+
</ThemeProvider>
|
|
220
|
+
);
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
`ThemeProvider` injects CSS Custom Properties via React 19 style hoisting and persists mode to localStorage.
|
|
224
|
+
|
|
225
|
+
### Hooks
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
import { useColorMode } from '@ttoss/fsl-theme/react';
|
|
229
|
+
|
|
230
|
+
const DarkToggle = () => {
|
|
231
|
+
const { resolvedMode, setMode } = useColorMode();
|
|
232
|
+
return (
|
|
233
|
+
<button onClick={() => setMode(resolvedMode === 'dark' ? 'light' : 'dark')}>
|
|
234
|
+
{resolvedMode === 'dark' ? '☀️' : '🌙'}
|
|
235
|
+
</button>
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
```tsx
|
|
241
|
+
import { useResolvedTokens } from '@ttoss/fsl-theme/react';
|
|
242
|
+
|
|
243
|
+
// Non-CSS environments (React Native, canvas) — resolved raw values
|
|
244
|
+
const resolved = useResolvedTokens();
|
|
245
|
+
// resolved['semantic.colors.action.primary.background.default'] → '#0469E3'
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Consuming tokens
|
|
249
|
+
|
|
250
|
+
```css
|
|
251
|
+
/* CSS — no JS overhead, no re-renders */
|
|
252
|
+
.button {
|
|
253
|
+
background: var(--tt-colors-action-primary-background-default);
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
```tsx
|
|
258
|
+
import { vars } from '@ttoss/fsl-theme/vars';
|
|
259
|
+
|
|
260
|
+
// Typed CSS variable references
|
|
261
|
+
<div style={{ color: vars.colors.informational.primary.background.default }} />;
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Extending `vars` with custom semantic tokens
|
|
265
|
+
|
|
266
|
+
`vars` is typed against the default `SemanticTokens` shape. If your project adds custom families (e.g. a dataviz palette, project-specific component tokens), those leaves won't appear on the default export. Build a typed mirror of your extended shape with the public `buildVarsMap` helper:
|
|
267
|
+
|
|
268
|
+
```ts
|
|
269
|
+
import { createTheme, type SemanticTokens } from '@ttoss/fsl-theme';
|
|
270
|
+
import { buildVarsMap, type CssVarsMap } from '@ttoss/fsl-theme/vars';
|
|
271
|
+
|
|
272
|
+
type MySemanticTokens = SemanticTokens & {
|
|
273
|
+
colors: SemanticTokens['colors'] & {
|
|
274
|
+
brandX: { primary: { default: string } };
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const myTheme = createTheme({
|
|
279
|
+
/* … */
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
export const myVars: CssVarsMap<MySemanticTokens> = buildVarsMap(
|
|
283
|
+
myTheme.base
|
|
284
|
+
) as CssVarsMap<MySemanticTokens>;
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
For one-off custom keys, use `toCssVarName` from `@ttoss/fsl-theme/css` directly — no extended type required.
|
|
288
|
+
|
|
289
|
+
## Next.js (SSR)
|
|
290
|
+
|
|
291
|
+
### React 19 App Router (recommended)
|
|
292
|
+
|
|
293
|
+
`ThemeProvider` with a `theme` prop uses React 19 style hoisting to inject CSS into `<head>` automatically. Only add `ThemeScript` for flash-prevention:
|
|
294
|
+
|
|
295
|
+
```tsx
|
|
296
|
+
// app/layout.tsx
|
|
297
|
+
import { ThemeScript, ThemeProvider } from '@ttoss/fsl-theme/react';
|
|
298
|
+
import { myTheme } from './theme';
|
|
299
|
+
|
|
300
|
+
export default function RootLayout({
|
|
301
|
+
children,
|
|
302
|
+
}: {
|
|
303
|
+
children: React.ReactNode;
|
|
304
|
+
}) {
|
|
305
|
+
return (
|
|
306
|
+
<html lang="en">
|
|
307
|
+
<head>
|
|
308
|
+
{/* Flash-prevention only — ThemeProvider handles CSS via React 19 hoisting */}
|
|
309
|
+
<ThemeScript defaultMode="system" />
|
|
310
|
+
</head>
|
|
311
|
+
<body>
|
|
312
|
+
<ThemeProvider theme={myTheme} defaultMode="system">
|
|
313
|
+
{children}
|
|
314
|
+
</ThemeProvider>
|
|
315
|
+
</body>
|
|
316
|
+
</html>
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Non-React-19 SSR / no style hoisting
|
|
322
|
+
|
|
323
|
+
Use `ThemeHead` (script + CSS) **without** a `theme` prop on `ThemeProvider` — or use `ThemeHead` standalone when
|
|
324
|
+
React style hoisting is unavailable:
|
|
325
|
+
|
|
326
|
+
```tsx
|
|
327
|
+
// app/layout.tsx — for frameworks without React 19 style hoisting
|
|
328
|
+
import { ThemeHead, ThemeProvider } from '@ttoss/fsl-theme/react';
|
|
329
|
+
import { myTheme } from './theme';
|
|
330
|
+
|
|
331
|
+
export default function RootLayout({
|
|
332
|
+
children,
|
|
333
|
+
}: {
|
|
334
|
+
children: React.ReactNode;
|
|
335
|
+
}) {
|
|
336
|
+
return (
|
|
337
|
+
<html lang="en">
|
|
338
|
+
<head>
|
|
339
|
+
{/* Injects flash-prevention script + CSS vars */}
|
|
340
|
+
<ThemeHead theme={myTheme} defaultMode="system" />
|
|
341
|
+
</head>
|
|
342
|
+
<body>
|
|
343
|
+
{/* No theme prop — CSS is already in <head> via ThemeHead */}
|
|
344
|
+
<ThemeProvider defaultMode="system">{children}</ThemeProvider>
|
|
345
|
+
</body>
|
|
346
|
+
</html>
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
> **Warning:** Do not combine `<ThemeHead theme={...}>` with `<ThemeProvider theme={...}>`. Both inject CSS — `ThemeHead` via a plain `<style>` tag and `ThemeProvider` via React 19 style hoisting — resulting in duplicate CSS in the document. Use one or the other.
|
|
352
|
+
|
|
353
|
+
## Dataviz extension
|
|
354
|
+
|
|
355
|
+
```ts
|
|
356
|
+
// theme.ts
|
|
357
|
+
import { createTheme } from '@ttoss/fsl-theme';
|
|
358
|
+
import { withDataviz } from '@ttoss/fsl-theme/dataviz';
|
|
359
|
+
|
|
360
|
+
export const myTheme = withDataviz(createTheme());
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
```tsx
|
|
364
|
+
// Consume via CSS vars — no JS overhead
|
|
365
|
+
<span style={{ color: `var(--tt-dataviz-color-series-${i + 1})` }}>
|
|
366
|
+
{category}
|
|
367
|
+
</span>
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## CSS generation (server / build-time)
|
|
371
|
+
|
|
372
|
+
```ts
|
|
373
|
+
import { getThemeStylesContent } from '@ttoss/fsl-theme/css';
|
|
374
|
+
|
|
375
|
+
const css = getThemeStylesContent(myTheme);
|
|
376
|
+
// → :root { --tt-* } + :root[data-tt-mode="dark"] { --tt-* (overrides) }
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Storybook / micro-frontends
|
|
380
|
+
|
|
381
|
+
Anchor theme attributes to a specific element instead of `<html>`:
|
|
382
|
+
|
|
383
|
+
```tsx
|
|
384
|
+
const rootRef = React.useRef<HTMLDivElement>(null);
|
|
385
|
+
<div ref={rootRef}>
|
|
386
|
+
<ThemeProvider theme={myTheme} root={rootRef.current ?? undefined}>
|
|
387
|
+
<Story />
|
|
388
|
+
</ThemeProvider>
|
|
389
|
+
</div>;
|
|
390
|
+
```
|