@splenddev/kreativ-ui 0.2.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +143 -1511
- package/dist/index.cjs +2450 -1255
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +328 -908
- package/dist/index.d.ts +328 -908
- package/dist/index.js +2306 -1149
- package/dist/index.js.map +1 -1
- package/dist/styles/index.css +2 -2
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,1613 +1,245 @@
|
|
|
1
1
|
# Kreativ UI
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A composable, themeable React component library built on [Kreativ Core](https://github.com/Vincentvirtuoso/kreativ-core).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Kreativ UI is the component layer of the Kreativ design system: layouts, forms, data displays, overlays, and interaction patterns, all written in TypeScript and all drawing from the same tokens, sizes, and recipes. Use it as a ready-made library, or as the starting point for your own design language.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
> **Status:** actively evolving. The API may change while we finish extracting the design-system layer into Core. For production apps, pin your versions and read the release notes before upgrading.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
- Built-in `ThemeToggler` with optional animated transitions
|
|
11
|
-
- CSS‑variable‑driven design tokens
|
|
12
|
-
- Primitive + semantic token architecture
|
|
13
|
-
- Component‑level theme overrides
|
|
14
|
-
- Fully accessible (ARIA, keyboard navigation, focus management)
|
|
15
|
-
- TypeScript‑first and tree‑shakable
|
|
16
|
-
- Theme extension APIs for composable customization
|
|
9
|
+
## Why Kreativ UI?
|
|
17
10
|
|
|
18
|
-
|
|
11
|
+
The design system should be the foundation, not an afterthought. Every component shares the same tokens, semantic colors, typography, size scales, recipes, and interaction conventions, so things look and behave consistently, and re-theming doesn't mean touching components.
|
|
19
12
|
|
|
20
|
-
|
|
13
|
+
- **Themeable:** customize tokens, semantic colors, typography, sizes, and recipes
|
|
14
|
+
- **Light and dark mode:** including system preference
|
|
15
|
+
- **Composable:** compound components and flexible composition patterns
|
|
16
|
+
- **Responsive:** breakpoints come from the theme
|
|
17
|
+
- **Accessible:** semantic HTML, keyboard support, focus management
|
|
18
|
+
- **TypeScript-first:** strongly typed component APIs
|
|
19
|
+
- **Toolable:** component metadata lets tools like the CLI and Playground understand your components
|
|
20
|
+
|
|
21
|
+
## Install
|
|
21
22
|
|
|
22
23
|
```bash
|
|
23
24
|
npm install @splenddev/kreativ-ui
|
|
24
25
|
```
|
|
25
26
|
|
|
26
|
-
Import the
|
|
27
|
-
|
|
28
|
-
```tsx
|
|
29
|
-
import "@splenddev/kreativ-ui/styles.css";
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
## 🚀 Quick Start
|
|
35
|
-
|
|
36
|
-
Wrap your app with `UIProvider` and use the `Button` component:
|
|
27
|
+
Import the styles and wrap your app with `KreativUIProvider`:
|
|
37
28
|
|
|
38
29
|
```tsx
|
|
39
|
-
import { UIProvider, Button } from "@splenddev/kreativ-ui";
|
|
40
30
|
import "@splenddev/kreativ-ui/styles.css";
|
|
31
|
+
import { KreativUIProvider } from "@splenddev/kreativ-ui";
|
|
41
32
|
|
|
42
|
-
export
|
|
33
|
+
export function App() {
|
|
43
34
|
return (
|
|
44
|
-
<
|
|
45
|
-
|
|
46
|
-
</
|
|
35
|
+
<KreativUIProvider>
|
|
36
|
+
{/* your application */}
|
|
37
|
+
</KreativUIProvider>
|
|
47
38
|
);
|
|
48
39
|
}
|
|
49
40
|
```
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
## Core Concepts
|
|
54
|
-
|
|
55
|
-
Kreativ UI is more than a collection of components — it's a design-system foundation built around a layered theme architecture.
|
|
56
|
-
|
|
57
|
-
### Runtime Theming
|
|
58
|
-
|
|
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.
|
|
60
|
-
|
|
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
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Each layer can be customized independently, making it easy to extend or override specific aspects of the design system.
|
|
76
|
-
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
## Theme System
|
|
80
|
-
|
|
81
|
-
### Primitive Tokens
|
|
82
|
-
|
|
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
|
-
};
|
|
115
|
-
```
|
|
116
|
-
|
|
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.
|
|
152
|
-
|
|
153
|
-
### Recipes
|
|
154
|
-
|
|
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.
|
|
156
|
-
|
|
157
|
-
---
|
|
158
|
-
|
|
159
|
-
## Theme API
|
|
160
|
-
|
|
161
|
-
Kreativ UI provides a set of theme extension helpers for composing custom themes without manually manipulating the internal theme structure.
|
|
162
|
-
|
|
163
|
-
### `extendTheme`
|
|
164
|
-
|
|
165
|
-
The recommended way to create a custom theme configuration:
|
|
166
|
-
|
|
167
|
-
```tsx
|
|
168
|
-
import { extendTheme, UIProvider } from "@splenddev/kreativ-ui";
|
|
169
|
-
|
|
170
|
-
const theme = extendTheme({
|
|
171
|
-
tokens: {
|
|
172
|
-
// custom primitive tokens
|
|
173
|
-
},
|
|
174
|
-
semanticTokens: {
|
|
175
|
-
// custom semantic tokens
|
|
176
|
-
},
|
|
177
|
-
typography: {
|
|
178
|
-
// custom typography presets
|
|
179
|
-
},
|
|
180
|
-
sizes: {
|
|
181
|
-
// custom sizes
|
|
182
|
-
},
|
|
183
|
-
recipes: {
|
|
184
|
-
// custom component recipes
|
|
185
|
-
},
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
<UIProvider theme={theme}>
|
|
189
|
-
<App />
|
|
190
|
-
</UIProvider>
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### Tokens
|
|
194
|
-
|
|
195
|
-
#### `defineToken`
|
|
196
|
-
|
|
197
|
-
Creates a single primitive token definition:
|
|
198
|
-
|
|
199
|
-
```ts
|
|
200
|
-
import { defineToken } from "@splenddev/kreativ-ui";
|
|
201
|
-
|
|
202
|
-
const bodyFont = defineToken("Inter, sans-serif");
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
#### `defineTokens`
|
|
206
|
-
|
|
207
|
-
Creates a collection of token definitions:
|
|
208
|
-
|
|
209
|
-
```ts
|
|
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
|
-
});
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
#### `extendTokens`
|
|
220
|
-
|
|
221
|
-
Extends existing token definitions:
|
|
222
|
-
|
|
223
|
-
```ts
|
|
224
|
-
import { extendTokens } from "@splenddev/kreativ-ui";
|
|
225
|
-
|
|
226
|
-
const customFonts = extendTokens({
|
|
227
|
-
display: "Georgia, serif",
|
|
228
|
-
});
|
|
229
|
-
```
|
|
230
|
-
|
|
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}",
|
|
245
|
-
},
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
```
|
|
249
|
-
|
|
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:
|
|
42
|
+
## Quick start
|
|
407
43
|
|
|
408
44
|
```tsx
|
|
409
|
-
import {
|
|
410
|
-
|
|
411
|
-
function ThemeSwitcher() {
|
|
412
|
-
const { mode, setMode } = useTheme();
|
|
45
|
+
import { Button, Card, Input, Stack, KreativUIProvider } from "@splenddev/kreativ-ui";
|
|
413
46
|
|
|
47
|
+
export default function App() {
|
|
414
48
|
return (
|
|
415
|
-
|
|
416
|
-
<
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
49
|
+
<KreativUIProvider>
|
|
50
|
+
<Card>
|
|
51
|
+
<Stack gap="md">
|
|
52
|
+
<Input placeholder="Your name" />
|
|
53
|
+
<Button>Continue</Button>
|
|
54
|
+
</Stack>
|
|
55
|
+
</Card>
|
|
56
|
+
</KreativUIProvider>
|
|
420
57
|
);
|
|
421
58
|
}
|
|
422
59
|
```
|
|
423
60
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
## 🌗 ThemeToggler
|
|
427
|
-
|
|
428
|
-
A ready‑to‑use theme switcher that integrates with `UIProvider`.
|
|
429
|
-
|
|
430
|
-
### Basic Usage
|
|
431
|
-
|
|
432
|
-
```tsx
|
|
433
|
-
import { ThemeToggler } from "@splenddev/kreativ-ui";
|
|
434
|
-
|
|
435
|
-
<ThemeToggler />
|
|
436
|
-
```
|
|
437
|
-
|
|
438
|
-
### With System Mode
|
|
61
|
+
## Components
|
|
439
62
|
|
|
440
|
-
|
|
441
|
-
<ThemeToggler allowSystem />
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
### Icon Only
|
|
445
|
-
|
|
446
|
-
```tsx
|
|
447
|
-
<ThemeToggler iconOnly allowSystem />
|
|
448
|
-
```
|
|
63
|
+
**Layout:** `Container`, `Stack`, `Flex`, `Grid`, `Center`, `AspectRatio`, `Separator`, `ScrollArea`, `Resizable`, `Masonry`, `Background`, `BackgroundOverlay`, `Card`
|
|
449
64
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
```tsx
|
|
453
|
-
<ThemeToggler variant="outline" activeVariant="solid" />
|
|
454
|
-
```
|
|
65
|
+
**Forms:** `Input`, `Textarea`, `Select`, `Checkbox`, `Switch`, `Radio`, `RadioGroup`, `Slider`, `Combobox`, `Form`, `FormField`, `NumberStepper`, `DatePicker`, `TimePicker`, `DateTimePicker`, `FileUpload`, `PinInput`. Form controls share the same state conventions, and the form infrastructure is built to work with schema-driven validation.
|
|
455
66
|
|
|
456
|
-
|
|
67
|
+
**Data display:** `DataTable`, `List`, `DescriptionList`, `Tree`, `Timeline`, `Stat`, `Badge`, `Tag`, `Avatar`, `Kbd`
|
|
457
68
|
|
|
458
|
-
|
|
459
|
-
<ThemeToggler orientation="vertical" allowSystem />
|
|
460
|
-
```
|
|
69
|
+
**Overlays:** `Tooltip`, `Popover`, `Dialog`, `DropdownMenu`, `ContextMenu`, `HoverCard`, `Sheet`. They're built around explicit composition and predictable state ownership.
|
|
461
70
|
|
|
462
|
-
|
|
71
|
+
## Patterns
|
|
463
72
|
|
|
464
|
-
|
|
465
|
-
import { SunMedium, MoonStar, LaptopMinimal } from "lucide-react";
|
|
466
|
-
|
|
467
|
-
<ThemeToggler
|
|
468
|
-
allowSystem
|
|
469
|
-
labels={{ light: "Day", dark: "Night", system: "Auto" }}
|
|
470
|
-
icons={{
|
|
471
|
-
light: <SunMedium size={18} />,
|
|
472
|
-
dark: <MoonStar size={18} />,
|
|
473
|
-
system: <LaptopMinimal size={18} />,
|
|
474
|
-
}}
|
|
475
|
-
/>
|
|
476
|
-
```
|
|
73
|
+
### Compound components
|
|
477
74
|
|
|
478
|
-
|
|
75
|
+
Complex components are split into parts, so relationships are explicit and each piece stays composable:
|
|
479
76
|
|
|
480
77
|
```tsx
|
|
481
|
-
<
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
78
|
+
<Card>
|
|
79
|
+
<Card.Header>
|
|
80
|
+
<Card.Title>Account</Card.Title>
|
|
81
|
+
</Card.Header>
|
|
82
|
+
<Card.Content>...</Card.Content>
|
|
83
|
+
<Card.Footer>
|
|
84
|
+
<Button>Save</Button>
|
|
85
|
+
</Card.Footer>
|
|
86
|
+
</Card>
|
|
486
87
|
```
|
|
487
88
|
|
|
488
|
-
|
|
489
|
-
|
|
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 |
|
|
508
|
-
|
|
509
|
-
---
|
|
89
|
+
### Controlled and uncontrolled
|
|
510
90
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
A versatile, theme-aware button component with support for variants, sizes, typography, loading states, icons, full-width layouts, and custom rendering.
|
|
514
|
-
|
|
515
|
-
### Basic Usage
|
|
91
|
+
Interactive components support both modes where it makes sense:
|
|
516
92
|
|
|
517
93
|
```tsx
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
<Button>Click me</Button>
|
|
94
|
+
<Tooltip defaultOpen>...</Tooltip> {/* uncontrolled */}
|
|
95
|
+
<Tooltip open={open} onOpenChange={setOpen}>...</Tooltip> {/* controlled */}
|
|
521
96
|
```
|
|
522
97
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
- `variant="solid"`
|
|
526
|
-
- `color="brand"`
|
|
527
|
-
- `size="md"`
|
|
528
|
-
- `typography="body"`
|
|
529
|
-
- `fullWidth={false}`
|
|
530
|
-
- `isLoading={false}`
|
|
531
|
-
- `disabled={false}`
|
|
532
|
-
|
|
533
|
-
### Variants
|
|
534
|
-
|
|
535
|
-
```tsx
|
|
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
|
-
```
|
|
98
|
+
### `asChild`
|
|
542
99
|
|
|
543
|
-
|
|
100
|
+
Components that support `asChild` apply their behavior to your element instead of adding a wrapper:
|
|
544
101
|
|
|
545
102
|
```tsx
|
|
546
|
-
<
|
|
547
|
-
<Button
|
|
548
|
-
|
|
103
|
+
<Tooltip.Trigger asChild>
|
|
104
|
+
<Button>Save</Button>
|
|
105
|
+
</Tooltip.Trigger>
|
|
549
106
|
```
|
|
550
107
|
|
|
551
|
-
|
|
108
|
+
The child stays the rendered element and receives the generated props and behavior.
|
|
552
109
|
|
|
553
|
-
|
|
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
|
-
```
|
|
110
|
+
### Component defaults
|
|
559
111
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
Button typography is controlled independently from its size:
|
|
112
|
+
Set default props for any component once, from the provider:
|
|
563
113
|
|
|
564
114
|
```tsx
|
|
565
|
-
<
|
|
566
|
-
<
|
|
567
|
-
|
|
115
|
+
<KreativUIProvider defaults={{ button: { size: "sm" } }}>
|
|
116
|
+
<App />
|
|
117
|
+
</KreativUIProvider>
|
|
568
118
|
```
|
|
569
119
|
|
|
570
|
-
|
|
120
|
+
Defaults are typed per component. Props you pass directly always win:
|
|
571
121
|
|
|
572
|
-
```tsx
|
|
573
|
-
<Button size="lg" typography="bodySmall">
|
|
574
|
-
Large Button, Small Typography
|
|
575
|
-
</Button>
|
|
576
122
|
```
|
|
577
|
-
|
|
578
|
-
### Loading State
|
|
579
|
-
|
|
580
|
-
```tsx
|
|
581
|
-
<Button isLoading>Saving...</Button>
|
|
123
|
+
provider defaults → component defaults → generated props → your props
|
|
582
124
|
```
|
|
583
125
|
|
|
584
|
-
|
|
585
|
-
- A loading indicator is displayed
|
|
586
|
-
- The Button becomes disabled
|
|
587
|
-
- The Button receives `aria-busy="true"`
|
|
588
|
-
- Normal icon rendering is suppressed
|
|
126
|
+
## Theming
|
|
589
127
|
|
|
590
|
-
|
|
128
|
+
Everything flows through one layered theme: primitive tokens → semantic tokens → typography → sizes → recipes → components. The default theme ships with Kreativ UI, and you can customize it without rebuilding anything.
|
|
591
129
|
|
|
592
130
|
```tsx
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
<Button leftIcon={<DownloadIcon />} rightIcon={<ArrowRightIcon />}>
|
|
596
|
-
Download
|
|
597
|
-
</Button>
|
|
598
|
-
```
|
|
131
|
+
import { KreativUIProvider } from "@splenddev/kreativ-ui";
|
|
132
|
+
import { defineSemanticToken } from "@splenddev/kreativ-core";
|
|
599
133
|
|
|
600
|
-
|
|
134
|
+
const theme = {
|
|
135
|
+
tokens: {
|
|
136
|
+
colors: { brand: { 500: "#7c3aed" } },
|
|
137
|
+
},
|
|
138
|
+
semanticTokens: {
|
|
139
|
+
colors: { brand: defineSemanticToken("{colors.brand.500}") },
|
|
140
|
+
},
|
|
141
|
+
};
|
|
601
142
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
143
|
+
export function App() {
|
|
144
|
+
return (
|
|
145
|
+
<KreativUIProvider theme={theme}>
|
|
146
|
+
...
|
|
147
|
+
</KreativUIProvider>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
606
150
|
```
|
|
607
151
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
### Full Width
|
|
611
|
-
|
|
612
|
-
```tsx
|
|
613
|
-
<Button fullWidth>Continue</Button>
|
|
614
|
-
```
|
|
152
|
+
You can customize tokens, semantic tokens, typography, recipes, size scales, intensity, and metadata. The theme API itself lives in Kreativ Core, so see its docs for the details.
|
|
615
153
|
|
|
616
|
-
###
|
|
154
|
+
### Color modes
|
|
617
155
|
|
|
618
156
|
```tsx
|
|
619
|
-
<
|
|
157
|
+
<KreativUIProvider defaultMode="light" />
|
|
158
|
+
<KreativUIProvider defaultMode="dark" />
|
|
159
|
+
<KreativUIProvider defaultMode="system" /> {/* follows prefers-color-scheme */}
|
|
620
160
|
```
|
|
621
161
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
The `render` prop provides an advanced escape hatch for rendering the Button's resolved styles and content using another element or component:
|
|
625
|
-
|
|
626
|
-
```tsx
|
|
627
|
-
<Button
|
|
628
|
-
render={(props) => (
|
|
629
|
-
<a {...props} href="/templates">
|
|
630
|
-
Templates
|
|
631
|
-
</a>
|
|
632
|
-
)}
|
|
633
|
-
>
|
|
634
|
-
Templates
|
|
635
|
-
</Button>
|
|
636
|
-
```
|
|
162
|
+
Components use semantic tokens instead of hard-coded light and dark values, so one implementation works in every theme.
|
|
637
163
|
|
|
638
|
-
The
|
|
164
|
+
### The default design language
|
|
639
165
|
|
|
640
|
-
**
|
|
166
|
+
- **Colors:** a structured scale with semantic roles: `brand`, `background`, `surface`, `border`, `text`, `muted text`, `destructive`, `success`, `warning`, `info`
|
|
167
|
+
- **Typography:** semantic presets for common interface roles
|
|
168
|
+
- **Sizes:** a shared `xs`, `sm`, `md`, `lg`, `xl` scale covering height, width, padding, font size, gap, icon size, and radius
|
|
169
|
+
- **Motion:** reusable animation tokens for common transitions and states
|
|
170
|
+
- **Intensity:** a theme value that the runtime and component styles can read
|
|
641
171
|
|
|
642
|
-
|
|
643
|
-
"use client";
|
|
172
|
+
### Recipes
|
|
644
173
|
|
|
645
|
-
|
|
174
|
+
Components are styled with recipes: base styles, variants, default variants, and compound variants. Styling stays declarative and theme-aware.
|
|
646
175
|
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
</a>
|
|
654
|
-
)}
|
|
655
|
-
>
|
|
656
|
-
Templates
|
|
657
|
-
</Button>
|
|
658
|
-
);
|
|
659
|
-
}
|
|
176
|
+
```ts
|
|
177
|
+
const recipe = defineRecipe({
|
|
178
|
+
base: "...",
|
|
179
|
+
variants: { variant: { solid: "...", outline: "...", ghost: "..." } },
|
|
180
|
+
defaultVariants: { variant: "solid" },
|
|
181
|
+
});
|
|
660
182
|
```
|
|
661
183
|
|
|
662
|
-
|
|
663
|
-
|
|
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 |
|
|
680
|
-
|
|
681
|
-
All standard HTML `<button>` attributes and event handlers are also supported.
|
|
682
|
-
|
|
683
|
-
---
|
|
684
|
-
|
|
685
|
-
## 🧩 Input
|
|
686
|
-
|
|
687
|
-
A flexible text input with support for variants, sizes, validation states, adornments, password visibility, clearing, and loading states.
|
|
688
|
-
|
|
689
|
-
### Basic Usage
|
|
690
|
-
|
|
691
|
-
```tsx
|
|
692
|
-
import { Input } from "@splenddev/kreativ-ui";
|
|
184
|
+
Recipes are powered by Kreativ Core.
|
|
693
185
|
|
|
694
|
-
|
|
695
|
-
```
|
|
186
|
+
### Responsive design
|
|
696
187
|
|
|
697
|
-
|
|
188
|
+
Breakpoints come from the active theme, and the runtime generates the responsive rules. Components never hard-code breakpoint values.
|
|
698
189
|
|
|
699
|
-
|
|
700
|
-
<Input variant="outline" />
|
|
701
|
-
<Input variant="filled" />
|
|
702
|
-
<Input variant="ghost" />
|
|
703
|
-
```
|
|
190
|
+
## Component metadata
|
|
704
191
|
|
|
705
|
-
|
|
192
|
+
Components can describe themselves through `__kui`: their role, compound group, form-control behavior, supported states, and skeleton behavior.
|
|
706
193
|
|
|
707
|
-
```
|
|
708
|
-
|
|
709
|
-
<Input inputSize="md" />
|
|
710
|
-
<Input inputSize="lg" />
|
|
194
|
+
```ts
|
|
195
|
+
{ __kui: { role: "overlay", groupSlot: "Tooltip" } }
|
|
711
196
|
```
|
|
712
197
|
|
|
713
|
-
|
|
198
|
+
This gives tools a machine-readable layer to build on: the Kreativ CLI, Playground, and Forge, plus component inspection, composition tooling, and code generation.
|
|
714
199
|
|
|
715
|
-
|
|
200
|
+
Skeleton behavior is declared the same way, with hints of `"text"`, `"rect"`, `"circle"`, `"input-shaped"`, or `"preserve"`.
|
|
716
201
|
|
|
717
|
-
|
|
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
|
-
```
|
|
202
|
+
## Accessibility
|
|
726
203
|
|
|
727
|
-
|
|
204
|
+
Components aim for accessible defaults: semantic HTML, keyboard interaction, focus management, appropriate ARIA, accessible states, and predictable overlay positioning and dismissal. Behavior varies by component, so check each component's docs for specifics.
|
|
728
205
|
|
|
729
|
-
|
|
730
|
-
<Input kind="email" hideKindIcon />
|
|
731
|
-
```
|
|
206
|
+
## Kreativ Core
|
|
732
207
|
|
|
733
|
-
|
|
208
|
+
Kreativ UI is built on Core, and the split is simple: **Core defines how the design system works, and Kreativ UI defines what the default one looks and feels like.** Tokens, themes, recipes, validation, CSS variables, and component metadata live in Core. The components, default theme, and the React-specific behavior live here.
|
|
734
209
|
|
|
735
|
-
|
|
736
|
-
<Input error />
|
|
737
|
-
<Input success />
|
|
738
|
-
```
|
|
210
|
+
`KreativUIProvider` is a thin wrapper around Core's `ThemeProvider`. It adds the default theme, the overlay root for popovers, dialogs, and toasts, and typed per-component defaults.
|
|
739
211
|
|
|
740
|
-
|
|
212
|
+
## The Kreativ ecosystem
|
|
741
213
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
214
|
+
- **Kreativ Core:** the design-system foundation
|
|
215
|
+
- **Kreativ UI:** the React component library
|
|
216
|
+
- **Kreativ CLI:** developer tooling for the ecosystem
|
|
217
|
+
- **Kreativ Playground:** a visual environment for exploring and composing Kreativ UI
|
|
218
|
+
- **Kreativ Forge:** turns Kreativ UI compositions into polished visual content
|
|
746
219
|
|
|
747
|
-
|
|
220
|
+
## Development
|
|
748
221
|
|
|
749
|
-
```
|
|
750
|
-
|
|
751
|
-
|
|
222
|
+
```bash
|
|
223
|
+
git clone https://github.com/Vincentvirtuoso/kreativ-ui.git
|
|
224
|
+
cd kreativ-ui
|
|
225
|
+
npm install
|
|
226
|
+
npm run dev # development environment
|
|
227
|
+
npm run build # build the package
|
|
752
228
|
```
|
|
753
229
|
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
```tsx
|
|
757
|
-
<Input clearable onClear={() => console.log("cleared")} />
|
|
758
|
-
```
|
|
759
|
-
|
|
760
|
-
### Controlled & Uncontrolled
|
|
761
|
-
|
|
762
|
-
```tsx
|
|
763
|
-
// Controlled
|
|
764
|
-
const [value, setValue] = useState("");
|
|
765
|
-
<Input value={value} onChange={(e) => setValue(e.target.value)} />
|
|
766
|
-
|
|
767
|
-
// Uncontrolled
|
|
768
|
-
<Input defaultValue="Initial value" />
|
|
769
|
-
```
|
|
770
|
-
|
|
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 |
|
|
791
|
-
|
|
792
|
-
All standard `<input>` attributes (except `size`) are forwarded to the underlying `<input>`.
|
|
793
|
-
|
|
794
|
-
---
|
|
795
|
-
## 🧩 FormField
|
|
796
|
-
|
|
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.
|
|
798
|
-
|
|
799
|
-
`FormField` can be used with controls such as `Input`, but it is not limited to a specific control component.
|
|
800
|
-
|
|
801
|
-
### Basic Structure
|
|
802
|
-
|
|
803
|
-
```tsx
|
|
804
|
-
import { FormField, Input } from "@splenddev/kreativ-ui";
|
|
805
|
-
|
|
806
|
-
<FormField>
|
|
807
|
-
<FormField.Label>Email address</FormField.Label>
|
|
808
|
-
|
|
809
|
-
<FormField.Description>
|
|
810
|
-
We'll only send receipts here.
|
|
811
|
-
</FormField.Description>
|
|
812
|
-
|
|
813
|
-
<FormField.Control>
|
|
814
|
-
<Input kind="email" placeholder="you@company.com" />
|
|
815
|
-
</FormField.Control>
|
|
816
|
-
</FormField>
|
|
817
|
-
````
|
|
818
|
-
### ⚠️ Important: Use `FormField.Control`
|
|
819
|
-
|
|
820
|
-
**`FormField.Control` should be used around the actual form control** when using `FormField`.
|
|
821
|
-
|
|
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`.
|
|
823
|
-
|
|
824
|
-
```tsx
|
|
825
|
-
<FormField>
|
|
826
|
-
<FormField.Label>Email</FormField.Label>
|
|
827
|
-
|
|
828
|
-
<FormField.Control>
|
|
829
|
-
<Input kind="email" />
|
|
830
|
-
</FormField.Control>
|
|
831
|
-
</FormField>
|
|
832
|
-
```
|
|
833
|
-
|
|
834
|
-
> Avoid placing the control directly inside `FormField`:
|
|
835
|
-
|
|
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.
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
---
|
|
847
|
-
|
|
848
|
-
The compound API consists of:
|
|
849
|
-
|
|
850
|
-
| Component | Purpose |
|
|
851
|
-
| -- | -- |
|
|
852
|
-
| `FormField` | Provides field context, IDs, validation state, and accessibility relationships |
|
|
853
|
-
| `FormField.Label` | Associates a visible label with the field |
|
|
854
|
-
| `FormField.Description` | Provides supporting or descriptive text |
|
|
855
|
-
| `FormField.Control` | Connects the actual form control to the field context |
|
|
856
|
-
| `FormField.Message` | Displays validation or custom feedback |
|
|
857
|
-
|
|
858
|
-
---
|
|
859
|
-
|
|
860
|
-
### `FormField`
|
|
861
|
-
|
|
862
|
-
The root `FormField` component owns the field's shared state and accessibility information.
|
|
863
|
-
|
|
864
|
-
```tsx
|
|
865
|
-
<FormField>
|
|
866
|
-
<FormField.Label>Username</FormField.Label>
|
|
867
|
-
|
|
868
|
-
<FormField.Control>
|
|
869
|
-
<Input />
|
|
870
|
-
</FormField.Control>
|
|
871
|
-
</FormField>
|
|
872
|
-
```
|
|
873
|
-
|
|
874
|
-
If an `id` is not supplied, `FormField` generates a unique ID automatically.
|
|
875
|
-
|
|
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`
|
|
885
|
-
|
|
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"`.
|
|
898
|
-
|
|
899
|
-
---
|
|
900
|
-
|
|
901
|
-
## Validation Status
|
|
902
|
-
|
|
903
|
-
Validation state is controlled through the `status` prop.
|
|
904
|
-
|
|
905
|
-
```tsx
|
|
906
|
-
<FormField status="error">
|
|
907
|
-
<FormField.Label>Email</FormField.Label>
|
|
908
|
-
|
|
909
|
-
<FormField.Control>
|
|
910
|
-
<Input kind="email" />
|
|
911
|
-
</FormField.Control>
|
|
912
|
-
</FormField>
|
|
913
|
-
```
|
|
914
|
-
|
|
915
|
-
The `status` contributes to the field's invalid state.
|
|
916
|
-
|
|
917
|
-
For example:
|
|
918
|
-
|
|
919
|
-
```tsx
|
|
920
|
-
<FormField status="error" message="Please enter a valid email address">
|
|
921
|
-
...
|
|
922
|
-
</FormField>
|
|
923
|
-
```
|
|
924
|
-
|
|
925
|
-
The field becomes invalid because its status is `"error"`.
|
|
926
|
-
|
|
927
|
-
---
|
|
928
|
-
|
|
929
|
-
## Validation Messages
|
|
930
|
-
|
|
931
|
-
`FormField` supports two ways of providing validation feedback:
|
|
932
|
-
|
|
933
|
-
1. A controlled `message` supplied to the root `FormField`.
|
|
934
|
-
2. A custom `<FormField.Message>` placed inside the field.
|
|
935
|
-
|
|
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>
|
|
949
|
-
```
|
|
950
|
-
|
|
951
|
-
When no custom `FormField.Message` is present, the root automatically renders one.
|
|
952
|
-
|
|
953
|
-
This means consumers do not need to manually render:
|
|
954
|
-
|
|
955
|
-
```tsx
|
|
956
|
-
<FormField.Message />
|
|
957
|
-
```
|
|
958
|
-
|
|
959
|
-
for the common controlled-message case.
|
|
960
|
-
|
|
961
|
-
---
|
|
962
|
-
|
|
963
|
-
## Custom Messages
|
|
964
|
-
|
|
965
|
-
A custom `FormField.Message` can also be placed inside the field.
|
|
966
|
-
|
|
967
|
-
```tsx
|
|
968
|
-
<FormField status="error">
|
|
969
|
-
<FormField.Label>Email address</FormField.Label>
|
|
970
|
-
|
|
971
|
-
<FormField.Control>
|
|
972
|
-
<Input kind="email" />
|
|
973
|
-
</FormField.Control>
|
|
974
|
-
|
|
975
|
-
<FormField.Message>
|
|
976
|
-
Please enter a valid email address.
|
|
977
|
-
</FormField.Message>
|
|
978
|
-
</FormField>
|
|
979
|
-
```
|
|
980
|
-
|
|
981
|
-
When a custom `FormField.Message` exists, the root `FormField` does not render an additional automatic message.
|
|
982
|
-
|
|
983
|
-
This allows the message content to be controlled directly at the composition level.
|
|
984
|
-
|
|
985
|
-
### One Custom Message
|
|
986
|
-
|
|
987
|
-
A `FormField` should contain at most one custom `FormField.Message`.
|
|
988
|
-
|
|
989
|
-
In development, Kreativ UI detects multiple custom message components and warns:
|
|
990
|
-
|
|
991
|
-
```text
|
|
992
|
-
[Kreativ UI] Multiple <FormField.Message /> components were detected inside the same <FormField>. Only one custom message should be provided.
|
|
993
|
-
```
|
|
994
|
-
|
|
995
|
-
---
|
|
996
|
-
|
|
997
|
-
## Native Control Validation
|
|
998
|
-
|
|
999
|
-
`FormField` can also receive validity information reported by the connected control.
|
|
1000
|
-
|
|
1001
|
-
The field maintains an internal validity state and can receive a `ReportedValidity` result through its context.
|
|
1002
|
-
|
|
1003
|
-
When the reported validity indicates an invalid control, the field can use the reported validation message.
|
|
1004
|
-
|
|
1005
|
-
Conceptually:
|
|
1006
|
-
|
|
1007
|
-
```text
|
|
1008
|
-
Native/control validity
|
|
1009
|
-
↓
|
|
1010
|
-
ReportedValidity
|
|
1011
|
-
↓
|
|
1012
|
-
FormField
|
|
1013
|
-
↓
|
|
1014
|
-
reported message
|
|
1015
|
-
↓
|
|
1016
|
-
FormField.Message
|
|
1017
|
-
```
|
|
1018
|
-
|
|
1019
|
-
A parent-provided `message` takes precedence over a message reported by the control.
|
|
1020
|
-
|
|
1021
|
-
The effective message is resolved as:
|
|
1022
|
-
|
|
1023
|
-
```text
|
|
1024
|
-
message prop
|
|
1025
|
-
↓
|
|
1026
|
-
reported validity message
|
|
1027
|
-
↓
|
|
1028
|
-
no message
|
|
1029
|
-
```
|
|
1030
|
-
|
|
1031
|
-
In other words, an explicitly supplied `message` overrides the automatically reported validity message.
|
|
1032
|
-
|
|
1033
|
-
---
|
|
1034
|
-
|
|
1035
|
-
## Required Fields
|
|
1036
|
-
|
|
1037
|
-
Set `required` on the root `FormField`:
|
|
1038
|
-
|
|
1039
|
-
```tsx
|
|
1040
|
-
<FormField required>
|
|
1041
|
-
<FormField.Label>Email address</FormField.Label>
|
|
1042
|
-
|
|
1043
|
-
<FormField.Control>
|
|
1044
|
-
<Input kind="email" />
|
|
1045
|
-
</FormField.Control>
|
|
1046
|
-
</FormField>
|
|
1047
|
-
```
|
|
1048
|
-
|
|
1049
|
-
The required state is exposed through the field context so that the associated components can apply the appropriate accessibility behavior.
|
|
1050
|
-
|
|
1051
|
-
---
|
|
1052
|
-
|
|
1053
|
-
## Labels
|
|
1054
|
-
|
|
1055
|
-
Use `FormField.Label` to provide the field's visible label.
|
|
1056
|
-
|
|
1057
|
-
```tsx
|
|
1058
|
-
<FormField>
|
|
1059
|
-
<FormField.Label>First name</FormField.Label>
|
|
1060
|
-
|
|
1061
|
-
<FormField.Control>
|
|
1062
|
-
<Input placeholder="Felix" />
|
|
1063
|
-
</FormField.Control>
|
|
1064
|
-
</FormField>
|
|
1065
|
-
```
|
|
1066
|
-
|
|
1067
|
-
The label is associated with the generated or supplied field ID.
|
|
1068
|
-
|
|
1069
|
-
`FormField` also tracks whether a label component is present. This allows the field to distinguish between a field with an external/registered label and one without one.
|
|
1070
|
-
|
|
1071
|
-
For accessibility, form controls should generally have an accessible name.
|
|
1072
|
-
|
|
1073
|
-
---
|
|
1074
|
-
|
|
1075
|
-
## Description
|
|
1076
|
-
|
|
1077
|
-
`FormField.Description` provides supporting information for the control.
|
|
1078
|
-
|
|
1079
|
-
```tsx
|
|
1080
|
-
<FormField>
|
|
1081
|
-
<FormField.Label>Password</FormField.Label>
|
|
1082
|
-
|
|
1083
|
-
<FormField.Description>
|
|
1084
|
-
Use at least 8 characters.
|
|
1085
|
-
</FormField.Description>
|
|
1086
|
-
|
|
1087
|
-
<FormField.Control>
|
|
1088
|
-
<Input type="password" />
|
|
1089
|
-
</FormField.Control>
|
|
1090
|
-
</FormField>
|
|
1091
|
-
```
|
|
1092
|
-
|
|
1093
|
-
The description receives an ID derived from the field ID and participates in the control's `aria-describedby` relationship.
|
|
1094
|
-
|
|
1095
|
-
---
|
|
1096
|
-
|
|
1097
|
-
## Control
|
|
1098
|
-
|
|
1099
|
-
`FormField.Control` connects the actual form control to the surrounding `FormField` context.
|
|
1100
|
-
|
|
1101
|
-
```tsx
|
|
1102
|
-
<FormField>
|
|
1103
|
-
<FormField.Label>Username</FormField.Label>
|
|
1104
|
-
|
|
1105
|
-
<FormField.Control>
|
|
1106
|
-
<Input />
|
|
1107
|
-
</FormField.Control>
|
|
1108
|
-
</FormField>
|
|
1109
|
-
```
|
|
1110
|
-
|
|
1111
|
-
The control is responsible for receiving the field's relevant accessibility information, including the generated field ID and description relationships.
|
|
1112
|
-
|
|
1113
|
-
This allows the root field to manage accessibility relationships without requiring consumers to manually coordinate IDs.
|
|
1114
|
-
|
|
1115
|
-
---
|
|
1116
|
-
|
|
1117
|
-
## Accessibility Relationships
|
|
1118
|
-
|
|
1119
|
-
A typical field establishes relationships similar to:
|
|
1120
|
-
|
|
1121
|
-
```text
|
|
1122
|
-
FormField
|
|
1123
|
-
│
|
|
1124
|
-
├── Label
|
|
1125
|
-
│ └── htmlFor → field ID
|
|
1126
|
-
│
|
|
1127
|
-
├── Description
|
|
1128
|
-
│ └── description ID
|
|
1129
|
-
│
|
|
1130
|
-
├── Control
|
|
1131
|
-
│ ├── id → field ID
|
|
1132
|
-
│ └── aria-describedby → description/message IDs
|
|
1133
|
-
│
|
|
1134
|
-
└── Message
|
|
1135
|
-
└── message ID
|
|
1136
|
-
```
|
|
1137
|
-
|
|
1138
|
-
When the field has a message or custom message, its message ID is included in the control's `aria-describedby`.
|
|
1139
|
-
|
|
1140
|
-
When the field is invalid, the field context exposes the invalid state so the control can apply the appropriate `aria-invalid` behavior.
|
|
1141
|
-
|
|
1142
|
-
When `required` is enabled, the required state is also exposed to the control.
|
|
1143
|
-
|
|
1144
|
-
---
|
|
1145
|
-
|
|
1146
|
-
## Message Resolution
|
|
1147
|
-
|
|
1148
|
-
The root component resolves the displayed message using the following precedence:
|
|
1149
|
-
|
|
1150
|
-
```text
|
|
1151
|
-
FormField.message
|
|
1152
|
-
↓
|
|
1153
|
-
reported validity message
|
|
1154
|
-
↓
|
|
1155
|
-
undefined
|
|
1156
|
-
```
|
|
1157
|
-
|
|
1158
|
-
Therefore, this:
|
|
1159
|
-
|
|
1160
|
-
```tsx
|
|
1161
|
-
<FormField
|
|
1162
|
-
status="error"
|
|
1163
|
-
message="Email is required"
|
|
1164
|
-
>
|
|
1165
|
-
```
|
|
1166
|
-
|
|
1167
|
-
takes precedence over a validation message reported by the connected control.
|
|
1168
|
-
|
|
1169
|
-
A custom:
|
|
1170
|
-
|
|
1171
|
-
```tsx
|
|
1172
|
-
<FormField.Message>
|
|
1173
|
-
...
|
|
1174
|
-
</FormField.Message>
|
|
1175
|
-
```
|
|
1176
|
-
|
|
1177
|
-
is handled separately as an explicit message component and prevents the root from rendering its automatic message component.
|
|
1178
|
-
|
|
1179
|
-
---
|
|
1180
|
-
|
|
1181
|
-
## Complete Example
|
|
1182
|
-
|
|
1183
|
-
```tsx
|
|
1184
|
-
import { useState } from "react";
|
|
1185
|
-
import { FormField, Input } from "@splenddev/kreativ-ui";
|
|
1186
|
-
|
|
1187
|
-
function EmailField() {
|
|
1188
|
-
const [email, setEmail] = useState("");
|
|
1189
|
-
const [message, setMessage] = useState("");
|
|
1190
|
-
|
|
1191
|
-
function validateEmail(value: string) {
|
|
1192
|
-
if (!value) {
|
|
1193
|
-
setMessage("Email address is required.");
|
|
1194
|
-
return;
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
if (!/\S+@\S+\.\S+/.test(value)) {
|
|
1198
|
-
setMessage("Please enter a valid email address.");
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
setMessage("");
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
return (
|
|
1206
|
-
<FormField
|
|
1207
|
-
id="email"
|
|
1208
|
-
required
|
|
1209
|
-
status={message ? "error" : "none"}
|
|
1210
|
-
message={message || undefined}
|
|
1211
|
-
>
|
|
1212
|
-
<FormField.Label>Email address</FormField.Label>
|
|
1213
|
-
|
|
1214
|
-
<FormField.Description>
|
|
1215
|
-
We'll only send receipts to this address.
|
|
1216
|
-
</FormField.Description>
|
|
1217
|
-
|
|
1218
|
-
<FormField.Control>
|
|
1219
|
-
<Input
|
|
1220
|
-
kind="email"
|
|
1221
|
-
value={email}
|
|
1222
|
-
placeholder="you@example.com"
|
|
1223
|
-
onChange={(event) => setEmail(event.target.value)}
|
|
1224
|
-
onBlur={() => validateEmail(email)}
|
|
1225
|
-
/>
|
|
1226
|
-
</FormField.Control>
|
|
1227
|
-
</FormField>
|
|
1228
|
-
);
|
|
1229
|
-
}
|
|
1230
|
-
```
|
|
1231
|
-
|
|
1232
|
-
This example demonstrates the intended separation of responsibilities:
|
|
1233
|
-
|
|
1234
|
-
```text
|
|
1235
|
-
FormField
|
|
1236
|
-
│
|
|
1237
|
-
├── Field identity
|
|
1238
|
-
│ └── id
|
|
1239
|
-
│
|
|
1240
|
-
├── Validation state
|
|
1241
|
-
│ ├── status
|
|
1242
|
-
│ └── message
|
|
1243
|
-
│
|
|
1244
|
-
├── Accessibility
|
|
1245
|
-
│ ├── label relationship
|
|
1246
|
-
│ ├── description relationship
|
|
1247
|
-
│ ├── message relationship
|
|
1248
|
-
│ └── required / invalid state
|
|
1249
|
-
│
|
|
1250
|
-
└── Control
|
|
1251
|
-
└── Input
|
|
1252
|
-
```
|
|
1253
|
-
|
|
1254
|
-
### Standalone Control vs FormField
|
|
1255
|
-
|
|
1256
|
-
Use a standalone component such as `Input` when the surrounding UI does not require the full field composition.
|
|
1257
|
-
|
|
1258
|
-
Use `FormField` when you need a coordinated:
|
|
1259
|
-
|
|
1260
|
-
* label
|
|
1261
|
-
* description
|
|
1262
|
-
* validation state
|
|
1263
|
-
* validation message
|
|
1264
|
-
* required state
|
|
1265
|
-
* accessibility relationship
|
|
1266
|
-
|
|
1267
|
-
The `FormField` system is designed to keep these concerns connected without requiring consumers to manually manage the generated IDs and ARIA relationships.
|
|
1268
|
-
|
|
1269
|
-
---
|
|
1270
|
-
|
|
1271
|
-
## 🧩 Select
|
|
1272
|
-
|
|
1273
|
-
A fully accessible, customizable select component with keyboard navigation, grouped options, and clearable selections.
|
|
1274
|
-
|
|
1275
|
-
### Basic Usage
|
|
1276
|
-
|
|
1277
|
-
```tsx
|
|
1278
|
-
import { Select } from "@splenddev/kreativ-ui";
|
|
1279
|
-
|
|
1280
|
-
<Select placeholder="Select a country">
|
|
1281
|
-
<Select.Trigger>
|
|
1282
|
-
<Select.Value />
|
|
1283
|
-
</Select.Trigger>
|
|
1284
|
-
|
|
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>
|
|
1291
|
-
```
|
|
1292
|
-
|
|
1293
|
-
### Controlled Select
|
|
1294
|
-
|
|
1295
|
-
```tsx
|
|
1296
|
-
import { useState } from "react";
|
|
1297
|
-
|
|
1298
|
-
function ControlledSelect() {
|
|
1299
|
-
const [value, setValue] = useState<string | undefined>("");
|
|
1300
|
-
|
|
1301
|
-
return (
|
|
1302
|
-
<Select value={value} onValueChange={setValue}>
|
|
1303
|
-
<Select.Trigger>
|
|
1304
|
-
<Select.Value placeholder="Choose a framework" />
|
|
1305
|
-
</Select.Trigger>
|
|
1306
|
-
|
|
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
|
-
}
|
|
1315
|
-
```
|
|
1316
|
-
|
|
1317
|
-
### Uncontrolled Select
|
|
1318
|
-
|
|
1319
|
-
```tsx
|
|
1320
|
-
<Select defaultValue="react">
|
|
1321
|
-
<Select.Trigger>
|
|
1322
|
-
<Select.Value placeholder="Choose a framework" />
|
|
1323
|
-
</Select.Trigger>
|
|
1324
|
-
|
|
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
|
-
```
|
|
1332
|
-
|
|
1333
|
-
### Props
|
|
1334
|
-
|
|
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 |
|
|
1351
|
-
|
|
1352
|
-
### Compound Components
|
|
1353
|
-
|
|
1354
|
-
#### `Select.Trigger`
|
|
1355
|
-
|
|
1356
|
-
The interactive button that toggles the dropdown:
|
|
1357
|
-
|
|
1358
|
-
```tsx
|
|
1359
|
-
<Select.Trigger>
|
|
1360
|
-
<Select.Value />
|
|
1361
|
-
</Select.Trigger>
|
|
1362
|
-
```
|
|
1363
|
-
|
|
1364
|
-
#### `Select.Value`
|
|
1365
|
-
|
|
1366
|
-
Renders the current selection or the placeholder:
|
|
1367
|
-
|
|
1368
|
-
```tsx
|
|
1369
|
-
<Select.Value placeholder="Choose an option" />
|
|
1370
|
-
```
|
|
1371
|
-
|
|
1372
|
-
#### `Select.Content`
|
|
1373
|
-
|
|
1374
|
-
The dropdown container:
|
|
1375
|
-
|
|
1376
|
-
```tsx
|
|
1377
|
-
<Select.Content>{/* items */}</Select.Content>
|
|
1378
|
-
```
|
|
1379
|
-
|
|
1380
|
-
#### `Select.Item`
|
|
1381
|
-
|
|
1382
|
-
A single selectable option:
|
|
1383
|
-
|
|
1384
|
-
```tsx
|
|
1385
|
-
<Select.Item value="react" disabled>
|
|
1386
|
-
React
|
|
1387
|
-
</Select.Item>
|
|
1388
|
-
```
|
|
1389
|
-
|
|
1390
|
-
#### `Select.Group`
|
|
1391
|
-
|
|
1392
|
-
Groups related options:
|
|
1393
|
-
|
|
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>
|
|
1400
|
-
```
|
|
1401
|
-
|
|
1402
|
-
#### `Select.Label`
|
|
1403
|
-
|
|
1404
|
-
A heading for a group of options:
|
|
1405
|
-
|
|
1406
|
-
```tsx
|
|
1407
|
-
<Select.Label>Backend</Select.Label>
|
|
1408
|
-
```
|
|
1409
|
-
|
|
1410
|
-
### Clearable Select
|
|
1411
|
-
|
|
1412
|
-
```tsx
|
|
1413
|
-
<Select clearable defaultValue="react">
|
|
1414
|
-
<Select.Trigger>
|
|
1415
|
-
<Select.Value placeholder="Pick a framework" />
|
|
1416
|
-
</Select.Trigger>
|
|
1417
|
-
|
|
1418
|
-
<Select.Content>
|
|
1419
|
-
<Select.Item value="react">React</Select.Item>
|
|
1420
|
-
<Select.Item value="vue">Vue</Select.Item>
|
|
1421
|
-
</Select.Content>
|
|
1422
|
-
</Select>
|
|
1423
|
-
```
|
|
1424
|
-
|
|
1425
|
-
### FormField Integration
|
|
1426
|
-
|
|
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>
|
|
1433
|
-
|
|
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>
|
|
1446
|
-
```
|
|
1447
|
-
|
|
1448
|
-
---
|
|
1449
|
-
|
|
1450
|
-
## 📝 Typography System
|
|
1451
|
-
|
|
1452
|
-
Kreativ UI provides a centralized, theme-aware typography system for controlling how text is rendered across your application.
|
|
1453
|
-
|
|
1454
|
-
### How It Works
|
|
1455
|
-
|
|
1456
|
-
Typography is built around four layers:
|
|
1457
|
-
|
|
1458
|
-
```
|
|
1459
|
-
Primitive Tokens
|
|
1460
|
-
↓
|
|
1461
|
-
Semantic Tokens
|
|
1462
|
-
↓
|
|
1463
|
-
Typography Presets
|
|
1464
|
-
↓
|
|
1465
|
-
useTypography()
|
|
1466
|
-
↓
|
|
1467
|
-
React.CSSProperties
|
|
1468
|
-
↓
|
|
1469
|
-
Component
|
|
1470
|
-
```
|
|
1471
|
-
|
|
1472
|
-
### Using `useTypography()`
|
|
1473
|
-
|
|
1474
|
-
Use the hook when creating a custom component:
|
|
1475
|
-
|
|
1476
|
-
```tsx
|
|
1477
|
-
import { useTypography } from "@splenddev/kreativ-ui";
|
|
1478
|
-
|
|
1479
|
-
function MyCustomCard() {
|
|
1480
|
-
const headingStyles = useTypography("heading");
|
|
1481
|
-
const bodyStyles = useTypography("body");
|
|
1482
|
-
|
|
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
|
-
}
|
|
1490
|
-
```
|
|
1491
|
-
|
|
1492
|
-
### Creating a Typography-Aware Custom Component
|
|
1493
|
-
|
|
1494
|
-
```tsx
|
|
1495
|
-
import { TypographyProps, useTypography } from "@splenddev/kreativ-ui";
|
|
1496
|
-
|
|
1497
|
-
interface MyTextProps extends TypographyProps {
|
|
1498
|
-
children: React.ReactNode;
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
function MyText({ typography = "body", children }: MyTextProps) {
|
|
1502
|
-
const styles = useTypography(typography);
|
|
1503
|
-
|
|
1504
|
-
return <p style={styles}>{children}</p>;
|
|
1505
|
-
}
|
|
1506
|
-
```
|
|
1507
|
-
|
|
1508
|
-
### Loading Fonts
|
|
1509
|
-
|
|
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.
|
|
1511
|
-
|
|
1512
|
-
#### Next.js `next/font` Example
|
|
1513
|
-
|
|
1514
|
-
```tsx
|
|
1515
|
-
import { Geist, Geist_Mono } from "next/font/google";
|
|
1516
|
-
import { UIProvider, defineToken } from "@splenddev/kreativ-ui";
|
|
1517
|
-
|
|
1518
|
-
const geistSans = Geist({
|
|
1519
|
-
variable: "--font-geist-sans",
|
|
1520
|
-
subsets: ["latin"],
|
|
1521
|
-
});
|
|
1522
|
-
|
|
1523
|
-
const geistMono = Geist_Mono({
|
|
1524
|
-
variable: "--font-geist-mono",
|
|
1525
|
-
subsets: ["latin"],
|
|
1526
|
-
});
|
|
1527
|
-
|
|
1528
|
-
const theme = extendTheme({
|
|
1529
|
-
tokens: {
|
|
1530
|
-
fonts: {
|
|
1531
|
-
body: defineToken("var(--font-geist-sans)"),
|
|
1532
|
-
heading: defineToken("var(--font-geist-sans)"),
|
|
1533
|
-
mono: defineToken("var(--font-geist-mono)"),
|
|
1534
|
-
},
|
|
1535
|
-
},
|
|
1536
|
-
});
|
|
1537
|
-
|
|
1538
|
-
export default function RootLayout({ children }) {
|
|
1539
|
-
return (
|
|
1540
|
-
<html className={`${geistSans.variable} ${geistMono.variable}`}>
|
|
1541
|
-
<body>
|
|
1542
|
-
<UIProvider theme={theme}>{children}</UIProvider>
|
|
1543
|
-
</body>
|
|
1544
|
-
</html>
|
|
1545
|
-
);
|
|
1546
|
-
}
|
|
1547
|
-
```
|
|
1548
|
-
|
|
1549
|
-
### Best Practices
|
|
1550
|
-
|
|
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
|
|
1559
|
-
|
|
1560
|
-
Kreativ UI components are built with accessibility in mind:
|
|
1561
|
-
|
|
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
|
|
1595
|
-
|
|
1596
|
-
---
|
|
1597
|
-
|
|
1598
|
-
## 🚧 Future Direction
|
|
1599
|
-
|
|
1600
|
-
> **Note:** The following describes future work that is not yet available in the current release.
|
|
1601
|
-
|
|
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.
|
|
1603
|
-
|
|
1604
|
-
---
|
|
230
|
+
## Contributing
|
|
1605
231
|
|
|
1606
|
-
|
|
232
|
+
Contributions are welcome. Please keep these in mind:
|
|
1607
233
|
|
|
1608
|
-
|
|
234
|
+
- prefer composition over unnecessary abstraction
|
|
235
|
+
- keep component APIs predictable
|
|
236
|
+
- reuse the theme system instead of adding isolated design values
|
|
237
|
+
- keep accessibility part of the component contract
|
|
238
|
+
- prefer explicit state ownership
|
|
239
|
+
- preserve TypeScript inference
|
|
240
|
+
- keep framework-specific behavior separated where practical
|
|
241
|
+
- add metadata when a component takes part in Kreativ's component model
|
|
1609
242
|
|
|
1610
|
-
|
|
243
|
+
## License
|
|
1611
244
|
|
|
1612
|
-
|
|
1613
|
-
Visit the [GitHub repository](https://github.com/Vincentvirtuoso/kreativ-ui) for updates.
|
|
245
|
+
See the repository license.
|