@splenddev/kreativ-ui 0.2.8 → 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 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‑in `ThemeToggler` with optional animated transitions
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
- # ☀️ UIProvider
53
+ ## Core Concepts
54
54
 
55
- The `UIProvider` component provides the theme context and manages the active colour mode. It must wrap any part of your application that uses Kreativ UI components.
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
- ### Modes
57
+ ### Runtime Theming
58
58
 
59
- | Mode | Description |
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
- ```tsx
66
- <UIProvider defaultMode="system">
67
- <App />
68
- </UIProvider>
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
- ### useTheme
75
+ Each layer can be customized independently, making it easy to extend or override specific aspects of the design system.
72
76
 
73
- Access and change the current mode anywhere in your app:
77
+ ---
74
78
 
75
- ```tsx
76
- import { useTheme } from "@splenddev/kreativ-ui";
79
+ ## Theme System
77
80
 
78
- function ThemeSwitcher() {
79
- const { mode, setMode } = useTheme();
81
+ ### Primitive Tokens
80
82
 
81
- return (
82
- <>
83
- <button onClick={() => setMode("light")}>Light</button>
84
- <button onClick={() => setMode("dark")}>Dark</button>
85
- <button onClick={() => setMode("system")}>System</button>
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
- # 🎨 Theming
153
+ ### Recipes
94
154
 
95
- Kreativ UI’s theme system is built around two layers:
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
- - **Primitive tokens** – raw values (colours, spacing, radii, fonts, etc.)
98
- - **Semantic tokens** – role‑based values that adapt to light/dark modes
157
+ ---
158
+
159
+ ## Theme API
99
160
 
100
- The library ships with a default theme. You can override any part of it using a `ThemeOverride` object.
161
+ Kreativ UI provides a set of theme extension helpers for composing custom themes without manually manipulating the internal theme structure.
101
162
 
102
- ## Overriding the Theme
163
+ ### `extendTheme`
103
164
 
104
- Pass a `theme` prop to `UIProvider`. Only the properties you provide will be merged with the default theme.
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
- colors: {
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
- ### Primitive vs Semantic Tokens
193
+ ### Tokens
194
+
195
+ #### `defineToken`
140
196
 
141
- **Primitive tokens** are raw values:
197
+ Creates a single primitive token definition:
142
198
 
143
199
  ```ts
144
- tokens.colors.blue.500 // → 59 130 246
145
- tokens.colors.gray.900 // → 17 24 39
146
- tokens.spacing.md // → 16px
200
+ import { defineToken } from "@splenddev/kreativ-ui";
201
+
202
+ const bodyFont = defineToken("Inter, sans-serif");
147
203
  ```
148
204
 
149
- **Semantic tokens** describe UI meaning and can reference primitive tokens or direct values:
205
+ #### `defineTokens`
206
+
207
+ Creates a collection of token definitions:
150
208
 
151
209
  ```ts
152
- semanticTokens.colors.brand = {
153
- value: { light: "{colors.blue.500}", dark: "{colors.blue.400}" },
154
- };
155
- semanticTokens.colors.text = {
156
- value: { light: "{colors.gray.900}", dark: "{colors.gray.50}" },
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
- The runtime engine resolves these references and applies the correct values based on the active colour mode.
219
+ #### `extendTokens`
161
220
 
162
- ### Custom Component Sizes
221
+ Extends existing token definitions:
163
222
 
164
- You can extend the size system by adding custom size definitions. For example, to add an `xl` button size:
223
+ ```ts
224
+ import { extendTokens } from "@splenddev/kreativ-ui";
165
225
 
166
- ```tsx
167
- import { defaultTheme } from "@splenddev/kreativ-ui";
226
+ const customFonts = extendTokens({
227
+ display: "Georgia, serif",
228
+ });
229
+ ```
168
230
 
169
- const theme = {
170
- ...defaultTheme,
171
- sizes: {
172
- xl: {
173
- height: "4.5rem",
174
- paddingX: "2.5rem",
175
- fontSize: "1.125rem",
176
- gap: "0.75rem",
177
- radius: "1rem",
178
- iconSize: "1.5rem",
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
- <UIProvider theme={theme}>
184
- <Button size="xl">Extra Large</Button>
185
- </UIProvider>;
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
- # 🌗 ThemeToggler
426
+ ## 🌗 ThemeToggler
191
427
 
192
428
  A ready‑to‑use theme switcher that integrates with `UIProvider`.
193
429
 
194
- ## Basic Usage
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
- ## With System Mode
438
+ ### With System Mode
203
439
 
204
440
  ```tsx
205
441
  <ThemeToggler allowSystem />
206
442
  ```
207
443
 
208
- ## Icon Only
444
+ ### Icon Only
209
445
 
210
446
  ```tsx
211
447
  <ThemeToggler iconOnly allowSystem />
212
448
  ```
213
449
 
214
- ## Custom Variants
450
+ ### Custom Variants
215
451
 
216
452
  ```tsx
217
453
  <ThemeToggler variant="outline" activeVariant="solid" />
218
454
  ```
219
455
 
220
- ## Vertical Layout
456
+ ### Vertical Layout
221
457
 
222
458
  ```tsx
223
459
  <ThemeToggler orientation="vertical" allowSystem />
224
460
  ```
225
461
 
226
- ## Custom Labels & Icons
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
- ## Cycle Mode with Animation
478
+ ### Cycle Mode with Animation
243
479
 
244
480
  ```tsx
245
481
  <ThemeToggler
@@ -251,36 +487,32 @@ import { SunMedium, MoonStar, LaptopMinimal } from "lucide-react";
251
487
 
252
488
  Supported transition types: `none`, `fade`, `slide`, `scale`, `rotate`.
253
489
 
254
- ## Props
255
-
256
- | Prop | Type | Default | Description |
257
- | --------------- | --------------------------------------------------------------- | ------------------ | ------------------------------------------- |
258
- | `variant` | `ThemeTogglerVariant` | `"ghost"` | Variant for inactive buttons |
259
- | `activeVariant` | `ThemeTogglerVariant` | `"solid"` | Variant for active button |
260
- | `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"sm"` | Button size |
261
- | `iconOnly` | `boolean` | `false` | Hide labels, show only icons |
262
- | `allowSystem` | `boolean` | `false` | Show system theme option |
263
- | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Layout direction |
264
- | `rounded` | `boolean` | `true` | Rounded container corners |
265
- | `unstyled` | `boolean` | `false` | Remove wrapper styles |
266
- | `display` | `"buttons" \| "cycle"` | `"buttons"` | Show all buttons or a single cycling button |
267
- | `transition` | `{ type?: TransitionType; duration?: number; easing?: string }` | `{ type: "none" }` | Animation configuration for cycle mode |
268
- | `labels` | `Partial<Record<"light" \| "dark" \| "system", string>>` | – | Override labels |
269
- | `icons` | `Partial<Record<"light" \| "dark" \| "system", ReactNode>>` | – | Override icons |
270
- | `buttonProps` | `Partial<ButtonProps>` | – | Props passed to every internal button |
271
- | `className` | `string` | – | Additional wrapper class |
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
- # Button
511
+ ## 🧩 Button
276
512
 
277
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
- `Button` is designed to work with Kreativ UI's recipe, sizing, and typography systems, allowing its appearance to be controlled centrally through the active theme.
280
-
281
- ---
282
-
283
- ## Basic Usage
515
+ ### Basic Usage
284
516
 
285
517
  ```tsx
286
518
  import { Button } from "@splenddev/kreativ-ui";
@@ -290,427 +522,122 @@ import { Button } from "@splenddev/kreativ-ui";
290
522
 
291
523
  By default, the Button uses:
292
524
 
293
- * `variant="solid"`
294
- * `color="brand"`
295
- * `size="md"`
296
- * `typography="body"`
297
- * `fullWidth={false}`
298
- * `isLoading={false}`
299
- * `disabled={false}`
525
+ - `variant="solid"`
526
+ - `color="brand"`
527
+ - `size="md"`
528
+ - `typography="body"`
529
+ - `fullWidth={false}`
530
+ - `isLoading={false}`
531
+ - `disabled={false}`
300
532
 
301
- ---
302
-
303
- ## Variants
304
-
305
- Use `variant` to control the Button's visual treatment.
533
+ ### Variants
306
534
 
307
535
  ```tsx
308
536
  <Button variant="solid">Solid</Button>
537
+ <Button variant="outline">Outline</Button>
538
+ <Button variant="ghost">Ghost</Button>
539
+ <Button variant="soft">Soft</Button>
540
+ <Button variant="link">Learn more</Button>
541
+ ```
309
542
 
310
- <Button variant="outline">
311
- Outline
312
- </Button>
313
-
314
- <Button variant="ghost">
315
- Ghost
316
- </Button>
317
-
318
- <Button variant="soft">
319
- Soft
320
- </Button>
543
+ ### Colors
321
544
 
322
- <Button variant="link">
323
- Learn more
324
- </Button>
545
+ ```tsx
546
+ <Button color="brand">Brand</Button>
547
+ <Button color="success">Success</Button>
548
+ <Button color="destructive">Delete</Button>
325
549
  ```
326
550
 
327
- Variants are defined through the Button recipe and can be customized through the theme.
551
+ ### Sizes
328
552
 
329
- ---
553
+ ```tsx
554
+ <Button size="xs">Extra Small</Button>
555
+ <Button size="sm">Small</Button>
556
+ <Button size="md">Medium</Button>
557
+ <Button size="lg">Large</Button>
558
+ ```
330
559
 
331
- ## Colors
560
+ ### Typography
332
561
 
333
- The `color` prop controls the semantic color used by the Button recipe.
562
+ Button typography is controlled independently from its size:
334
563
 
335
564
  ```tsx
565
+ <Button typography="body">Default</Button>
566
+ <Button typography="bodySmall">Small Text</Button>
567
+ <Button typography="headingSmall">Heading Style</Button>
568
+ ```
336
569
 
337
- <Button color="brand">
338
- Brand
339
- </Button>
340
-
341
- <Button color="success">
342
- Success
343
- </Button>
344
-
345
- <Button variant="destructive">
346
- Delete
347
- </Button>
570
+ Example combining size and typography:
348
571
 
349
- <Button variant="success">
350
- Success
572
+ ```tsx
573
+ <Button size="lg" typography="bodySmall">
574
+ Large Button, Small Typography
351
575
  </Button>
352
576
  ```
353
577
 
354
- Available colors depend on the configured Button recipe and theme.
578
+ ### Loading State
355
579
 
356
- ---
580
+ ```tsx
581
+ <Button isLoading>Saving...</Button>
582
+ ```
357
583
 
358
- ## Sizes
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
359
589
 
360
- Buttons support the standard Kreativ UI size scale:
590
+ ### Icons
361
591
 
362
592
  ```tsx
363
- <Button size="xs">
364
- Extra Small
365
- </Button>
366
-
367
- <Button size="sm">
368
- Small
369
- </Button>
370
-
371
- <Button size="md">
372
- Medium
593
+ <Button leftIcon={<SearchIcon />}>Search</Button>
594
+ <Button rightIcon={<ArrowRightIcon />}>Continue</Button>
595
+ <Button leftIcon={<DownloadIcon />} rightIcon={<ArrowRightIcon />}>
596
+ Download
373
597
  </Button>
598
+ ```
374
599
 
375
- <Button size="lg">
376
- Large
377
- </Button>
600
+ ### Icon Only
378
601
 
379
- <Button size="xl">
380
- Extra Large
602
+ ```tsx
603
+ <Button iconOnly aria-label="Search">
604
+ <SearchIcon />
381
605
  </Button>
382
606
  ```
383
607
 
384
- The size system controls layout-related properties such as:
608
+ > **Accessibility:** Always provide an accessible label when the Button contains no visible text.
385
609
 
386
- * Height
387
- * Horizontal padding
388
- * Gap
389
- * Icon size
390
- * Border radius
610
+ ### Full Width
391
611
 
392
- Typography is handled independently by the `typography` prop.
612
+ ```tsx
613
+ <Button fullWidth>Continue</Button>
614
+ ```
393
615
 
394
- ---
616
+ ### Disabled
395
617
 
396
- ## Custom Sizes
618
+ ```tsx
619
+ <Button disabled>Unavailable</Button>
620
+ ```
397
621
 
398
- Button sizes are theme-driven.
622
+ ### Custom Rendering
399
623
 
400
- You can define additional sizes through the theme and reference them by name.
624
+ The `render` prop provides an advanced escape hatch for rendering the Button's resolved styles and content using another element or component:
401
625
 
402
626
  ```tsx
403
- <Button size="custom">
404
- Custom Size
627
+ <Button
628
+ render={(props) => (
629
+ <a {...props} href="/templates">
630
+ Templates
631
+ </a>
632
+ )}
633
+ >
634
+ Templates
405
635
  </Button>
406
636
  ```
407
637
 
408
- For example:
638
+ The render function receives the resolved Button properties (`className`, `style`, `disabled`, `aria-busy`, `children`).
409
639
 
410
- ```ts
411
- const theme = {
412
- sizes: {
413
- custom: {
414
- height: "3.5rem",
415
- paddingX: "2rem",
416
- fontSize: "1rem",
417
- gap: "0.75rem",
418
- iconSize: "1.25rem",
419
- radius: "1.25rem",
420
- },
421
- },
422
- };
423
- ```
424
-
425
- This allows applications to extend the Button's sizing system without modifying the component itself.
426
-
427
- ---
428
-
429
- # Typography
430
-
431
- Button typography is controlled independently from its size.
432
-
433
- ```tsx
434
- <Button typography="body">
435
- Default
436
- </Button>
437
-
438
- <Button typography="bodySmall">
439
- Small Text
440
- </Button>
441
-
442
- <Button typography="headingSmall">
443
- Heading Style
444
- </Button>
445
- ```
446
-
447
- The `typography` prop references a typography preset from the active Kreativ UI theme.
448
-
449
- For example:
450
-
451
- ```tsx
452
- <Button
453
- size="lg"
454
- typography="bodySmall"
455
- >
456
- Large Button, Small Typography
457
- </Button>
458
- ```
459
-
460
- Here:
461
-
462
- * `size="lg"` controls the Button's dimensions.
463
- * `typography="bodySmall"` controls the text appearance.
464
-
465
- This separation makes the system predictable and themeable.
466
-
467
- See the [Typography documentation](./typography.md) for more information.
468
-
469
- ---
470
-
471
- ## Loading State
472
-
473
- Use `isLoading` when an operation is in progress.
474
-
475
- ```tsx
476
- <Button isLoading>
477
- Saving...
478
- </Button>
479
- ```
480
-
481
- When loading:
482
-
483
- * A loading indicator is displayed.
484
- * The Button becomes disabled.
485
- * The Button receives `aria-busy="true"`.
486
- * Normal icon rendering is suppressed while the loading indicator is displayed.
487
-
488
- You can also use loading without text:
489
-
490
- ```tsx
491
- <Button
492
- isLoading
493
- iconOnly
494
- aria-label="Loading"
495
- >
496
- <SearchIcon />
497
- </Button>
498
- ```
499
-
500
- ---
501
-
502
- # Icons
503
-
504
- Buttons support icons on either side of their content.
505
-
506
- ### Left Icon
507
-
508
- ```tsx
509
- <Button leftIcon={<SearchIcon />}>
510
- Search
511
- </Button>
512
- ```
513
-
514
- ### Right Icon
515
-
516
- ```tsx
517
- <Button rightIcon={<ArrowRightIcon />}>
518
- Continue
519
- </Button>
520
- ```
521
-
522
- ### Both Icons
523
-
524
- ```tsx
525
- <Button
526
- leftIcon={<DownloadIcon />}
527
- rightIcon={<ArrowRightIcon />}
528
- >
529
- Download
530
- </Button>
531
- ```
532
-
533
- Icon sizing is automatically derived from the Button's active size.
534
-
535
- For example:
536
-
537
- ```text
538
- size="sm"
539
- ↓
540
- sm.iconSize
541
- ↓
542
- icon dimensions
543
-
544
- size="lg"
545
- ↓
546
- lg.iconSize
547
- ↓
548
- larger icon dimensions
549
- ```
550
-
551
- ---
552
-
553
- # Icon Only
554
-
555
- Use `iconOnly` for buttons containing only an icon.
556
-
557
- ```tsx
558
- <Button
559
- iconOnly
560
- aria-label="Search"
561
- >
562
- <SearchIcon />
563
- </Button>
564
- ```
565
-
566
- `iconOnly` changes the Button's layout so that normal horizontal content padding is not applied.
567
-
568
- ### Accessibility
569
-
570
- Always provide an accessible label when the Button contains no visible text:
571
-
572
- ```tsx
573
- <Button
574
- iconOnly
575
- aria-label="Open settings"
576
- >
577
- <SettingsIcon />
578
- </Button>
579
- ```
580
-
581
- ---
582
-
583
- # Full Width
584
-
585
- Use `fullWidth` to make the Button fill its available horizontal space.
586
-
587
- ```tsx
588
- <Button fullWidth>
589
- Continue
590
- </Button>
591
- ```
592
-
593
- This is useful for:
594
-
595
- * Forms
596
- * Mobile layouts
597
- * Authentication screens
598
- * Dialog actions
599
- * Card actions
600
-
601
- ---
602
-
603
- # Disabled
604
-
605
- Buttons can be disabled using the standard `disabled` prop.
606
-
607
- ```tsx
608
- <Button disabled>
609
- Unavailable
610
- </Button>
611
- ```
612
-
613
- A disabled Button cannot be interacted with.
614
-
615
- Loading automatically disables the Button as well:
616
-
617
- ```tsx
618
- <Button isLoading>
619
- Saving...
620
- </Button>
621
- ```
622
-
623
- is effectively treated as disabled while the loading state is active.
624
-
625
- ---
626
-
627
- # Custom Rendering
628
-
629
- The `render` prop provides an advanced escape hatch for rendering the Button's resolved styles and content using another element or component.
630
-
631
- ```tsx
632
- <Button
633
- render={(props) => (
634
- <a
635
- {...props}
636
- href="/templates"
637
- >
638
- Templates
639
- </a>
640
- )}
641
- >
642
- Templates
643
- </Button>
644
- ```
645
-
646
- The render function receives the resolved Button properties:
647
-
648
- ```ts
649
- interface ButtonRenderProps {
650
- className?: string;
651
- style?: React.CSSProperties;
652
- disabled?: boolean;
653
- "aria-busy"?: boolean;
654
- children?: React.ReactNode;
655
- }
656
- ```
657
-
658
- This means the custom element automatically receives the Button's:
659
-
660
- * Recipe classes
661
- * Resolved typography
662
- * Resolved size styles
663
- * Loading state
664
- * Button content
665
-
666
- ### Using a Custom Component
667
-
668
- The same pattern can be used with another component:
669
-
670
- ```tsx
671
- <Button
672
- render={(props) => (
673
- <CustomLink
674
- {...props}
675
- href="/templates"
676
- />
677
- )}
678
- >
679
- Templates
680
- </Button>
681
- ```
682
-
683
- ---
684
-
685
- ## Next.js Server Component Note
686
-
687
- The `render` prop contains a function.
688
-
689
- Because functions cannot cross the Next.js Server Component → Client Component boundary, `render` should be used from a Client Component.
690
-
691
- ### ❌ This can fail
692
-
693
- ```tsx
694
- // page.tsx
695
-
696
- import { Button } from "@splenddev/kreativ-ui";
697
-
698
- export default function Page() {
699
- return (
700
- <Button
701
- render={(props) => (
702
- <a {...props} href="/templates">
703
- Templates
704
- </a>
705
- )}
706
- >
707
- Templates
708
- </Button>
709
- );
710
- }
711
- ```
712
-
713
- ### ✅ Create the render function in a Client Component
640
+ **Next.js Server Component Note:** Since `render` is a function prop, it should be used from a Client Component:
714
641
 
715
642
  ```tsx
716
643
  "use client";
@@ -732,2442 +659,861 @@ export function TemplatesButton() {
732
659
  }
733
660
  ```
734
661
 
735
- The Client Component can then be rendered from your Server Component:
736
-
737
- ```tsx
738
- import { TemplatesButton } from "./TemplatesButton";
739
-
740
- export default function Page() {
741
- return <TemplatesButton />;
742
- }
743
- ```
744
-
745
- > **Note:** `render` is intentionally retained as an advanced rendering API. For ordinary Buttons, simply use `<Button>`.
746
-
747
- ---
748
-
749
- # Combining Features
750
-
751
- Button features can be combined.
752
-
753
- ```tsx
754
- <Button
755
- variant="outline"
756
- color="brand"
757
- size="lg"
758
- typography="body"
759
- leftIcon={<DownloadIcon />}
760
- fullWidth
761
- >
762
- Download
763
- </Button>
764
- ```
765
-
766
- Another example:
767
-
768
- ```tsx
769
- <Button
770
- variant="solid"
771
- size="sm"
772
- typography="bodySmall"
773
- isLoading
774
- >
775
- Processing...
776
- </Button>
777
- ```
778
-
779
- ---
780
-
781
- # Theming
782
-
783
- Button behavior and appearance are driven by the active Kreativ UI theme.
784
-
785
- The Button recipe controls visual variants:
786
-
787
- ```ts
788
- const theme = {
789
- recipes: {
790
- Button: {
791
- // recipe configuration
792
- },
793
- },
794
- };
795
- ```
796
-
797
- The size system controls dimensions:
798
-
799
- ```ts
800
- const theme = {
801
- sizes: {
802
- // ...
803
- },
804
- };
805
- ```
806
-
807
- Typography controls text styling:
808
-
809
- ```ts
810
- const theme = {
811
- typography: {
812
- body: {
813
- fontFamily: "{fonts.body}",
814
- fontSize: "{fontSizes.md}",
815
- fontWeight: "{fontWeights.normal}",
816
- lineHeight: "{lineHeights.normal}",
817
- },
818
- },
819
- };
820
- ```
821
-
822
- This gives the Button three independent styling layers:
823
-
824
- ```text
825
- Button
826
- │
827
- ├── Recipe
828
- │ └── variant + color
829
- │
830
- ├── Size
831
- │ └── dimensions + spacing
832
- │
833
- └── Typography
834
- └── font + text styling
835
- ```
836
-
837
- ---
838
-
839
- # Props
840
-
841
- | Prop | Type | Default | Description |
842
- | ------------ | -------------------------------------------- | --------: | -------------------------------------------------------- |
843
- | `variant` | `ButtonVariant` | `"solid"` | Controls the Button's visual variant. |
844
- | `color` | `ButtonColor` | `"brand"` | Controls the Button's semantic color. |
845
- | `size` | `ButtonSize` | `"md"` | Controls Button dimensions and icon sizing. |
846
- | `typography` | `string` | `"body"` | Name of the typography preset used for Button text. |
847
- | `isLoading` | `boolean` | `false` | Displays the loading indicator and disables interaction. |
848
- | `leftIcon` | `ReactNode` | — | Icon displayed before the Button content. |
849
- | `rightIcon` | `ReactNode` | — | Icon displayed after the Button content. |
850
- | `iconOnly` | `boolean` | `false` | Optimizes the Button layout for icon-only content. |
851
- | `fullWidth` | `boolean` | `false` | Makes the Button fill its available width. |
852
- | `disabled` | `boolean` | `false` | Disables interaction with the Button. |
853
- | `render` | `(props: ButtonRenderProps) => ReactElement` | — | Advanced custom rendering escape hatch. |
854
- | `className` | `string` | — | Additional CSS classes. |
855
- | `style` | `React.CSSProperties` | — | Inline style overrides. |
856
- | `children` | `ReactNode` | — | Button content. |
857
-
858
- All applicable standard HTML `<button>` attributes and event handlers are also supported.
859
-
860
- ---
861
-
862
- # `ButtonRenderProps`
863
-
864
- The `render` callback receives:
865
-
866
- ```ts
867
- interface ButtonRenderProps {
868
- className?: string;
869
- style?: React.CSSProperties;
870
- disabled?: boolean;
871
- "aria-disabled"?: boolean;
872
- "aria-busy"?: boolean;
873
- children?: React.ReactNode;
874
- }
875
- ```
876
-
877
- Example:
878
-
879
- ```tsx
880
- <Button
881
- render={(props) => (
882
- <a
883
- {...props}
884
- href="/templates"
885
- />
886
- )}
887
- >
888
- Templates
889
- </Button>
890
- ```
891
-
892
- ---
893
-
894
- # Styling Precedence
895
-
896
- Button styling follows a predictable order:
897
-
898
- ```text
899
- Theme Recipe
900
- ↓
901
- Component Size
902
- ↓
903
- Typography
904
- ↓
905
- className
906
- ↓
907
- style
908
- ```
909
-
910
- Typography controls text presentation:
911
-
912
- ```text
913
- fontFamily
914
- fontSize
915
- fontWeight
916
- lineHeight
917
- letterSpacing
918
- ```
919
-
920
- Size controls layout:
921
-
922
- ```text
923
- height
924
- padding
925
- gap
926
- iconSize
927
- radius
928
- ```
929
-
930
- This separation allows you to change typography without unexpectedly changing Button dimensions.
931
-
932
- ---
933
-
934
- # Accessibility
935
-
936
- Buttons should always have an accessible name.
937
-
938
- For text Buttons:
939
-
940
- ```tsx
941
- <Button>
942
- Save changes
943
- </Button>
944
- ```
945
-
946
- For icon-only Buttons:
947
-
948
- ```tsx
949
- <Button
950
- iconOnly
951
- aria-label="Search"
952
- >
953
- <SearchIcon />
954
- </Button>
955
- ```
956
-
957
- When using `isLoading`, the Button communicates its busy state through:
958
-
959
- ```html
960
- aria-busy="true"
961
- ```
962
-
963
- Always provide meaningful labels for actions whose visible content does not describe their purpose.
964
-
965
- ---
966
-
967
- # Recommended Usage
968
-
969
- ### Use variants for visual intent
970
-
971
- ```tsx
972
- <Button variant="solid" color="destructive">
973
- Delete account
974
- </Button>
975
- ```
976
-
977
- ### Use sizes for component dimensions
978
-
979
- ```tsx
980
- <Button size="sm">
981
- Cancel
982
- </Button>
983
- ```
984
-
985
- ### Use typography for text presentation
986
-
987
- ```tsx
988
- <Button typography="bodySmall">
989
- Cancel
990
- </Button>
991
- ```
992
-
993
- ### Use `style` for exceptional one-off overrides
994
-
995
- ```tsx
996
- <Button
997
- style={{
998
- letterSpacing: "0.02em",
999
- }}
1000
- >
1001
- Continue
1002
- </Button>
1003
- ```
1004
-
1005
- For repeated styles, prefer creating a typography preset instead.
1006
-
1007
- ---
1008
-
1009
- # Complete Example
1010
-
1011
- ```tsx
1012
- import {
1013
- Button,
1014
- } from "@splenddev/kreativ-ui";
1015
-
1016
- function Actions() {
1017
- return (
1018
- <div className="flex gap-3">
1019
- <Button
1020
- variant="outline"
1021
- size="sm"
1022
- typography="bodySmall"
1023
- >
1024
- Cancel
1025
- </Button>
1026
-
1027
- <Button
1028
- variant="solid"
1029
- color="brand"
1030
- size="sm"
1031
- typography="bodySmall"
1032
- rightIcon={<ArrowRightIcon />}
1033
- >
1034
- Continue
1035
- </Button>
1036
-
1037
- <Button
1038
- variant="solid"
1039
- color="destructive"
1040
- size="sm"
1041
- typography="bodySmall"
1042
- >
1043
- Delete
1044
- </Button>
1045
- </div>
1046
- );
1047
- }
1048
- ```
1049
-
1050
- The result is a Button that combines **recipe styling, theme-driven sizing, centralized typography, icons, loading behavior, accessibility, and custom rendering** without requiring those concerns to be manually managed by the consumer.
1051
-
1052
- # 🧩 Input & FormField
1053
-
1054
- This section covers the `Input` component and the `FormField` composition system for building accessible, validated form controls.
1055
-
1056
- ---
1057
-
1058
- ## Input
1059
-
1060
- A flexible text input with support for variants, sizes, validation states, adornments, password visibility, clearing, and loading states.
1061
-
1062
- ### Basic Usage
1063
-
1064
- ```tsx
1065
- import { Input } from "@splenddev/kreativ-ui";
1066
-
1067
- <Input placeholder="Enter your name" />;
1068
- ```
1069
-
1070
- ### Variants
1071
-
1072
- ```tsx
1073
- <Input variant="outline" />
1074
- <Input variant="filled" />
1075
- <Input variant="ghost" />
1076
- ```
1077
-
1078
- ### Sizes
1079
-
1080
- ```tsx
1081
- <Input inputSize="sm" />
1082
- <Input inputSize="md" />
1083
- <Input inputSize="lg" />
1084
- ```
1085
-
1086
- ### Input Kinds
1087
-
1088
- The `kind` prop sets sensible defaults for `type`, `inputMode`, `autoComplete`, and sometimes a placeholder and icon. Any explicit prop overrides the kind default.
1089
-
1090
- ```tsx
1091
- <Input kind="email" />
1092
- <Input kind="tel" />
1093
- <Input kind="url" />
1094
- <Input kind="search" />
1095
- <Input kind="numeric" />
1096
- <Input kind="password-current" /> // autoComplete="current-password" + show/hide toggle
1097
- <Input kind="password-new" /> // autoComplete="new-password" + show/hide toggle
1098
- ```
1099
-
1100
- To suppress the icon that comes with certain kinds (e.g., `email`, `search`):
1101
-
1102
- ```tsx
1103
- <Input kind="email" hideKindIcon />
1104
- ```
1105
-
1106
- ### Validation States
1107
-
1108
- ```tsx
1109
- <Input error />
1110
- <Input success />
1111
- ```
1112
-
1113
- The `error` state also sets `aria-invalid="true"`.
1114
-
1115
- ### Disabled & Loading
1116
-
1117
- ```tsx
1118
- <Input disabled />
1119
- <Input isLoading /> // shows a spinner, makes the field read‑only (not disabled)
1120
- ```
1121
-
1122
- ### Adornments (Icons)
1123
-
1124
- ```tsx
1125
- <Input startIcon={<SearchIcon />} />
1126
- <Input endIcon={<MailIcon />} />
1127
- ```
1128
-
1129
- ### Clearable
1130
-
1131
- ```tsx
1132
- <Input clearable onClear={() => console.log("cleared")} />
1133
- ```
1134
-
1135
- A clear button appears when the field has a value. Clicking it clears the value and calls `onClear`.
1136
-
1137
- ### Password Input
1138
-
1139
- With `kind="password-current"` or `kind="password-new"`, a toggle button is shown to reveal/hide the password.
1140
-
1141
- ### Full Width & Rounded
1142
-
1143
- ```tsx
1144
- <Input fullWidth /> // default: true
1145
- <Input rounded /> // fully rounded corners
1146
- ```
1147
-
1148
- ### Controlled & Uncontrolled
1149
-
1150
- ```tsx
1151
- // Controlled
1152
- const [value, setValue] = useState("");
1153
- <Input value={value} onChange={(e) => setValue(e.target.value)} />
1154
-
1155
- // Uncontrolled
1156
- <Input defaultValue="Initial value" />
1157
- ```
1158
-
1159
- ### Ref Forwarding
1160
-
1161
- `Input` forwards refs to the underlying `<input>` element.
1162
-
1163
- ### Native Props
1164
-
1165
- All standard `<input>` attributes (except `size`) are forwarded to the native input element.
1166
-
1167
- ### Size-Aware Styling
1168
-
1169
- The component uses `useSizeStyle` to apply theme‑aware sizing from the `sizes` object in the theme.
1170
-
1171
- ---
1172
-
1173
- ## FormField
1174
-
1175
- `FormField` is a higher‑level component that composes a label, description, control, and validation message into an accessible form field. It automatically wires `id`, `aria-describedby`, `aria-invalid`, and `aria-required` – no manual ID juggling.
1176
-
1177
- ### Basic Structure
1178
-
1179
- ```tsx
1180
- import { FormField, Input } from "@splenddev/kreativ-ui";
1181
-
1182
- <FormField>
1183
- <FormField.Label>Email address</FormField.Label>
1184
- <FormField.Description>We'll only send receipts here.</FormField.Description>
1185
- <FormField.Control>
1186
- <Input kind="email" placeholder="you@company.com" />
1187
- </FormField.Control>
1188
- <FormField.Message>Enter a valid email.</FormField.Message>
1189
- </FormField>;
1190
- ```
1191
-
1192
- ### Subcomponents
1193
-
1194
- | Component | Purpose |
1195
- | ----------------------- | -------------------------------------------------------------- |
1196
- | `FormField` | Provides context, manages `id` and accessibility relationships |
1197
- | `FormField.Label` | Renders a label associated with the control via `htmlFor` |
1198
- | `FormField.Description` | Renders helper text, linked via `aria-describedby` |
1199
- | `FormField.Control` | Injects the field ID and accessibility props into its child |
1200
- | `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
1201
-
1202
- ### Field‑Level Props
1203
-
1204
- `FormField` accepts:
1205
-
1206
- | Prop | Type | Default | Description |
1207
- | ----------- | ----------- | -------------- | ------------------------------------------------- |
1208
- | `id` | `string` | auto‑generated | Explicit `id` for the control |
1209
- | `error` | `string` | – | Validation error message (overrides description) |
1210
- | `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
1211
- | `className` | `string` | – | Additional wrapper classes |
1212
- | `children` | `ReactNode` | – | The field content (typically subcomponents) |
1213
-
1214
- ### Error Handling
1215
-
1216
- When `error` is provided:
1217
-
1218
- - The error message is displayed (replacing any `Description`).
1219
- - The control receives `aria-invalid="true"`.
1220
- - The error message is linked via `aria-describedby`.
1221
-
1222
- ### Required Indicator
1223
-
1224
- When `required` is `true`, the label gets a `*` suffix and the control receives `aria-required="true"`.
1225
-
1226
- ### Auto‑Generated IDs
1227
-
1228
- If no `id` is provided, `FormField` generates a unique ID using `useId` (React 18+) and passes it to the control via `FormField.Control`.
1229
-
1230
- ---
1231
-
1232
- ## FormField + Input Integration
1233
-
1234
- This is the recommended way to build accessible forms with Kreativ UI.
1235
-
1236
- ```tsx
1237
- import { FormField, Input } from "@splenddev/kreativ-ui";
1238
-
1239
- function EmailField() {
1240
- const [error, setError] = useState("");
1241
-
1242
- const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
1243
- const value = e.target.value;
1244
- if (!value) setError("Email is required");
1245
- else if (!/\S+@\S+\.\S+/.test(value)) setError("Enter a valid email");
1246
- else setError("");
1247
- };
1248
-
1249
- return (
1250
- <FormField id="email" required error={error}>
1251
- <FormField.Label>Email address</FormField.Label>
1252
- <FormField.Description>
1253
- We'll only send receipts here.
1254
- </FormField.Description>
1255
- <FormField.Control>
1256
- <Input kind="email" placeholder="you@company.com" onBlur={handleBlur} />
1257
- </FormField.Control>
1258
- {error && <FormField.Message>{error}</FormField.Message>}
1259
- </FormField>
1260
- );
1261
- }
1262
- ```
1263
-
1264
- **Responsibilities**:
1265
-
1266
- - `FormField` – owns field‑level state and accessibility relationships.
1267
- - `FormField.Label` – provides the accessible label.
1268
- - `FormField.Description` – provides supporting text (hidden when `error` exists).
1269
- - `FormField.Control` – connects the actual control to the field context.
1270
- - `Input` – handles the input behavior and presentation.
1271
- - `FormField.Message` – displays validation feedback.
1272
-
1273
- ---
1274
-
1275
- ## Accessibility
1276
-
1277
- The library ensures the following relationships are automatically established:
1278
-
1279
- ```
1280
- Label
1281
- ↓
1282
- for → input[id]
1283
-
1284
- Description
1285
- ↓
1286
- aria-describedby → description id
1287
-
1288
- Validation message
1289
- ↓
1290
- aria-describedby → message id (appended to description ids)
1291
-
1292
- Validation state
1293
- ↓
1294
- aria-invalid="true" (when error is present)
1295
- ```
1296
-
1297
- When using `FormField`, consumers **should** wrap the input with `FormField.Control` to benefit from these automatic connections.
1298
-
1299
- ---
1300
-
1301
- ## Validation Behavior
1302
-
1303
- ### Field‑Level vs. Input‑Level
1304
-
1305
- ```tsx
1306
- // Field-level validation (manages error message and aria state)
1307
- <FormField error="Invalid email">
1308
- <FormField.Control>
1309
- <Input />
1310
- </FormField.Control>
1311
- </FormField>
1312
-
1313
- // Input-level error (only visual style and aria-invalid)
1314
- <Input error />
1315
- ```
1316
-
1317
- `FormField` manages the error message and overall accessibility, while `Input` controls its own visual presentation. Using both together gives full feedback.
1318
-
1319
- ### State‑Transition Feedback
1320
-
1321
- When the `error` or `success` state changes on an `Input`, the component briefly animates the change (e.g., a subtle colour transition) rather than continuously animating the validation state. This provides a smooth user experience without being distracting.
1322
-
1323
- ---
1324
-
1325
- ## Standalone vs. FormField Usage
1326
-
1327
- - **Standalone `Input`**: Use when you need a simple input without label/description/validation relationships. Ideal for search bars, inline inputs, or custom layouts.
1328
- - **`FormField` + `Input`**: Use for labeled, described, or validated form controls. This ensures proper accessibility and reduces manual ARIA management.
1329
-
1330
- ---
1331
-
1332
- ## API Reference
1333
-
1334
- ### Input Props
1335
-
1336
- | Prop | Type | Default | Description |
1337
- | ---------------- | ---------------------------------- | ----------- | ---------------------------------------------------------------------------- |
1338
- | `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
1339
- | `inputSize` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding, font size |
1340
- | `kind` | `InputKind` | `"text"` | Sets defaults for `type`, `inputMode`, `autoComplete`, placeholder, and icon |
1341
- | `hideKindIcon` | `boolean` | `false` | Suppress the default icon from `kind` |
1342
- | `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
1343
- | `success` | `boolean` | `false` | Success styling |
1344
- | `disabled` | `boolean` | `false` | Disables the input |
1345
- | `isLoading` | `boolean` | `false` | Shows spinner and marks read‑only |
1346
- | `clearable` | `boolean` | `false` | Shows clear button when value is present |
1347
- | `onClear` | `() => void` | – | Called after clear |
1348
- | `rounded` | `boolean` | `false` | Fully rounded wrapper |
1349
- | `fullWidth` | `boolean` | `true` | Stretch to container width |
1350
- | `startIcon` | `ReactNode` | – | Content before the input (e.g., icon) |
1351
- | `endIcon` | `ReactNode` | – | Content after the input (e.g., icon) |
1352
- | `className` | `string` | – | Additional wrapper class |
1353
- | `inputClassName` | `string` | – | Additional class for the native input element |
1354
-
1355
- All standard `<input>` attributes (except `size`) are forwarded to the underlying `<input>`.
1356
-
1357
- ### FormField Props
1358
-
1359
- | Prop | Type | Default | Description |
1360
- | ----------- | ----------- | -------------- | ------------------------------------------------- |
1361
- | `id` | `string` | auto‑generated | Explicit `id` for the control |
1362
- | `error` | `string` | – | Validation error message (overrides description) |
1363
- | `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
1364
- | `className` | `string` | – | Additional wrapper classes |
1365
- | `children` | `ReactNode` | – | The field content (typically subcomponents) |
1366
-
1367
- ### FormField Subcomponents
1368
-
1369
- | Component | Description |
1370
- | ----------------------- | ------------------------------------------------------------ |
1371
- | `FormField.Label` | Renders a label associated with the control via `htmlFor` |
1372
- | `FormField.Description` | Renders helper text, linked via `aria-describedby` |
1373
- | `FormField.Control` | Injects the field ID and accessibility props into its child |
1374
- | `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
1375
-
1376
- ---
1377
-
1378
- For more advanced usage (e.g., integrating with `react-hook-form`), see the [GitHub repository examples](https://github.com/Vincentvirtuoso/kreativ-ui).
1379
-
1380
- ---
1381
-
1382
- # 🧩 Select
1383
-
1384
- A fully accessible, customizable select component with keyboard navigation, grouped options, clearable selections, and optional integration with `FormField`. Built as a compound component for maximum flexibility.
1385
-
1386
- ---
1387
-
1388
- ## Overview
1389
-
1390
- `Select` is a headless‑style compound component that implements the WAI‑ARIA combobox pattern. It consists of:
1391
-
1392
- - `Select` – root container, manages state and context
1393
- - `Select.Trigger` – interactive button that opens/closes the dropdown
1394
- - `Select.Value` – displays the selected option or a placeholder
1395
- - `Select.Content` – dropdown container for options
1396
- - `Select.Item` – an individual selectable option
1397
- - `Select.Group` – groups related options
1398
- - `Select.Label` – heading for a group
1399
-
1400
- Supports both **controlled** (`value`/`onValueChange`) and **uncontrolled** (`defaultValue`) usage.
1401
-
1402
- ---
1403
-
1404
- ## Import
1405
-
1406
- ```tsx
1407
- import { Select } from "@splenddev/kreativ-ui";
1408
- ```
1409
-
1410
- ---
1411
-
1412
- ## Basic Usage
1413
-
1414
- ```tsx
1415
- <Select placeholder="Select a country">
1416
- <Select.Trigger>
1417
- <Select.Value />
1418
- </Select.Trigger>
1419
-
1420
- <Select.Content>
1421
- <Select.Item value="us">United States</Select.Item>
1422
- <Select.Item value="ca">Canada</Select.Item>
1423
- <Select.Item value="mx">Mexico</Select.Item>
1424
- </Select.Content>
1425
- </Select>
1426
- ```
1427
-
1428
- ---
1429
-
1430
- ## Controlled Select
1431
-
1432
- Use `value` and `onValueChange` to control the selection from a parent component.
1433
-
1434
- ```tsx
1435
- import { useState } from "react";
1436
-
1437
- function ControlledSelect() {
1438
- const [value, setValue] = useState<string | undefined>("");
1439
-
1440
- return (
1441
- <Select value={value} onValueChange={setValue}>
1442
- <Select.Trigger>
1443
- <Select.Value placeholder="Choose a framework" />
1444
- </Select.Trigger>
1445
-
1446
- <Select.Content>
1447
- <Select.Item value="react">React</Select.Item>
1448
- <Select.Item value="vue">Vue</Select.Item>
1449
- <Select.Item value="svelte">Svelte</Select.Item>
1450
- </Select.Content>
1451
- </Select>
1452
- );
1453
- }
1454
- ```
1455
-
1456
- > When `clearable` is enabled, clearing the value will call `onValueChange(undefined)`. The parent must handle this state change accordingly.
1457
-
1458
- ---
1459
-
1460
- ## Uncontrolled Select
1461
-
1462
- Use `defaultValue` for an uncontrolled component.
1463
-
1464
- ```tsx
1465
- <Select defaultValue="react">
1466
- <Select.Trigger>
1467
- <Select.Value placeholder="Choose a framework" />
1468
- </Select.Trigger>
1469
-
1470
- <Select.Content>
1471
- <Select.Item value="react">React</Select.Item>
1472
- <Select.Item value="vue">Vue</Select.Item>
1473
- <Select.Item value="angular">Angular</Select.Item>
1474
- </Select.Content>
1475
- </Select>
1476
- ```
1477
-
1478
- ---
1479
-
1480
- ## Props
1481
-
1482
- | Prop | Type | Default | Description |
1483
- | --------------- | ---------------------------------- | ----------- | -------------------------------------------------- |
1484
- | `value` | `string` | – | Controlled selected value |
1485
- | `defaultValue` | `string` | – | Uncontrolled initial value |
1486
- | `onValueChange` | `(value?: string) => void` | – | Called when selection changes |
1487
- | `placeholder` | `string` | – | Text shown when no value is selected |
1488
- | `required` | `boolean` | `false` | Marks the field as required (`aria-required`) |
1489
- | `name` | `string` | – | Name for the hidden input used in form submissions |
1490
- | `disabled` | `boolean` | `false` | Disables the entire select |
1491
- | `clearable` | `boolean` | `false` | Shows a clear button (removes selection) |
1492
- | `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
1493
- | `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size of the trigger and content |
1494
- | `error` | `boolean` | `false` | Shows error state and sets `aria-invalid="true"` |
1495
- | `success` | `boolean` | `false` | Shows success state |
1496
- | `rounded` | `boolean` | `false` | Applies fully rounded corners to the trigger |
1497
- | `className` | `string` | – | Additional class names for the root container |
1498
-
1499
- ---
1500
-
1501
- ## Compound Components
1502
-
1503
- ### `Select.Trigger`
1504
-
1505
- The interactive button that toggles the dropdown. It receives all necessary ARIA attributes from the root `Select`.
1506
-
1507
- ```tsx
1508
- <Select.Trigger>
1509
- <Select.Value />
1510
- </Select.Trigger>
1511
- ```
1512
-
1513
- ### `Select.Value`
1514
-
1515
- Renders the current selection or the placeholder. The label is derived from the matching `Select.Item`’s children.
1516
-
1517
- ```tsx
1518
- <Select.Value placeholder="Choose an option" />
1519
- ```
1520
-
1521
- ### `Select.Content`
1522
-
1523
- The dropdown container. Renders its children (items, groups, labels) inside a listbox.
1524
-
1525
- ```tsx
1526
- <Select.Content>{/* items */}</Select.Content>
1527
- ```
1528
-
1529
- ### `Select.Item`
1530
-
1531
- A single selectable option.
1532
-
1533
- | Prop | Type | Default | Description |
1534
- | ---------- | ----------- | -------- | -------------------- |
1535
- | `value` | `string` | required | Value of the option |
1536
- | `disabled` | `boolean` | `false` | Disables this option |
1537
- | `children` | `ReactNode` | – | Display label |
1538
-
1539
- ```tsx
1540
- <Select.Item value="react" disabled>
1541
- React
1542
- </Select.Item>
1543
- ```
1544
-
1545
- ### `Select.Group`
1546
-
1547
- Groups related options, typically used with `Select.Label`.
1548
-
1549
- ```tsx
1550
- <Select.Group>
1551
- <Select.Label>Frontend</Select.Label>
1552
- <Select.Item value="react">React</Select.Item>
1553
- <Select.Item value="vue">Vue</Select.Item>
1554
- </Select.Group>
1555
- ```
1556
-
1557
- ### `Select.Label`
1558
-
1559
- A heading for a group of options. It is rendered as a non‑interactive label inside the listbox.
1560
-
1561
- ```tsx
1562
- <Select.Label>Backend</Select.Label>
1563
- ```
1564
-
1565
- ---
1566
-
1567
- ## Accessibility
1568
-
1569
- `Select` implements the WAI‑ARIA combobox pattern and manages all necessary relationships automatically.
1570
-
1571
- **Roles & Attributes**:
1572
-
1573
- - Trigger: `role="combobox"`, `aria-haspopup="listbox"`, `aria-expanded`, `aria-controls`, `aria-activedescendant`
1574
- - Content: `role="listbox"`
1575
- - Items: `role="option"`, `aria-selected`, `aria-disabled`
1576
-
1577
- **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`.
1578
-
1579
- **FormField integration**: When placed inside a `FormField`, the Select consumes the following context:
1580
-
1581
- - `id` – becomes the trigger’s `id`
1582
- - `labelId` – linked via `aria-labelledby`
1583
- - `descriptionId` / `messageId` – linked via `aria-describedby`
1584
- - `invalid` – sets `aria-invalid`
1585
- - `required` – sets `aria-required`
1586
-
1587
- This ensures full ARIA support with no manual configuration.
1588
-
1589
- ---
1590
-
1591
- ## Keyboard Navigation
1592
-
1593
- | Key | Open state | Closed state |
1594
- | ----------- | ------------------ | ----------------------------------------- |
1595
- | `ArrowDown` | Next item | Opens the dropdown |
1596
- | `ArrowUp` | Previous item | Opens the dropdown (or no-op) |
1597
- | `Home` | First item | Opens and selects first? (implementation) |
1598
- | `End` | Last item | Opens and selects last? |
1599
- | `Enter` | Select active item | Opens the dropdown |
1600
- | `Space` | Select active item | Opens the dropdown |
1601
- | `Escape` | Closes dropdown | – |
1602
- | `Backspace` | – | Clears selection (if `clearable`) |
1603
- | `Delete` | – | Clears selection (if `clearable`) |
1604
-
1605
- > 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.
1606
-
1607
- ---
1608
-
1609
- ## Clearable Select
1610
-
1611
- When `clearable` is `true`, a clear button appears inside the trigger when a value is selected. Clicking it resets the selection to `undefined`.
1612
-
1613
- ```tsx
1614
- <Select clearable defaultValue="react">
1615
- <Select.Trigger>
1616
- <Select.Value placeholder="Pick a framework" />
1617
- </Select.Trigger>
1618
-
1619
- <Select.Content>
1620
- <Select.Item value="react">React</Select.Item>
1621
- <Select.Item value="vue">Vue</Select.Item>
1622
- </Select.Content>
1623
- </Select>
1624
- ```
1625
-
1626
- **Controlled behavior**: The parent must handle `onValueChange(undefined)` to update its own state.
1627
-
1628
- **Uncontrolled behavior**: The internal state is cleared automatically.
1629
-
1630
- ---
1631
-
1632
- ## Disabled Options
1633
-
1634
- 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.
1635
-
1636
- ```tsx
1637
- <Select.Item value="legacy" disabled>
1638
- Legacy
1639
- </Select.Item>
1640
- ```
1641
-
1642
- Disabled items are skipped when navigating with arrow keys.
1643
-
1644
- ---
1645
-
1646
- ## Validation States
1647
-
1648
- ### Error
1649
-
1650
- ```tsx
1651
- <Select error>
1652
- <Select.Trigger>
1653
- <Select.Value placeholder="Choose" />
1654
- </Select.Trigger>
1655
- <Select.Content>...</Select.Content>
1656
- </Select>
1657
- ```
1658
-
1659
- Visually styles the trigger with error colours and sets `aria-invalid="true"`.
1660
-
1661
- ### Success
1662
-
1663
- ```tsx
1664
- <Select success>...</Select>
1665
- ```
1666
-
1667
- Applies success styling.
1668
-
1669
- ---
1670
-
1671
- ## FormField Integration
1672
-
1673
- When used inside a `FormField`, the Select automatically inherits the field’s `id`, `required`, and validation state.
1674
-
1675
- ```tsx
1676
- <FormField required error="Please select a country">
1677
- <FormField.Label>Country</FormField.Label>
1678
- <FormField.Description>
1679
- Select your country of residence.
1680
- </FormField.Description>
1681
-
1682
- <Select>
1683
- <Select.Trigger>
1684
- <Select.Value placeholder="Select a country" />
1685
- </Select.Trigger>
1686
- <Select.Content>
1687
- <Select.Item value="us">United States</Select.Item>
1688
- <Select.Item value="ca">Canada</Select.Item>
1689
- </Select.Content>
1690
- </Select>
1691
-
1692
- <FormField.Message />
1693
- </FormField>
1694
- ```
1695
-
1696
- > No extra props are needed – the Select picks up the context automatically.
1697
-
1698
- ---
1699
-
1700
- ## Native Form Submission
1701
-
1702
- The `name` prop renders a hidden `<input>` that is included in form submissions. The value submitted is the currently selected `value`.
1703
-
1704
- ```tsx
1705
- <form onSubmit={handleSubmit}>
1706
- <Select name="country" defaultValue="us">
1707
- <Select.Trigger>
1708
- <Select.Value placeholder="Select a country" />
1709
- </Select.Trigger>
1710
- <Select.Content>
1711
- <Select.Item value="us">United States</Select.Item>
1712
- <Select.Item value="ca">Canada</Select.Item>
1713
- </Select.Content>
1714
- </Select>
1715
-
1716
- <button type="submit">Submit</button>
1717
- </form>
1718
- ```
1719
-
1720
- ---
1721
-
1722
- ## Styling and Theming
1723
-
1724
- Select uses the same theming infrastructure as other Kreativ UI form controls:
1725
-
1726
- - `theme.recipes.FormControl` defines base, variant, and size styles.
1727
- - `useSizeStyle` applies height, padding, and font size from the `sizes` token.
1728
- - Variants (`outline`, `filled`, `ghost`) are resolved via `resolveRecipe`.
1729
- - Validation states (`error`, `success`) are applied through CSS variables and class names.
1730
-
1731
- All styling is driven by the runtime theme, so overriding the visual appearance can be done by providing a custom `FormControl` recipe in the theme.
1732
-
1733
- ---
1734
-
1735
- ## Data Attributes
1736
-
1737
- The Select exposes several data attributes for styling or testing:
1738
-
1739
- | Attribute | Element | Values | Description |
1740
- | --------------- | ---------------- | ---------------------------- | ------------------------------ |
1741
- | `data-state` | `Select.Trigger` | `"open"`, `"closed"` | Current dropdown state |
1742
- | `data-state` | `Select.Item` | `"selected"`, `"unselected"` | Selection state of the item |
1743
- | `data-active` | `Select.Item` | present when highlighted | Keyboard‑focused item (active) |
1744
- | `data-disabled` | `Select.Item` | present when disabled | Disabled state |
1745
- | `data-invalid` | `Select.Trigger` | present when error | Error state |
1746
-
1747
- ---
1748
-
1749
- ## Complete Example
1750
-
1751
- ```tsx
1752
- import { useState } from "react";
1753
- import { FormField, Select } from "@splenddev/kreativ-ui";
1754
-
1755
- function CountrySelect() {
1756
- const [country, setCountry] = useState<string | undefined>("");
1757
- const [error, setError] = useState("");
1758
-
1759
- const validate = (value?: string) => {
1760
- if (!value) setError("Please select a country");
1761
- else setError("");
1762
- };
1763
-
1764
- return (
1765
- <FormField required error={error}>
1766
- <FormField.Label>Country</FormField.Label>
1767
- <FormField.Description>
1768
- Choose your country of residence.
1769
- </FormField.Description>
1770
-
1771
- <Select
1772
- value={country}
1773
- onValueChange={(val) => {
1774
- setCountry(val);
1775
- validate(val);
1776
- }}
1777
- clearable
1778
- name="country"
1779
- error={!!error}
1780
- >
1781
- <Select.Trigger>
1782
- <Select.Value placeholder="Select a country" />
1783
- </Select.Trigger>
1784
-
1785
- <Select.Content>
1786
- <Select.Group>
1787
- <Select.Label>North America</Select.Label>
1788
- <Select.Item value="us">United States</Select.Item>
1789
- <Select.Item value="ca">Canada</Select.Item>
1790
- <Select.Item value="mx">Mexico</Select.Item>
1791
- </Select.Group>
1792
-
1793
- <Select.Group>
1794
- <Select.Label>Europe</Select.Label>
1795
- <Select.Item value="uk">United Kingdom</Select.Item>
1796
- <Select.Item value="de">Germany</Select.Item>
1797
- <Select.Item value="fr" disabled>
1798
- France (disabled)
1799
- </Select.Item>
1800
- </Select.Group>
1801
- </Select.Content>
1802
- </Select>
1803
-
1804
- {error && <FormField.Message>{error}</FormField.Message>}
1805
- </FormField>
1806
- );
1807
- }
1808
- ```
1809
-
1810
- ---
1811
-
1812
- For more advanced use cases (e.g., async loading, custom rendering), refer to the [GitHub repository examples](https://github.com/Vincentvirtuoso/kreativ-ui).
1813
-
1814
- ---
1815
-
1816
- # Typography System
1817
-
1818
- Kreativ UI provides a centralized, theme-aware typography system for controlling how text is rendered across your application and component library.
1819
-
1820
- 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.
1821
-
1822
- The system supports:
1823
-
1824
- * Reusable typography presets
1825
- * Primitive design tokens
1826
- * Semantic tokens
1827
- * Custom font families
1828
- * `next/font`
1829
- * CSS custom properties
1830
- * Local fonts
1831
- * Runtime theme customization
1832
- * Custom typography presets
1833
- * Component-level typography selection
1834
- * Custom component integration
1835
- * Type-safe token definitions
1836
- * Direct CSS value overrides
1837
-
1838
- ---
1839
-
1840
- ## How It Works
1841
-
1842
- Kreativ UI typography is built around four layers:
1843
-
1844
- ```text
1845
- Primitive Tokens
1846
- ↓
1847
- Semantic Tokens
1848
- ↓
1849
- Typography Presets
1850
- ↓
1851
- useTypography()
1852
- ↓
1853
- React.CSSProperties
1854
- ↓
1855
- Component
1856
- ```
1857
-
1858
- ### Primitive Tokens
1859
-
1860
- Primitive tokens contain reusable values such as:
1861
-
1862
- ```ts
1863
- fonts.body
1864
- fonts.heading
1865
- fonts.mono
1866
-
1867
- fontSizes.sm
1868
- fontSizes.md
1869
- fontSizes.lg
1870
-
1871
- fontWeights.normal
1872
- fontWeights.medium
1873
- fontWeights.bold
1874
-
1875
- lineHeights.tight
1876
- lineHeights.normal
1877
- lineHeights.relaxed
1878
- ```
1879
-
1880
- They are defined with `defineToken()`.
1881
-
1882
- ```ts
1883
- const fonts = {
1884
- body: defineToken("Inter, sans-serif"),
1885
- heading: defineToken("Poppins, sans-serif"),
1886
- };
1887
- ```
1888
-
1889
- ---
1890
-
1891
- ### Semantic Tokens
1892
-
1893
- Semantic tokens represent values that can change depending on the active theme or color mode.
1894
-
1895
- They are defined with `defineSemanticToken()`.
1896
-
1897
- ```ts
1898
- const colors = {
1899
- text: defineSemanticToken(
1900
- "{colors.gray.900}",
1901
- "{colors.gray.100}",
1902
- ),
1903
- };
1904
- ```
1905
-
1906
- Typography itself is generally not mode-dependent, but typography definitions can reference semantic tokens when appropriate.
1907
-
1908
- ---
1909
-
1910
- ### Typography Presets
1911
-
1912
- Typography presets combine tokens into meaningful styles.
1913
-
1914
- ```ts
1915
- const typography = {
1916
- body: {
1917
- fontFamily: "{fonts.body}",
1918
- fontSize: "{fontSizes.md}",
1919
- fontWeight: "{fontWeights.normal}",
1920
- lineHeight: "{lineHeights.normal}",
1921
- },
1922
-
1923
- heading: {
1924
- fontFamily: "{fonts.heading}",
1925
- fontSize: "{fontSizes.2xl}",
1926
- fontWeight: "{fontWeights.bold}",
1927
- lineHeight: "{lineHeights.tight}",
1928
- },
1929
- };
1930
- ```
1931
-
1932
- A preset is referenced by name:
1933
-
1934
- ```tsx
1935
- <Button typography="body" />
1936
- ```
1937
-
1938
- ---
1939
-
1940
- ### `useTypography()`
1941
-
1942
- The `useTypography()` hook retrieves the typography preset from the active theme and resolves all token references into CSS values.
1943
-
1944
- ```tsx
1945
- const styles = useTypography("heading");
1946
- ```
1947
-
1948
- The result is suitable for React's `style` prop:
1949
-
1950
- ```tsx
1951
- <h1 style={styles}>Welcome</h1>
1952
- ```
1953
-
1954
- ---
1955
-
1956
- # Typography Architecture
1957
-
1958
- A typical Kreativ UI theme contains:
1959
-
1960
- ```ts
1961
- const theme = {
1962
- tokens: {
1963
- fonts: {
1964
- body: defineToken("Inter, sans-serif"),
1965
- heading: defineToken("Poppins, sans-serif"),
1966
- mono: defineToken("JetBrains Mono, monospace"),
1967
- },
1968
-
1969
- fontSizes: {
1970
- sm: defineToken("0.875rem"),
1971
- md: defineToken("1rem"),
1972
- lg: defineToken("1.125rem"),
1973
- },
1974
-
1975
- fontWeights: {
1976
- normal: defineToken(400),
1977
- medium: defineToken(500),
1978
- semibold: defineToken(600),
1979
- bold: defineToken(700),
1980
- },
1981
-
1982
- lineHeights: {
1983
- tight: defineToken(1.2),
1984
- normal: defineToken(1.5),
1985
- relaxed: defineToken(1.75),
1986
- },
1987
- },
1988
-
1989
- typography: {
1990
- body: {
1991
- fontFamily: "{fonts.body}",
1992
- fontSize: "{fontSizes.md}",
1993
- fontWeight: "{fontWeights.normal}",
1994
- lineHeight: "{lineHeights.normal}",
1995
- },
1996
-
1997
- heading: {
1998
- fontFamily: "{fonts.heading}",
1999
- fontSize: "{fontSizes.lg}",
2000
- fontWeight: "{fontWeights.bold}",
2001
- lineHeight: "{lineHeights.tight}",
2002
- },
2003
- },
2004
- };
2005
- ```
2006
-
2007
- This creates a clear separation between **what a value is** and **how that value is used**.
2008
-
2009
- For example:
2010
-
2011
- ```text
2012
- "Inter, sans-serif"
2013
- ↓
2014
- fonts.body
2015
- ↓
2016
- typography.body
2017
- ↓
2018
- useTypography("body")
2019
- ↓
2020
- CSSProperties
2021
- ```
2022
-
2023
- ---
2024
-
2025
- # Using Typography in Components
2026
-
2027
- There are several ways to consume the typography system.
2028
-
2029
- ---
2030
-
2031
- ## 1. Using `useTypography()` Directly
2032
-
2033
- Use the hook when you are creating a custom component or need direct access to resolved typography styles.
2034
-
2035
- ```tsx
2036
- import { useTypography } from "@splenddev/kreativ-ui";
2037
-
2038
- function MyCustomCard() {
2039
- const headingStyles = useTypography("heading");
2040
- const bodyStyles = useTypography("body");
2041
-
2042
- return (
2043
- <div>
2044
- <h2 style={headingStyles}>
2045
- Card Title
2046
- </h2>
2047
-
2048
- <p style={bodyStyles}>
2049
- This is the card content.
2050
- </p>
2051
- </div>
2052
- );
2053
- }
2054
- ```
2055
-
2056
- The component does not need to know what font family, size, weight, or line height is currently configured.
2057
-
2058
- ---
2059
-
2060
- # 2. Creating a Reusable Component with `TypographyProps`
2061
-
2062
- Kreativ UI exposes `TypographyProps` so custom components can participate in the same typography system.
2063
-
2064
- ```ts
2065
- export interface TypographyProps {
2066
- /**
2067
- * Defines the typography style to apply to the component.
2068
- * The value must match a typography style registered in the theme.
2069
- */
2070
- typography?: string;
2071
- }
2072
- ```
2073
-
2074
- A custom component can extend this interface:
2075
-
2076
- ```tsx
2077
- import {
2078
- TypographyProps,
2079
- useTypography,
2080
- } from "@splenddev/kreativ-ui";
2081
-
2082
- interface MyTextProps extends TypographyProps {
2083
- children: React.ReactNode;
2084
- }
2085
-
2086
- function MyText({
2087
- typography = "body",
2088
- children,
2089
- }: MyTextProps) {
2090
- const styles = useTypography(typography);
2091
-
2092
- return (
2093
- <p style={styles}>
2094
- {children}
2095
- </p>
2096
- );
2097
- }
2098
- ```
2099
-
2100
- Usage:
2101
-
2102
- ```tsx
2103
- <MyText>
2104
- Default body text
2105
- </MyText>
2106
-
2107
- <MyText typography="heading">
2108
- Heading text
2109
- </MyText>
2110
-
2111
- <MyText typography="caption">
2112
- Caption text
2113
- </MyText>
2114
- ```
2115
-
2116
- This allows custom components to behave consistently with Kreativ UI's built-in components.
2117
-
2118
- ---
2119
-
2120
- # 3. Using Typography with Built-in Components
2121
-
2122
- Built-in components that render text can expose the `typography` prop.
2123
-
2124
- ```tsx
2125
- <Button typography="bodySmall">
2126
- Small Button
2127
- </Button>
2128
-
2129
- <Input typography="body" />
2130
-
2131
- <Select typography="body" />
2132
- ```
2133
-
2134
- The typography prop controls typography-related properties while component-specific layout remains independent.
2135
-
2136
- For example:
2137
-
2138
- ```text
2139
- Typography
2140
- ├── fontFamily
2141
- ├── fontSize
2142
- ├── fontWeight
2143
- ├── lineHeight
2144
- └── letterSpacing
2145
-
2146
- Component Size
2147
- ├── height
2148
- ├── padding
2149
- ├── gap
2150
- ├── iconSize
2151
- └── radius
2152
- ```
2153
-
2154
- This separation prevents changing a typography preset from unexpectedly changing component dimensions.
2155
-
2156
- ---
2157
-
2158
- # 4. Typography and Component Size
2159
-
2160
- Components such as `Button` often have their own size system:
2161
-
2162
- ```ts
2163
- sizes: {
2164
- sm: {
2165
- height: "2rem",
2166
- paddingX: "0.75rem",
2167
- gap: "0.375rem",
2168
- iconSize: "1rem",
2169
- radius: "0.8rem",
2170
- },
2171
-
2172
- md: {
2173
- height: "2.5rem",
2174
- paddingX: "1rem",
2175
- gap: "0.5rem",
2176
- iconSize: "1.125rem",
2177
- radius: "1rem",
2178
- },
2179
- }
2180
- ```
2181
-
2182
- Typography should remain responsible for text properties.
2183
-
2184
- For example:
2185
-
2186
- ```tsx
2187
- <Button
2188
- size="lg"
2189
- typography="bodySmall"
2190
- >
2191
- Continue
2192
- </Button>
2193
- ```
2194
-
2195
- The button can use the large component dimensions while using the `bodySmall` typography preset.
2196
-
2197
- Recommended responsibility:
2198
-
2199
- ```text
2200
- size
2201
- → dimensions and component geometry
2202
-
2203
- typography
2204
- → text presentation
2205
-
2206
- style
2207
- → final consumer override
2208
- ```
2209
-
2210
- ---
2211
-
2212
- # Loading Fonts
2213
-
2214
- Kreativ UI does **not need to load fonts itself**.
2215
-
2216
- Instead, your application is responsible for loading the font.
2217
-
2218
- Kreativ UI only needs to know which font family should be used.
2219
-
2220
- This allows Kreativ UI to work with:
2221
-
2222
- * `next/font`
2223
- * Google Fonts
2224
- * local fonts
2225
- * CSS `@font-face`
2226
- * system fonts
2227
- * CSS variables
2228
- * external font providers
2229
-
2230
- This separation makes the library framework-agnostic.
2231
-
2232
- ---
2233
-
2234
- # 5. Using Next.js `next/font`
2235
-
2236
- This is one of the most common setups for a Next.js application.
2237
-
2238
- For example:
2239
-
2240
- ```tsx
2241
- import { Geist, Geist_Mono } from "next/font/google";
2242
-
2243
- const geistSans = Geist({
2244
- variable: "--font-geist-sans",
2245
- subsets: ["latin"],
2246
- });
2247
-
2248
- const geistMono = Geist_Mono({
2249
- variable: "--font-geist-mono",
2250
- subsets: ["latin"],
2251
- });
2252
- ```
2253
-
2254
- Apply the generated variables to the document:
2255
-
2256
- ```tsx
2257
- <html
2258
- lang="en"
2259
- className={`${geistSans.variable} ${geistMono.variable}`}
2260
- >
2261
- ```
2262
-
2263
- The CSS variables are now available to your application.
2264
-
2265
- You can register them with Kreativ UI:
2266
-
2267
- ```tsx
2268
- import {
2269
- UIProvider,
2270
- defineToken,
2271
- } from "@splenddev/kreativ-ui";
2272
-
2273
- <UIProvider
2274
- theme={{
2275
- tokens: {
2276
- fonts: {
2277
- body: defineToken("var(--font-geist-sans)"),
2278
- heading: defineToken("var(--font-geist-sans)"),
2279
- mono: defineToken("var(--font-geist-mono)"),
2280
- },
2281
- },
2282
- }}
2283
- >
2284
- {children}
2285
- </UIProvider>
2286
- ```
2287
-
2288
- Your typography presets can continue to reference semantic font roles:
2289
-
2290
- ```ts
2291
- const typography = {
2292
- body: {
2293
- fontFamily: "{fonts.body}",
2294
- fontSize: "{fontSizes.md}",
2295
- fontWeight: "{fontWeights.normal}",
2296
- lineHeight: "{lineHeights.normal}",
2297
- },
2298
-
2299
- code: {
2300
- fontFamily: "{fonts.mono}",
2301
- fontSize: "{fontSizes.sm}",
2302
- lineHeight: "{lineHeights.normal}",
2303
- },
2304
- };
2305
- ```
2306
-
2307
- This produces the following flow:
2308
-
2309
- ```text
2310
- next/font
2311
- ↓
2312
- --font-geist-sans
2313
- ↓
2314
- fonts.body
2315
- ↓
2316
- typography.body
2317
- ↓
2318
- useTypography("body")
2319
- ↓
2320
- fontFamily: var(--font-geist-sans)
2321
- ```
2322
-
2323
- ### Why this approach is recommended
2324
-
2325
- Kreativ UI does not need to know that the font came from Next.js.
2326
-
2327
- It only consumes:
2328
-
2329
- ```css
2330
- var(--font-geist-sans)
2331
- ```
2332
-
2333
- This keeps the design system independent from the framework responsible for loading the font.
2334
-
2335
- ---
2336
-
2337
- # 6. Using Google Fonts Without `next/font`
2338
-
2339
- If your application loads a font through CSS or another font provider, you can register it directly.
2340
-
2341
- ```ts
2342
- const theme = {
2343
- tokens: {
2344
- fonts: {
2345
- body: defineToken("Inter, sans-serif"),
2346
- heading: defineToken("Poppins, sans-serif"),
2347
- },
2348
- },
2349
- };
2350
- ```
2351
-
2352
- Your typography definitions remain unchanged:
662
+ ### Props
2353
663
 
2354
- ```ts
2355
- const typography = {
2356
- body: {
2357
- fontFamily: "{fonts.body}",
2358
- fontSize: "{fontSizes.md}",
2359
- lineHeight: "{lineHeights.normal}",
2360
- },
2361
- };
2362
- ```
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 |
2363
680
 
2364
- The typography system does not care how the font was loaded.
681
+ All standard HTML `<button>` attributes and event handlers are also supported.
2365
682
 
2366
683
  ---
2367
684
 
2368
- # 7. Using Local Fonts
2369
-
2370
- If your application defines a local font using `@font-face`:
2371
-
2372
- ```css
2373
- @font-face {
2374
- font-family: "MyBrandFont";
2375
- src: url("/fonts/my-brand-font.woff2") format("woff2");
2376
- }
2377
- ```
685
+ ## 🧩 Input
2378
686
 
2379
- Register it:
687
+ A flexible text input with support for variants, sizes, validation states, adornments, password visibility, clearing, and loading states.
2380
688
 
2381
- ```ts
2382
- const theme = {
2383
- tokens: {
2384
- fonts: {
2385
- body: defineToken("MyBrandFont, sans-serif"),
2386
- },
2387
- },
2388
- };
2389
- ```
689
+ ### Basic Usage
2390
690
 
2391
- Then reference it from typography:
691
+ ```tsx
692
+ import { Input } from "@splenddev/kreativ-ui";
2392
693
 
2393
- ```ts
2394
- const typography = {
2395
- body: {
2396
- fontFamily: "{fonts.body}",
2397
- fontSize: "{fontSizes.md}",
2398
- lineHeight: "{lineHeights.normal}",
2399
- },
2400
- };
694
+ <Input placeholder="Enter your name" />
2401
695
  ```
2402
696
 
2403
- ---
2404
-
2405
- # 8. Using CSS Variables for Fonts
2406
-
2407
- CSS variables are particularly useful when the application already has a global font system.
697
+ ### Variants
2408
698
 
2409
- ```css
2410
- :root {
2411
- --app-font-body: "Inter", sans-serif;
2412
- --app-font-heading: "Poppins", sans-serif;
2413
- }
699
+ ```tsx
700
+ <Input variant="outline" />
701
+ <Input variant="filled" />
702
+ <Input variant="ghost" />
2414
703
  ```
2415
704
 
2416
- Register them:
705
+ ### Sizes
2417
706
 
2418
- ```ts
2419
- const theme = {
2420
- tokens: {
2421
- fonts: {
2422
- body: defineToken("var(--app-font-body)"),
2423
- heading: defineToken("var(--app-font-heading)"),
2424
- },
2425
- },
2426
- };
707
+ ```tsx
708
+ <Input inputSize="sm" />
709
+ <Input inputSize="md" />
710
+ <Input inputSize="lg" />
2427
711
  ```
2428
712
 
2429
- This also allows the font to be changed without changing the typography definitions themselves.
2430
-
2431
- ---
2432
-
2433
- # 9. Using a System Font Stack
713
+ ### Input Kinds
2434
714
 
2435
- You do not need a custom font.
715
+ The `kind` prop sets sensible defaults for `type`, `inputMode`, `autoComplete`, and sometimes a placeholder and icon:
2436
716
 
2437
- ```ts
2438
- const theme = {
2439
- tokens: {
2440
- fonts: {
2441
- body: defineToken(
2442
- "ui-sans-serif, system-ui, sans-serif",
2443
- ),
717
+ ```tsx
718
+ <Input kind="email" />
719
+ <Input kind="tel" />
720
+ <Input kind="url" />
721
+ <Input kind="search" />
722
+ <Input kind="numeric" />
723
+ <Input kind="password-current" /> // autoComplete="current-password" + show/hide toggle
724
+ <Input kind="password-new" /> // autoComplete="new-password" + show/hide toggle
725
+ ```
2444
726
 
2445
- heading: defineToken(
2446
- "ui-sans-serif, system-ui, sans-serif",
2447
- ),
727
+ To suppress the icon that comes with certain kinds:
2448
728
 
2449
- mono: defineToken(
2450
- "ui-monospace, SFMono-Regular, Menlo, monospace",
2451
- ),
2452
- },
2453
- },
2454
- };
729
+ ```tsx
730
+ <Input kind="email" hideKindIcon />
2455
731
  ```
2456
732
 
2457
- ---
2458
-
2459
- # Customising Typography
733
+ ### Validation States
2460
734
 
2461
- ## 10. Extending the Default Presets
735
+ ```tsx
736
+ <Input error />
737
+ <Input success />
738
+ ```
2462
739
 
2463
- You can add custom typography presets while retaining the defaults.
740
+ ### Disabled & Loading
2464
741
 
2465
742
  ```tsx
2466
- import {
2467
- UIProvider,
2468
- defaultTheme,
2469
- } from "@splenddev/kreativ-ui";
2470
-
2471
- const typography = {
2472
- ...defaultTheme.typography,
743
+ <Input disabled />
744
+ <Input isLoading /> // shows a spinner, makes the field read‑only
745
+ ```
2473
746
 
2474
- display: {
2475
- fontFamily: "{fonts.heading}",
2476
- fontSize: "4rem",
2477
- fontWeight: 700,
2478
- lineHeight: "1",
2479
- letterSpacing: "-0.04em",
2480
- },
747
+ ### Adornments (Icons)
2481
748
 
2482
- label: {
2483
- fontFamily: "{fonts.body}",
2484
- fontSize: "0.75rem",
2485
- fontWeight: 600,
2486
- lineHeight: "1.2",
2487
- },
2488
- };
749
+ ```tsx
750
+ <Input startIcon={<SearchIcon />} />
751
+ <Input endIcon={<MailIcon />} />
752
+ ```
2489
753
 
2490
- const theme = {
2491
- ...defaultTheme,
2492
- typography,
2493
- };
754
+ ### Clearable
2494
755
 
2495
- <UIProvider theme={theme}>
2496
- <App />
2497
- </UIProvider>;
756
+ ```tsx
757
+ <Input clearable onClear={() => console.log("cleared")} />
2498
758
  ```
2499
759
 
2500
- You can now use:
760
+ ### Controlled & Uncontrolled
2501
761
 
2502
762
  ```tsx
2503
- <Button typography="label">
2504
- Continue
2505
- </Button>
763
+ // Controlled
764
+ const [value, setValue] = useState("");
765
+ <Input value={value} onChange={(e) => setValue(e.target.value)} />
2506
766
 
2507
- <MyText typography="display">
2508
- Welcome
2509
- </MyText>
767
+ // Uncontrolled
768
+ <Input defaultValue="Initial value" />
2510
769
  ```
2511
770
 
2512
- ---
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 |
2513
791
 
2514
- # 11. Overriding an Existing Typography Preset
792
+ All standard `<input>` attributes (except `size`) are forwarded to the underlying `<input>`.
2515
793
 
2516
- You can also modify a built-in preset.
794
+ ---
795
+ ## 🧩 FormField
2517
796
 
2518
- ```ts
2519
- const typography = {
2520
- ...defaultTheme.typography,
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.
2521
798
 
2522
- body: {
2523
- ...defaultTheme.typography.body,
2524
- fontSize: "{fontSizes.lg}",
2525
- },
2526
- };
2527
- ```
799
+ `FormField` can be used with controls such as `Input`, but it is not limited to a specific control component.
2528
800
 
2529
- Every component using:
801
+ ### Basic Structure
2530
802
 
2531
803
  ```tsx
2532
- typography="body"
2533
- ```
804
+ import { FormField, Input } from "@splenddev/kreativ-ui";
805
+
806
+ <FormField>
807
+ <FormField.Label>Email address</FormField.Label>
2534
808
 
2535
- will now use the customized definition.
809
+ <FormField.Description>
810
+ We'll only send receipts here.
811
+ </FormField.Description>
2536
812
 
2537
- This is useful when you want to change the application's typography globally without modifying every component.
813
+ <FormField.Control>
814
+ <Input kind="email" placeholder="you@company.com" />
815
+ </FormField.Control>
816
+ </FormField>
817
+ ````
818
+ ### ⚠️ Important: Use `FormField.Control`
2538
819
 
2539
- ---
820
+ **`FormField.Control` should be used around the actual form control** when using `FormField`.
2540
821
 
2541
- # 12. Creating Typography with `defineTypography()`
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`.
2542
823
 
2543
- For design-system authors, Kreativ UI provides `defineTypography()`.
824
+ ```tsx
825
+ <FormField>
826
+ <FormField.Label>Email</FormField.Label>
2544
827
 
2545
- ```ts
2546
- import {
2547
- defineTypography,
2548
- } from "@splenddev/kreativ-ui";
828
+ <FormField.Control>
829
+ <Input kind="email" />
830
+ </FormField.Control>
831
+ </FormField>
832
+ ```
2549
833
 
2550
- const typography = {
2551
- display: defineTypography({
2552
- fontFamily: "{fonts.heading}",
2553
- fontSize: "{fontSizes.4xl}",
2554
- fontWeight: "{fontWeights.bold}",
2555
- lineHeight: "{lineHeights.tight}",
2556
- letterSpacing: "-0.04em",
2557
- }),
2558
- };
2559
- ```
834
+ > Avoid placing the control directly inside `FormField`:
2560
835
 
2561
- `defineTypography()` provides a consistent definition API and ensures the typography object conforms to the expected typography structure.
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.
2562
844
 
2563
- It is especially useful when creating reusable theme configurations.
2564
845
 
2565
846
  ---
2566
847
 
2567
- # 13. Defining Custom Tokens with `defineToken()`
848
+ The compound API consists of:
2568
849
 
2569
- Use `defineToken()` for primitive values.
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 |
2570
857
 
2571
- ```ts
2572
- import { defineToken } from "@splenddev/kreativ-ui";
858
+ ---
2573
859
 
2574
- const tokens = {
2575
- fonts: {
2576
- serif: defineToken("Georgia, serif"),
2577
- },
860
+ ### `FormField`
2578
861
 
2579
- fontSizes: {
2580
- "5xl": defineToken("3rem"),
2581
- },
862
+ The root `FormField` component owns the field's shared state and accessibility information.
2582
863
 
2583
- fontWeights: {
2584
- black: defineToken(900),
2585
- },
2586
- };
864
+ ```tsx
865
+ <FormField>
866
+ <FormField.Label>Username</FormField.Label>
867
+
868
+ <FormField.Control>
869
+ <Input />
870
+ </FormField.Control>
871
+ </FormField>
2587
872
  ```
2588
873
 
2589
- These tokens can then be referenced by typography:
874
+ If an `id` is not supplied, `FormField` generates a unique ID automatically.
2590
875
 
2591
- ```ts
2592
- const typography = {
2593
- serifDisplay: defineTypography({
2594
- fontFamily: "{fonts.serif}",
2595
- fontSize: "{fontSizes.5xl}",
2596
- fontWeight: "{fontWeights.black}",
2597
- lineHeight: "{lineHeights.tight}",
2598
- }),
2599
- };
2600
- ```
876
+ The generated field IDs are used to coordinate:
877
+
878
+ * the control ID
879
+ * label association
880
+ * description association
881
+ * validation message association
882
+ * `aria-describedby`
883
+ * `aria-invalid`
884
+ * `aria-required`
2601
885
 
2602
- Using `defineToken()` ensures the values follow the token structure expected by the theme engine.
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"`.
2603
898
 
2604
899
  ---
2605
900
 
2606
- # 14. Semantic Tokens
901
+ ## Validation Status
2607
902
 
2608
- Semantic tokens are useful when a value needs to change according to the active theme or color mode.
903
+ Validation state is controlled through the `status` prop.
2609
904
 
2610
- ```ts
2611
- const tokens = {
2612
- colors: {
2613
- brandText: defineSemanticToken(
2614
- "{colors.blue.700}",
2615
- "{colors.blue.200}",
2616
- ),
2617
- },
2618
- };
2619
- ```
905
+ ```tsx
906
+ <FormField status="error">
907
+ <FormField.Label>Email</FormField.Label>
2620
908
 
2621
- Typography itself generally does not need separate light and dark definitions.
909
+ <FormField.Control>
910
+ <Input kind="email" />
911
+ </FormField.Control>
912
+ </FormField>
913
+ ```
2622
914
 
2623
- Instead, semantic tokens are most useful when typography is combined with color or other semantic styling.
915
+ The `status` contributes to the field's invalid state.
2624
916
 
2625
917
  For example:
2626
918
 
2627
- ```ts
2628
- const semanticTokens = {
2629
- text: {
2630
- primary: defineSemanticToken(
2631
- "{colors.gray.900}",
2632
- "{colors.gray.100}",
2633
- ),
2634
- },
2635
- };
919
+ ```tsx
920
+ <FormField status="error" message="Please enter a valid email address">
921
+ ...
922
+ </FormField>
2636
923
  ```
2637
924
 
2638
- A component can then combine typography with the semantic text color.
925
+ The field becomes invalid because its status is `"error"`.
2639
926
 
2640
927
  ---
2641
928
 
2642
- # 15. Direct CSS Values
929
+ ## Validation Messages
2643
930
 
2644
- Typography values do not have to reference tokens.
931
+ `FormField` supports two ways of providing validation feedback:
2645
932
 
2646
- You can use literal CSS values:
933
+ 1. A controlled `message` supplied to the root `FormField`.
934
+ 2. A custom `<FormField.Message>` placed inside the field.
2647
935
 
2648
- ```ts
2649
- const typography = {
2650
- custom: defineTypography({
2651
- fontFamily: "Georgia, serif",
2652
- fontSize: "1.125rem",
2653
- fontWeight: 600,
2654
- lineHeight: 1.6,
2655
- letterSpacing: "-0.01em",
2656
- }),
2657
- };
936
+ ### Controlled Message
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>
2658
949
  ```
2659
950
 
2660
- This is useful for typography that is intentionally unique.
951
+ When no custom `FormField.Message` is present, the root automatically renders one.
2661
952
 
2662
- However, reusable design-system values should generally be represented as tokens.
953
+ This means consumers do not need to manually render:
2663
954
 
2664
- ---
955
+ ```tsx
956
+ <FormField.Message />
957
+ ```
958
+
959
+ for the common controlled-message case.
2665
960
 
2666
- # 16. Combining Typography with Component Overrides
961
+ ---
2667
962
 
2668
- Typography provides the baseline text styling, while consumers can still make one-off overrides.
963
+ ## Custom Messages
2669
964
 
2670
- For example:
965
+ A custom `FormField.Message` can also be placed inside the field.
2671
966
 
2672
967
  ```tsx
2673
- <Button
2674
- typography="body"
2675
- style={{
2676
- fontWeight: 700,
2677
- }}
2678
- >
2679
- Continue
2680
- </Button>
2681
- ```
968
+ <FormField status="error">
969
+ <FormField.Label>Email address</FormField.Label>
2682
970
 
2683
- The recommended precedence is:
971
+ <FormField.Control>
972
+ <Input kind="email" />
973
+ </FormField.Control>
2684
974
 
2685
- ```text
2686
- Component defaults
2687
- ↓
2688
- Component size/layout
2689
- ↓
2690
- Typography preset
2691
- ↓
2692
- Explicit style prop
975
+ <FormField.Message>
976
+ Please enter a valid email address.
977
+ </FormField.Message>
978
+ </FormField>
2693
979
  ```
2694
980
 
2695
- This means the `style` prop remains an escape hatch for application-specific cases.
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`.
2696
988
 
2697
- Avoid using it repeatedly for values that should actually become part of your theme.
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
+ ```
2698
994
 
2699
995
  ---
2700
996
 
2701
- # 17. Creating a Typography-Aware Custom Component
997
+ ## Native Control Validation
2702
998
 
2703
- A complete custom component might look like this:
999
+ `FormField` can also receive validity information reported by the connected control.
2704
1000
 
2705
- ```tsx
2706
- import {
2707
- TypographyProps,
2708
- useTypography,
2709
- } from "@splenddev/kreativ-ui";
1001
+ The field maintains an internal validity state and can receive a `ReportedValidity` result through its context.
2710
1002
 
2711
- interface CardTitleProps extends TypographyProps {
2712
- children: React.ReactNode;
2713
- }
1003
+ When the reported validity indicates an invalid control, the field can use the reported validation message.
2714
1004
 
2715
- function CardTitle({
2716
- typography = "headingSmall",
2717
- children,
2718
- }: CardTitleProps) {
2719
- const typographyStyles = useTypography(typography);
1005
+ Conceptually:
2720
1006
 
2721
- return (
2722
- <h3 style={typographyStyles}>
2723
- {children}
2724
- </h3>
2725
- );
2726
- }
1007
+ ```text
1008
+ Native/control validity
1009
+ ↓
1010
+ ReportedValidity
1011
+ ↓
1012
+ FormField
1013
+ ↓
1014
+ reported message
1015
+ ↓
1016
+ FormField.Message
2727
1017
  ```
2728
1018
 
2729
- Usage:
2730
-
2731
- ```tsx
2732
- <CardTitle>
2733
- Default title
2734
- </CardTitle>
1019
+ A parent-provided `message` takes precedence over a message reported by the control.
2735
1020
 
2736
- <CardTitle typography="heading">
2737
- Large title
2738
- </CardTitle>
1021
+ The effective message is resolved as:
2739
1022
 
2740
- <CardTitle typography="display">
2741
- Custom display title
2742
- </CardTitle>
1023
+ ```text
1024
+ message prop
1025
+ ↓
1026
+ reported validity message
1027
+ ↓
1028
+ no message
2743
1029
  ```
2744
1030
 
2745
- The component remains completely independent of the actual font values.
1031
+ In other words, an explicitly supplied `message` overrides the automatically reported validity message.
2746
1032
 
2747
1033
  ---
2748
1034
 
2749
- # 18. Using Typography Without a Preset Name
1035
+ ## Required Fields
2750
1036
 
2751
- If a component needs to use typography dynamically, it can simply pass the name received from its props:
1037
+ Set `required` on the root `FormField`:
2752
1038
 
2753
1039
  ```tsx
2754
- function MyComponent({
2755
- typography = "body",
2756
- }: TypographyProps) {
2757
- const styles = useTypography(typography);
1040
+ <FormField required>
1041
+ <FormField.Label>Email address</FormField.Label>
2758
1042
 
2759
- return (
2760
- <div style={styles}>
2761
- Content
2762
- </div>
2763
- );
2764
- }
1043
+ <FormField.Control>
1044
+ <Input kind="email" />
1045
+ </FormField.Control>
1046
+ </FormField>
2765
1047
  ```
2766
1048
 
2767
- The component does not need to maintain its own list of typography styles.
2768
-
2769
- This allows application-defined styles to work automatically.
1049
+ The required state is exposed through the field context so that the associated components can apply the appropriate accessibility behavior.
2770
1050
 
2771
1051
  ---
2772
1052
 
2773
- # Runtime Theme Changes
1053
+ ## Labels
2774
1054
 
2775
- Typography is resolved against the active theme.
1055
+ Use `FormField.Label` to provide the field's visible label.
2776
1056
 
2777
- For example, suppose the default theme contains:
1057
+ ```tsx
1058
+ <FormField>
1059
+ <FormField.Label>First name</FormField.Label>
2778
1060
 
2779
- ```ts
2780
- fonts: {
2781
- body: defineToken("Inter, sans-serif"),
2782
- }
1061
+ <FormField.Control>
1062
+ <Input placeholder="Felix" />
1063
+ </FormField.Control>
1064
+ </FormField>
2783
1065
  ```
2784
1066
 
2785
- and a custom theme changes it to:
1067
+ The label is associated with the generated or supplied field ID.
2786
1068
 
2787
- ```ts
2788
- fonts: {
2789
- body: defineToken("Poppins, sans-serif"),
2790
- }
2791
- ```
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.
2792
1070
 
2793
- A typography preset referencing:
1071
+ For accessibility, form controls should generally have an accessible name.
2794
1072
 
2795
- ```ts
2796
- fontFamily: "{fonts.body}"
2797
- ```
1073
+ ---
2798
1074
 
2799
- does not need to change.
1075
+ ## Description
2800
1076
 
2801
- It automatically resolves to the active token value.
1077
+ `FormField.Description` provides supporting information for the control.
2802
1078
 
2803
- ```text
2804
- Typography
2805
- ↓
2806
- {fonts.body}
2807
- ↓
2808
- Active theme
2809
- ↓
2810
- Poppins, sans-serif
2811
- ```
1079
+ ```tsx
1080
+ <FormField>
1081
+ <FormField.Label>Password</FormField.Label>
2812
1082
 
2813
- This is one of the primary benefits of the token-based architecture.
1083
+ <FormField.Description>
1084
+ Use at least 8 characters.
1085
+ </FormField.Description>
2814
1086
 
2815
- ---
1087
+ <FormField.Control>
1088
+ <Input type="password" />
1089
+ </FormField.Control>
1090
+ </FormField>
1091
+ ```
2816
1092
 
2817
- # Recommended Typography Structure
1093
+ The description receives an ID derived from the field ID and participates in the control's `aria-describedby` relationship.
2818
1094
 
2819
- For most applications, a semantic typography structure works well:
1095
+ ---
2820
1096
 
2821
- ```ts
2822
- const typography = {
2823
- body: {},
2824
- bodySmall: {},
1097
+ ## Control
2825
1098
 
2826
- heading: {},
2827
- headingSmall: {},
1099
+ `FormField.Control` connects the actual form control to the surrounding `FormField` context.
2828
1100
 
2829
- caption: {},
1101
+ ```tsx
1102
+ <FormField>
1103
+ <FormField.Label>Username</FormField.Label>
2830
1104
 
2831
- label: {},
1105
+ <FormField.Control>
1106
+ <Input />
1107
+ </FormField.Control>
1108
+ </FormField>
1109
+ ```
2832
1110
 
2833
- code: {},
1111
+ The control is responsible for receiving the field's relevant accessibility information, including the generated field ID and description relationships.
2834
1112
 
2835
- display: {},
2836
- };
2837
- ```
1113
+ This allows the root field to manage accessibility relationships without requiring consumers to manually coordinate IDs.
2838
1114
 
2839
- The exact names are completely customizable.
1115
+ ---
2840
1116
 
2841
- Avoid names such as:
1117
+ ## Accessibility Relationships
2842
1118
 
2843
- ```ts
2844
- small12
2845
- font14
2846
- large20
2847
- bold16
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
2848
1136
  ```
2849
1137
 
2850
- Prefer semantic names:
1138
+ When the field has a message or custom message, its message ID is included in the control's `aria-describedby`.
2851
1139
 
2852
- ```ts
2853
- bodySmall
2854
- body
2855
- heading
2856
- caption
2857
- label
2858
- display
2859
- ```
1140
+ When the field is invalid, the field context exposes the invalid state so the control can apply the appropriate `aria-invalid` behavior.
2860
1141
 
2861
- This makes the design system easier to maintain when the actual values change.
1142
+ When `required` is enabled, the required state is also exposed to the control.
2862
1143
 
2863
1144
  ---
2864
1145
 
2865
- # Best Practices
1146
+ ## Message Resolution
2866
1147
 
2867
- ### Prefer semantic typography names
1148
+ The root component resolves the displayed message using the following precedence:
2868
1149
 
2869
- Use:
2870
-
2871
- ```tsx
2872
- typography="heading"
1150
+ ```text
1151
+ FormField.message
1152
+ ↓
1153
+ reported validity message
1154
+ ↓
1155
+ undefined
2873
1156
  ```
2874
1157
 
2875
- instead of:
1158
+ Therefore, this:
2876
1159
 
2877
1160
  ```tsx
2878
- typography="font24"
1161
+ <FormField
1162
+ status="error"
1163
+ message="Email is required"
1164
+ >
2879
1165
  ```
2880
1166
 
2881
- ---
2882
-
2883
- ### Use tokens for reusable values
1167
+ takes precedence over a validation message reported by the connected control.
2884
1168
 
2885
- Prefer:
1169
+ A custom:
2886
1170
 
2887
- ```ts
2888
- fontSize: "{fontSizes.md}"
1171
+ ```tsx
1172
+ <FormField.Message>
1173
+ ...
1174
+ </FormField.Message>
2889
1175
  ```
2890
1176
 
2891
- over repeatedly writing:
2892
-
2893
- ```ts
2894
- fontSize: "0.875rem"
2895
- ```
1177
+ is handled separately as an explicit message component and prevents the root from rendering its automatic message component.
2896
1178
 
2897
1179
  ---
2898
1180
 
2899
- ### Let the application load fonts
1181
+ ## Complete Example
1182
+
1183
+ ```tsx
1184
+ import { useState } from "react";
1185
+ import { FormField, Input } from "@splenddev/kreativ-ui";
2900
1186
 
2901
- Kreativ UI should consume fonts rather than own the font-loading mechanism.
1187
+ function EmailField() {
1188
+ const [email, setEmail] = useState("");
1189
+ const [message, setMessage] = useState("");
2902
1190
 
2903
- This allows it to work with:
1191
+ function validateEmail(value: string) {
1192
+ if (!value) {
1193
+ setMessage("Email address is required.");
1194
+ return;
1195
+ }
2904
1196
 
2905
- * Next.js
2906
- * Vite
2907
- * Remix
2908
- * CRA
2909
- * plain React
2910
- * CSS
2911
- * local fonts
2912
- * external font providers
1197
+ if (!/\S+@\S+\.\S+/.test(value)) {
1198
+ setMessage("Please enter a valid email address.");
1199
+ return;
1200
+ }
2913
1201
 
2914
- ---
1202
+ setMessage("");
1203
+ }
2915
1204
 
2916
- ### Use `defineToken()`
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>
2917
1213
 
2918
- Prefer:
1214
+ <FormField.Description>
1215
+ We'll only send receipts to this address.
1216
+ </FormField.Description>
2919
1217
 
2920
- ```ts
2921
- fonts: {
2922
- body: defineToken("Inter, sans-serif"),
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
+ );
2923
1229
  }
2924
1230
  ```
2925
1231
 
2926
- over manually constructing:
1232
+ This example demonstrates the intended separation of responsibilities:
2927
1233
 
2928
- ```ts
2929
- fonts: {
2930
- body: {
2931
- value: "Inter, sans-serif",
2932
- },
2933
- }
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
2934
1252
  ```
2935
1253
 
2936
- ---
1254
+ ### Standalone Control vs FormField
2937
1255
 
2938
- ### Use `defineTypography()`
1256
+ Use a standalone component such as `Input` when the surrounding UI does not require the full field composition.
2939
1257
 
2940
- When creating reusable typography definitions:
1258
+ Use `FormField` when you need a coordinated:
2941
1259
 
2942
- ```ts
2943
- heading: defineTypography({
2944
- fontFamily: "{fonts.heading}",
2945
- fontSize: "{fontSizes.2xl}",
2946
- fontWeight: "{fontWeights.bold}",
2947
- lineHeight: "{lineHeights.tight}",
2948
- })
2949
- ```
1260
+ * label
1261
+ * description
1262
+ * validation state
1263
+ * validation message
1264
+ * required state
1265
+ * accessibility relationship
2950
1266
 
2951
- This gives the definition a clear and consistent API.
1267
+ The `FormField` system is designed to keep these concerns connected without requiring consumers to manually manage the generated IDs and ARIA relationships.
2952
1268
 
2953
1269
  ---
2954
1270
 
2955
- ### Use `useTypography()` in custom components
1271
+ ## 🧩 Select
2956
1272
 
2957
- Avoid manually accessing:
1273
+ A fully accessible, customizable select component with keyboard navigation, grouped options, and clearable selections.
2958
1274
 
2959
- ```ts
2960
- theme.typography
2961
- ```
1275
+ ### Basic Usage
2962
1276
 
2963
- inside every component.
1277
+ ```tsx
1278
+ import { Select } from "@splenddev/kreativ-ui";
2964
1279
 
2965
- Prefer:
1280
+ <Select placeholder="Select a country">
1281
+ <Select.Trigger>
1282
+ <Select.Value />
1283
+ </Select.Trigger>
2966
1284
 
2967
- ```ts
2968
- const styles = useTypography("body");
1285
+ <Select.Content>
1286
+ <Select.Item value="us">United States</Select.Item>
1287
+ <Select.Item value="ca">Canada</Select.Item>
1288
+ <Select.Item value="mx">Mexico</Select.Item>
1289
+ </Select.Content>
1290
+ </Select>
2969
1291
  ```
2970
1292
 
2971
- This keeps typography resolution centralized.
1293
+ ### Controlled Select
2972
1294
 
2973
- ---
1295
+ ```tsx
1296
+ import { useState } from "react";
2974
1297
 
2975
- ### Keep typography separate from layout
1298
+ function ControlledSelect() {
1299
+ const [value, setValue] = useState<string | undefined>("");
2976
1300
 
2977
- Typography should control:
1301
+ return (
1302
+ <Select value={value} onValueChange={setValue}>
1303
+ <Select.Trigger>
1304
+ <Select.Value placeholder="Choose a framework" />
1305
+ </Select.Trigger>
2978
1306
 
2979
- ```text
2980
- fontFamily
2981
- fontSize
2982
- fontWeight
2983
- lineHeight
2984
- letterSpacing
1307
+ <Select.Content>
1308
+ <Select.Item value="react">React</Select.Item>
1309
+ <Select.Item value="vue">Vue</Select.Item>
1310
+ <Select.Item value="svelte">Svelte</Select.Item>
1311
+ </Select.Content>
1312
+ </Select>
1313
+ );
1314
+ }
2985
1315
  ```
2986
1316
 
2987
- Component size should control:
1317
+ ### Uncontrolled Select
2988
1318
 
2989
- ```text
2990
- height
2991
- padding
2992
- gap
2993
- radius
2994
- iconSize
2995
- ```
1319
+ ```tsx
1320
+ <Select defaultValue="react">
1321
+ <Select.Trigger>
1322
+ <Select.Value placeholder="Choose a framework" />
1323
+ </Select.Trigger>
2996
1324
 
2997
- This makes components more predictable.
1325
+ <Select.Content>
1326
+ <Select.Item value="react">React</Select.Item>
1327
+ <Select.Item value="vue">Vue</Select.Item>
1328
+ <Select.Item value="angular">Angular</Select.Item>
1329
+ </Select.Content>
1330
+ </Select>
1331
+ ```
2998
1332
 
2999
- ---
1333
+ ### Props
3000
1334
 
3001
- # API Reference
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 |
3002
1351
 
3003
- ## `useTypography()`
1352
+ ### Compound Components
3004
1353
 
3005
- ```ts
3006
- useTypography(name?: string): React.CSSProperties
3007
- ```
1354
+ #### `Select.Trigger`
3008
1355
 
3009
- Resolves a typography preset from the active theme and returns React-compatible CSS properties.
1356
+ The interactive button that toggles the dropdown:
3010
1357
 
3011
- ### Parameters
1358
+ ```tsx
1359
+ <Select.Trigger>
1360
+ <Select.Value />
1361
+ </Select.Trigger>
1362
+ ```
3012
1363
 
3013
- | Parameter | Type | Description |
3014
- | --------- | -------- | ----------------------------- |
3015
- | `name` | `string` | Name of the typography preset |
1364
+ #### `Select.Value`
3016
1365
 
3017
- ### Example
1366
+ Renders the current selection or the placeholder:
3018
1367
 
3019
1368
  ```tsx
3020
- const styles = useTypography("heading");
3021
-
3022
- return <h1 style={styles}>Hello</h1>;
1369
+ <Select.Value placeholder="Choose an option" />
3023
1370
  ```
3024
1371
 
3025
- ---
1372
+ #### `Select.Content`
3026
1373
 
3027
- ## `TypographyProps`
1374
+ The dropdown container:
3028
1375
 
3029
- ```ts
3030
- interface TypographyProps {
3031
- typography?: string;
3032
- }
1376
+ ```tsx
1377
+ <Select.Content>{/* items */}</Select.Content>
3033
1378
  ```
3034
1379
 
3035
- Allows a component to expose the theme's typography presets through a `typography` prop.
1380
+ #### `Select.Item`
3036
1381
 
3037
- ---
3038
-
3039
- ## `TypographyStyle`
1382
+ A single selectable option:
3040
1383
 
3041
- ```ts
3042
- interface TypographyStyle {
3043
- fontFamily?: string;
3044
- fontSize?: string;
3045
- fontWeight?: string | number;
3046
- lineHeight?: string | number;
3047
- letterSpacing?: string;
3048
- }
1384
+ ```tsx
1385
+ <Select.Item value="react" disabled>
1386
+ React
1387
+ </Select.Item>
3049
1388
  ```
3050
1389
 
3051
- Defines the typography properties supported by Kreativ UI.
1390
+ #### `Select.Group`
3052
1391
 
3053
- ---
3054
-
3055
- ## `Typography`
1392
+ Groups related options:
3056
1393
 
3057
- ```ts
3058
- type Typography = Record<string, TypographyStyle>;
1394
+ ```tsx
1395
+ <Select.Group>
1396
+ <Select.Label>Frontend</Select.Label>
1397
+ <Select.Item value="react">React</Select.Item>
1398
+ <Select.Item value="vue">Vue</Select.Item>
1399
+ </Select.Group>
3059
1400
  ```
3060
1401
 
3061
- Represents the collection of named typography presets available in a theme.
3062
-
3063
- ---
1402
+ #### `Select.Label`
3064
1403
 
3065
- ## `defineTypography()`
1404
+ A heading for a group of options:
3066
1405
 
3067
- ```ts
3068
- defineTypography(
3069
- typography: TypographyStyle,
3070
- ): TypographyStyle
1406
+ ```tsx
1407
+ <Select.Label>Backend</Select.Label>
3071
1408
  ```
3072
1409
 
3073
- Defines and type-checks a typography preset.
1410
+ ### Clearable Select
3074
1411
 
3075
- Example:
1412
+ ```tsx
1413
+ <Select clearable defaultValue="react">
1414
+ <Select.Trigger>
1415
+ <Select.Value placeholder="Pick a framework" />
1416
+ </Select.Trigger>
3076
1417
 
3077
- ```ts
3078
- const heading = defineTypography({
3079
- fontFamily: "{fonts.heading}",
3080
- fontSize: "{fontSizes.2xl}",
3081
- fontWeight: "{fontWeights.bold}",
3082
- lineHeight: "{lineHeights.tight}",
3083
- });
1418
+ <Select.Content>
1419
+ <Select.Item value="react">React</Select.Item>
1420
+ <Select.Item value="vue">Vue</Select.Item>
1421
+ </Select.Content>
1422
+ </Select>
3084
1423
  ```
3085
1424
 
3086
- ---
1425
+ ### FormField Integration
3087
1426
 
3088
- ## `defineToken()`
1427
+ ```tsx
1428
+ <FormField required error="Please select a country">
1429
+ <FormField.Label>Country</FormField.Label>
1430
+ <FormField.Description>
1431
+ Select your country of residence.
1432
+ </FormField.Description>
3089
1433
 
3090
- ```ts
3091
- defineToken<T>(value: T): {
3092
- value: T;
3093
- }
1434
+ <Select>
1435
+ <Select.Trigger>
1436
+ <Select.Value placeholder="Select a country" />
1437
+ </Select.Trigger>
1438
+ <Select.Content>
1439
+ <Select.Item value="us">United States</Select.Item>
1440
+ <Select.Item value="ca">Canada</Select.Item>
1441
+ </Select.Content>
1442
+ </Select>
1443
+
1444
+ <FormField.Message />
1445
+ </FormField>
3094
1446
  ```
3095
1447
 
3096
- Creates a primitive design token.
1448
+ ---
3097
1449
 
3098
- Example:
1450
+ ## 📝 Typography System
3099
1451
 
3100
- ```ts
3101
- const bodyFont = defineToken(
3102
- "Inter, sans-serif",
3103
- );
3104
- ```
1452
+ Kreativ UI provides a centralized, theme-aware typography system for controlling how text is rendered across your application.
3105
1453
 
3106
- ---
1454
+ ### How It Works
3107
1455
 
3108
- ## `defineSemanticToken()`
1456
+ Typography is built around four layers:
3109
1457
 
3110
- ```ts
3111
- defineSemanticToken<T>(
3112
- light: T,
3113
- dark: T,
3114
- ): {
3115
- value: {
3116
- light: T;
3117
- dark: T;
3118
- };
3119
- }
1458
+ ```
1459
+ Primitive Tokens
1460
+ ↓
1461
+ Semantic Tokens
1462
+ ↓
1463
+ Typography Presets
1464
+ ↓
1465
+ useTypography()
1466
+ ↓
1467
+ React.CSSProperties
1468
+ ↓
1469
+ Component
3120
1470
  ```
3121
1471
 
3122
- Creates a theme-aware semantic token.
3123
-
3124
- ---
1472
+ ### Using `useTypography()`
3125
1473
 
3126
- ## `resolveTokenReference()`
1474
+ Use the hook when creating a custom component:
3127
1475
 
3128
- ```ts
3129
- resolveTokenReference(
3130
- value: unknown,
3131
- tokens: DesignTokens,
3132
- ): string | number
3133
- ```
1476
+ ```tsx
1477
+ import { useTypography } from "@splenddev/kreativ-ui";
3134
1478
 
3135
- Resolves a token reference such as:
1479
+ function MyCustomCard() {
1480
+ const headingStyles = useTypography("heading");
1481
+ const bodyStyles = useTypography("body");
3136
1482
 
3137
- ```ts
3138
- "{fonts.body}"
1483
+ return (
1484
+ <div>
1485
+ <h2 style={headingStyles}>Card Title</h2>
1486
+ <p style={bodyStyles}>This is the card content.</p>
1487
+ </div>
1488
+ );
1489
+ }
3139
1490
  ```
3140
1491
 
3141
- against the active design-token collection.
1492
+ ### Creating a Typography-Aware Custom Component
3142
1493
 
3143
- ---
1494
+ ```tsx
1495
+ import { TypographyProps, useTypography } from "@splenddev/kreativ-ui";
3144
1496
 
3145
- ## `resolveTypography()`
1497
+ interface MyTextProps extends TypographyProps {
1498
+ children: React.ReactNode;
1499
+ }
3146
1500
 
3147
- ```ts
3148
- resolveTypography(
3149
- typography: TypographyStyle | undefined,
3150
- tokens: DesignTokens,
3151
- ): React.CSSProperties
3152
- ```
1501
+ function MyText({ typography = "body", children }: MyTextProps) {
1502
+ const styles = useTypography(typography);
3153
1503
 
3154
- Converts a typography definition into resolved React CSS properties.
1504
+ return <p style={styles}>{children}</p>;
1505
+ }
1506
+ ```
3155
1507
 
3156
- ---
1508
+ ### Loading Fonts
3157
1509
 
3158
- # Complete Example
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.
3159
1511
 
3160
- The following example demonstrates a complete Next.js setup using `next/font`, Kreativ UI tokens, typography, and a custom component.
1512
+ #### Next.js `next/font` Example
3161
1513
 
3162
1514
  ```tsx
3163
1515
  import { Geist, Geist_Mono } from "next/font/google";
3164
-
3165
- import {
3166
- UIProvider,
3167
- defineToken,
3168
- defineTypography,
3169
- defaultTheme,
3170
- } from "@splenddev/kreativ-ui";
1516
+ import { UIProvider, defineToken } from "@splenddev/kreativ-ui";
3171
1517
 
3172
1518
  const geistSans = Geist({
3173
1519
  variable: "--font-geist-sans",
@@ -3179,111 +1525,89 @@ const geistMono = Geist_Mono({
3179
1525
  subsets: ["latin"],
3180
1526
  });
3181
1527
 
3182
- const theme = {
3183
- ...defaultTheme,
3184
-
1528
+ const theme = extendTheme({
3185
1529
  tokens: {
3186
- ...defaultTheme.tokens,
3187
-
3188
1530
  fonts: {
3189
- ...defaultTheme.tokens.fonts,
3190
-
3191
- body: defineToken(
3192
- "var(--font-geist-sans)",
3193
- ),
3194
-
3195
- heading: defineToken(
3196
- "var(--font-geist-sans)",
3197
- ),
3198
-
3199
- mono: defineToken(
3200
- "var(--font-geist-mono)",
3201
- ),
1531
+ body: defineToken("var(--font-geist-sans)"),
1532
+ heading: defineToken("var(--font-geist-sans)"),
1533
+ mono: defineToken("var(--font-geist-mono)"),
3202
1534
  },
3203
1535
  },
1536
+ });
3204
1537
 
3205
- typography: {
3206
- ...defaultTheme.typography,
3207
-
3208
- display: defineTypography({
3209
- fontFamily: "{fonts.heading}",
3210
- fontSize: "4rem",
3211
- fontWeight: "{fontWeights.bold}",
3212
- lineHeight: "1",
3213
- letterSpacing: "-0.04em",
3214
- }),
3215
- },
3216
- };
3217
-
3218
- export default function RootLayout({
3219
- children,
3220
- }: LayoutProps<"/">) {
1538
+ export default function RootLayout({ children }) {
3221
1539
  return (
3222
- <html
3223
- lang="en"
3224
- className={`${geistSans.variable} ${geistMono.variable}`}
3225
- >
1540
+ <html className={`${geistSans.variable} ${geistMono.variable}`}>
3226
1541
  <body>
3227
- <UIProvider theme={theme}>
3228
- {children}
3229
- </UIProvider>
1542
+ <UIProvider theme={theme}>{children}</UIProvider>
3230
1543
  </body>
3231
1544
  </html>
3232
1545
  );
3233
1546
  }
3234
1547
  ```
3235
1548
 
3236
- The important separation is:
1549
+ ### Best Practices
3237
1550
 
3238
- ```text
3239
- Next.js
3240
- │
3241
- └── Loads Geist
3242
- │
3243
- └── --font-geist-sans
3244
- │
3245
- ▼
3246
- Kreativ UI font token
3247
- │
3248
- └── fonts.body
3249
- │
3250
- ▼
3251
- Typography preset
3252
- │
3253
- └── typography.body
3254
- │
3255
- ▼
3256
- useTypography("body")
3257
- │
3258
- ▼
3259
- React.CSSProperties
3260
- ```
3261
-
3262
- 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.
3263
-
3264
- # ♿ Accessibility
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
1555
+
1556
+ ---
1557
+
1558
+ ## ♿ Accessibility
3265
1559
 
3266
1560
  Kreativ UI components are built with accessibility in mind:
3267
1561
 
3268
- - All interactive elements support keyboard navigation.
3269
- - Focus management and visible focus indicators.
3270
- - ARIA attributes are applied automatically where needed (e.g., `aria-label`, `aria-describedby`, `aria-invalid`).
3271
- - Colour contrast respects system‑level settings.
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`
1569
+
1570
+ ---
1571
+
1572
+ ## 📦 Browser Support
1573
+
1574
+ Kreativ UI works in all modern browsers (Chrome, Firefox, Safari, Edge). Requires React 18 or later.
1575
+
1576
+ ---
1577
+
1578
+ ## 🔧 TypeScript
1579
+
1580
+ Kreativ UI is TypeScript‑first, with typed theme configuration, component props, and extension APIs.
1581
+
1582
+ All theme helpers (`defineToken`, `extendTheme`, `defineSize`, etc.) are fully typed for a safe and predictable customization experience.
1583
+
1584
+ ---
1585
+
1586
+ ## 🎯 API Design Philosophy
1587
+
1588
+ Kreativ UI is designed around several key principles:
1589
+
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
3272
1595
 
3273
1596
  ---
3274
1597
 
3275
- # 📦 Browser Support
1598
+ ## 🚧 Future Direction
1599
+
1600
+ > **Note:** The following describes future work that is not yet available in the current release.
3276
1601
 
3277
- Kreativ UI works in all modern browsers (Chrome, Firefox, Safari, Edge).
3278
- 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.
3279
1603
 
3280
1604
  ---
3281
1605
 
3282
- # 📄 License
1606
+ ## 📄 License
3283
1607
 
3284
1608
  MIT
3285
1609
 
3286
1610
  ---
3287
1611
 
3288
- **More component documentation (Textarea, Checkbox, RadioGroup, etc.) coming soon.**
3289
- 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.