@splenddev/kreativ-ui 0.2.7 → 0.2.9
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 +987 -1965
- package/dist/index.cjs +1428 -1055
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +235 -269
- package/dist/index.d.ts +235 -269
- package/dist/index.js +1423 -1033
- package/dist/index.js.map +1 -1
- package/dist/styles/index.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# Kreativ UI
|
|
2
2
|
|
|
3
|
-
A modern, themeable React component library built with **React**, **TypeScript**, **Tailwind CSS v4**, and **CSS Variables**.
|
|
4
|
-
Kreativ UI provides a runtime theme engine that lets you customize colors, typography, radius, sizes, and component styles **without rebuilding CSS**.
|
|
3
|
+
A modern, themeable React component library built with **React**, **TypeScript**, **Tailwind CSS v4**, and **CSS Variables**. Kreativ UI provides a runtime theme engine that lets you customize colors, typography, radius, sizes, and component styles **without rebuilding CSS**.
|
|
5
4
|
|
|
6
5
|
---
|
|
7
6
|
|
|
8
7
|
## ✨ Features
|
|
9
8
|
|
|
10
9
|
- Runtime theme switching (`light`, `dark`, `system`)
|
|
11
|
-
- Built
|
|
10
|
+
- Built-in `ThemeToggler` with optional animated transitions
|
|
12
11
|
- CSS‑variable‑driven design tokens
|
|
13
12
|
- Primitive + semantic token architecture
|
|
14
13
|
- Component‑level theme overrides
|
|
15
14
|
- Fully accessible (ARIA, keyboard navigation, focus management)
|
|
16
15
|
- TypeScript‑first and tree‑shakable
|
|
16
|
+
- Theme extension APIs for composable customization
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
@@ -50,180 +50,416 @@ export default function App() {
|
|
|
50
50
|
|
|
51
51
|
---
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
## Core Concepts
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
Kreativ UI is more than a collection of components — it's a design-system foundation built around a layered theme architecture.
|
|
56
56
|
|
|
57
|
-
###
|
|
57
|
+
### Runtime Theming
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
| -------- | ---------------------------------------------- |
|
|
61
|
-
| `light` | Forces light mode |
|
|
62
|
-
| `dark` | Forces dark mode |
|
|
63
|
-
| `system` | Follows the user’s operating system preference |
|
|
59
|
+
The theme system resolves values at runtime using CSS variables. When you switch between light and dark modes, the UI updates instantly without rebuilding your application.
|
|
64
60
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
### Theme Architecture
|
|
62
|
+
|
|
63
|
+
The theme consists of several independent layers:
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
Theme
|
|
67
|
+
├── tokens → primitive design values
|
|
68
|
+
├── semanticTokens → role-based values (mode-aware)
|
|
69
|
+
├── typography → text presentation presets
|
|
70
|
+
├── recipes → component visual behavior
|
|
71
|
+
├── sizes → component dimensions and spacing
|
|
72
|
+
└── intensity → color intensity scaling
|
|
69
73
|
```
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
Each layer can be customized independently, making it easy to extend or override specific aspects of the design system.
|
|
72
76
|
|
|
73
|
-
|
|
77
|
+
---
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
import { useTheme } from "@splenddev/kreativ-ui";
|
|
79
|
+
## Theme System
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
const { mode, setMode } = useTheme();
|
|
81
|
+
### Primitive Tokens
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
Primitive tokens represent raw design values — the building blocks of your theme.
|
|
84
|
+
|
|
85
|
+
Examples of primitive tokens include:
|
|
86
|
+
|
|
87
|
+
- Colors (`tokens.colors.blue.500`, `tokens.colors.gray.900`)
|
|
88
|
+
- Spacing (`tokens.spacing.md`)
|
|
89
|
+
- Radii (`tokens.radii.md`)
|
|
90
|
+
- Fonts (`tokens.fonts.body`)
|
|
91
|
+
- Font sizes (`tokens.fontSizes.md`)
|
|
92
|
+
- Font weights (`tokens.fontWeights.bold`)
|
|
93
|
+
- Line heights (`tokens.lineHeights.normal`)
|
|
94
|
+
|
|
95
|
+
Primitive tokens are defined using `defineToken` or `defineTokens`.
|
|
96
|
+
|
|
97
|
+
### Semantic Tokens
|
|
98
|
+
|
|
99
|
+
Semantic tokens represent UI meaning rather than raw values. They reference primitive tokens and provide mode‑specific values.
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
semanticTokens.colors.brand = {
|
|
103
|
+
value: {
|
|
104
|
+
light: "{colors.blue.500}",
|
|
105
|
+
dark: "{colors.blue.400}"
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
semanticTokens.colors.text = {
|
|
110
|
+
value: {
|
|
111
|
+
light: "{colors.gray.900}",
|
|
112
|
+
dark: "{colors.gray.50}"
|
|
113
|
+
}
|
|
114
|
+
};
|
|
89
115
|
```
|
|
90
116
|
|
|
91
|
-
|
|
117
|
+
Semantic tokens make components easier to maintain because they reference meaningful roles instead of hard‑coded colors. Changing the brand color updates every component that uses the `brand` semantic token.
|
|
118
|
+
|
|
119
|
+
### Sizes
|
|
120
|
+
|
|
121
|
+
The centralized size system controls component dimensions and layout properties. Built‑in sizes include:
|
|
122
|
+
|
|
123
|
+
| Size | Height | Padding X | Font Size | Gap | Icon Size | Radius |
|
|
124
|
+
|------|--------|-----------|-----------|-----|-----------|--------|
|
|
125
|
+
| `xs` | 1.75rem | 0.5rem | 0.75rem | 0.25rem | 0.875rem | 0.65rem |
|
|
126
|
+
| `sm` | 2rem | 0.75rem | 0.8125rem | 0.375rem | 1rem | 0.8rem |
|
|
127
|
+
| `md` | 2.5rem | 1rem | 0.875rem | 0.5rem | 1.125rem | 1rem |
|
|
128
|
+
| `lg` | 3rem | 1.5rem | 1rem | 0.625rem | 1.25rem | 1.15rem |
|
|
129
|
+
|
|
130
|
+
You can extend the size system with custom sizes.
|
|
131
|
+
|
|
132
|
+
### Typography
|
|
133
|
+
|
|
134
|
+
Typography controls text presentation independently from component sizing. A typography preset defines:
|
|
135
|
+
|
|
136
|
+
- `fontFamily`
|
|
137
|
+
- `fontSize`
|
|
138
|
+
- `fontWeight`
|
|
139
|
+
- `lineHeight`
|
|
140
|
+
- `letterSpacing`
|
|
141
|
+
|
|
142
|
+
This separation is a key architectural principle:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
Component
|
|
146
|
+
├── Recipe → visual variant/color behavior
|
|
147
|
+
├── Size → dimensions and layout
|
|
148
|
+
└── Typography → text presentation
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Using `size="lg"` and `typography="bodySmall"` together gives you a large button with small text — the size controls the button's dimensions while typography controls the text appearance.
|
|
92
152
|
|
|
93
|
-
|
|
153
|
+
### Recipes
|
|
94
154
|
|
|
95
|
-
|
|
155
|
+
Recipes define component visual behavior such as variants and semantic colors. Each component can have its own recipe, and recipes can be extended or overridden through the theme.
|
|
96
156
|
|
|
97
|
-
|
|
98
|
-
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Theme API
|
|
99
160
|
|
|
100
|
-
|
|
161
|
+
Kreativ UI provides a set of theme extension helpers for composing custom themes without manually manipulating the internal theme structure.
|
|
101
162
|
|
|
102
|
-
|
|
163
|
+
### `extendTheme`
|
|
103
164
|
|
|
104
|
-
|
|
165
|
+
The recommended way to create a custom theme configuration:
|
|
105
166
|
|
|
106
167
|
```tsx
|
|
107
|
-
import { UIProvider } from "@splenddev/kreativ-ui";
|
|
168
|
+
import { extendTheme, UIProvider } from "@splenddev/kreativ-ui";
|
|
108
169
|
|
|
109
|
-
const theme = {
|
|
170
|
+
const theme = extendTheme({
|
|
171
|
+
tokens: {
|
|
172
|
+
// custom primitive tokens
|
|
173
|
+
},
|
|
110
174
|
semanticTokens: {
|
|
111
|
-
|
|
112
|
-
brand: {
|
|
113
|
-
value: {
|
|
114
|
-
light: "16 128 224", // RGB channel values
|
|
115
|
-
dark: "71 153 235",
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
surface: {
|
|
119
|
-
value: {
|
|
120
|
-
light: "255 255 255",
|
|
121
|
-
dark: "15 23 42",
|
|
122
|
-
},
|
|
123
|
-
},
|
|
124
|
-
text: {
|
|
125
|
-
value: {
|
|
126
|
-
light: "15 23 42",
|
|
127
|
-
dark: "241 245 249",
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
},
|
|
175
|
+
// custom semantic tokens
|
|
131
176
|
},
|
|
132
|
-
|
|
177
|
+
typography: {
|
|
178
|
+
// custom typography presets
|
|
179
|
+
},
|
|
180
|
+
sizes: {
|
|
181
|
+
// custom sizes
|
|
182
|
+
},
|
|
183
|
+
recipes: {
|
|
184
|
+
// custom component recipes
|
|
185
|
+
},
|
|
186
|
+
});
|
|
133
187
|
|
|
134
188
|
<UIProvider theme={theme}>
|
|
135
189
|
<App />
|
|
136
|
-
</UIProvider
|
|
190
|
+
</UIProvider>
|
|
137
191
|
```
|
|
138
192
|
|
|
139
|
-
###
|
|
193
|
+
### Tokens
|
|
140
194
|
|
|
141
|
-
|
|
195
|
+
#### `defineToken`
|
|
196
|
+
|
|
197
|
+
Creates a single primitive token definition:
|
|
142
198
|
|
|
143
199
|
```ts
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
200
|
+
import { defineToken } from "@splenddev/kreativ-ui";
|
|
201
|
+
|
|
202
|
+
const bodyFont = defineToken("Inter, sans-serif");
|
|
147
203
|
```
|
|
148
204
|
|
|
149
|
-
|
|
205
|
+
#### `defineTokens`
|
|
206
|
+
|
|
207
|
+
Creates a collection of token definitions:
|
|
150
208
|
|
|
151
209
|
```ts
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
210
|
+
import { defineTokens } from "@splenddev/kreativ-ui";
|
|
211
|
+
|
|
212
|
+
const fonts = defineTokens({
|
|
213
|
+
body: "Inter, sans-serif",
|
|
214
|
+
heading: "Poppins, sans-serif",
|
|
215
|
+
mono: "JetBrains Mono, monospace",
|
|
216
|
+
});
|
|
158
217
|
```
|
|
159
218
|
|
|
160
|
-
|
|
219
|
+
#### `extendTokens`
|
|
161
220
|
|
|
162
|
-
|
|
221
|
+
Extends existing token definitions:
|
|
163
222
|
|
|
164
|
-
|
|
223
|
+
```ts
|
|
224
|
+
import { extendTokens } from "@splenddev/kreativ-ui";
|
|
165
225
|
|
|
166
|
-
|
|
167
|
-
|
|
226
|
+
const customFonts = extendTokens({
|
|
227
|
+
display: "Georgia, serif",
|
|
228
|
+
});
|
|
229
|
+
```
|
|
168
230
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
231
|
+
### Semantic Tokens
|
|
232
|
+
|
|
233
|
+
#### `extendSemanticToken`
|
|
234
|
+
|
|
235
|
+
Extends semantic token definitions:
|
|
236
|
+
|
|
237
|
+
```ts
|
|
238
|
+
import { extendSemanticToken } from "@splenddev/kreativ-ui";
|
|
239
|
+
|
|
240
|
+
const customSemanticColors = extendSemanticToken({
|
|
241
|
+
accent: {
|
|
242
|
+
value: {
|
|
243
|
+
light: "{colors.purple.500}",
|
|
244
|
+
dark: "{colors.purple.300}",
|
|
179
245
|
},
|
|
180
246
|
},
|
|
181
|
-
};
|
|
247
|
+
});
|
|
248
|
+
```
|
|
182
249
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
250
|
+
### Sizes
|
|
251
|
+
|
|
252
|
+
#### `defineSize`
|
|
253
|
+
|
|
254
|
+
Creates a reusable size definition:
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
import { defineSize } from "@splenddev/kreativ-ui";
|
|
258
|
+
|
|
259
|
+
const xlSize = defineSize({
|
|
260
|
+
height: "3.5rem",
|
|
261
|
+
paddingX: "2rem",
|
|
262
|
+
fontSize: "1rem",
|
|
263
|
+
gap: "0.75rem",
|
|
264
|
+
iconSize: "1.25rem",
|
|
265
|
+
radius: "1.25rem",
|
|
266
|
+
});
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### `defineSizes`
|
|
270
|
+
|
|
271
|
+
Defines multiple size definitions:
|
|
272
|
+
|
|
273
|
+
```ts
|
|
274
|
+
import { defineSizes } from "@splenddev/kreativ-ui";
|
|
275
|
+
|
|
276
|
+
const customSizes = defineSizes({
|
|
277
|
+
xl: {
|
|
278
|
+
height: "3.5rem",
|
|
279
|
+
paddingX: "2rem",
|
|
280
|
+
fontSize: "1rem",
|
|
281
|
+
gap: "0.75rem",
|
|
282
|
+
iconSize: "1.25rem",
|
|
283
|
+
radius: "1.25rem",
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
#### `extendSizes`
|
|
289
|
+
|
|
290
|
+
Extends the existing size system:
|
|
291
|
+
|
|
292
|
+
```ts
|
|
293
|
+
import { extendSizes } from "@splenddev/kreativ-ui";
|
|
294
|
+
|
|
295
|
+
const sizes = extendSizes({
|
|
296
|
+
xl: {
|
|
297
|
+
height: "3.5rem",
|
|
298
|
+
paddingX: "2rem",
|
|
299
|
+
fontSize: "1rem",
|
|
300
|
+
gap: "0.75rem",
|
|
301
|
+
iconSize: "1.25rem",
|
|
302
|
+
radius: "1.25rem",
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Typography
|
|
308
|
+
|
|
309
|
+
#### `defineTypography`
|
|
310
|
+
|
|
311
|
+
Creates a typography preset:
|
|
312
|
+
|
|
313
|
+
```ts
|
|
314
|
+
import { defineTypography } from "@splenddev/kreativ-ui";
|
|
315
|
+
|
|
316
|
+
const heading = defineTypography({
|
|
317
|
+
fontFamily: "{fonts.heading}",
|
|
318
|
+
fontSize: "{fontSizes.2xl}",
|
|
319
|
+
fontWeight: "{fontWeights.bold}",
|
|
320
|
+
lineHeight: "{lineHeights.tight}",
|
|
321
|
+
});
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### `extendTypography`
|
|
325
|
+
|
|
326
|
+
Extends existing typography presets:
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
import { extendTypography } from "@splenddev/kreativ-ui";
|
|
330
|
+
|
|
331
|
+
const typography = extendTypography({
|
|
332
|
+
display: {
|
|
333
|
+
fontFamily: "{fonts.heading}",
|
|
334
|
+
fontSize: "4rem",
|
|
335
|
+
fontWeight: "{fontWeights.bold}",
|
|
336
|
+
lineHeight: "1",
|
|
337
|
+
letterSpacing: "-0.04em",
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
### Recipes
|
|
343
|
+
|
|
344
|
+
#### `defineRecipe`
|
|
345
|
+
|
|
346
|
+
Defines a component recipe:
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
import { defineRecipe } from "@splenddev/kreativ-ui";
|
|
350
|
+
|
|
351
|
+
const ButtonRecipe = defineRecipe({
|
|
352
|
+
// recipe configuration
|
|
353
|
+
});
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
#### `extendRecipe`
|
|
357
|
+
|
|
358
|
+
Extends an existing component recipe:
|
|
359
|
+
|
|
360
|
+
```ts
|
|
361
|
+
import { extendRecipe } from "@splenddev/kreativ-ui";
|
|
362
|
+
|
|
363
|
+
const customButtonRecipe = extendRecipe({
|
|
364
|
+
// custom recipe overrides
|
|
365
|
+
});
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## ☀️ UIProvider
|
|
371
|
+
|
|
372
|
+
The `UIProvider` component provides the theme context and manages the active color mode. It must wrap any part of your application that uses Kreativ UI components.
|
|
373
|
+
|
|
374
|
+
### Modes
|
|
375
|
+
|
|
376
|
+
| Mode | Description |
|
|
377
|
+
|------|-------------|
|
|
378
|
+
| `light` | Forces light mode |
|
|
379
|
+
| `dark` | Forces dark mode |
|
|
380
|
+
| `system` | Follows the user's operating system preference |
|
|
381
|
+
|
|
382
|
+
### Props
|
|
383
|
+
|
|
384
|
+
| Prop | Type | Default | Description |
|
|
385
|
+
|------|------|---------|-------------|
|
|
386
|
+
| `children` | `ReactNode` | – | Application content |
|
|
387
|
+
| `theme` | `Theme` | default theme | Custom theme configuration |
|
|
388
|
+
| `defaultMode` | `"light" \| "dark" \| "system"` | `"system"` | Initial color mode |
|
|
389
|
+
| `as` | `ElementType` | `"div"` | Root element type |
|
|
390
|
+
| `fallbackSize` | `string` | `"md"` | Fallback size when theme size is missing |
|
|
391
|
+
|
|
392
|
+
### Example
|
|
393
|
+
|
|
394
|
+
```tsx
|
|
395
|
+
import { UIProvider } from "@splenddev/kreativ-ui";
|
|
396
|
+
|
|
397
|
+
<UIProvider defaultMode="system">
|
|
398
|
+
<App />
|
|
399
|
+
</UIProvider>
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
---
|
|
403
|
+
|
|
404
|
+
## `useTheme`
|
|
405
|
+
|
|
406
|
+
Access and change the current color mode anywhere in your app:
|
|
407
|
+
|
|
408
|
+
```tsx
|
|
409
|
+
import { useTheme } from "@splenddev/kreativ-ui";
|
|
410
|
+
|
|
411
|
+
function ThemeSwitcher() {
|
|
412
|
+
const { mode, setMode } = useTheme();
|
|
413
|
+
|
|
414
|
+
return (
|
|
415
|
+
<>
|
|
416
|
+
<button onClick={() => setMode("light")}>Light</button>
|
|
417
|
+
<button onClick={() => setMode("dark")}>Dark</button>
|
|
418
|
+
<button onClick={() => setMode("system")}>System</button>
|
|
419
|
+
</>
|
|
420
|
+
);
|
|
421
|
+
}
|
|
186
422
|
```
|
|
187
423
|
|
|
188
424
|
---
|
|
189
425
|
|
|
190
|
-
|
|
426
|
+
## 🌗 ThemeToggler
|
|
191
427
|
|
|
192
428
|
A ready‑to‑use theme switcher that integrates with `UIProvider`.
|
|
193
429
|
|
|
194
|
-
|
|
430
|
+
### Basic Usage
|
|
195
431
|
|
|
196
432
|
```tsx
|
|
197
433
|
import { ThemeToggler } from "@splenddev/kreativ-ui";
|
|
198
434
|
|
|
199
|
-
<ThemeToggler
|
|
435
|
+
<ThemeToggler />
|
|
200
436
|
```
|
|
201
437
|
|
|
202
|
-
|
|
438
|
+
### With System Mode
|
|
203
439
|
|
|
204
440
|
```tsx
|
|
205
441
|
<ThemeToggler allowSystem />
|
|
206
442
|
```
|
|
207
443
|
|
|
208
|
-
|
|
444
|
+
### Icon Only
|
|
209
445
|
|
|
210
446
|
```tsx
|
|
211
447
|
<ThemeToggler iconOnly allowSystem />
|
|
212
448
|
```
|
|
213
449
|
|
|
214
|
-
|
|
450
|
+
### Custom Variants
|
|
215
451
|
|
|
216
452
|
```tsx
|
|
217
453
|
<ThemeToggler variant="outline" activeVariant="solid" />
|
|
218
454
|
```
|
|
219
455
|
|
|
220
|
-
|
|
456
|
+
### Vertical Layout
|
|
221
457
|
|
|
222
458
|
```tsx
|
|
223
459
|
<ThemeToggler orientation="vertical" allowSystem />
|
|
224
460
|
```
|
|
225
461
|
|
|
226
|
-
|
|
462
|
+
### Custom Labels & Icons
|
|
227
463
|
|
|
228
464
|
```tsx
|
|
229
465
|
import { SunMedium, MoonStar, LaptopMinimal } from "lucide-react";
|
|
@@ -236,10 +472,10 @@ import { SunMedium, MoonStar, LaptopMinimal } from "lucide-react";
|
|
|
236
472
|
dark: <MoonStar size={18} />,
|
|
237
473
|
system: <LaptopMinimal size={18} />,
|
|
238
474
|
}}
|
|
239
|
-
|
|
475
|
+
/>
|
|
240
476
|
```
|
|
241
477
|
|
|
242
|
-
|
|
478
|
+
### Cycle Mode with Animation
|
|
243
479
|
|
|
244
480
|
```tsx
|
|
245
481
|
<ThemeToggler
|
|
@@ -251,73 +487,117 @@ import { SunMedium, MoonStar, LaptopMinimal } from "lucide-react";
|
|
|
251
487
|
|
|
252
488
|
Supported transition types: `none`, `fade`, `slide`, `scale`, `rotate`.
|
|
253
489
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
| Prop
|
|
257
|
-
|
|
258
|
-
| `variant`
|
|
259
|
-
| `activeVariant` | `ThemeTogglerVariant`
|
|
260
|
-
| `size`
|
|
261
|
-
| `iconOnly`
|
|
262
|
-
| `allowSystem`
|
|
263
|
-
| `orientation`
|
|
264
|
-
| `rounded`
|
|
265
|
-
| `unstyled`
|
|
266
|
-
| `display`
|
|
267
|
-
| `transition`
|
|
268
|
-
| `labels`
|
|
269
|
-
| `icons`
|
|
270
|
-
| `buttonProps`
|
|
271
|
-
| `className`
|
|
490
|
+
### Props
|
|
491
|
+
|
|
492
|
+
| Prop | Type | Default | Description |
|
|
493
|
+
|------|------|---------|-------------|
|
|
494
|
+
| `variant` | `ThemeTogglerVariant` | `"ghost"` | Variant for inactive buttons |
|
|
495
|
+
| `activeVariant` | `ThemeTogglerVariant` | `"solid"` | Variant for active button |
|
|
496
|
+
| `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"sm"` | Button size |
|
|
497
|
+
| `iconOnly` | `boolean` | `false` | Hide labels, show only icons |
|
|
498
|
+
| `allowSystem` | `boolean` | `false` | Show system theme option |
|
|
499
|
+
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Layout direction |
|
|
500
|
+
| `rounded` | `boolean` | `true` | Rounded container corners |
|
|
501
|
+
| `unstyled` | `boolean` | `false` | Remove wrapper styles |
|
|
502
|
+
| `display` | `"buttons" \| "cycle"` | `"buttons"` | Show all buttons or a single cycling button |
|
|
503
|
+
| `transition` | `{ type?: TransitionType; duration?: number; easing?: string }` | `{ type: "none" }` | Animation configuration for cycle mode |
|
|
504
|
+
| `labels` | `Partial<Record<"light" \| "dark" \| "system", string>>` | – | Override labels |
|
|
505
|
+
| `icons` | `Partial<Record<"light" \| "dark" \| "system", ReactNode>>` | – | Override icons |
|
|
506
|
+
| `buttonProps` | `Partial<ButtonProps>` | – | Props passed to every internal button |
|
|
507
|
+
| `className` | `string` | – | Additional wrapper class |
|
|
272
508
|
|
|
273
509
|
---
|
|
274
510
|
|
|
275
|
-
|
|
511
|
+
## 🧩 Button
|
|
276
512
|
|
|
277
|
-
A versatile button with support for variants, sizes, loading states, icons, and
|
|
513
|
+
A versatile, theme-aware button component with support for variants, sizes, typography, loading states, icons, full-width layouts, and custom rendering.
|
|
278
514
|
|
|
279
|
-
|
|
515
|
+
### Basic Usage
|
|
280
516
|
|
|
281
517
|
```tsx
|
|
518
|
+
import { Button } from "@splenddev/kreativ-ui";
|
|
519
|
+
|
|
282
520
|
<Button>Click me</Button>
|
|
283
521
|
```
|
|
284
522
|
|
|
285
|
-
|
|
523
|
+
By default, the Button uses:
|
|
524
|
+
|
|
525
|
+
- `variant="solid"`
|
|
526
|
+
- `color="brand"`
|
|
527
|
+
- `size="md"`
|
|
528
|
+
- `typography="body"`
|
|
529
|
+
- `fullWidth={false}`
|
|
530
|
+
- `isLoading={false}`
|
|
531
|
+
- `disabled={false}`
|
|
532
|
+
|
|
533
|
+
### Variants
|
|
286
534
|
|
|
287
535
|
```tsx
|
|
288
536
|
<Button variant="solid">Solid</Button>
|
|
289
537
|
<Button variant="outline">Outline</Button>
|
|
290
538
|
<Button variant="ghost">Ghost</Button>
|
|
291
539
|
<Button variant="soft">Soft</Button>
|
|
292
|
-
<Button variant="destructive">Delete</Button>
|
|
293
|
-
<Button variant="success">Success</Button>
|
|
294
540
|
<Button variant="link">Learn more</Button>
|
|
295
541
|
```
|
|
296
542
|
|
|
297
|
-
|
|
543
|
+
### Colors
|
|
544
|
+
|
|
545
|
+
```tsx
|
|
546
|
+
<Button color="brand">Brand</Button>
|
|
547
|
+
<Button color="success">Success</Button>
|
|
548
|
+
<Button color="destructive">Delete</Button>
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
### Sizes
|
|
298
552
|
|
|
299
553
|
```tsx
|
|
300
554
|
<Button size="xs">Extra Small</Button>
|
|
301
555
|
<Button size="sm">Small</Button>
|
|
302
556
|
<Button size="md">Medium</Button>
|
|
303
557
|
<Button size="lg">Large</Button>
|
|
304
|
-
<Button size="xl">Extra Large</Button>
|
|
305
558
|
```
|
|
306
559
|
|
|
307
|
-
|
|
560
|
+
### Typography
|
|
561
|
+
|
|
562
|
+
Button typography is controlled independently from its size:
|
|
563
|
+
|
|
564
|
+
```tsx
|
|
565
|
+
<Button typography="body">Default</Button>
|
|
566
|
+
<Button typography="bodySmall">Small Text</Button>
|
|
567
|
+
<Button typography="headingSmall">Heading Style</Button>
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
Example combining size and typography:
|
|
571
|
+
|
|
572
|
+
```tsx
|
|
573
|
+
<Button size="lg" typography="bodySmall">
|
|
574
|
+
Large Button, Small Typography
|
|
575
|
+
</Button>
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
### Loading State
|
|
308
579
|
|
|
309
580
|
```tsx
|
|
310
581
|
<Button isLoading>Saving...</Button>
|
|
311
582
|
```
|
|
312
583
|
|
|
313
|
-
|
|
584
|
+
When loading:
|
|
585
|
+
- A loading indicator is displayed
|
|
586
|
+
- The Button becomes disabled
|
|
587
|
+
- The Button receives `aria-busy="true"`
|
|
588
|
+
- Normal icon rendering is suppressed
|
|
589
|
+
|
|
590
|
+
### Icons
|
|
314
591
|
|
|
315
592
|
```tsx
|
|
316
593
|
<Button leftIcon={<SearchIcon />}>Search</Button>
|
|
317
594
|
<Button rightIcon={<ArrowRightIcon />}>Continue</Button>
|
|
595
|
+
<Button leftIcon={<DownloadIcon />} rightIcon={<ArrowRightIcon />}>
|
|
596
|
+
Download
|
|
597
|
+
</Button>
|
|
318
598
|
```
|
|
319
599
|
|
|
320
|
-
|
|
600
|
+
### Icon Only
|
|
321
601
|
|
|
322
602
|
```tsx
|
|
323
603
|
<Button iconOnly aria-label="Search">
|
|
@@ -325,39 +605,84 @@ A versatile button with support for variants, sizes, loading states, icons, and
|
|
|
325
605
|
</Button>
|
|
326
606
|
```
|
|
327
607
|
|
|
328
|
-
|
|
608
|
+
> **Accessibility:** Always provide an accessible label when the Button contains no visible text.
|
|
609
|
+
|
|
610
|
+
### Full Width
|
|
329
611
|
|
|
330
612
|
```tsx
|
|
331
613
|
<Button fullWidth>Continue</Button>
|
|
332
614
|
```
|
|
333
615
|
|
|
334
|
-
|
|
616
|
+
### Disabled
|
|
617
|
+
|
|
618
|
+
```tsx
|
|
619
|
+
<Button disabled>Unavailable</Button>
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
### Custom Rendering
|
|
623
|
+
|
|
624
|
+
The `render` prop provides an advanced escape hatch for rendering the Button's resolved styles and content using another element or component:
|
|
625
|
+
|
|
626
|
+
```tsx
|
|
627
|
+
<Button
|
|
628
|
+
render={(props) => (
|
|
629
|
+
<a {...props} href="/templates">
|
|
630
|
+
Templates
|
|
631
|
+
</a>
|
|
632
|
+
)}
|
|
633
|
+
>
|
|
634
|
+
Templates
|
|
635
|
+
</Button>
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
The render function receives the resolved Button properties (`className`, `style`, `disabled`, `aria-busy`, `children`).
|
|
335
639
|
|
|
336
|
-
|
|
640
|
+
**Next.js Server Component Note:** Since `render` is a function prop, it should be used from a Client Component:
|
|
337
641
|
|
|
338
|
-
|
|
642
|
+
```tsx
|
|
643
|
+
"use client";
|
|
339
644
|
|
|
340
|
-
|
|
341
|
-
| ------------------------ | ----------------------------------------------------------------------------------- | --------- | ------------------------------------------- |
|
|
342
|
-
| `variant` | `"solid" \| "outline" \| "ghost" \| "soft" \| "destructive" \| "success" \| "link"` | `"solid"` | Visual style |
|
|
343
|
-
| `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl" \| string` | `"md"` | Size (theme‑driven; custom strings allowed) |
|
|
344
|
-
| `isLoading` | `boolean` | `false` | Shows spinner and disables |
|
|
345
|
-
| `leftIcon` / `rightIcon` | `ReactNode` | – | Icon elements |
|
|
346
|
-
| `fullWidth` | `boolean` | `false` | Stretch to container width |
|
|
347
|
-
| `disabled` | `boolean` | `false` | Disables interactions |
|
|
348
|
-
| `iconOnly` | `boolean` | `false` | Remove padding for icon‑only layout |
|
|
645
|
+
import { Button } from "@splenddev/kreativ-ui";
|
|
349
646
|
|
|
350
|
-
|
|
647
|
+
export function TemplatesButton() {
|
|
648
|
+
return (
|
|
649
|
+
<Button
|
|
650
|
+
render={(props) => (
|
|
651
|
+
<a {...props} href="/templates">
|
|
652
|
+
Templates
|
|
653
|
+
</a>
|
|
654
|
+
)}
|
|
655
|
+
>
|
|
656
|
+
Templates
|
|
657
|
+
</Button>
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
```
|
|
351
661
|
|
|
352
|
-
|
|
662
|
+
### Props
|
|
353
663
|
|
|
354
|
-
|
|
664
|
+
| Prop | Type | Default | Description |
|
|
665
|
+
|------|------|---------|-------------|
|
|
666
|
+
| `variant` | `ButtonVariant` | `"solid"` | Visual variant |
|
|
667
|
+
| `color` | `ButtonColor` | `"brand"` | Semantic color |
|
|
668
|
+
| `size` | `ButtonSize` | `"md"` | Dimensions and icon sizing |
|
|
669
|
+
| `typography` | `string` | `"body"` | Typography preset |
|
|
670
|
+
| `isLoading` | `boolean` | `false` | Shows loading indicator and disables interaction |
|
|
671
|
+
| `leftIcon` | `ReactNode` | – | Icon before content |
|
|
672
|
+
| `rightIcon` | `ReactNode` | – | Icon after content |
|
|
673
|
+
| `iconOnly` | `boolean` | `false` | Optimizes layout for icon-only content |
|
|
674
|
+
| `fullWidth` | `boolean` | `false` | Fills available width |
|
|
675
|
+
| `disabled` | `boolean` | `false` | Disables interaction |
|
|
676
|
+
| `render` | `(props: ButtonRenderProps) => ReactElement` | – | Custom rendering escape hatch |
|
|
677
|
+
| `className` | `string` | – | Additional CSS classes |
|
|
678
|
+
| `style` | `React.CSSProperties` | – | Inline style overrides |
|
|
679
|
+
| `children` | `ReactNode` | – | Button content |
|
|
355
680
|
|
|
356
|
-
|
|
681
|
+
All standard HTML `<button>` attributes and event handlers are also supported.
|
|
357
682
|
|
|
358
683
|
---
|
|
359
684
|
|
|
360
|
-
## Input
|
|
685
|
+
## 🧩 Input
|
|
361
686
|
|
|
362
687
|
A flexible text input with support for variants, sizes, validation states, adornments, password visibility, clearing, and loading states.
|
|
363
688
|
|
|
@@ -366,7 +691,7 @@ A flexible text input with support for variants, sizes, validation states, adorn
|
|
|
366
691
|
```tsx
|
|
367
692
|
import { Input } from "@splenddev/kreativ-ui";
|
|
368
693
|
|
|
369
|
-
<Input placeholder="Enter your name"
|
|
694
|
+
<Input placeholder="Enter your name" />
|
|
370
695
|
```
|
|
371
696
|
|
|
372
697
|
### Variants
|
|
@@ -387,7 +712,7 @@ import { Input } from "@splenddev/kreativ-ui";
|
|
|
387
712
|
|
|
388
713
|
### Input Kinds
|
|
389
714
|
|
|
390
|
-
The `kind` prop sets sensible defaults for `type`, `inputMode`, `autoComplete`, and sometimes a placeholder and icon
|
|
715
|
+
The `kind` prop sets sensible defaults for `type`, `inputMode`, `autoComplete`, and sometimes a placeholder and icon:
|
|
391
716
|
|
|
392
717
|
```tsx
|
|
393
718
|
<Input kind="email" />
|
|
@@ -399,7 +724,7 @@ The `kind` prop sets sensible defaults for `type`, `inputMode`, `autoComplete`,
|
|
|
399
724
|
<Input kind="password-new" /> // autoComplete="new-password" + show/hide toggle
|
|
400
725
|
```
|
|
401
726
|
|
|
402
|
-
To suppress the icon that comes with certain kinds
|
|
727
|
+
To suppress the icon that comes with certain kinds:
|
|
403
728
|
|
|
404
729
|
```tsx
|
|
405
730
|
<Input kind="email" hideKindIcon />
|
|
@@ -412,13 +737,11 @@ To suppress the icon that comes with certain kinds (e.g., `email`, `search`):
|
|
|
412
737
|
<Input success />
|
|
413
738
|
```
|
|
414
739
|
|
|
415
|
-
The `error` state also sets `aria-invalid="true"`.
|
|
416
|
-
|
|
417
740
|
### Disabled & Loading
|
|
418
741
|
|
|
419
742
|
```tsx
|
|
420
743
|
<Input disabled />
|
|
421
|
-
<Input isLoading /> // shows a spinner, makes the field read‑only
|
|
744
|
+
<Input isLoading /> // shows a spinner, makes the field read‑only
|
|
422
745
|
```
|
|
423
746
|
|
|
424
747
|
### Adornments (Icons)
|
|
@@ -434,19 +757,6 @@ The `error` state also sets `aria-invalid="true"`.
|
|
|
434
757
|
<Input clearable onClear={() => console.log("cleared")} />
|
|
435
758
|
```
|
|
436
759
|
|
|
437
|
-
A clear button appears when the field has a value. Clicking it clears the value and calls `onClear`.
|
|
438
|
-
|
|
439
|
-
### Password Input
|
|
440
|
-
|
|
441
|
-
With `kind="password-current"` or `kind="password-new"`, a toggle button is shown to reveal/hide the password.
|
|
442
|
-
|
|
443
|
-
### Full Width & Rounded
|
|
444
|
-
|
|
445
|
-
```tsx
|
|
446
|
-
<Input fullWidth /> // default: true
|
|
447
|
-
<Input rounded /> // fully rounded corners
|
|
448
|
-
```
|
|
449
|
-
|
|
450
760
|
### Controlled & Uncontrolled
|
|
451
761
|
|
|
452
762
|
```tsx
|
|
@@ -458,23 +768,35 @@ const [value, setValue] = useState("");
|
|
|
458
768
|
<Input defaultValue="Initial value" />
|
|
459
769
|
```
|
|
460
770
|
|
|
461
|
-
###
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
771
|
+
### Props
|
|
772
|
+
|
|
773
|
+
| Prop | Type | Default | Description |
|
|
774
|
+
|------|------|---------|-------------|
|
|
775
|
+
| `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
|
|
776
|
+
| `inputSize` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding, font size |
|
|
777
|
+
| `kind` | `InputKind` | `"text"` | Sets defaults for type, inputMode, autoComplete, placeholder, and icon |
|
|
778
|
+
| `hideKindIcon` | `boolean` | `false` | Suppress the default icon from `kind` |
|
|
779
|
+
| `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
|
|
780
|
+
| `success` | `boolean` | `false` | Success styling |
|
|
781
|
+
| `disabled` | `boolean` | `false` | Disables the input |
|
|
782
|
+
| `isLoading` | `boolean` | `false` | Shows spinner and marks read‑only |
|
|
783
|
+
| `clearable` | `boolean` | `false` | Shows clear button when value is present |
|
|
784
|
+
| `onClear` | `() => void` | – | Called after clear |
|
|
785
|
+
| `rounded` | `boolean` | `false` | Fully rounded wrapper |
|
|
786
|
+
| `fullWidth` | `boolean` | `true` | Stretch to container width |
|
|
787
|
+
| `startIcon` | `ReactNode` | – | Content before the input |
|
|
788
|
+
| `endIcon` | `ReactNode` | – | Content after the input |
|
|
789
|
+
| `className` | `string` | – | Additional wrapper class |
|
|
790
|
+
| `inputClassName` | `string` | – | Additional class for the native input element |
|
|
468
791
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
The component uses `useSizeStyle` to apply theme‑aware sizing from the `sizes` object in the theme.
|
|
792
|
+
All standard `<input>` attributes (except `size`) are forwarded to the underlying `<input>`.
|
|
472
793
|
|
|
473
794
|
---
|
|
795
|
+
## 🧩 FormField
|
|
474
796
|
|
|
475
|
-
|
|
797
|
+
`FormField` is a compound component for building accessible form fields. It provides shared field context for labels, descriptions, controls, and validation messages while automatically coordinating IDs and accessibility attributes.
|
|
476
798
|
|
|
477
|
-
`FormField`
|
|
799
|
+
`FormField` can be used with controls such as `Input`, but it is not limited to a specific control component.
|
|
478
800
|
|
|
479
801
|
### Basic Structure
|
|
480
802
|
|
|
@@ -483,237 +805,478 @@ import { FormField, Input } from "@splenddev/kreativ-ui";
|
|
|
483
805
|
|
|
484
806
|
<FormField>
|
|
485
807
|
<FormField.Label>Email address</FormField.Label>
|
|
486
|
-
|
|
808
|
+
|
|
809
|
+
<FormField.Description>
|
|
810
|
+
We'll only send receipts here.
|
|
811
|
+
</FormField.Description>
|
|
812
|
+
|
|
487
813
|
<FormField.Control>
|
|
488
814
|
<Input kind="email" placeholder="you@company.com" />
|
|
489
815
|
</FormField.Control>
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
816
|
+
</FormField>
|
|
817
|
+
````
|
|
818
|
+
### ⚠️ Important: Use `FormField.Control`
|
|
493
819
|
|
|
494
|
-
|
|
820
|
+
**`FormField.Control` should be used around the actual form control** when using `FormField`.
|
|
495
821
|
|
|
496
|
-
|
|
497
|
-
| ----------------------- | -------------------------------------------------------------- |
|
|
498
|
-
| `FormField` | Provides context, manages `id` and accessibility relationships |
|
|
499
|
-
| `FormField.Label` | Renders a label associated with the control via `htmlFor` |
|
|
500
|
-
| `FormField.Description` | Renders helper text, linked via `aria-describedby` |
|
|
501
|
-
| `FormField.Control` | Injects the field ID and accessibility props into its child |
|
|
502
|
-
| `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
|
|
822
|
+
`FormField` provides the field context, but `FormField.Control` is responsible for connecting that context to the underlying control. This includes applying the generated field ID and relevant accessibility attributes such as `aria-describedby`, `aria-invalid`, and `aria-required`.
|
|
503
823
|
|
|
504
|
-
|
|
824
|
+
```tsx
|
|
825
|
+
<FormField>
|
|
826
|
+
<FormField.Label>Email</FormField.Label>
|
|
505
827
|
|
|
506
|
-
|
|
828
|
+
<FormField.Control>
|
|
829
|
+
<Input kind="email" />
|
|
830
|
+
</FormField.Control>
|
|
831
|
+
</FormField>
|
|
832
|
+
```
|
|
507
833
|
|
|
508
|
-
|
|
509
|
-
| ----------- | ----------- | -------------- | ------------------------------------------------- |
|
|
510
|
-
| `id` | `string` | auto‑generated | Explicit `id` for the control |
|
|
511
|
-
| `error` | `string` | – | Validation error message (overrides description) |
|
|
512
|
-
| `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
|
|
513
|
-
| `className` | `string` | – | Additional wrapper classes |
|
|
514
|
-
| `children` | `ReactNode` | – | The field content (typically subcomponents) |
|
|
834
|
+
> Avoid placing the control directly inside `FormField`:
|
|
515
835
|
|
|
516
|
-
|
|
836
|
+
```tsx
|
|
837
|
+
{/* ❌ Avoid */}
|
|
838
|
+
<FormField>
|
|
839
|
+
<FormField.Label>Email</FormField.Label>
|
|
840
|
+
<Input kind="email" />
|
|
841
|
+
</FormField>
|
|
842
|
+
```
|
|
843
|
+
> Without `FormField.Control`, the control is not connected to the `FormField` accessibility context.
|
|
517
844
|
|
|
518
|
-
When `error` is provided:
|
|
519
845
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
846
|
+
---
|
|
847
|
+
|
|
848
|
+
The compound API consists of:
|
|
849
|
+
|
|
850
|
+
| Component | Purpose |
|
|
851
|
+
| -- | -- |
|
|
852
|
+
| `FormField` | Provides field context, IDs, validation state, and accessibility relationships |
|
|
853
|
+
| `FormField.Label` | Associates a visible label with the field |
|
|
854
|
+
| `FormField.Description` | Provides supporting or descriptive text |
|
|
855
|
+
| `FormField.Control` | Connects the actual form control to the field context |
|
|
856
|
+
| `FormField.Message` | Displays validation or custom feedback |
|
|
857
|
+
|
|
858
|
+
---
|
|
859
|
+
|
|
860
|
+
### `FormField`
|
|
861
|
+
|
|
862
|
+
The root `FormField` component owns the field's shared state and accessibility information.
|
|
863
|
+
|
|
864
|
+
```tsx
|
|
865
|
+
<FormField>
|
|
866
|
+
<FormField.Label>Username</FormField.Label>
|
|
867
|
+
|
|
868
|
+
<FormField.Control>
|
|
869
|
+
<Input />
|
|
870
|
+
</FormField.Control>
|
|
871
|
+
</FormField>
|
|
872
|
+
```
|
|
523
873
|
|
|
524
|
-
|
|
874
|
+
If an `id` is not supplied, `FormField` generates a unique ID automatically.
|
|
525
875
|
|
|
526
|
-
|
|
876
|
+
The generated field IDs are used to coordinate:
|
|
527
877
|
|
|
528
|
-
|
|
878
|
+
* the control ID
|
|
879
|
+
* label association
|
|
880
|
+
* description association
|
|
881
|
+
* validation message association
|
|
882
|
+
* `aria-describedby`
|
|
883
|
+
* `aria-invalid`
|
|
884
|
+
* `aria-required`
|
|
529
885
|
|
|
530
|
-
|
|
886
|
+
### Props
|
|
887
|
+
|
|
888
|
+
| Prop | Type | Default | Description |
|
|
889
|
+
| ----------- | ----------------- | -------------- | ------------------------------------------------------------- |
|
|
890
|
+
| `id` | `string` | auto-generated | Explicit ID for the form control |
|
|
891
|
+
| `status` | `FormFieldStatus` | `"none"` | Controls the field's validation status |
|
|
892
|
+
| `message` | `string` | — | Validation or feedback message controlled by the parent field |
|
|
893
|
+
| `required` | `boolean` | `false` | Marks the field as required |
|
|
894
|
+
| `className` | `string` | — | Additional classes for the root wrapper |
|
|
895
|
+
| `children` | `ReactNode` | — | Field content |
|
|
896
|
+
|
|
897
|
+
> The exact available values for `status` depend on the exported `FormFieldStatus` type. The root component explicitly supports `"none"` and `"error"`.
|
|
531
898
|
|
|
532
899
|
---
|
|
533
900
|
|
|
534
|
-
##
|
|
901
|
+
## Validation Status
|
|
535
902
|
|
|
536
|
-
|
|
903
|
+
Validation state is controlled through the `status` prop.
|
|
537
904
|
|
|
538
905
|
```tsx
|
|
539
|
-
|
|
906
|
+
<FormField status="error">
|
|
907
|
+
<FormField.Label>Email</FormField.Label>
|
|
540
908
|
|
|
541
|
-
|
|
542
|
-
|
|
909
|
+
<FormField.Control>
|
|
910
|
+
<Input kind="email" />
|
|
911
|
+
</FormField.Control>
|
|
912
|
+
</FormField>
|
|
913
|
+
```
|
|
543
914
|
|
|
544
|
-
|
|
545
|
-
const value = e.target.value;
|
|
546
|
-
if (!value) setError("Email is required");
|
|
547
|
-
else if (!/\S+@\S+\.\S+/.test(value)) setError("Enter a valid email");
|
|
548
|
-
else setError("");
|
|
549
|
-
};
|
|
915
|
+
The `status` contributes to the field's invalid state.
|
|
550
916
|
|
|
551
|
-
|
|
552
|
-
<FormField id="email" required error={error}>
|
|
553
|
-
<FormField.Label>Email address</FormField.Label>
|
|
554
|
-
<FormField.Description>
|
|
555
|
-
We'll only send receipts here.
|
|
556
|
-
</FormField.Description>
|
|
557
|
-
<FormField.Control>
|
|
558
|
-
<Input kind="email" placeholder="you@company.com" onBlur={handleBlur} />
|
|
559
|
-
</FormField.Control>
|
|
560
|
-
{error && <FormField.Message>{error}</FormField.Message>}
|
|
561
|
-
</FormField>
|
|
562
|
-
);
|
|
563
|
-
}
|
|
564
|
-
```
|
|
917
|
+
For example:
|
|
565
918
|
|
|
566
|
-
|
|
919
|
+
```tsx
|
|
920
|
+
<FormField status="error" message="Please enter a valid email address">
|
|
921
|
+
...
|
|
922
|
+
</FormField>
|
|
923
|
+
```
|
|
567
924
|
|
|
568
|
-
|
|
569
|
-
- `FormField.Label` – provides the accessible label.
|
|
570
|
-
- `FormField.Description` – provides supporting text (hidden when `error` exists).
|
|
571
|
-
- `FormField.Control` – connects the actual control to the field context.
|
|
572
|
-
- `Input` – handles the input behavior and presentation.
|
|
573
|
-
- `FormField.Message` – displays validation feedback.
|
|
925
|
+
The field becomes invalid because its status is `"error"`.
|
|
574
926
|
|
|
575
927
|
---
|
|
576
928
|
|
|
577
|
-
##
|
|
929
|
+
## Validation Messages
|
|
930
|
+
|
|
931
|
+
`FormField` supports two ways of providing validation feedback:
|
|
932
|
+
|
|
933
|
+
1. A controlled `message` supplied to the root `FormField`.
|
|
934
|
+
2. A custom `<FormField.Message>` placed inside the field.
|
|
578
935
|
|
|
579
|
-
|
|
936
|
+
### Controlled Message
|
|
580
937
|
|
|
938
|
+
```tsx
|
|
939
|
+
<FormField
|
|
940
|
+
status="error"
|
|
941
|
+
message="Please enter a valid email address"
|
|
942
|
+
>
|
|
943
|
+
<FormField.Label>Email address</FormField.Label>
|
|
944
|
+
|
|
945
|
+
<FormField.Control>
|
|
946
|
+
<Input kind="email" />
|
|
947
|
+
</FormField.Control>
|
|
948
|
+
</FormField>
|
|
581
949
|
```
|
|
582
|
-
Label
|
|
583
|
-
↓
|
|
584
|
-
for → input[id]
|
|
585
950
|
|
|
586
|
-
|
|
587
|
-
↓
|
|
588
|
-
aria-describedby → description id
|
|
951
|
+
When no custom `FormField.Message` is present, the root automatically renders one.
|
|
589
952
|
|
|
590
|
-
|
|
591
|
-
↓
|
|
592
|
-
aria-describedby → message id (appended to description ids)
|
|
953
|
+
This means consumers do not need to manually render:
|
|
593
954
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
aria-invalid="true" (when error is present)
|
|
955
|
+
```tsx
|
|
956
|
+
<FormField.Message />
|
|
597
957
|
```
|
|
598
958
|
|
|
599
|
-
|
|
959
|
+
for the common controlled-message case.
|
|
600
960
|
|
|
601
961
|
---
|
|
602
962
|
|
|
603
|
-
##
|
|
963
|
+
## Custom Messages
|
|
604
964
|
|
|
605
|
-
|
|
965
|
+
A custom `FormField.Message` can also be placed inside the field.
|
|
606
966
|
|
|
607
967
|
```tsx
|
|
608
|
-
|
|
609
|
-
<FormField
|
|
968
|
+
<FormField status="error">
|
|
969
|
+
<FormField.Label>Email address</FormField.Label>
|
|
970
|
+
|
|
610
971
|
<FormField.Control>
|
|
611
|
-
<Input />
|
|
972
|
+
<Input kind="email" />
|
|
612
973
|
</FormField.Control>
|
|
974
|
+
|
|
975
|
+
<FormField.Message>
|
|
976
|
+
Please enter a valid email address.
|
|
977
|
+
</FormField.Message>
|
|
613
978
|
</FormField>
|
|
979
|
+
```
|
|
614
980
|
|
|
615
|
-
|
|
616
|
-
|
|
981
|
+
When a custom `FormField.Message` exists, the root `FormField` does not render an additional automatic message.
|
|
982
|
+
|
|
983
|
+
This allows the message content to be controlled directly at the composition level.
|
|
984
|
+
|
|
985
|
+
### One Custom Message
|
|
986
|
+
|
|
987
|
+
A `FormField` should contain at most one custom `FormField.Message`.
|
|
988
|
+
|
|
989
|
+
In development, Kreativ UI detects multiple custom message components and warns:
|
|
990
|
+
|
|
991
|
+
```text
|
|
992
|
+
[Kreativ UI] Multiple <FormField.Message /> components were detected inside the same <FormField>. Only one custom message should be provided.
|
|
993
|
+
```
|
|
994
|
+
|
|
995
|
+
---
|
|
996
|
+
|
|
997
|
+
## Native Control Validation
|
|
998
|
+
|
|
999
|
+
`FormField` can also receive validity information reported by the connected control.
|
|
1000
|
+
|
|
1001
|
+
The field maintains an internal validity state and can receive a `ReportedValidity` result through its context.
|
|
1002
|
+
|
|
1003
|
+
When the reported validity indicates an invalid control, the field can use the reported validation message.
|
|
1004
|
+
|
|
1005
|
+
Conceptually:
|
|
1006
|
+
|
|
1007
|
+
```text
|
|
1008
|
+
Native/control validity
|
|
1009
|
+
↓
|
|
1010
|
+
ReportedValidity
|
|
1011
|
+
↓
|
|
1012
|
+
FormField
|
|
1013
|
+
↓
|
|
1014
|
+
reported message
|
|
1015
|
+
↓
|
|
1016
|
+
FormField.Message
|
|
617
1017
|
```
|
|
618
1018
|
|
|
619
|
-
|
|
1019
|
+
A parent-provided `message` takes precedence over a message reported by the control.
|
|
620
1020
|
|
|
621
|
-
|
|
1021
|
+
The effective message is resolved as:
|
|
1022
|
+
|
|
1023
|
+
```text
|
|
1024
|
+
message prop
|
|
1025
|
+
↓
|
|
1026
|
+
reported validity message
|
|
1027
|
+
↓
|
|
1028
|
+
no message
|
|
1029
|
+
```
|
|
622
1030
|
|
|
623
|
-
|
|
1031
|
+
In other words, an explicitly supplied `message` overrides the automatically reported validity message.
|
|
624
1032
|
|
|
625
1033
|
---
|
|
626
1034
|
|
|
627
|
-
##
|
|
1035
|
+
## Required Fields
|
|
1036
|
+
|
|
1037
|
+
Set `required` on the root `FormField`:
|
|
628
1038
|
|
|
629
|
-
|
|
630
|
-
|
|
1039
|
+
```tsx
|
|
1040
|
+
<FormField required>
|
|
1041
|
+
<FormField.Label>Email address</FormField.Label>
|
|
1042
|
+
|
|
1043
|
+
<FormField.Control>
|
|
1044
|
+
<Input kind="email" />
|
|
1045
|
+
</FormField.Control>
|
|
1046
|
+
</FormField>
|
|
1047
|
+
```
|
|
1048
|
+
|
|
1049
|
+
The required state is exposed through the field context so that the associated components can apply the appropriate accessibility behavior.
|
|
631
1050
|
|
|
632
1051
|
---
|
|
633
1052
|
|
|
634
|
-
##
|
|
635
|
-
|
|
636
|
-
### Input Props
|
|
637
|
-
|
|
638
|
-
| Prop | Type | Default | Description |
|
|
639
|
-
| ---------------- | ---------------------------------- | ----------- | ---------------------------------------------------------------------------- |
|
|
640
|
-
| `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
|
|
641
|
-
| `inputSize` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding, font size |
|
|
642
|
-
| `kind` | `InputKind` | `"text"` | Sets defaults for `type`, `inputMode`, `autoComplete`, placeholder, and icon |
|
|
643
|
-
| `hideKindIcon` | `boolean` | `false` | Suppress the default icon from `kind` |
|
|
644
|
-
| `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
|
|
645
|
-
| `success` | `boolean` | `false` | Success styling |
|
|
646
|
-
| `disabled` | `boolean` | `false` | Disables the input |
|
|
647
|
-
| `isLoading` | `boolean` | `false` | Shows spinner and marks read‑only |
|
|
648
|
-
| `clearable` | `boolean` | `false` | Shows clear button when value is present |
|
|
649
|
-
| `onClear` | `() => void` | – | Called after clear |
|
|
650
|
-
| `rounded` | `boolean` | `false` | Fully rounded wrapper |
|
|
651
|
-
| `fullWidth` | `boolean` | `true` | Stretch to container width |
|
|
652
|
-
| `startIcon` | `ReactNode` | – | Content before the input (e.g., icon) |
|
|
653
|
-
| `endIcon` | `ReactNode` | – | Content after the input (e.g., icon) |
|
|
654
|
-
| `className` | `string` | – | Additional wrapper class |
|
|
655
|
-
| `inputClassName` | `string` | – | Additional class for the native input element |
|
|
1053
|
+
## Labels
|
|
656
1054
|
|
|
657
|
-
|
|
1055
|
+
Use `FormField.Label` to provide the field's visible label.
|
|
1056
|
+
|
|
1057
|
+
```tsx
|
|
1058
|
+
<FormField>
|
|
1059
|
+
<FormField.Label>First name</FormField.Label>
|
|
1060
|
+
|
|
1061
|
+
<FormField.Control>
|
|
1062
|
+
<Input placeholder="Felix" />
|
|
1063
|
+
</FormField.Control>
|
|
1064
|
+
</FormField>
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
The label is associated with the generated or supplied field ID.
|
|
1068
|
+
|
|
1069
|
+
`FormField` also tracks whether a label component is present. This allows the field to distinguish between a field with an external/registered label and one without one.
|
|
1070
|
+
|
|
1071
|
+
For accessibility, form controls should generally have an accessible name.
|
|
1072
|
+
|
|
1073
|
+
---
|
|
1074
|
+
|
|
1075
|
+
## Description
|
|
1076
|
+
|
|
1077
|
+
`FormField.Description` provides supporting information for the control.
|
|
658
1078
|
|
|
659
|
-
|
|
1079
|
+
```tsx
|
|
1080
|
+
<FormField>
|
|
1081
|
+
<FormField.Label>Password</FormField.Label>
|
|
660
1082
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
| `error` | `string` | – | Validation error message (overrides description) |
|
|
665
|
-
| `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
|
|
666
|
-
| `className` | `string` | – | Additional wrapper classes |
|
|
667
|
-
| `children` | `ReactNode` | – | The field content (typically subcomponents) |
|
|
1083
|
+
<FormField.Description>
|
|
1084
|
+
Use at least 8 characters.
|
|
1085
|
+
</FormField.Description>
|
|
668
1086
|
|
|
669
|
-
|
|
1087
|
+
<FormField.Control>
|
|
1088
|
+
<Input type="password" />
|
|
1089
|
+
</FormField.Control>
|
|
1090
|
+
</FormField>
|
|
1091
|
+
```
|
|
670
1092
|
|
|
671
|
-
|
|
672
|
-
| ----------------------- | ------------------------------------------------------------ |
|
|
673
|
-
| `FormField.Label` | Renders a label associated with the control via `htmlFor` |
|
|
674
|
-
| `FormField.Description` | Renders helper text, linked via `aria-describedby` |
|
|
675
|
-
| `FormField.Control` | Injects the field ID and accessibility props into its child |
|
|
676
|
-
| `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
|
|
1093
|
+
The description receives an ID derived from the field ID and participates in the control's `aria-describedby` relationship.
|
|
677
1094
|
|
|
678
1095
|
---
|
|
679
1096
|
|
|
680
|
-
|
|
1097
|
+
## Control
|
|
1098
|
+
|
|
1099
|
+
`FormField.Control` connects the actual form control to the surrounding `FormField` context.
|
|
1100
|
+
|
|
1101
|
+
```tsx
|
|
1102
|
+
<FormField>
|
|
1103
|
+
<FormField.Label>Username</FormField.Label>
|
|
1104
|
+
|
|
1105
|
+
<FormField.Control>
|
|
1106
|
+
<Input />
|
|
1107
|
+
</FormField.Control>
|
|
1108
|
+
</FormField>
|
|
1109
|
+
```
|
|
1110
|
+
|
|
1111
|
+
The control is responsible for receiving the field's relevant accessibility information, including the generated field ID and description relationships.
|
|
1112
|
+
|
|
1113
|
+
This allows the root field to manage accessibility relationships without requiring consumers to manually coordinate IDs.
|
|
681
1114
|
|
|
682
1115
|
---
|
|
683
1116
|
|
|
684
|
-
|
|
1117
|
+
## Accessibility Relationships
|
|
1118
|
+
|
|
1119
|
+
A typical field establishes relationships similar to:
|
|
1120
|
+
|
|
1121
|
+
```text
|
|
1122
|
+
FormField
|
|
1123
|
+
│
|
|
1124
|
+
├── Label
|
|
1125
|
+
│ └── htmlFor → field ID
|
|
1126
|
+
│
|
|
1127
|
+
├── Description
|
|
1128
|
+
│ └── description ID
|
|
1129
|
+
│
|
|
1130
|
+
├── Control
|
|
1131
|
+
│ ├── id → field ID
|
|
1132
|
+
│ └── aria-describedby → description/message IDs
|
|
1133
|
+
│
|
|
1134
|
+
└── Message
|
|
1135
|
+
└── message ID
|
|
1136
|
+
```
|
|
1137
|
+
|
|
1138
|
+
When the field has a message or custom message, its message ID is included in the control's `aria-describedby`.
|
|
1139
|
+
|
|
1140
|
+
When the field is invalid, the field context exposes the invalid state so the control can apply the appropriate `aria-invalid` behavior.
|
|
685
1141
|
|
|
686
|
-
|
|
1142
|
+
When `required` is enabled, the required state is also exposed to the control.
|
|
687
1143
|
|
|
688
1144
|
---
|
|
689
1145
|
|
|
690
|
-
##
|
|
1146
|
+
## Message Resolution
|
|
1147
|
+
|
|
1148
|
+
The root component resolves the displayed message using the following precedence:
|
|
1149
|
+
|
|
1150
|
+
```text
|
|
1151
|
+
FormField.message
|
|
1152
|
+
↓
|
|
1153
|
+
reported validity message
|
|
1154
|
+
↓
|
|
1155
|
+
undefined
|
|
1156
|
+
```
|
|
1157
|
+
|
|
1158
|
+
Therefore, this:
|
|
1159
|
+
|
|
1160
|
+
```tsx
|
|
1161
|
+
<FormField
|
|
1162
|
+
status="error"
|
|
1163
|
+
message="Email is required"
|
|
1164
|
+
>
|
|
1165
|
+
```
|
|
1166
|
+
|
|
1167
|
+
takes precedence over a validation message reported by the connected control.
|
|
691
1168
|
|
|
692
|
-
|
|
1169
|
+
A custom:
|
|
693
1170
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
- `Select.Group` – groups related options
|
|
700
|
-
- `Select.Label` – heading for a group
|
|
1171
|
+
```tsx
|
|
1172
|
+
<FormField.Message>
|
|
1173
|
+
...
|
|
1174
|
+
</FormField.Message>
|
|
1175
|
+
```
|
|
701
1176
|
|
|
702
|
-
|
|
1177
|
+
is handled separately as an explicit message component and prevents the root from rendering its automatic message component.
|
|
703
1178
|
|
|
704
1179
|
---
|
|
705
1180
|
|
|
706
|
-
##
|
|
1181
|
+
## Complete Example
|
|
707
1182
|
|
|
708
1183
|
```tsx
|
|
709
|
-
import {
|
|
1184
|
+
import { useState } from "react";
|
|
1185
|
+
import { FormField, Input } from "@splenddev/kreativ-ui";
|
|
1186
|
+
|
|
1187
|
+
function EmailField() {
|
|
1188
|
+
const [email, setEmail] = useState("");
|
|
1189
|
+
const [message, setMessage] = useState("");
|
|
1190
|
+
|
|
1191
|
+
function validateEmail(value: string) {
|
|
1192
|
+
if (!value) {
|
|
1193
|
+
setMessage("Email address is required.");
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1197
|
+
if (!/\S+@\S+\.\S+/.test(value)) {
|
|
1198
|
+
setMessage("Please enter a valid email address.");
|
|
1199
|
+
return;
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
setMessage("");
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
return (
|
|
1206
|
+
<FormField
|
|
1207
|
+
id="email"
|
|
1208
|
+
required
|
|
1209
|
+
status={message ? "error" : "none"}
|
|
1210
|
+
message={message || undefined}
|
|
1211
|
+
>
|
|
1212
|
+
<FormField.Label>Email address</FormField.Label>
|
|
1213
|
+
|
|
1214
|
+
<FormField.Description>
|
|
1215
|
+
We'll only send receipts to this address.
|
|
1216
|
+
</FormField.Description>
|
|
1217
|
+
|
|
1218
|
+
<FormField.Control>
|
|
1219
|
+
<Input
|
|
1220
|
+
kind="email"
|
|
1221
|
+
value={email}
|
|
1222
|
+
placeholder="you@example.com"
|
|
1223
|
+
onChange={(event) => setEmail(event.target.value)}
|
|
1224
|
+
onBlur={() => validateEmail(email)}
|
|
1225
|
+
/>
|
|
1226
|
+
</FormField.Control>
|
|
1227
|
+
</FormField>
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
```
|
|
1231
|
+
|
|
1232
|
+
This example demonstrates the intended separation of responsibilities:
|
|
1233
|
+
|
|
1234
|
+
```text
|
|
1235
|
+
FormField
|
|
1236
|
+
│
|
|
1237
|
+
├── Field identity
|
|
1238
|
+
│ └── id
|
|
1239
|
+
│
|
|
1240
|
+
├── Validation state
|
|
1241
|
+
│ ├── status
|
|
1242
|
+
│ └── message
|
|
1243
|
+
│
|
|
1244
|
+
├── Accessibility
|
|
1245
|
+
│ ├── label relationship
|
|
1246
|
+
│ ├── description relationship
|
|
1247
|
+
│ ├── message relationship
|
|
1248
|
+
│ └── required / invalid state
|
|
1249
|
+
│
|
|
1250
|
+
└── Control
|
|
1251
|
+
└── Input
|
|
710
1252
|
```
|
|
711
1253
|
|
|
1254
|
+
### Standalone Control vs FormField
|
|
1255
|
+
|
|
1256
|
+
Use a standalone component such as `Input` when the surrounding UI does not require the full field composition.
|
|
1257
|
+
|
|
1258
|
+
Use `FormField` when you need a coordinated:
|
|
1259
|
+
|
|
1260
|
+
* label
|
|
1261
|
+
* description
|
|
1262
|
+
* validation state
|
|
1263
|
+
* validation message
|
|
1264
|
+
* required state
|
|
1265
|
+
* accessibility relationship
|
|
1266
|
+
|
|
1267
|
+
The `FormField` system is designed to keep these concerns connected without requiring consumers to manually manage the generated IDs and ARIA relationships.
|
|
1268
|
+
|
|
712
1269
|
---
|
|
713
1270
|
|
|
714
|
-
##
|
|
1271
|
+
## 🧩 Select
|
|
1272
|
+
|
|
1273
|
+
A fully accessible, customizable select component with keyboard navigation, grouped options, and clearable selections.
|
|
1274
|
+
|
|
1275
|
+
### Basic Usage
|
|
715
1276
|
|
|
716
1277
|
```tsx
|
|
1278
|
+
import { Select } from "@splenddev/kreativ-ui";
|
|
1279
|
+
|
|
717
1280
|
<Select placeholder="Select a country">
|
|
718
1281
|
<Select.Trigger>
|
|
719
1282
|
<Select.Value />
|
|
@@ -727,11 +1290,7 @@ import { Select } from "@splenddev/kreativ-ui";
|
|
|
727
1290
|
</Select>
|
|
728
1291
|
```
|
|
729
1292
|
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
## Controlled Select
|
|
733
|
-
|
|
734
|
-
Use `value` and `onValueChange` to control the selection from a parent component.
|
|
1293
|
+
### Controlled Select
|
|
735
1294
|
|
|
736
1295
|
```tsx
|
|
737
1296
|
import { useState } from "react";
|
|
@@ -755,13 +1314,7 @@ function ControlledSelect() {
|
|
|
755
1314
|
}
|
|
756
1315
|
```
|
|
757
1316
|
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
---
|
|
761
|
-
|
|
762
|
-
## Uncontrolled Select
|
|
763
|
-
|
|
764
|
-
Use `defaultValue` for an uncontrolled component.
|
|
1317
|
+
### Uncontrolled Select
|
|
765
1318
|
|
|
766
1319
|
```tsx
|
|
767
1320
|
<Select defaultValue="react">
|
|
@@ -777,34 +1330,30 @@ Use `defaultValue` for an uncontrolled component.
|
|
|
777
1330
|
</Select>
|
|
778
1331
|
```
|
|
779
1332
|
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
## Props
|
|
783
|
-
|
|
784
|
-
| Prop | Type | Default | Description |
|
|
785
|
-
| --------------- | ---------------------------------- | ----------- | -------------------------------------------------- |
|
|
786
|
-
| `value` | `string` | – | Controlled selected value |
|
|
787
|
-
| `defaultValue` | `string` | – | Uncontrolled initial value |
|
|
788
|
-
| `onValueChange` | `(value?: string) => void` | – | Called when selection changes |
|
|
789
|
-
| `placeholder` | `string` | – | Text shown when no value is selected |
|
|
790
|
-
| `required` | `boolean` | `false` | Marks the field as required (`aria-required`) |
|
|
791
|
-
| `name` | `string` | – | Name for the hidden input used in form submissions |
|
|
792
|
-
| `disabled` | `boolean` | `false` | Disables the entire select |
|
|
793
|
-
| `clearable` | `boolean` | `false` | Shows a clear button (removes selection) |
|
|
794
|
-
| `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
|
|
795
|
-
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size of the trigger and content |
|
|
796
|
-
| `error` | `boolean` | `false` | Shows error state and sets `aria-invalid="true"` |
|
|
797
|
-
| `success` | `boolean` | `false` | Shows success state |
|
|
798
|
-
| `rounded` | `boolean` | `false` | Applies fully rounded corners to the trigger |
|
|
799
|
-
| `className` | `string` | – | Additional class names for the root container |
|
|
1333
|
+
### Props
|
|
800
1334
|
|
|
801
|
-
|
|
1335
|
+
| Prop | Type | Default | Description |
|
|
1336
|
+
|------|------|---------|-------------|
|
|
1337
|
+
| `value` | `string` | – | Controlled selected value |
|
|
1338
|
+
| `defaultValue` | `string` | – | Uncontrolled initial value |
|
|
1339
|
+
| `onValueChange` | `(value?: string) => void` | – | Called when selection changes |
|
|
1340
|
+
| `placeholder` | `string` | – | Text shown when no value is selected |
|
|
1341
|
+
| `required` | `boolean` | `false` | Marks the field as required |
|
|
1342
|
+
| `name` | `string` | – | Name for the hidden input used in form submissions |
|
|
1343
|
+
| `disabled` | `boolean` | `false` | Disables the entire select |
|
|
1344
|
+
| `clearable` | `boolean` | `false` | Shows a clear button |
|
|
1345
|
+
| `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
|
|
1346
|
+
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size of the trigger and content |
|
|
1347
|
+
| `error` | `boolean` | `false` | Shows error state |
|
|
1348
|
+
| `success` | `boolean` | `false` | Shows success state |
|
|
1349
|
+
| `rounded` | `boolean` | `false` | Applies fully rounded corners to the trigger |
|
|
1350
|
+
| `className` | `string` | – | Additional class names for the root container |
|
|
802
1351
|
|
|
803
|
-
|
|
1352
|
+
### Compound Components
|
|
804
1353
|
|
|
805
|
-
|
|
1354
|
+
#### `Select.Trigger`
|
|
806
1355
|
|
|
807
|
-
The interactive button that toggles the dropdown
|
|
1356
|
+
The interactive button that toggles the dropdown:
|
|
808
1357
|
|
|
809
1358
|
```tsx
|
|
810
1359
|
<Select.Trigger>
|
|
@@ -812,31 +1361,25 @@ The interactive button that toggles the dropdown. It receives all necessary ARIA
|
|
|
812
1361
|
</Select.Trigger>
|
|
813
1362
|
```
|
|
814
1363
|
|
|
815
|
-
|
|
1364
|
+
#### `Select.Value`
|
|
816
1365
|
|
|
817
|
-
Renders the current selection or the placeholder
|
|
1366
|
+
Renders the current selection or the placeholder:
|
|
818
1367
|
|
|
819
1368
|
```tsx
|
|
820
1369
|
<Select.Value placeholder="Choose an option" />
|
|
821
1370
|
```
|
|
822
1371
|
|
|
823
|
-
|
|
1372
|
+
#### `Select.Content`
|
|
824
1373
|
|
|
825
|
-
The dropdown container
|
|
1374
|
+
The dropdown container:
|
|
826
1375
|
|
|
827
1376
|
```tsx
|
|
828
1377
|
<Select.Content>{/* items */}</Select.Content>
|
|
829
1378
|
```
|
|
830
1379
|
|
|
831
|
-
|
|
1380
|
+
#### `Select.Item`
|
|
832
1381
|
|
|
833
|
-
A single selectable option
|
|
834
|
-
|
|
835
|
-
| Prop | Type | Default | Description |
|
|
836
|
-
| ---------- | ----------- | -------- | -------------------- |
|
|
837
|
-
| `value` | `string` | required | Value of the option |
|
|
838
|
-
| `disabled` | `boolean` | `false` | Disables this option |
|
|
839
|
-
| `children` | `ReactNode` | – | Display label |
|
|
1382
|
+
A single selectable option:
|
|
840
1383
|
|
|
841
1384
|
```tsx
|
|
842
1385
|
<Select.Item value="react" disabled>
|
|
@@ -844,9 +1387,9 @@ A single selectable option.
|
|
|
844
1387
|
</Select.Item>
|
|
845
1388
|
```
|
|
846
1389
|
|
|
847
|
-
|
|
1390
|
+
#### `Select.Group`
|
|
848
1391
|
|
|
849
|
-
Groups related options
|
|
1392
|
+
Groups related options:
|
|
850
1393
|
|
|
851
1394
|
```tsx
|
|
852
1395
|
<Select.Group>
|
|
@@ -856,61 +1399,15 @@ Groups related options, typically used with `Select.Label`.
|
|
|
856
1399
|
</Select.Group>
|
|
857
1400
|
```
|
|
858
1401
|
|
|
859
|
-
|
|
1402
|
+
#### `Select.Label`
|
|
860
1403
|
|
|
861
|
-
A heading for a group of options
|
|
1404
|
+
A heading for a group of options:
|
|
862
1405
|
|
|
863
1406
|
```tsx
|
|
864
1407
|
<Select.Label>Backend</Select.Label>
|
|
865
1408
|
```
|
|
866
1409
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
## Accessibility
|
|
870
|
-
|
|
871
|
-
`Select` implements the WAI‑ARIA combobox pattern and manages all necessary relationships automatically.
|
|
872
|
-
|
|
873
|
-
**Roles & Attributes**:
|
|
874
|
-
|
|
875
|
-
- Trigger: `role="combobox"`, `aria-haspopup="listbox"`, `aria-expanded`, `aria-controls`, `aria-activedescendant`
|
|
876
|
-
- Content: `role="listbox"`
|
|
877
|
-
- Items: `role="option"`, `aria-selected`, `aria-disabled`
|
|
878
|
-
|
|
879
|
-
**Automatic IDs**: The root generates unique IDs for the trigger, content, and each option. These are used to connect the trigger to the listbox and to manage `aria-activedescendant`.
|
|
880
|
-
|
|
881
|
-
**FormField integration**: When placed inside a `FormField`, the Select consumes the following context:
|
|
882
|
-
|
|
883
|
-
- `id` – becomes the trigger’s `id`
|
|
884
|
-
- `labelId` – linked via `aria-labelledby`
|
|
885
|
-
- `descriptionId` / `messageId` – linked via `aria-describedby`
|
|
886
|
-
- `invalid` – sets `aria-invalid`
|
|
887
|
-
- `required` – sets `aria-required`
|
|
888
|
-
|
|
889
|
-
This ensures full ARIA support with no manual configuration.
|
|
890
|
-
|
|
891
|
-
---
|
|
892
|
-
|
|
893
|
-
## Keyboard Navigation
|
|
894
|
-
|
|
895
|
-
| Key | Open state | Closed state |
|
|
896
|
-
| ----------- | ------------------ | ----------------------------------------- |
|
|
897
|
-
| `ArrowDown` | Next item | Opens the dropdown |
|
|
898
|
-
| `ArrowUp` | Previous item | Opens the dropdown (or no-op) |
|
|
899
|
-
| `Home` | First item | Opens and selects first? (implementation) |
|
|
900
|
-
| `End` | Last item | Opens and selects last? |
|
|
901
|
-
| `Enter` | Select active item | Opens the dropdown |
|
|
902
|
-
| `Space` | Select active item | Opens the dropdown |
|
|
903
|
-
| `Escape` | Closes dropdown | – |
|
|
904
|
-
| `Backspace` | – | Clears selection (if `clearable`) |
|
|
905
|
-
| `Delete` | – | Clears selection (if `clearable`) |
|
|
906
|
-
|
|
907
|
-
> When the dropdown is open, `ArrowDown`/`ArrowUp` navigate through items. `Enter`/`Space` select the active (highlighted) item and close the dropdown. `Escape` closes the dropdown without selection.
|
|
908
|
-
|
|
909
|
-
---
|
|
910
|
-
|
|
911
|
-
## Clearable Select
|
|
912
|
-
|
|
913
|
-
When `clearable` is `true`, a clear button appears inside the trigger when a value is selected. Clicking it resets the selection to `undefined`.
|
|
1410
|
+
### Clearable Select
|
|
914
1411
|
|
|
915
1412
|
```tsx
|
|
916
1413
|
<Select clearable defaultValue="react">
|
|
@@ -925,54 +1422,7 @@ When `clearable` is `true`, a clear button appears inside the trigger when a val
|
|
|
925
1422
|
</Select>
|
|
926
1423
|
```
|
|
927
1424
|
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
**Uncontrolled behavior**: The internal state is cleared automatically.
|
|
931
|
-
|
|
932
|
-
---
|
|
933
|
-
|
|
934
|
-
## Disabled Options
|
|
935
|
-
|
|
936
|
-
Individual items can be disabled using the `disabled` prop. They are not selectable via mouse or keyboard navigation and are announced as disabled by screen readers.
|
|
937
|
-
|
|
938
|
-
```tsx
|
|
939
|
-
<Select.Item value="legacy" disabled>
|
|
940
|
-
Legacy
|
|
941
|
-
</Select.Item>
|
|
942
|
-
```
|
|
943
|
-
|
|
944
|
-
Disabled items are skipped when navigating with arrow keys.
|
|
945
|
-
|
|
946
|
-
---
|
|
947
|
-
|
|
948
|
-
## Validation States
|
|
949
|
-
|
|
950
|
-
### Error
|
|
951
|
-
|
|
952
|
-
```tsx
|
|
953
|
-
<Select error>
|
|
954
|
-
<Select.Trigger>
|
|
955
|
-
<Select.Value placeholder="Choose" />
|
|
956
|
-
</Select.Trigger>
|
|
957
|
-
<Select.Content>...</Select.Content>
|
|
958
|
-
</Select>
|
|
959
|
-
```
|
|
960
|
-
|
|
961
|
-
Visually styles the trigger with error colours and sets `aria-invalid="true"`.
|
|
962
|
-
|
|
963
|
-
### Success
|
|
964
|
-
|
|
965
|
-
```tsx
|
|
966
|
-
<Select success>...</Select>
|
|
967
|
-
```
|
|
968
|
-
|
|
969
|
-
Applies success styling.
|
|
970
|
-
|
|
971
|
-
---
|
|
972
|
-
|
|
973
|
-
## FormField Integration
|
|
974
|
-
|
|
975
|
-
When used inside a `FormField`, the Select automatically inherits the field’s `id`, `required`, and validation state.
|
|
1425
|
+
### FormField Integration
|
|
976
1426
|
|
|
977
1427
|
```tsx
|
|
978
1428
|
<FormField required error="Please select a country">
|
|
@@ -995,155 +1445,17 @@ When used inside a `FormField`, the Select automatically inherits the field’s
|
|
|
995
1445
|
</FormField>
|
|
996
1446
|
```
|
|
997
1447
|
|
|
998
|
-
> No extra props are needed – the Select picks up the context automatically.
|
|
999
|
-
|
|
1000
|
-
---
|
|
1001
|
-
|
|
1002
|
-
## Native Form Submission
|
|
1003
|
-
|
|
1004
|
-
The `name` prop renders a hidden `<input>` that is included in form submissions. The value submitted is the currently selected `value`.
|
|
1005
|
-
|
|
1006
|
-
```tsx
|
|
1007
|
-
<form onSubmit={handleSubmit}>
|
|
1008
|
-
<Select name="country" defaultValue="us">
|
|
1009
|
-
<Select.Trigger>
|
|
1010
|
-
<Select.Value placeholder="Select a country" />
|
|
1011
|
-
</Select.Trigger>
|
|
1012
|
-
<Select.Content>
|
|
1013
|
-
<Select.Item value="us">United States</Select.Item>
|
|
1014
|
-
<Select.Item value="ca">Canada</Select.Item>
|
|
1015
|
-
</Select.Content>
|
|
1016
|
-
</Select>
|
|
1017
|
-
|
|
1018
|
-
<button type="submit">Submit</button>
|
|
1019
|
-
</form>
|
|
1020
|
-
```
|
|
1021
|
-
|
|
1022
1448
|
---
|
|
1023
1449
|
|
|
1024
|
-
##
|
|
1450
|
+
## 📝 Typography System
|
|
1025
1451
|
|
|
1026
|
-
|
|
1452
|
+
Kreativ UI provides a centralized, theme-aware typography system for controlling how text is rendered across your application.
|
|
1027
1453
|
|
|
1028
|
-
|
|
1029
|
-
- `useSizeStyle` applies height, padding, and font size from the `sizes` token.
|
|
1030
|
-
- Variants (`outline`, `filled`, `ghost`) are resolved via `resolveRecipe`.
|
|
1031
|
-
- Validation states (`error`, `success`) are applied through CSS variables and class names.
|
|
1454
|
+
### How It Works
|
|
1032
1455
|
|
|
1033
|
-
|
|
1456
|
+
Typography is built around four layers:
|
|
1034
1457
|
|
|
1035
|
-
---
|
|
1036
|
-
|
|
1037
|
-
## Data Attributes
|
|
1038
|
-
|
|
1039
|
-
The Select exposes several data attributes for styling or testing:
|
|
1040
|
-
|
|
1041
|
-
| Attribute | Element | Values | Description |
|
|
1042
|
-
| --------------- | ---------------- | ---------------------------- | ------------------------------ |
|
|
1043
|
-
| `data-state` | `Select.Trigger` | `"open"`, `"closed"` | Current dropdown state |
|
|
1044
|
-
| `data-state` | `Select.Item` | `"selected"`, `"unselected"` | Selection state of the item |
|
|
1045
|
-
| `data-active` | `Select.Item` | present when highlighted | Keyboard‑focused item (active) |
|
|
1046
|
-
| `data-disabled` | `Select.Item` | present when disabled | Disabled state |
|
|
1047
|
-
| `data-invalid` | `Select.Trigger` | present when error | Error state |
|
|
1048
|
-
|
|
1049
|
-
---
|
|
1050
|
-
|
|
1051
|
-
## Complete Example
|
|
1052
|
-
|
|
1053
|
-
```tsx
|
|
1054
|
-
import { useState } from "react";
|
|
1055
|
-
import { FormField, Select } from "@splenddev/kreativ-ui";
|
|
1056
|
-
|
|
1057
|
-
function CountrySelect() {
|
|
1058
|
-
const [country, setCountry] = useState<string | undefined>("");
|
|
1059
|
-
const [error, setError] = useState("");
|
|
1060
|
-
|
|
1061
|
-
const validate = (value?: string) => {
|
|
1062
|
-
if (!value) setError("Please select a country");
|
|
1063
|
-
else setError("");
|
|
1064
|
-
};
|
|
1065
|
-
|
|
1066
|
-
return (
|
|
1067
|
-
<FormField required error={error}>
|
|
1068
|
-
<FormField.Label>Country</FormField.Label>
|
|
1069
|
-
<FormField.Description>
|
|
1070
|
-
Choose your country of residence.
|
|
1071
|
-
</FormField.Description>
|
|
1072
|
-
|
|
1073
|
-
<Select
|
|
1074
|
-
value={country}
|
|
1075
|
-
onValueChange={(val) => {
|
|
1076
|
-
setCountry(val);
|
|
1077
|
-
validate(val);
|
|
1078
|
-
}}
|
|
1079
|
-
clearable
|
|
1080
|
-
name="country"
|
|
1081
|
-
error={!!error}
|
|
1082
|
-
>
|
|
1083
|
-
<Select.Trigger>
|
|
1084
|
-
<Select.Value placeholder="Select a country" />
|
|
1085
|
-
</Select.Trigger>
|
|
1086
|
-
|
|
1087
|
-
<Select.Content>
|
|
1088
|
-
<Select.Group>
|
|
1089
|
-
<Select.Label>North America</Select.Label>
|
|
1090
|
-
<Select.Item value="us">United States</Select.Item>
|
|
1091
|
-
<Select.Item value="ca">Canada</Select.Item>
|
|
1092
|
-
<Select.Item value="mx">Mexico</Select.Item>
|
|
1093
|
-
</Select.Group>
|
|
1094
|
-
|
|
1095
|
-
<Select.Group>
|
|
1096
|
-
<Select.Label>Europe</Select.Label>
|
|
1097
|
-
<Select.Item value="uk">United Kingdom</Select.Item>
|
|
1098
|
-
<Select.Item value="de">Germany</Select.Item>
|
|
1099
|
-
<Select.Item value="fr" disabled>
|
|
1100
|
-
France (disabled)
|
|
1101
|
-
</Select.Item>
|
|
1102
|
-
</Select.Group>
|
|
1103
|
-
</Select.Content>
|
|
1104
|
-
</Select>
|
|
1105
|
-
|
|
1106
|
-
{error && <FormField.Message>{error}</FormField.Message>}
|
|
1107
|
-
</FormField>
|
|
1108
|
-
);
|
|
1109
|
-
}
|
|
1110
1458
|
```
|
|
1111
|
-
|
|
1112
|
-
---
|
|
1113
|
-
|
|
1114
|
-
For more advanced use cases (e.g., async loading, custom rendering), refer to the [GitHub repository examples](https://github.com/Vincentvirtuoso/kreativ-ui).
|
|
1115
|
-
|
|
1116
|
-
---
|
|
1117
|
-
|
|
1118
|
-
# Typography System
|
|
1119
|
-
|
|
1120
|
-
Kreativ UI provides a centralized, theme-aware typography system for controlling how text is rendered across your application and component library.
|
|
1121
|
-
|
|
1122
|
-
Typography styles can be defined once and reused across built-in components such as `Button`, `Input`, and `Select`, as well as custom components created by your application.
|
|
1123
|
-
|
|
1124
|
-
The system supports:
|
|
1125
|
-
|
|
1126
|
-
* Reusable typography presets
|
|
1127
|
-
* Primitive design tokens
|
|
1128
|
-
* Semantic tokens
|
|
1129
|
-
* Custom font families
|
|
1130
|
-
* `next/font`
|
|
1131
|
-
* CSS custom properties
|
|
1132
|
-
* Local fonts
|
|
1133
|
-
* Runtime theme customization
|
|
1134
|
-
* Custom typography presets
|
|
1135
|
-
* Component-level typography selection
|
|
1136
|
-
* Custom component integration
|
|
1137
|
-
* Type-safe token definitions
|
|
1138
|
-
* Direct CSS value overrides
|
|
1139
|
-
|
|
1140
|
-
---
|
|
1141
|
-
|
|
1142
|
-
## How It Works
|
|
1143
|
-
|
|
1144
|
-
Kreativ UI typography is built around four layers:
|
|
1145
|
-
|
|
1146
|
-
```text
|
|
1147
1459
|
Primitive Tokens
|
|
1148
1460
|
↓
|
|
1149
1461
|
Semantic Tokens
|
|
@@ -1157,182 +1469,9 @@ React.CSSProperties
|
|
|
1157
1469
|
Component
|
|
1158
1470
|
```
|
|
1159
1471
|
|
|
1160
|
-
###
|
|
1161
|
-
|
|
1162
|
-
Primitive tokens contain reusable values such as:
|
|
1163
|
-
|
|
1164
|
-
```ts
|
|
1165
|
-
fonts.body
|
|
1166
|
-
fonts.heading
|
|
1167
|
-
fonts.mono
|
|
1168
|
-
|
|
1169
|
-
fontSizes.sm
|
|
1170
|
-
fontSizes.md
|
|
1171
|
-
fontSizes.lg
|
|
1172
|
-
|
|
1173
|
-
fontWeights.normal
|
|
1174
|
-
fontWeights.medium
|
|
1175
|
-
fontWeights.bold
|
|
1176
|
-
|
|
1177
|
-
lineHeights.tight
|
|
1178
|
-
lineHeights.normal
|
|
1179
|
-
lineHeights.relaxed
|
|
1180
|
-
```
|
|
1181
|
-
|
|
1182
|
-
They are defined with `defineToken()`.
|
|
1183
|
-
|
|
1184
|
-
```ts
|
|
1185
|
-
const fonts = {
|
|
1186
|
-
body: defineToken("Inter, sans-serif"),
|
|
1187
|
-
heading: defineToken("Poppins, sans-serif"),
|
|
1188
|
-
};
|
|
1189
|
-
```
|
|
1190
|
-
|
|
1191
|
-
---
|
|
1192
|
-
|
|
1193
|
-
### Semantic Tokens
|
|
1194
|
-
|
|
1195
|
-
Semantic tokens represent values that can change depending on the active theme or color mode.
|
|
1196
|
-
|
|
1197
|
-
They are defined with `defineSemanticToken()`.
|
|
1198
|
-
|
|
1199
|
-
```ts
|
|
1200
|
-
const colors = {
|
|
1201
|
-
text: defineSemanticToken(
|
|
1202
|
-
"{colors.gray.900}",
|
|
1203
|
-
"{colors.gray.100}",
|
|
1204
|
-
),
|
|
1205
|
-
};
|
|
1206
|
-
```
|
|
1207
|
-
|
|
1208
|
-
Typography itself is generally not mode-dependent, but typography definitions can reference semantic tokens when appropriate.
|
|
1209
|
-
|
|
1210
|
-
---
|
|
1211
|
-
|
|
1212
|
-
### Typography Presets
|
|
1213
|
-
|
|
1214
|
-
Typography presets combine tokens into meaningful styles.
|
|
1215
|
-
|
|
1216
|
-
```ts
|
|
1217
|
-
const typography = {
|
|
1218
|
-
body: {
|
|
1219
|
-
fontFamily: "{fonts.body}",
|
|
1220
|
-
fontSize: "{fontSizes.md}",
|
|
1221
|
-
fontWeight: "{fontWeights.normal}",
|
|
1222
|
-
lineHeight: "{lineHeights.normal}",
|
|
1223
|
-
},
|
|
1224
|
-
|
|
1225
|
-
heading: {
|
|
1226
|
-
fontFamily: "{fonts.heading}",
|
|
1227
|
-
fontSize: "{fontSizes.2xl}",
|
|
1228
|
-
fontWeight: "{fontWeights.bold}",
|
|
1229
|
-
lineHeight: "{lineHeights.tight}",
|
|
1230
|
-
},
|
|
1231
|
-
};
|
|
1232
|
-
```
|
|
1233
|
-
|
|
1234
|
-
A preset is referenced by name:
|
|
1235
|
-
|
|
1236
|
-
```tsx
|
|
1237
|
-
<Button typography="body" />
|
|
1238
|
-
```
|
|
1239
|
-
|
|
1240
|
-
---
|
|
1241
|
-
|
|
1242
|
-
### `useTypography()`
|
|
1243
|
-
|
|
1244
|
-
The `useTypography()` hook retrieves the typography preset from the active theme and resolves all token references into CSS values.
|
|
1245
|
-
|
|
1246
|
-
```tsx
|
|
1247
|
-
const styles = useTypography("heading");
|
|
1248
|
-
```
|
|
1249
|
-
|
|
1250
|
-
The result is suitable for React's `style` prop:
|
|
1251
|
-
|
|
1252
|
-
```tsx
|
|
1253
|
-
<h1 style={styles}>Welcome</h1>
|
|
1254
|
-
```
|
|
1255
|
-
|
|
1256
|
-
---
|
|
1257
|
-
|
|
1258
|
-
# Typography Architecture
|
|
1259
|
-
|
|
1260
|
-
A typical Kreativ UI theme contains:
|
|
1261
|
-
|
|
1262
|
-
```ts
|
|
1263
|
-
const theme = {
|
|
1264
|
-
tokens: {
|
|
1265
|
-
fonts: {
|
|
1266
|
-
body: defineToken("Inter, sans-serif"),
|
|
1267
|
-
heading: defineToken("Poppins, sans-serif"),
|
|
1268
|
-
mono: defineToken("JetBrains Mono, monospace"),
|
|
1269
|
-
},
|
|
1270
|
-
|
|
1271
|
-
fontSizes: {
|
|
1272
|
-
sm: defineToken("0.875rem"),
|
|
1273
|
-
md: defineToken("1rem"),
|
|
1274
|
-
lg: defineToken("1.125rem"),
|
|
1275
|
-
},
|
|
1276
|
-
|
|
1277
|
-
fontWeights: {
|
|
1278
|
-
normal: defineToken(400),
|
|
1279
|
-
medium: defineToken(500),
|
|
1280
|
-
semibold: defineToken(600),
|
|
1281
|
-
bold: defineToken(700),
|
|
1282
|
-
},
|
|
1283
|
-
|
|
1284
|
-
lineHeights: {
|
|
1285
|
-
tight: defineToken(1.2),
|
|
1286
|
-
normal: defineToken(1.5),
|
|
1287
|
-
relaxed: defineToken(1.75),
|
|
1288
|
-
},
|
|
1289
|
-
},
|
|
1290
|
-
|
|
1291
|
-
typography: {
|
|
1292
|
-
body: {
|
|
1293
|
-
fontFamily: "{fonts.body}",
|
|
1294
|
-
fontSize: "{fontSizes.md}",
|
|
1295
|
-
fontWeight: "{fontWeights.normal}",
|
|
1296
|
-
lineHeight: "{lineHeights.normal}",
|
|
1297
|
-
},
|
|
1298
|
-
|
|
1299
|
-
heading: {
|
|
1300
|
-
fontFamily: "{fonts.heading}",
|
|
1301
|
-
fontSize: "{fontSizes.lg}",
|
|
1302
|
-
fontWeight: "{fontWeights.bold}",
|
|
1303
|
-
lineHeight: "{lineHeights.tight}",
|
|
1304
|
-
},
|
|
1305
|
-
},
|
|
1306
|
-
};
|
|
1307
|
-
```
|
|
1308
|
-
|
|
1309
|
-
This creates a clear separation between **what a value is** and **how that value is used**.
|
|
1310
|
-
|
|
1311
|
-
For example:
|
|
1312
|
-
|
|
1313
|
-
```text
|
|
1314
|
-
"Inter, sans-serif"
|
|
1315
|
-
↓
|
|
1316
|
-
fonts.body
|
|
1317
|
-
↓
|
|
1318
|
-
typography.body
|
|
1319
|
-
↓
|
|
1320
|
-
useTypography("body")
|
|
1321
|
-
↓
|
|
1322
|
-
CSSProperties
|
|
1323
|
-
```
|
|
1324
|
-
|
|
1325
|
-
---
|
|
1326
|
-
|
|
1327
|
-
# Using Typography in Components
|
|
1328
|
-
|
|
1329
|
-
There are several ways to consume the typography system.
|
|
1330
|
-
|
|
1331
|
-
---
|
|
1332
|
-
|
|
1333
|
-
## 1. Using `useTypography()` Directly
|
|
1472
|
+
### Using `useTypography()`
|
|
1334
1473
|
|
|
1335
|
-
Use the hook when
|
|
1474
|
+
Use the hook when creating a custom component:
|
|
1336
1475
|
|
|
1337
1476
|
```tsx
|
|
1338
1477
|
import { useTypography } from "@splenddev/kreativ-ui";
|
|
@@ -1343,204 +1482,38 @@ function MyCustomCard() {
|
|
|
1343
1482
|
|
|
1344
1483
|
return (
|
|
1345
1484
|
<div>
|
|
1346
|
-
<h2 style={headingStyles}>
|
|
1347
|
-
|
|
1348
|
-
</h2>
|
|
1349
|
-
|
|
1350
|
-
<p style={bodyStyles}>
|
|
1351
|
-
This is the card content.
|
|
1352
|
-
</p>
|
|
1485
|
+
<h2 style={headingStyles}>Card Title</h2>
|
|
1486
|
+
<p style={bodyStyles}>This is the card content.</p>
|
|
1353
1487
|
</div>
|
|
1354
1488
|
);
|
|
1355
1489
|
}
|
|
1356
1490
|
```
|
|
1357
1491
|
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
---
|
|
1361
|
-
|
|
1362
|
-
# 2. Creating a Reusable Component with `TypographyProps`
|
|
1363
|
-
|
|
1364
|
-
Kreativ UI exposes `TypographyProps` so custom components can participate in the same typography system.
|
|
1365
|
-
|
|
1366
|
-
```ts
|
|
1367
|
-
export interface TypographyProps {
|
|
1368
|
-
/**
|
|
1369
|
-
* Defines the typography style to apply to the component.
|
|
1370
|
-
* The value must match a typography style registered in the theme.
|
|
1371
|
-
*/
|
|
1372
|
-
typography?: string;
|
|
1373
|
-
}
|
|
1374
|
-
```
|
|
1375
|
-
|
|
1376
|
-
A custom component can extend this interface:
|
|
1492
|
+
### Creating a Typography-Aware Custom Component
|
|
1377
1493
|
|
|
1378
1494
|
```tsx
|
|
1379
|
-
import {
|
|
1380
|
-
TypographyProps,
|
|
1381
|
-
useTypography,
|
|
1382
|
-
} from "@splenddev/kreativ-ui";
|
|
1495
|
+
import { TypographyProps, useTypography } from "@splenddev/kreativ-ui";
|
|
1383
1496
|
|
|
1384
1497
|
interface MyTextProps extends TypographyProps {
|
|
1385
1498
|
children: React.ReactNode;
|
|
1386
1499
|
}
|
|
1387
1500
|
|
|
1388
|
-
function MyText({
|
|
1389
|
-
typography = "body",
|
|
1390
|
-
children,
|
|
1391
|
-
}: MyTextProps) {
|
|
1501
|
+
function MyText({ typography = "body", children }: MyTextProps) {
|
|
1392
1502
|
const styles = useTypography(typography);
|
|
1393
1503
|
|
|
1394
|
-
return
|
|
1395
|
-
<p style={styles}>
|
|
1396
|
-
{children}
|
|
1397
|
-
</p>
|
|
1398
|
-
);
|
|
1399
|
-
}
|
|
1400
|
-
```
|
|
1401
|
-
|
|
1402
|
-
Usage:
|
|
1403
|
-
|
|
1404
|
-
```tsx
|
|
1405
|
-
<MyText>
|
|
1406
|
-
Default body text
|
|
1407
|
-
</MyText>
|
|
1408
|
-
|
|
1409
|
-
<MyText typography="heading">
|
|
1410
|
-
Heading text
|
|
1411
|
-
</MyText>
|
|
1412
|
-
|
|
1413
|
-
<MyText typography="caption">
|
|
1414
|
-
Caption text
|
|
1415
|
-
</MyText>
|
|
1416
|
-
```
|
|
1417
|
-
|
|
1418
|
-
This allows custom components to behave consistently with Kreativ UI's built-in components.
|
|
1419
|
-
|
|
1420
|
-
---
|
|
1421
|
-
|
|
1422
|
-
# 3. Using Typography with Built-in Components
|
|
1423
|
-
|
|
1424
|
-
Built-in components that render text can expose the `typography` prop.
|
|
1425
|
-
|
|
1426
|
-
```tsx
|
|
1427
|
-
<Button typography="bodySmall">
|
|
1428
|
-
Small Button
|
|
1429
|
-
</Button>
|
|
1430
|
-
|
|
1431
|
-
<Input typography="body" />
|
|
1432
|
-
|
|
1433
|
-
<Select typography="body" />
|
|
1434
|
-
```
|
|
1435
|
-
|
|
1436
|
-
The typography prop controls typography-related properties while component-specific layout remains independent.
|
|
1437
|
-
|
|
1438
|
-
For example:
|
|
1439
|
-
|
|
1440
|
-
```text
|
|
1441
|
-
Typography
|
|
1442
|
-
├── fontFamily
|
|
1443
|
-
├── fontSize
|
|
1444
|
-
├── fontWeight
|
|
1445
|
-
├── lineHeight
|
|
1446
|
-
└── letterSpacing
|
|
1447
|
-
|
|
1448
|
-
Component Size
|
|
1449
|
-
├── height
|
|
1450
|
-
├── padding
|
|
1451
|
-
├── gap
|
|
1452
|
-
├── iconSize
|
|
1453
|
-
└── radius
|
|
1454
|
-
```
|
|
1455
|
-
|
|
1456
|
-
This separation prevents changing a typography preset from unexpectedly changing component dimensions.
|
|
1457
|
-
|
|
1458
|
-
---
|
|
1459
|
-
|
|
1460
|
-
# 4. Typography and Component Size
|
|
1461
|
-
|
|
1462
|
-
Components such as `Button` often have their own size system:
|
|
1463
|
-
|
|
1464
|
-
```ts
|
|
1465
|
-
sizes: {
|
|
1466
|
-
sm: {
|
|
1467
|
-
height: "2rem",
|
|
1468
|
-
paddingX: "0.75rem",
|
|
1469
|
-
gap: "0.375rem",
|
|
1470
|
-
iconSize: "1rem",
|
|
1471
|
-
radius: "0.8rem",
|
|
1472
|
-
},
|
|
1473
|
-
|
|
1474
|
-
md: {
|
|
1475
|
-
height: "2.5rem",
|
|
1476
|
-
paddingX: "1rem",
|
|
1477
|
-
gap: "0.5rem",
|
|
1478
|
-
iconSize: "1.125rem",
|
|
1479
|
-
radius: "1rem",
|
|
1480
|
-
},
|
|
1504
|
+
return <p style={styles}>{children}</p>;
|
|
1481
1505
|
}
|
|
1482
1506
|
```
|
|
1483
1507
|
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
For example:
|
|
1487
|
-
|
|
1488
|
-
```tsx
|
|
1489
|
-
<Button
|
|
1490
|
-
size="lg"
|
|
1491
|
-
typography="bodySmall"
|
|
1492
|
-
>
|
|
1493
|
-
Continue
|
|
1494
|
-
</Button>
|
|
1495
|
-
```
|
|
1496
|
-
|
|
1497
|
-
The button can use the large component dimensions while using the `bodySmall` typography preset.
|
|
1498
|
-
|
|
1499
|
-
Recommended responsibility:
|
|
1500
|
-
|
|
1501
|
-
```text
|
|
1502
|
-
size
|
|
1503
|
-
→ dimensions and component geometry
|
|
1504
|
-
|
|
1505
|
-
typography
|
|
1506
|
-
→ text presentation
|
|
1507
|
-
|
|
1508
|
-
style
|
|
1509
|
-
→ final consumer override
|
|
1510
|
-
```
|
|
1511
|
-
|
|
1512
|
-
---
|
|
1513
|
-
|
|
1514
|
-
# Loading Fonts
|
|
1515
|
-
|
|
1516
|
-
Kreativ UI does **not need to load fonts itself**.
|
|
1517
|
-
|
|
1518
|
-
Instead, your application is responsible for loading the font.
|
|
1519
|
-
|
|
1520
|
-
Kreativ UI only needs to know which font family should be used.
|
|
1521
|
-
|
|
1522
|
-
This allows Kreativ UI to work with:
|
|
1508
|
+
### Loading Fonts
|
|
1523
1509
|
|
|
1524
|
-
|
|
1525
|
-
* Google Fonts
|
|
1526
|
-
* local fonts
|
|
1527
|
-
* CSS `@font-face`
|
|
1528
|
-
* system fonts
|
|
1529
|
-
* CSS variables
|
|
1530
|
-
* external font providers
|
|
1510
|
+
Kreativ UI does **not** load fonts itself. Your application is responsible for loading fonts, and Kreativ UI consumes the font family values through the theme.
|
|
1531
1511
|
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
---
|
|
1535
|
-
|
|
1536
|
-
# 5. Using Next.js `next/font`
|
|
1537
|
-
|
|
1538
|
-
This is one of the most common setups for a Next.js application.
|
|
1539
|
-
|
|
1540
|
-
For example:
|
|
1512
|
+
#### Next.js `next/font` Example
|
|
1541
1513
|
|
|
1542
1514
|
```tsx
|
|
1543
1515
|
import { Geist, Geist_Mono } from "next/font/google";
|
|
1516
|
+
import { UIProvider, defineToken } from "@splenddev/kreativ-ui";
|
|
1544
1517
|
|
|
1545
1518
|
const geistSans = Geist({
|
|
1546
1519
|
variable: "--font-geist-sans",
|
|
@@ -1551,1041 +1524,90 @@ const geistMono = Geist_Mono({
|
|
|
1551
1524
|
variable: "--font-geist-mono",
|
|
1552
1525
|
subsets: ["latin"],
|
|
1553
1526
|
});
|
|
1554
|
-
```
|
|
1555
|
-
|
|
1556
|
-
Apply the generated variables to the document:
|
|
1557
1527
|
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
The CSS variables are now available to your application.
|
|
1566
|
-
|
|
1567
|
-
You can register them with Kreativ UI:
|
|
1568
|
-
|
|
1569
|
-
```tsx
|
|
1570
|
-
import {
|
|
1571
|
-
UIProvider,
|
|
1572
|
-
defineToken,
|
|
1573
|
-
} from "@splenddev/kreativ-ui";
|
|
1574
|
-
|
|
1575
|
-
<UIProvider
|
|
1576
|
-
theme={{
|
|
1577
|
-
tokens: {
|
|
1578
|
-
fonts: {
|
|
1579
|
-
body: defineToken("var(--font-geist-sans)"),
|
|
1580
|
-
heading: defineToken("var(--font-geist-sans)"),
|
|
1581
|
-
mono: defineToken("var(--font-geist-mono)"),
|
|
1582
|
-
},
|
|
1528
|
+
const theme = extendTheme({
|
|
1529
|
+
tokens: {
|
|
1530
|
+
fonts: {
|
|
1531
|
+
body: defineToken("var(--font-geist-sans)"),
|
|
1532
|
+
heading: defineToken("var(--font-geist-sans)"),
|
|
1533
|
+
mono: defineToken("var(--font-geist-mono)"),
|
|
1583
1534
|
},
|
|
1584
|
-
}}
|
|
1585
|
-
>
|
|
1586
|
-
{children}
|
|
1587
|
-
</UIProvider>
|
|
1588
|
-
```
|
|
1589
|
-
|
|
1590
|
-
Your typography presets can continue to reference semantic font roles:
|
|
1591
|
-
|
|
1592
|
-
```ts
|
|
1593
|
-
const typography = {
|
|
1594
|
-
body: {
|
|
1595
|
-
fontFamily: "{fonts.body}",
|
|
1596
|
-
fontSize: "{fontSizes.md}",
|
|
1597
|
-
fontWeight: "{fontWeights.normal}",
|
|
1598
|
-
lineHeight: "{lineHeights.normal}",
|
|
1599
1535
|
},
|
|
1536
|
+
});
|
|
1600
1537
|
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1538
|
+
export default function RootLayout({ children }) {
|
|
1539
|
+
return (
|
|
1540
|
+
<html className={`${geistSans.variable} ${geistMono.variable}`}>
|
|
1541
|
+
<body>
|
|
1542
|
+
<UIProvider theme={theme}>{children}</UIProvider>
|
|
1543
|
+
</body>
|
|
1544
|
+
</html>
|
|
1545
|
+
);
|
|
1546
|
+
}
|
|
1607
1547
|
```
|
|
1608
1548
|
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
```text
|
|
1612
|
-
next/font
|
|
1613
|
-
↓
|
|
1614
|
-
--font-geist-sans
|
|
1615
|
-
↓
|
|
1616
|
-
fonts.body
|
|
1617
|
-
↓
|
|
1618
|
-
typography.body
|
|
1619
|
-
↓
|
|
1620
|
-
useTypography("body")
|
|
1621
|
-
↓
|
|
1622
|
-
fontFamily: var(--font-geist-sans)
|
|
1623
|
-
```
|
|
1549
|
+
### Best Practices
|
|
1624
1550
|
|
|
1625
|
-
|
|
1551
|
+
- **Prefer semantic typography names**: Use `typography="heading"` instead of `typography="font24"`
|
|
1552
|
+
- **Use tokens for reusable values**: `fontSize: "{fontSizes.md}"` instead of `fontSize: "0.875rem"`
|
|
1553
|
+
- **Let the application load fonts**: Kreativ UI should consume fonts rather than own the font-loading mechanism
|
|
1554
|
+
- **Keep typography separate from layout**: Typography controls text properties; size controls dimensions
|
|
1626
1555
|
|
|
1627
|
-
|
|
1556
|
+
---
|
|
1628
1557
|
|
|
1629
|
-
|
|
1558
|
+
## ♿ Accessibility
|
|
1630
1559
|
|
|
1631
|
-
|
|
1632
|
-
var(--font-geist-sans)
|
|
1633
|
-
```
|
|
1560
|
+
Kreativ UI components are built with accessibility in mind:
|
|
1634
1561
|
|
|
1635
|
-
|
|
1562
|
+
- All interactive elements support keyboard navigation
|
|
1563
|
+
- Focus management and visible focus indicators
|
|
1564
|
+
- ARIA attributes are applied automatically where needed (`aria-label`, `aria-describedby`, `aria-invalid`)
|
|
1565
|
+
- Color contrast respects system‑level settings
|
|
1566
|
+
- FormField automatically manages `aria-describedby` relationships
|
|
1567
|
+
- Loading states communicate `aria-busy="true"`
|
|
1568
|
+
- Icon‑only buttons require `aria-label`
|
|
1636
1569
|
|
|
1637
1570
|
---
|
|
1638
1571
|
|
|
1639
|
-
|
|
1572
|
+
## 📦 Browser Support
|
|
1640
1573
|
|
|
1641
|
-
|
|
1574
|
+
Kreativ UI works in all modern browsers (Chrome, Firefox, Safari, Edge). Requires React 18 or later.
|
|
1642
1575
|
|
|
1643
|
-
|
|
1644
|
-
const theme = {
|
|
1645
|
-
tokens: {
|
|
1646
|
-
fonts: {
|
|
1647
|
-
body: defineToken("Inter, sans-serif"),
|
|
1648
|
-
heading: defineToken("Poppins, sans-serif"),
|
|
1649
|
-
},
|
|
1650
|
-
},
|
|
1651
|
-
};
|
|
1652
|
-
```
|
|
1576
|
+
---
|
|
1653
1577
|
|
|
1654
|
-
|
|
1578
|
+
## 🔧 TypeScript
|
|
1655
1579
|
|
|
1656
|
-
|
|
1657
|
-
const typography = {
|
|
1658
|
-
body: {
|
|
1659
|
-
fontFamily: "{fonts.body}",
|
|
1660
|
-
fontSize: "{fontSizes.md}",
|
|
1661
|
-
lineHeight: "{lineHeights.normal}",
|
|
1662
|
-
},
|
|
1663
|
-
};
|
|
1664
|
-
```
|
|
1580
|
+
Kreativ UI is TypeScript‑first, with typed theme configuration, component props, and extension APIs.
|
|
1665
1581
|
|
|
1666
|
-
|
|
1582
|
+
All theme helpers (`defineToken`, `extendTheme`, `defineSize`, etc.) are fully typed for a safe and predictable customization experience.
|
|
1667
1583
|
|
|
1668
1584
|
---
|
|
1669
1585
|
|
|
1670
|
-
|
|
1586
|
+
## 🎯 API Design Philosophy
|
|
1671
1587
|
|
|
1672
|
-
|
|
1588
|
+
Kreativ UI is designed around several key principles:
|
|
1673
1589
|
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
```
|
|
1680
|
-
|
|
1681
|
-
Register it:
|
|
1682
|
-
|
|
1683
|
-
```ts
|
|
1684
|
-
const theme = {
|
|
1685
|
-
tokens: {
|
|
1686
|
-
fonts: {
|
|
1687
|
-
body: defineToken("MyBrandFont, sans-serif"),
|
|
1688
|
-
},
|
|
1689
|
-
},
|
|
1690
|
-
};
|
|
1691
|
-
```
|
|
1692
|
-
|
|
1693
|
-
Then reference it from typography:
|
|
1694
|
-
|
|
1695
|
-
```ts
|
|
1696
|
-
const typography = {
|
|
1697
|
-
body: {
|
|
1698
|
-
fontFamily: "{fonts.body}",
|
|
1699
|
-
fontSize: "{fontSizes.md}",
|
|
1700
|
-
lineHeight: "{lineHeights.normal}",
|
|
1701
|
-
},
|
|
1702
|
-
};
|
|
1703
|
-
```
|
|
1704
|
-
|
|
1705
|
-
---
|
|
1706
|
-
|
|
1707
|
-
# 8. Using CSS Variables for Fonts
|
|
1708
|
-
|
|
1709
|
-
CSS variables are particularly useful when the application already has a global font system.
|
|
1710
|
-
|
|
1711
|
-
```css
|
|
1712
|
-
:root {
|
|
1713
|
-
--app-font-body: "Inter", sans-serif;
|
|
1714
|
-
--app-font-heading: "Poppins", sans-serif;
|
|
1715
|
-
}
|
|
1716
|
-
```
|
|
1717
|
-
|
|
1718
|
-
Register them:
|
|
1719
|
-
|
|
1720
|
-
```ts
|
|
1721
|
-
const theme = {
|
|
1722
|
-
tokens: {
|
|
1723
|
-
fonts: {
|
|
1724
|
-
body: defineToken("var(--app-font-body)"),
|
|
1725
|
-
heading: defineToken("var(--app-font-heading)"),
|
|
1726
|
-
},
|
|
1727
|
-
},
|
|
1728
|
-
};
|
|
1729
|
-
```
|
|
1730
|
-
|
|
1731
|
-
This also allows the font to be changed without changing the typography definitions themselves.
|
|
1732
|
-
|
|
1733
|
-
---
|
|
1734
|
-
|
|
1735
|
-
# 9. Using a System Font Stack
|
|
1736
|
-
|
|
1737
|
-
You do not need a custom font.
|
|
1738
|
-
|
|
1739
|
-
```ts
|
|
1740
|
-
const theme = {
|
|
1741
|
-
tokens: {
|
|
1742
|
-
fonts: {
|
|
1743
|
-
body: defineToken(
|
|
1744
|
-
"ui-sans-serif, system-ui, sans-serif",
|
|
1745
|
-
),
|
|
1746
|
-
|
|
1747
|
-
heading: defineToken(
|
|
1748
|
-
"ui-sans-serif, system-ui, sans-serif",
|
|
1749
|
-
),
|
|
1750
|
-
|
|
1751
|
-
mono: defineToken(
|
|
1752
|
-
"ui-monospace, SFMono-Regular, Menlo, monospace",
|
|
1753
|
-
),
|
|
1754
|
-
},
|
|
1755
|
-
},
|
|
1756
|
-
};
|
|
1757
|
-
```
|
|
1758
|
-
|
|
1759
|
-
---
|
|
1760
|
-
|
|
1761
|
-
# Customising Typography
|
|
1762
|
-
|
|
1763
|
-
## 10. Extending the Default Presets
|
|
1764
|
-
|
|
1765
|
-
You can add custom typography presets while retaining the defaults.
|
|
1766
|
-
|
|
1767
|
-
```tsx
|
|
1768
|
-
import {
|
|
1769
|
-
UIProvider,
|
|
1770
|
-
defaultTheme,
|
|
1771
|
-
} from "@splenddev/kreativ-ui";
|
|
1772
|
-
|
|
1773
|
-
const typography = {
|
|
1774
|
-
...defaultTheme.typography,
|
|
1775
|
-
|
|
1776
|
-
display: {
|
|
1777
|
-
fontFamily: "{fonts.heading}",
|
|
1778
|
-
fontSize: "4rem",
|
|
1779
|
-
fontWeight: 700,
|
|
1780
|
-
lineHeight: "1",
|
|
1781
|
-
letterSpacing: "-0.04em",
|
|
1782
|
-
},
|
|
1783
|
-
|
|
1784
|
-
label: {
|
|
1785
|
-
fontFamily: "{fonts.body}",
|
|
1786
|
-
fontSize: "0.75rem",
|
|
1787
|
-
fontWeight: 600,
|
|
1788
|
-
lineHeight: "1.2",
|
|
1789
|
-
},
|
|
1790
|
-
};
|
|
1791
|
-
|
|
1792
|
-
const theme = {
|
|
1793
|
-
...defaultTheme,
|
|
1794
|
-
typography,
|
|
1795
|
-
};
|
|
1796
|
-
|
|
1797
|
-
<UIProvider theme={theme}>
|
|
1798
|
-
<App />
|
|
1799
|
-
</UIProvider>;
|
|
1800
|
-
```
|
|
1801
|
-
|
|
1802
|
-
You can now use:
|
|
1803
|
-
|
|
1804
|
-
```tsx
|
|
1805
|
-
<Button typography="label">
|
|
1806
|
-
Continue
|
|
1807
|
-
</Button>
|
|
1808
|
-
|
|
1809
|
-
<MyText typography="display">
|
|
1810
|
-
Welcome
|
|
1811
|
-
</MyText>
|
|
1812
|
-
```
|
|
1813
|
-
|
|
1814
|
-
---
|
|
1815
|
-
|
|
1816
|
-
# 11. Overriding an Existing Typography Preset
|
|
1817
|
-
|
|
1818
|
-
You can also modify a built-in preset.
|
|
1819
|
-
|
|
1820
|
-
```ts
|
|
1821
|
-
const typography = {
|
|
1822
|
-
...defaultTheme.typography,
|
|
1823
|
-
|
|
1824
|
-
body: {
|
|
1825
|
-
...defaultTheme.typography.body,
|
|
1826
|
-
fontSize: "{fontSizes.lg}",
|
|
1827
|
-
},
|
|
1828
|
-
};
|
|
1829
|
-
```
|
|
1830
|
-
|
|
1831
|
-
Every component using:
|
|
1832
|
-
|
|
1833
|
-
```tsx
|
|
1834
|
-
typography="body"
|
|
1835
|
-
```
|
|
1836
|
-
|
|
1837
|
-
will now use the customized definition.
|
|
1838
|
-
|
|
1839
|
-
This is useful when you want to change the application's typography globally without modifying every component.
|
|
1840
|
-
|
|
1841
|
-
---
|
|
1842
|
-
|
|
1843
|
-
# 12. Creating Typography with `defineTypography()`
|
|
1844
|
-
|
|
1845
|
-
For design-system authors, Kreativ UI provides `defineTypography()`.
|
|
1846
|
-
|
|
1847
|
-
```ts
|
|
1848
|
-
import {
|
|
1849
|
-
defineTypography,
|
|
1850
|
-
} from "@splenddev/kreativ-ui";
|
|
1851
|
-
|
|
1852
|
-
const typography = {
|
|
1853
|
-
display: defineTypography({
|
|
1854
|
-
fontFamily: "{fonts.heading}",
|
|
1855
|
-
fontSize: "{fontSizes.4xl}",
|
|
1856
|
-
fontWeight: "{fontWeights.bold}",
|
|
1857
|
-
lineHeight: "{lineHeights.tight}",
|
|
1858
|
-
letterSpacing: "-0.04em",
|
|
1859
|
-
}),
|
|
1860
|
-
};
|
|
1861
|
-
```
|
|
1862
|
-
|
|
1863
|
-
`defineTypography()` provides a consistent definition API and ensures the typography object conforms to the expected typography structure.
|
|
1864
|
-
|
|
1865
|
-
It is especially useful when creating reusable theme configurations.
|
|
1866
|
-
|
|
1867
|
-
---
|
|
1868
|
-
|
|
1869
|
-
# 13. Defining Custom Tokens with `defineToken()`
|
|
1870
|
-
|
|
1871
|
-
Use `defineToken()` for primitive values.
|
|
1872
|
-
|
|
1873
|
-
```ts
|
|
1874
|
-
import { defineToken } from "@splenddev/kreativ-ui";
|
|
1875
|
-
|
|
1876
|
-
const tokens = {
|
|
1877
|
-
fonts: {
|
|
1878
|
-
serif: defineToken("Georgia, serif"),
|
|
1879
|
-
},
|
|
1880
|
-
|
|
1881
|
-
fontSizes: {
|
|
1882
|
-
"5xl": defineToken("3rem"),
|
|
1883
|
-
},
|
|
1884
|
-
|
|
1885
|
-
fontWeights: {
|
|
1886
|
-
black: defineToken(900),
|
|
1887
|
-
},
|
|
1888
|
-
};
|
|
1889
|
-
```
|
|
1890
|
-
|
|
1891
|
-
These tokens can then be referenced by typography:
|
|
1892
|
-
|
|
1893
|
-
```ts
|
|
1894
|
-
const typography = {
|
|
1895
|
-
serifDisplay: defineTypography({
|
|
1896
|
-
fontFamily: "{fonts.serif}",
|
|
1897
|
-
fontSize: "{fontSizes.5xl}",
|
|
1898
|
-
fontWeight: "{fontWeights.black}",
|
|
1899
|
-
lineHeight: "{lineHeights.tight}",
|
|
1900
|
-
}),
|
|
1901
|
-
};
|
|
1902
|
-
```
|
|
1903
|
-
|
|
1904
|
-
Using `defineToken()` ensures the values follow the token structure expected by the theme engine.
|
|
1905
|
-
|
|
1906
|
-
---
|
|
1907
|
-
|
|
1908
|
-
# 14. Semantic Tokens
|
|
1909
|
-
|
|
1910
|
-
Semantic tokens are useful when a value needs to change according to the active theme or color mode.
|
|
1911
|
-
|
|
1912
|
-
```ts
|
|
1913
|
-
const tokens = {
|
|
1914
|
-
colors: {
|
|
1915
|
-
brandText: defineSemanticToken(
|
|
1916
|
-
"{colors.blue.700}",
|
|
1917
|
-
"{colors.blue.200}",
|
|
1918
|
-
),
|
|
1919
|
-
},
|
|
1920
|
-
};
|
|
1921
|
-
```
|
|
1922
|
-
|
|
1923
|
-
Typography itself generally does not need separate light and dark definitions.
|
|
1924
|
-
|
|
1925
|
-
Instead, semantic tokens are most useful when typography is combined with color or other semantic styling.
|
|
1926
|
-
|
|
1927
|
-
For example:
|
|
1928
|
-
|
|
1929
|
-
```ts
|
|
1930
|
-
const semanticTokens = {
|
|
1931
|
-
text: {
|
|
1932
|
-
primary: defineSemanticToken(
|
|
1933
|
-
"{colors.gray.900}",
|
|
1934
|
-
"{colors.gray.100}",
|
|
1935
|
-
),
|
|
1936
|
-
},
|
|
1937
|
-
};
|
|
1938
|
-
```
|
|
1939
|
-
|
|
1940
|
-
A component can then combine typography with the semantic text color.
|
|
1941
|
-
|
|
1942
|
-
---
|
|
1943
|
-
|
|
1944
|
-
# 15. Direct CSS Values
|
|
1945
|
-
|
|
1946
|
-
Typography values do not have to reference tokens.
|
|
1947
|
-
|
|
1948
|
-
You can use literal CSS values:
|
|
1949
|
-
|
|
1950
|
-
```ts
|
|
1951
|
-
const typography = {
|
|
1952
|
-
custom: defineTypography({
|
|
1953
|
-
fontFamily: "Georgia, serif",
|
|
1954
|
-
fontSize: "1.125rem",
|
|
1955
|
-
fontWeight: 600,
|
|
1956
|
-
lineHeight: 1.6,
|
|
1957
|
-
letterSpacing: "-0.01em",
|
|
1958
|
-
}),
|
|
1959
|
-
};
|
|
1960
|
-
```
|
|
1961
|
-
|
|
1962
|
-
This is useful for typography that is intentionally unique.
|
|
1963
|
-
|
|
1964
|
-
However, reusable design-system values should generally be represented as tokens.
|
|
1965
|
-
|
|
1966
|
-
---
|
|
1967
|
-
|
|
1968
|
-
# 16. Combining Typography with Component Overrides
|
|
1969
|
-
|
|
1970
|
-
Typography provides the baseline text styling, while consumers can still make one-off overrides.
|
|
1971
|
-
|
|
1972
|
-
For example:
|
|
1973
|
-
|
|
1974
|
-
```tsx
|
|
1975
|
-
<Button
|
|
1976
|
-
typography="body"
|
|
1977
|
-
style={{
|
|
1978
|
-
fontWeight: 700,
|
|
1979
|
-
}}
|
|
1980
|
-
>
|
|
1981
|
-
Continue
|
|
1982
|
-
</Button>
|
|
1983
|
-
```
|
|
1984
|
-
|
|
1985
|
-
The recommended precedence is:
|
|
1986
|
-
|
|
1987
|
-
```text
|
|
1988
|
-
Component defaults
|
|
1989
|
-
↓
|
|
1990
|
-
Component size/layout
|
|
1991
|
-
↓
|
|
1992
|
-
Typography preset
|
|
1993
|
-
↓
|
|
1994
|
-
Explicit style prop
|
|
1995
|
-
```
|
|
1996
|
-
|
|
1997
|
-
This means the `style` prop remains an escape hatch for application-specific cases.
|
|
1998
|
-
|
|
1999
|
-
Avoid using it repeatedly for values that should actually become part of your theme.
|
|
2000
|
-
|
|
2001
|
-
---
|
|
2002
|
-
|
|
2003
|
-
# 17. Creating a Typography-Aware Custom Component
|
|
2004
|
-
|
|
2005
|
-
A complete custom component might look like this:
|
|
2006
|
-
|
|
2007
|
-
```tsx
|
|
2008
|
-
import {
|
|
2009
|
-
TypographyProps,
|
|
2010
|
-
useTypography,
|
|
2011
|
-
} from "@splenddev/kreativ-ui";
|
|
2012
|
-
|
|
2013
|
-
interface CardTitleProps extends TypographyProps {
|
|
2014
|
-
children: React.ReactNode;
|
|
2015
|
-
}
|
|
2016
|
-
|
|
2017
|
-
function CardTitle({
|
|
2018
|
-
typography = "headingSmall",
|
|
2019
|
-
children,
|
|
2020
|
-
}: CardTitleProps) {
|
|
2021
|
-
const typographyStyles = useTypography(typography);
|
|
2022
|
-
|
|
2023
|
-
return (
|
|
2024
|
-
<h3 style={typographyStyles}>
|
|
2025
|
-
{children}
|
|
2026
|
-
</h3>
|
|
2027
|
-
);
|
|
2028
|
-
}
|
|
2029
|
-
```
|
|
2030
|
-
|
|
2031
|
-
Usage:
|
|
2032
|
-
|
|
2033
|
-
```tsx
|
|
2034
|
-
<CardTitle>
|
|
2035
|
-
Default title
|
|
2036
|
-
</CardTitle>
|
|
2037
|
-
|
|
2038
|
-
<CardTitle typography="heading">
|
|
2039
|
-
Large title
|
|
2040
|
-
</CardTitle>
|
|
2041
|
-
|
|
2042
|
-
<CardTitle typography="display">
|
|
2043
|
-
Custom display title
|
|
2044
|
-
</CardTitle>
|
|
2045
|
-
```
|
|
2046
|
-
|
|
2047
|
-
The component remains completely independent of the actual font values.
|
|
2048
|
-
|
|
2049
|
-
---
|
|
2050
|
-
|
|
2051
|
-
# 18. Using Typography Without a Preset Name
|
|
2052
|
-
|
|
2053
|
-
If a component needs to use typography dynamically, it can simply pass the name received from its props:
|
|
2054
|
-
|
|
2055
|
-
```tsx
|
|
2056
|
-
function MyComponent({
|
|
2057
|
-
typography = "body",
|
|
2058
|
-
}: TypographyProps) {
|
|
2059
|
-
const styles = useTypography(typography);
|
|
2060
|
-
|
|
2061
|
-
return (
|
|
2062
|
-
<div style={styles}>
|
|
2063
|
-
Content
|
|
2064
|
-
</div>
|
|
2065
|
-
);
|
|
2066
|
-
}
|
|
2067
|
-
```
|
|
2068
|
-
|
|
2069
|
-
The component does not need to maintain its own list of typography styles.
|
|
2070
|
-
|
|
2071
|
-
This allows application-defined styles to work automatically.
|
|
2072
|
-
|
|
2073
|
-
---
|
|
2074
|
-
|
|
2075
|
-
# Runtime Theme Changes
|
|
2076
|
-
|
|
2077
|
-
Typography is resolved against the active theme.
|
|
2078
|
-
|
|
2079
|
-
For example, suppose the default theme contains:
|
|
2080
|
-
|
|
2081
|
-
```ts
|
|
2082
|
-
fonts: {
|
|
2083
|
-
body: defineToken("Inter, sans-serif"),
|
|
2084
|
-
}
|
|
2085
|
-
```
|
|
2086
|
-
|
|
2087
|
-
and a custom theme changes it to:
|
|
2088
|
-
|
|
2089
|
-
```ts
|
|
2090
|
-
fonts: {
|
|
2091
|
-
body: defineToken("Poppins, sans-serif"),
|
|
2092
|
-
}
|
|
2093
|
-
```
|
|
2094
|
-
|
|
2095
|
-
A typography preset referencing:
|
|
2096
|
-
|
|
2097
|
-
```ts
|
|
2098
|
-
fontFamily: "{fonts.body}"
|
|
2099
|
-
```
|
|
2100
|
-
|
|
2101
|
-
does not need to change.
|
|
2102
|
-
|
|
2103
|
-
It automatically resolves to the active token value.
|
|
2104
|
-
|
|
2105
|
-
```text
|
|
2106
|
-
Typography
|
|
2107
|
-
↓
|
|
2108
|
-
{fonts.body}
|
|
2109
|
-
↓
|
|
2110
|
-
Active theme
|
|
2111
|
-
↓
|
|
2112
|
-
Poppins, sans-serif
|
|
2113
|
-
```
|
|
2114
|
-
|
|
2115
|
-
This is one of the primary benefits of the token-based architecture.
|
|
2116
|
-
|
|
2117
|
-
---
|
|
2118
|
-
|
|
2119
|
-
# Recommended Typography Structure
|
|
2120
|
-
|
|
2121
|
-
For most applications, a semantic typography structure works well:
|
|
2122
|
-
|
|
2123
|
-
```ts
|
|
2124
|
-
const typography = {
|
|
2125
|
-
body: {},
|
|
2126
|
-
bodySmall: {},
|
|
2127
|
-
|
|
2128
|
-
heading: {},
|
|
2129
|
-
headingSmall: {},
|
|
2130
|
-
|
|
2131
|
-
caption: {},
|
|
2132
|
-
|
|
2133
|
-
label: {},
|
|
2134
|
-
|
|
2135
|
-
code: {},
|
|
2136
|
-
|
|
2137
|
-
display: {},
|
|
2138
|
-
};
|
|
2139
|
-
```
|
|
2140
|
-
|
|
2141
|
-
The exact names are completely customizable.
|
|
2142
|
-
|
|
2143
|
-
Avoid names such as:
|
|
2144
|
-
|
|
2145
|
-
```ts
|
|
2146
|
-
small12
|
|
2147
|
-
font14
|
|
2148
|
-
large20
|
|
2149
|
-
bold16
|
|
2150
|
-
```
|
|
2151
|
-
|
|
2152
|
-
Prefer semantic names:
|
|
2153
|
-
|
|
2154
|
-
```ts
|
|
2155
|
-
bodySmall
|
|
2156
|
-
body
|
|
2157
|
-
heading
|
|
2158
|
-
caption
|
|
2159
|
-
label
|
|
2160
|
-
display
|
|
2161
|
-
```
|
|
2162
|
-
|
|
2163
|
-
This makes the design system easier to maintain when the actual values change.
|
|
2164
|
-
|
|
2165
|
-
---
|
|
2166
|
-
|
|
2167
|
-
# Best Practices
|
|
2168
|
-
|
|
2169
|
-
### Prefer semantic typography names
|
|
2170
|
-
|
|
2171
|
-
Use:
|
|
2172
|
-
|
|
2173
|
-
```tsx
|
|
2174
|
-
typography="heading"
|
|
2175
|
-
```
|
|
2176
|
-
|
|
2177
|
-
instead of:
|
|
2178
|
-
|
|
2179
|
-
```tsx
|
|
2180
|
-
typography="font24"
|
|
2181
|
-
```
|
|
2182
|
-
|
|
2183
|
-
---
|
|
2184
|
-
|
|
2185
|
-
### Use tokens for reusable values
|
|
2186
|
-
|
|
2187
|
-
Prefer:
|
|
2188
|
-
|
|
2189
|
-
```ts
|
|
2190
|
-
fontSize: "{fontSizes.md}"
|
|
2191
|
-
```
|
|
2192
|
-
|
|
2193
|
-
over repeatedly writing:
|
|
2194
|
-
|
|
2195
|
-
```ts
|
|
2196
|
-
fontSize: "0.875rem"
|
|
2197
|
-
```
|
|
2198
|
-
|
|
2199
|
-
---
|
|
2200
|
-
|
|
2201
|
-
### Let the application load fonts
|
|
2202
|
-
|
|
2203
|
-
Kreativ UI should consume fonts rather than own the font-loading mechanism.
|
|
2204
|
-
|
|
2205
|
-
This allows it to work with:
|
|
2206
|
-
|
|
2207
|
-
* Next.js
|
|
2208
|
-
* Vite
|
|
2209
|
-
* Remix
|
|
2210
|
-
* CRA
|
|
2211
|
-
* plain React
|
|
2212
|
-
* CSS
|
|
2213
|
-
* local fonts
|
|
2214
|
-
* external font providers
|
|
2215
|
-
|
|
2216
|
-
---
|
|
2217
|
-
|
|
2218
|
-
### Use `defineToken()`
|
|
2219
|
-
|
|
2220
|
-
Prefer:
|
|
2221
|
-
|
|
2222
|
-
```ts
|
|
2223
|
-
fonts: {
|
|
2224
|
-
body: defineToken("Inter, sans-serif"),
|
|
2225
|
-
}
|
|
2226
|
-
```
|
|
2227
|
-
|
|
2228
|
-
over manually constructing:
|
|
2229
|
-
|
|
2230
|
-
```ts
|
|
2231
|
-
fonts: {
|
|
2232
|
-
body: {
|
|
2233
|
-
value: "Inter, sans-serif",
|
|
2234
|
-
},
|
|
2235
|
-
}
|
|
2236
|
-
```
|
|
2237
|
-
|
|
2238
|
-
---
|
|
2239
|
-
|
|
2240
|
-
### Use `defineTypography()`
|
|
2241
|
-
|
|
2242
|
-
When creating reusable typography definitions:
|
|
2243
|
-
|
|
2244
|
-
```ts
|
|
2245
|
-
heading: defineTypography({
|
|
2246
|
-
fontFamily: "{fonts.heading}",
|
|
2247
|
-
fontSize: "{fontSizes.2xl}",
|
|
2248
|
-
fontWeight: "{fontWeights.bold}",
|
|
2249
|
-
lineHeight: "{lineHeights.tight}",
|
|
2250
|
-
})
|
|
2251
|
-
```
|
|
2252
|
-
|
|
2253
|
-
This gives the definition a clear and consistent API.
|
|
1590
|
+
- **Separation of concerns**: Typography, sizing, and visual variants are independent layers
|
|
1591
|
+
- **Composable customization**: Theme extension helpers provide type‑safe, intentional customization
|
|
1592
|
+
- **Runtime theming**: CSS variables enable instant mode switching without rebuilding
|
|
1593
|
+
- **Accessibility first**: ARIA, keyboard navigation, and focus management are built in
|
|
1594
|
+
- **TypeScript‑first**: All APIs are fully typed for a great developer experience
|
|
2254
1595
|
|
|
2255
1596
|
---
|
|
2256
1597
|
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
Avoid manually accessing:
|
|
2260
|
-
|
|
2261
|
-
```ts
|
|
2262
|
-
theme.typography
|
|
2263
|
-
```
|
|
2264
|
-
|
|
2265
|
-
inside every component.
|
|
2266
|
-
|
|
2267
|
-
Prefer:
|
|
2268
|
-
|
|
2269
|
-
```ts
|
|
2270
|
-
const styles = useTypography("body");
|
|
2271
|
-
```
|
|
2272
|
-
|
|
2273
|
-
This keeps typography resolution centralized.
|
|
2274
|
-
|
|
2275
|
-
---
|
|
2276
|
-
|
|
2277
|
-
### Keep typography separate from layout
|
|
2278
|
-
|
|
2279
|
-
Typography should control:
|
|
2280
|
-
|
|
2281
|
-
```text
|
|
2282
|
-
fontFamily
|
|
2283
|
-
fontSize
|
|
2284
|
-
fontWeight
|
|
2285
|
-
lineHeight
|
|
2286
|
-
letterSpacing
|
|
2287
|
-
```
|
|
2288
|
-
|
|
2289
|
-
Component size should control:
|
|
2290
|
-
|
|
2291
|
-
```text
|
|
2292
|
-
height
|
|
2293
|
-
padding
|
|
2294
|
-
gap
|
|
2295
|
-
radius
|
|
2296
|
-
iconSize
|
|
2297
|
-
```
|
|
2298
|
-
|
|
2299
|
-
This makes components more predictable.
|
|
2300
|
-
|
|
2301
|
-
---
|
|
2302
|
-
|
|
2303
|
-
# API Reference
|
|
2304
|
-
|
|
2305
|
-
## `useTypography()`
|
|
2306
|
-
|
|
2307
|
-
```ts
|
|
2308
|
-
useTypography(name?: string): React.CSSProperties
|
|
2309
|
-
```
|
|
2310
|
-
|
|
2311
|
-
Resolves a typography preset from the active theme and returns React-compatible CSS properties.
|
|
2312
|
-
|
|
2313
|
-
### Parameters
|
|
2314
|
-
|
|
2315
|
-
| Parameter | Type | Description |
|
|
2316
|
-
| --------- | -------- | ----------------------------- |
|
|
2317
|
-
| `name` | `string` | Name of the typography preset |
|
|
2318
|
-
|
|
2319
|
-
### Example
|
|
2320
|
-
|
|
2321
|
-
```tsx
|
|
2322
|
-
const styles = useTypography("heading");
|
|
2323
|
-
|
|
2324
|
-
return <h1 style={styles}>Hello</h1>;
|
|
2325
|
-
```
|
|
2326
|
-
|
|
2327
|
-
---
|
|
2328
|
-
|
|
2329
|
-
## `TypographyProps`
|
|
2330
|
-
|
|
2331
|
-
```ts
|
|
2332
|
-
interface TypographyProps {
|
|
2333
|
-
typography?: string;
|
|
2334
|
-
}
|
|
2335
|
-
```
|
|
2336
|
-
|
|
2337
|
-
Allows a component to expose the theme's typography presets through a `typography` prop.
|
|
2338
|
-
|
|
2339
|
-
---
|
|
2340
|
-
|
|
2341
|
-
## `TypographyStyle`
|
|
2342
|
-
|
|
2343
|
-
```ts
|
|
2344
|
-
interface TypographyStyle {
|
|
2345
|
-
fontFamily?: string;
|
|
2346
|
-
fontSize?: string;
|
|
2347
|
-
fontWeight?: string | number;
|
|
2348
|
-
lineHeight?: string | number;
|
|
2349
|
-
letterSpacing?: string;
|
|
2350
|
-
}
|
|
2351
|
-
```
|
|
2352
|
-
|
|
2353
|
-
Defines the typography properties supported by Kreativ UI.
|
|
2354
|
-
|
|
2355
|
-
---
|
|
2356
|
-
|
|
2357
|
-
## `Typography`
|
|
2358
|
-
|
|
2359
|
-
```ts
|
|
2360
|
-
type Typography = Record<string, TypographyStyle>;
|
|
2361
|
-
```
|
|
2362
|
-
|
|
2363
|
-
Represents the collection of named typography presets available in a theme.
|
|
2364
|
-
|
|
2365
|
-
---
|
|
2366
|
-
|
|
2367
|
-
## `defineTypography()`
|
|
2368
|
-
|
|
2369
|
-
```ts
|
|
2370
|
-
defineTypography(
|
|
2371
|
-
typography: TypographyStyle,
|
|
2372
|
-
): TypographyStyle
|
|
2373
|
-
```
|
|
2374
|
-
|
|
2375
|
-
Defines and type-checks a typography preset.
|
|
2376
|
-
|
|
2377
|
-
Example:
|
|
2378
|
-
|
|
2379
|
-
```ts
|
|
2380
|
-
const heading = defineTypography({
|
|
2381
|
-
fontFamily: "{fonts.heading}",
|
|
2382
|
-
fontSize: "{fontSizes.2xl}",
|
|
2383
|
-
fontWeight: "{fontWeights.bold}",
|
|
2384
|
-
lineHeight: "{lineHeights.tight}",
|
|
2385
|
-
});
|
|
2386
|
-
```
|
|
2387
|
-
|
|
2388
|
-
---
|
|
2389
|
-
|
|
2390
|
-
## `defineToken()`
|
|
2391
|
-
|
|
2392
|
-
```ts
|
|
2393
|
-
defineToken<T>(value: T): {
|
|
2394
|
-
value: T;
|
|
2395
|
-
}
|
|
2396
|
-
```
|
|
2397
|
-
|
|
2398
|
-
Creates a primitive design token.
|
|
2399
|
-
|
|
2400
|
-
Example:
|
|
2401
|
-
|
|
2402
|
-
```ts
|
|
2403
|
-
const bodyFont = defineToken(
|
|
2404
|
-
"Inter, sans-serif",
|
|
2405
|
-
);
|
|
2406
|
-
```
|
|
2407
|
-
|
|
2408
|
-
---
|
|
2409
|
-
|
|
2410
|
-
## `defineSemanticToken()`
|
|
2411
|
-
|
|
2412
|
-
```ts
|
|
2413
|
-
defineSemanticToken<T>(
|
|
2414
|
-
light: T,
|
|
2415
|
-
dark: T,
|
|
2416
|
-
): {
|
|
2417
|
-
value: {
|
|
2418
|
-
light: T;
|
|
2419
|
-
dark: T;
|
|
2420
|
-
};
|
|
2421
|
-
}
|
|
2422
|
-
```
|
|
2423
|
-
|
|
2424
|
-
Creates a theme-aware semantic token.
|
|
2425
|
-
|
|
2426
|
-
---
|
|
2427
|
-
|
|
2428
|
-
## `resolveTokenReference()`
|
|
2429
|
-
|
|
2430
|
-
```ts
|
|
2431
|
-
resolveTokenReference(
|
|
2432
|
-
value: unknown,
|
|
2433
|
-
tokens: DesignTokens,
|
|
2434
|
-
): string | number
|
|
2435
|
-
```
|
|
2436
|
-
|
|
2437
|
-
Resolves a token reference such as:
|
|
2438
|
-
|
|
2439
|
-
```ts
|
|
2440
|
-
"{fonts.body}"
|
|
2441
|
-
```
|
|
2442
|
-
|
|
2443
|
-
against the active design-token collection.
|
|
2444
|
-
|
|
2445
|
-
---
|
|
2446
|
-
|
|
2447
|
-
## `resolveTypography()`
|
|
2448
|
-
|
|
2449
|
-
```ts
|
|
2450
|
-
resolveTypography(
|
|
2451
|
-
typography: TypographyStyle | undefined,
|
|
2452
|
-
tokens: DesignTokens,
|
|
2453
|
-
): React.CSSProperties
|
|
2454
|
-
```
|
|
2455
|
-
|
|
2456
|
-
Converts a typography definition into resolved React CSS properties.
|
|
2457
|
-
|
|
2458
|
-
---
|
|
2459
|
-
|
|
2460
|
-
# Complete Example
|
|
2461
|
-
|
|
2462
|
-
The following example demonstrates a complete Next.js setup using `next/font`, Kreativ UI tokens, typography, and a custom component.
|
|
2463
|
-
|
|
2464
|
-
```tsx
|
|
2465
|
-
import { Geist, Geist_Mono } from "next/font/google";
|
|
2466
|
-
|
|
2467
|
-
import {
|
|
2468
|
-
UIProvider,
|
|
2469
|
-
defineToken,
|
|
2470
|
-
defineTypography,
|
|
2471
|
-
defaultTheme,
|
|
2472
|
-
} from "@splenddev/kreativ-ui";
|
|
2473
|
-
|
|
2474
|
-
const geistSans = Geist({
|
|
2475
|
-
variable: "--font-geist-sans",
|
|
2476
|
-
subsets: ["latin"],
|
|
2477
|
-
});
|
|
2478
|
-
|
|
2479
|
-
const geistMono = Geist_Mono({
|
|
2480
|
-
variable: "--font-geist-mono",
|
|
2481
|
-
subsets: ["latin"],
|
|
2482
|
-
});
|
|
2483
|
-
|
|
2484
|
-
const theme = {
|
|
2485
|
-
...defaultTheme,
|
|
2486
|
-
|
|
2487
|
-
tokens: {
|
|
2488
|
-
...defaultTheme.tokens,
|
|
2489
|
-
|
|
2490
|
-
fonts: {
|
|
2491
|
-
...defaultTheme.tokens.fonts,
|
|
2492
|
-
|
|
2493
|
-
body: defineToken(
|
|
2494
|
-
"var(--font-geist-sans)",
|
|
2495
|
-
),
|
|
2496
|
-
|
|
2497
|
-
heading: defineToken(
|
|
2498
|
-
"var(--font-geist-sans)",
|
|
2499
|
-
),
|
|
2500
|
-
|
|
2501
|
-
mono: defineToken(
|
|
2502
|
-
"var(--font-geist-mono)",
|
|
2503
|
-
),
|
|
2504
|
-
},
|
|
2505
|
-
},
|
|
2506
|
-
|
|
2507
|
-
typography: {
|
|
2508
|
-
...defaultTheme.typography,
|
|
2509
|
-
|
|
2510
|
-
display: defineTypography({
|
|
2511
|
-
fontFamily: "{fonts.heading}",
|
|
2512
|
-
fontSize: "4rem",
|
|
2513
|
-
fontWeight: "{fontWeights.bold}",
|
|
2514
|
-
lineHeight: "1",
|
|
2515
|
-
letterSpacing: "-0.04em",
|
|
2516
|
-
}),
|
|
2517
|
-
},
|
|
2518
|
-
};
|
|
2519
|
-
|
|
2520
|
-
export default function RootLayout({
|
|
2521
|
-
children,
|
|
2522
|
-
}: LayoutProps<"/">) {
|
|
2523
|
-
return (
|
|
2524
|
-
<html
|
|
2525
|
-
lang="en"
|
|
2526
|
-
className={`${geistSans.variable} ${geistMono.variable}`}
|
|
2527
|
-
>
|
|
2528
|
-
<body>
|
|
2529
|
-
<UIProvider theme={theme}>
|
|
2530
|
-
{children}
|
|
2531
|
-
</UIProvider>
|
|
2532
|
-
</body>
|
|
2533
|
-
</html>
|
|
2534
|
-
);
|
|
2535
|
-
}
|
|
2536
|
-
```
|
|
2537
|
-
|
|
2538
|
-
The important separation is:
|
|
2539
|
-
|
|
2540
|
-
```text
|
|
2541
|
-
Next.js
|
|
2542
|
-
│
|
|
2543
|
-
└── Loads Geist
|
|
2544
|
-
│
|
|
2545
|
-
└── --font-geist-sans
|
|
2546
|
-
│
|
|
2547
|
-
▼
|
|
2548
|
-
Kreativ UI font token
|
|
2549
|
-
│
|
|
2550
|
-
└── fonts.body
|
|
2551
|
-
│
|
|
2552
|
-
▼
|
|
2553
|
-
Typography preset
|
|
2554
|
-
│
|
|
2555
|
-
└── typography.body
|
|
2556
|
-
│
|
|
2557
|
-
▼
|
|
2558
|
-
useTypography("body")
|
|
2559
|
-
│
|
|
2560
|
-
▼
|
|
2561
|
-
React.CSSProperties
|
|
2562
|
-
```
|
|
2563
|
-
|
|
2564
|
-
This allows Kreativ UI to remain completely independent of the application's font-loading strategy while still providing a centralized, reusable, and theme-aware typography system.
|
|
2565
|
-
|
|
2566
|
-
# ♿ Accessibility
|
|
2567
|
-
|
|
2568
|
-
Kreativ UI components are built with accessibility in mind:
|
|
2569
|
-
|
|
2570
|
-
- All interactive elements support keyboard navigation.
|
|
2571
|
-
- Focus management and visible focus indicators.
|
|
2572
|
-
- ARIA attributes are applied automatically where needed (e.g., `aria-label`, `aria-describedby`, `aria-invalid`).
|
|
2573
|
-
- Colour contrast respects system‑level settings.
|
|
2574
|
-
|
|
2575
|
-
---
|
|
1598
|
+
## 🚧 Future Direction
|
|
2576
1599
|
|
|
2577
|
-
|
|
1600
|
+
> **Note:** The following describes future work that is not yet available in the current release.
|
|
2578
1601
|
|
|
2579
|
-
Kreativ UI
|
|
2580
|
-
Requires React 18 or later.
|
|
1602
|
+
The long‑term direction for Kreativ UI includes a broader ecosystem involving UI tooling, templates, CLI functionality, exports, analytics, and other developer/design tools. These features will be documented as they become available.
|
|
2581
1603
|
|
|
2582
1604
|
---
|
|
2583
1605
|
|
|
2584
|
-
|
|
1606
|
+
## 📄 License
|
|
2585
1607
|
|
|
2586
1608
|
MIT
|
|
2587
1609
|
|
|
2588
1610
|
---
|
|
2589
1611
|
|
|
2590
|
-
**More component documentation (Textarea,
|
|
2591
|
-
Visit the [GitHub repository](https://github.com/Vincentvirtuoso/kreativ-ui) for updates.
|
|
1612
|
+
**More component documentation (Checkbox, RadioGroup, Switch, Textarea, MarkdownEditor, Combobox, MultiSelect, InputField) coming soon.**
|
|
1613
|
+
Visit the [GitHub repository](https://github.com/Vincentvirtuoso/kreativ-ui) for updates.
|