@splenddev/kreativ-ui 0.1.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 +1365 -0
- package/dist/index.cjs +5 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +571 -0
- package/dist/index.d.ts +571 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/index.css +2 -0
- package/package.json +66 -0
package/README.md
ADDED
|
@@ -0,0 +1,1365 @@
|
|
|
1
|
+
# Kreativ UI
|
|
2
|
+
|
|
3
|
+
A modern, themeable React component library built with **React**, **Tailwind CSS v4**, and **CSS Variables**.
|
|
4
|
+
|
|
5
|
+
Kreativ UI provides a runtime theme engine, allowing colors, typography, radius, animations, and component styles to be customized **without rebuilding CSS**.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## β¨ Features
|
|
10
|
+
|
|
11
|
+
* π¨ Runtime theme switching (light, dark, system)
|
|
12
|
+
* π Builtβin `ThemeToggler` with optional animated icon transitions
|
|
13
|
+
* β‘ Tailwind CSS v4 integration
|
|
14
|
+
* π― CSS Variable powered design tokens
|
|
15
|
+
* π§© Componentβlevel theme overrides
|
|
16
|
+
* π Builtβin animation utilities (spin, fade, scale, slide, bounce, pulse, shimmer, and more)
|
|
17
|
+
* βΏ Fully accessible (ARIA, keyboard navigation, focus management)
|
|
18
|
+
* π¦ Treeβshakable and TypeScriptβfirst
|
|
19
|
+
* π§© Smart form components: `Input` with **kind** defaults, `FormField` with automatic ARIA wiring
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## π¦ Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install kreativ-ui
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Import the stylesheet **once** in your application entry.
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import "kreativ-ui/styles.css";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## π Quick Start
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { Button, UIProvider } from "kreativ-ui";
|
|
41
|
+
import "kreativ-ui/styles.css";
|
|
42
|
+
|
|
43
|
+
export default function App() {
|
|
44
|
+
return (
|
|
45
|
+
<UIProvider defaultMode="system">
|
|
46
|
+
<Button>Click me</Button>
|
|
47
|
+
</UIProvider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
# Theme Provider
|
|
55
|
+
|
|
56
|
+
Wrap your application with `UIProvider` to enable theme context.
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
<UIProvider defaultMode="system">
|
|
60
|
+
<App />
|
|
61
|
+
</UIProvider>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Available Modes
|
|
65
|
+
|
|
66
|
+
* `"light"`
|
|
67
|
+
* `"dark"`
|
|
68
|
+
* `"system"` (follows OS preference)
|
|
69
|
+
|
|
70
|
+
Switch themes anywhere using the `useTheme` hook.
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { useTheme } from "kreativ-ui";
|
|
74
|
+
|
|
75
|
+
function ThemeSwitcher() {
|
|
76
|
+
const { mode, setMode } = useTheme();
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<>
|
|
80
|
+
<button onClick={() => setMode("light")}>Light</button>
|
|
81
|
+
<button onClick={() => setMode("dark")}>Dark</button>
|
|
82
|
+
<button onClick={() => setMode("system")}>System</button>
|
|
83
|
+
</>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
# Custom Themes
|
|
91
|
+
|
|
92
|
+
Override only the tokens you need. Pass a `theme` object to `UIProvider`.
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
<UIProvider
|
|
96
|
+
theme={{
|
|
97
|
+
light: {
|
|
98
|
+
colors: {
|
|
99
|
+
brand: "16 185 129", // emerald-600
|
|
100
|
+
brandFg: "255 255 255",
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
dark: {
|
|
104
|
+
colors: {
|
|
105
|
+
brand: "52 211 153", // emerald-400
|
|
106
|
+
brandFg: "0 0 0",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
radius: "0.75rem",
|
|
110
|
+
font: "'Inter', sans-serif",
|
|
111
|
+
}}
|
|
112
|
+
>
|
|
113
|
+
<App />
|
|
114
|
+
</UIProvider>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
All CSS variables are generated automatically and applied to the `<html>` element.
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
# Theme Tokens
|
|
122
|
+
|
|
123
|
+
## Colors
|
|
124
|
+
|
|
125
|
+
| Token | Description |
|
|
126
|
+
|-------|-------------|
|
|
127
|
+
| `brand` | Primary accent color (RGB values) |
|
|
128
|
+
| `brandHover` | Hover state of brand |
|
|
129
|
+
| `brandFg` | Foreground (text/icon) on brand |
|
|
130
|
+
| `surface` | Background of surfaces |
|
|
131
|
+
| `surfaceRaised` | Elevated surfaces (cards, modals) |
|
|
132
|
+
| `surfaceSunken` | Sunken surfaces (inputs, inset) |
|
|
133
|
+
| `border` | Default border color |
|
|
134
|
+
| `text` | Primary text |
|
|
135
|
+
| `textMuted` | Secondary / muted text |
|
|
136
|
+
| `danger` | Error/danger color |
|
|
137
|
+
| `dangerFg` | Foreground on danger |
|
|
138
|
+
| `destructive` / `destructiveHover` / `destructiveFg` | Destructive actions |
|
|
139
|
+
| `success` / `successHover` / `successFg` | Success states |
|
|
140
|
+
| `warning` / `warningHover` / `warningFg` | Warning states |
|
|
141
|
+
| `info` / `infoHover` / `infoFg` | Informational states |
|
|
142
|
+
|
|
143
|
+
## Radius
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
radius // default: 0.375rem (6px)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Typography
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
font // font-family stack
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Motion
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
durationFast // 150ms
|
|
159
|
+
durationNormal // 300ms
|
|
160
|
+
durationSlow // 500ms
|
|
161
|
+
|
|
162
|
+
easeDefault // ease-in-out
|
|
163
|
+
easeIn // ease-in
|
|
164
|
+
easeOut // ease-out
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
# Components
|
|
170
|
+
|
|
171
|
+
## Button
|
|
172
|
+
|
|
173
|
+
A versatile button with variant, size, loading, and icon support.
|
|
174
|
+
|
|
175
|
+
### Basic Usage
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
<Button>Click me</Button>
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Variants
|
|
182
|
+
|
|
183
|
+
```tsx
|
|
184
|
+
<Button variant="solid" />
|
|
185
|
+
<Button variant="outline" />
|
|
186
|
+
<Button variant="ghost" />
|
|
187
|
+
<Button variant="soft" />
|
|
188
|
+
<Button variant="destructive" />
|
|
189
|
+
<Button variant="success" />
|
|
190
|
+
<Button variant="link" />
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Sizes
|
|
194
|
+
|
|
195
|
+
```tsx
|
|
196
|
+
<Button size="xs" />
|
|
197
|
+
<Button size="sm" />
|
|
198
|
+
<Button size="md" />
|
|
199
|
+
<Button size="lg" />
|
|
200
|
+
<Button size="xl" /> {/* custom size via theme */}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Loading State
|
|
204
|
+
|
|
205
|
+
```tsx
|
|
206
|
+
<Button isLoading>Save</Button>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Disabled
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
<Button disabled>Submit</Button>
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Icons
|
|
216
|
+
|
|
217
|
+
```tsx
|
|
218
|
+
<Button leftIcon={<SearchIcon />}>Search</Button>
|
|
219
|
+
<Button rightIcon={<ArrowRightIcon />}>Next</Button>
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### Full Width
|
|
223
|
+
|
|
224
|
+
```tsx
|
|
225
|
+
<Button fullWidth>Full width</Button>
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Props
|
|
229
|
+
|
|
230
|
+
| Prop | Type | Default | Description |
|
|
231
|
+
|------|------|---------|-------------|
|
|
232
|
+
| `variant` | `Variant` | `"solid"` | Visual style |
|
|
233
|
+
| `size` | `SizeValue` | `"md"` | Size (supports custom sizes via theme) |
|
|
234
|
+
| `isLoading` | `boolean` | `false` | Shows spinner and disables |
|
|
235
|
+
| `leftIcon` / `rightIcon` | `ReactNode` | β | Icon elements |
|
|
236
|
+
| `fullWidth` | `boolean` | `false` | Stretches to container width |
|
|
237
|
+
| `disabled` | `boolean` | `false` | Disables interactions |
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## ThemeToggler
|
|
242
|
+
|
|
243
|
+
A readyβtoβuse theme switcher that integrates with `UIProvider`. Supports buttonβstyle or cycleβstyle (single button with animated icon transitions).
|
|
244
|
+
|
|
245
|
+
### Basic Usage
|
|
246
|
+
|
|
247
|
+
```tsx
|
|
248
|
+
import { ThemeToggler } from "kreativ-ui";
|
|
249
|
+
|
|
250
|
+
<ThemeToggler />
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### With System Mode
|
|
254
|
+
|
|
255
|
+
```tsx
|
|
256
|
+
<ThemeToggler allowSystem />
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Icon Only
|
|
260
|
+
|
|
261
|
+
```tsx
|
|
262
|
+
<ThemeToggler iconOnly allowSystem />
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Custom Variants
|
|
266
|
+
|
|
267
|
+
```tsx
|
|
268
|
+
<ThemeToggler variant="outline" activeVariant="solid" />
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Vertical Layout
|
|
272
|
+
|
|
273
|
+
```tsx
|
|
274
|
+
<ThemeToggler orientation="vertical" allowSystem />
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Custom Labels
|
|
278
|
+
|
|
279
|
+
```tsx
|
|
280
|
+
<ThemeToggler
|
|
281
|
+
allowSystem
|
|
282
|
+
labels={{ light: "Day", dark: "Night", system: "Auto" }}
|
|
283
|
+
/>
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Custom Icons
|
|
287
|
+
|
|
288
|
+
```tsx
|
|
289
|
+
import { SunMedium, MoonStar, LaptopMinimal } from "lucide-react";
|
|
290
|
+
|
|
291
|
+
<ThemeToggler
|
|
292
|
+
allowSystem
|
|
293
|
+
icons={{
|
|
294
|
+
light: <SunMedium size={18} />,
|
|
295
|
+
dark: <MoonStar size={18} />,
|
|
296
|
+
system: <LaptopMinimal size={18} />,
|
|
297
|
+
}}
|
|
298
|
+
/>
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Cycle Mode with Animation
|
|
302
|
+
|
|
303
|
+
```tsx
|
|
304
|
+
<ThemeToggler
|
|
305
|
+
display="cycle"
|
|
306
|
+
allowSystem
|
|
307
|
+
transition={{ type: "rotate", duration: 400, easing: "ease-in-out" }}
|
|
308
|
+
/>
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
Supported transition types: `"none"`, `"fade"`, `"slide"`, `"scale"`, `"rotate"`.
|
|
312
|
+
|
|
313
|
+
### Styling
|
|
314
|
+
|
|
315
|
+
```tsx
|
|
316
|
+
<ThemeToggler rounded={false} unstyled />
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Props
|
|
320
|
+
|
|
321
|
+
| Prop | Type | Default | Description |
|
|
322
|
+
|------|------|---------|-------------|
|
|
323
|
+
| `variant` | `ThemeTogglerVariant` | `"ghost"` | Variant for inactive buttons |
|
|
324
|
+
| `activeVariant` | `ThemeTogglerVariant` | `"solid"` | Variant for active button |
|
|
325
|
+
| `size` | `SizeValue` | `"sm"` | Button size |
|
|
326
|
+
| `iconOnly` | `boolean` | `false` | Hide labels, show icons only |
|
|
327
|
+
| `allowSystem` | `boolean` | `false` | Show system theme option |
|
|
328
|
+
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Layout direction |
|
|
329
|
+
| `rounded` | `boolean` | `true` | Rounded container corners |
|
|
330
|
+
| `unstyled` | `boolean` | `false` | Remove wrapper styles |
|
|
331
|
+
| `display` | `"buttons" \| "cycle"` | `"buttons"` | Show all buttons or a single cycling button |
|
|
332
|
+
| `transition` | `ThemeTogglerTransition` | `{ type: "none", duration: 300, easing: "ease-in-out" }` | Animation configuration for cycle mode |
|
|
333
|
+
| `labels` | `Partial<Record<"light" \| "dark" \| "system", string>>` | β | Override labels |
|
|
334
|
+
| `icons` | `Partial<Record<"light" \| "dark" \| "system", ReactNode>>` | β | Override icons |
|
|
335
|
+
| `buttonProps` | `Partial<ButtonProps>` | β | Props passed to every internal button |
|
|
336
|
+
| `className` | `string` | β | Additional wrapper class |
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Input
|
|
341
|
+
|
|
342
|
+
A flexible text input with variants, sizes, validation states, adornments, and **kindβaware defaults** for common field types. Built to work seamlessly with `FormField`.
|
|
343
|
+
|
|
344
|
+
### Basic Usage
|
|
345
|
+
|
|
346
|
+
```tsx
|
|
347
|
+
import { Input } from "kreativ-ui";
|
|
348
|
+
|
|
349
|
+
<Input placeholder="you@company.com" />
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### Variants
|
|
353
|
+
|
|
354
|
+
```tsx
|
|
355
|
+
<Input variant="outline" />
|
|
356
|
+
<Input variant="filled" />
|
|
357
|
+
<Input variant="ghost" />
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Sizes
|
|
361
|
+
|
|
362
|
+
```tsx
|
|
363
|
+
<Input inputSize="sm" />
|
|
364
|
+
<Input inputSize="md" />
|
|
365
|
+
<Input inputSize="lg" />
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
### Validation States
|
|
369
|
+
|
|
370
|
+
```tsx
|
|
371
|
+
<Input error />
|
|
372
|
+
<Input success />
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
### Adornments
|
|
376
|
+
|
|
377
|
+
```tsx
|
|
378
|
+
<Input startAdornment={<SearchIcon />} />
|
|
379
|
+
<Input endAdornment={<MailIcon />} />
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Loading State
|
|
383
|
+
|
|
384
|
+
Shows a spinner and makes the field readβonly (not disabled) while a request is in flight.
|
|
385
|
+
|
|
386
|
+
```tsx
|
|
387
|
+
<Input isLoading />
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Clearable
|
|
391
|
+
|
|
392
|
+
Adds an internal clear button that appears when the field has a value.
|
|
393
|
+
|
|
394
|
+
```tsx
|
|
395
|
+
<Input clearable onClear={() => console.log("cleared")} />
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
### Kind
|
|
399
|
+
|
|
400
|
+
Sets sensible defaults for `type`, `inputMode`, `autoComplete`, `placeholder`, and optionally a default icon. Any explicit prop overrides the kind default.
|
|
401
|
+
|
|
402
|
+
```tsx
|
|
403
|
+
<Input kind="email" />
|
|
404
|
+
<Input kind="tel" />
|
|
405
|
+
<Input kind="url" />
|
|
406
|
+
<Input kind="search" />
|
|
407
|
+
<Input kind="numeric" />
|
|
408
|
+
<Input kind="password-current" /> // autoComplete="current-password" + show/hide toggle
|
|
409
|
+
<Input kind="password-new" /> // autoComplete="new-password" + show/hide toggle
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
To suppress the icon that comes with certain kinds (e.g., `email`, `search`):
|
|
413
|
+
|
|
414
|
+
```tsx
|
|
415
|
+
<Input kind="email" hideKindIcon />
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Rounded
|
|
419
|
+
|
|
420
|
+
```tsx
|
|
421
|
+
<Input rounded />
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
### Props
|
|
425
|
+
|
|
426
|
+
| Prop | Type | Default | Description |
|
|
427
|
+
|------|------|---------|-------------|
|
|
428
|
+
| `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
|
|
429
|
+
| `inputSize` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding, font size |
|
|
430
|
+
| `kind` | `InputKind` | `"text"` | Sets defaults for `type`, `inputMode`, `autoComplete`, placeholder, and icon |
|
|
431
|
+
| `hideKindIcon` | `boolean` | `false` | Suppress the default icon from `kind` |
|
|
432
|
+
| `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
|
|
433
|
+
| `success` | `boolean` | `false` | Success styling |
|
|
434
|
+
| `rounded` | `boolean` | `false` | Fully rounded wrapper |
|
|
435
|
+
| `fullWidth` | `boolean` | `true` | Stretch to container width |
|
|
436
|
+
| `isLoading` | `boolean` | `false` | Shows spinner and marks readβonly |
|
|
437
|
+
| `clearable` | `boolean` | `false` | Shows clear button when value present |
|
|
438
|
+
| `onClear` | `() => void` | β | Called after clear |
|
|
439
|
+
| `startAdornment` / `endAdornment` | `ReactNode` | β | Content before/after input |
|
|
440
|
+
| `className` / `inputClassName` | `string` | β | Additional class(es) |
|
|
441
|
+
|
|
442
|
+
All standard `<input>` attributes (except `size`) are forwarded.
|
|
443
|
+
|
|
444
|
+
---
|
|
445
|
+
|
|
446
|
+
## FormField
|
|
447
|
+
|
|
448
|
+
Wraps a form control (e.g., `Input`) and automatically wires `id`, `aria-describedby`, `aria-invalid`, and `aria-required` β no manual idβjuggling.
|
|
449
|
+
|
|
450
|
+
### Basic Usage
|
|
451
|
+
|
|
452
|
+
```tsx
|
|
453
|
+
import { FormField, Input } from "kreativ-ui";
|
|
454
|
+
|
|
455
|
+
<FormField label="Email address">
|
|
456
|
+
<Input kind="email" />
|
|
457
|
+
</FormField>
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### With Description
|
|
461
|
+
|
|
462
|
+
```tsx
|
|
463
|
+
<FormField
|
|
464
|
+
label="Email address"
|
|
465
|
+
description="We'll only use this to send receipts."
|
|
466
|
+
>
|
|
467
|
+
<Input kind="email" />
|
|
468
|
+
</FormField>
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### With Error
|
|
472
|
+
|
|
473
|
+
Error replaces description when both are provided.
|
|
474
|
+
|
|
475
|
+
```tsx
|
|
476
|
+
<FormField
|
|
477
|
+
label="Email address"
|
|
478
|
+
error="Enter a valid email address."
|
|
479
|
+
>
|
|
480
|
+
<Input kind="email" error />
|
|
481
|
+
</FormField>
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Required
|
|
485
|
+
|
|
486
|
+
```tsx
|
|
487
|
+
<FormField label="Email address" required>
|
|
488
|
+
<Input kind="email" required />
|
|
489
|
+
</FormField>
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### Props
|
|
493
|
+
|
|
494
|
+
| Prop | Type | Default | Description |
|
|
495
|
+
|------|------|---------|-------------|
|
|
496
|
+
| `label` | `string` | β | Label text, linked to control |
|
|
497
|
+
| `description` | `string` | β | Helper text (hidden when `error` set) |
|
|
498
|
+
| `error` | `string` | β | Error message, linked via `aria-describedby` |
|
|
499
|
+
| `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
|
|
500
|
+
| `id` | `string` | autoβgenerated | Explicit `id` for the control |
|
|
501
|
+
| `className` | `string` | β | Additional wrapper classes |
|
|
502
|
+
| `children` | `ReactNode` | β | The form control (must accept `id` prop) |
|
|
503
|
+
|
|
504
|
+
---
|
|
505
|
+
|
|
506
|
+
# Select
|
|
507
|
+
|
|
508
|
+
A fully accessible, customizable select component with keyboard navigation, grouped options, clearable selections, and optional integration with `FormField`.
|
|
509
|
+
|
|
510
|
+
## Features
|
|
511
|
+
|
|
512
|
+
- βΏ Accessible (ARIA-compliant combobox)
|
|
513
|
+
- β¨οΈ Full keyboard navigation
|
|
514
|
+
- π¨ Multiple variants and sizes
|
|
515
|
+
- π§© Compound component API
|
|
516
|
+
- π Works standalone or inside `FormField`
|
|
517
|
+
- β Clearable selections
|
|
518
|
+
- β
Error and success states
|
|
519
|
+
- π Disabled state
|
|
520
|
+
- π― Controlled and uncontrolled modes
|
|
521
|
+
- π¦ Hidden input support for HTML forms
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
## Import
|
|
526
|
+
|
|
527
|
+
```tsx
|
|
528
|
+
import { Select } from "@kreativ-ui/react";
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
---
|
|
532
|
+
|
|
533
|
+
## Basic Usage
|
|
534
|
+
|
|
535
|
+
```tsx
|
|
536
|
+
<Select placeholder="Select a country">
|
|
537
|
+
<Select.Trigger>
|
|
538
|
+
<Select.Value />
|
|
539
|
+
</Select.Trigger>
|
|
540
|
+
|
|
541
|
+
<Select.Content>
|
|
542
|
+
<Select.Item value="ng">Nigeria</Select.Item>
|
|
543
|
+
<Select.Item value="gh">Ghana</Select.Item>
|
|
544
|
+
<Select.Item value="za">South Africa</Select.Item>
|
|
545
|
+
</Select.Content>
|
|
546
|
+
</Select>
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
---
|
|
550
|
+
|
|
551
|
+
## Controlled
|
|
552
|
+
|
|
553
|
+
```tsx
|
|
554
|
+
const [value, setValue] = useState("");
|
|
555
|
+
|
|
556
|
+
<Select
|
|
557
|
+
value={value}
|
|
558
|
+
onValueChange={setValue}
|
|
559
|
+
>
|
|
560
|
+
<Select.Trigger>
|
|
561
|
+
<Select.Value />
|
|
562
|
+
</Select.Trigger>
|
|
563
|
+
|
|
564
|
+
<Select.Content>
|
|
565
|
+
<Select.Item value="react">React</Select.Item>
|
|
566
|
+
<Select.Item value="vue">Vue</Select.Item>
|
|
567
|
+
<Select.Item value="svelte">Svelte</Select.Item>
|
|
568
|
+
</Select.Content>
|
|
569
|
+
</Select>
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
---
|
|
573
|
+
|
|
574
|
+
## Uncontrolled
|
|
575
|
+
|
|
576
|
+
```tsx
|
|
577
|
+
<Select defaultValue="react">
|
|
578
|
+
<Select.Trigger>
|
|
579
|
+
<Select.Value />
|
|
580
|
+
</Select.Trigger>
|
|
581
|
+
|
|
582
|
+
<Select.Content>
|
|
583
|
+
<Select.Item value="react">React</Select.Item>
|
|
584
|
+
<Select.Item value="vue">Vue</Select.Item>
|
|
585
|
+
<Select.Item value="angular">Angular</Select.Item>
|
|
586
|
+
</Select.Content>
|
|
587
|
+
</Select>
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
---
|
|
591
|
+
|
|
592
|
+
## Placeholder
|
|
593
|
+
|
|
594
|
+
```tsx
|
|
595
|
+
<Select placeholder="Choose an option">
|
|
596
|
+
<Select.Trigger>
|
|
597
|
+
<Select.Value />
|
|
598
|
+
</Select.Trigger>
|
|
599
|
+
|
|
600
|
+
<Select.Content>
|
|
601
|
+
...
|
|
602
|
+
</Select.Content>
|
|
603
|
+
</Select>
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
---
|
|
607
|
+
|
|
608
|
+
## Clearable
|
|
609
|
+
|
|
610
|
+
```tsx
|
|
611
|
+
<Select clearable defaultValue="react">
|
|
612
|
+
<Select.Trigger>
|
|
613
|
+
<Select.Value />
|
|
614
|
+
</Select.Trigger>
|
|
615
|
+
|
|
616
|
+
<Select.Content>
|
|
617
|
+
...
|
|
618
|
+
</Select.Content>
|
|
619
|
+
</Select>
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
## Disabled
|
|
625
|
+
|
|
626
|
+
```tsx
|
|
627
|
+
<Select disabled>
|
|
628
|
+
<Select.Trigger>
|
|
629
|
+
<Select.Value />
|
|
630
|
+
</Select.Trigger>
|
|
631
|
+
|
|
632
|
+
<Select.Content>
|
|
633
|
+
...
|
|
634
|
+
</Select.Content>
|
|
635
|
+
</Select>
|
|
636
|
+
```
|
|
637
|
+
|
|
638
|
+
---
|
|
639
|
+
|
|
640
|
+
## Validation States
|
|
641
|
+
|
|
642
|
+
### Error
|
|
643
|
+
|
|
644
|
+
```tsx
|
|
645
|
+
<Select error>
|
|
646
|
+
...
|
|
647
|
+
</Select>
|
|
648
|
+
```
|
|
649
|
+
|
|
650
|
+
### Success
|
|
651
|
+
|
|
652
|
+
```tsx
|
|
653
|
+
<Select success>
|
|
654
|
+
...
|
|
655
|
+
</Select>
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
When used inside a `FormField`, the validation state is inherited automatically.
|
|
659
|
+
|
|
660
|
+
```tsx
|
|
661
|
+
<FormField invalid>
|
|
662
|
+
<Select>
|
|
663
|
+
...
|
|
664
|
+
</Select>
|
|
665
|
+
</FormField>
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
Explicit `error` always takes precedence over inherited state.
|
|
669
|
+
|
|
670
|
+
---
|
|
671
|
+
|
|
672
|
+
## Variants
|
|
673
|
+
|
|
674
|
+
```tsx
|
|
675
|
+
<Select variant="outline" />
|
|
676
|
+
<Select variant="filled" />
|
|
677
|
+
<Select variant="ghost" />
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
---
|
|
681
|
+
|
|
682
|
+
## Sizes
|
|
683
|
+
|
|
684
|
+
```tsx
|
|
685
|
+
<Select size="sm" />
|
|
686
|
+
<Select size="md" />
|
|
687
|
+
<Select size="lg" />
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
---
|
|
691
|
+
|
|
692
|
+
## Option Groups
|
|
693
|
+
|
|
694
|
+
```tsx
|
|
695
|
+
<Select>
|
|
696
|
+
<Select.Trigger>
|
|
697
|
+
<Select.Value />
|
|
698
|
+
</Select.Trigger>
|
|
699
|
+
|
|
700
|
+
<Select.Content>
|
|
701
|
+
<Select.Group>
|
|
702
|
+
<Select.Label>Frontend</Select.Label>
|
|
703
|
+
|
|
704
|
+
<Select.Item value="react">
|
|
705
|
+
React
|
|
706
|
+
</Select.Item>
|
|
707
|
+
|
|
708
|
+
<Select.Item value="vue">
|
|
709
|
+
Vue
|
|
710
|
+
</Select.Item>
|
|
711
|
+
</Select.Group>
|
|
712
|
+
|
|
713
|
+
<Select.Group>
|
|
714
|
+
<Select.Label>Backend</Select.Label>
|
|
715
|
+
|
|
716
|
+
<Select.Item value="node">
|
|
717
|
+
Node.js
|
|
718
|
+
</Select.Item>
|
|
719
|
+
|
|
720
|
+
<Select.Item value="go">
|
|
721
|
+
Go
|
|
722
|
+
</Select.Item>
|
|
723
|
+
</Select.Group>
|
|
724
|
+
</Select.Content>
|
|
725
|
+
</Select>
|
|
726
|
+
```
|
|
727
|
+
|
|
728
|
+
---
|
|
729
|
+
|
|
730
|
+
## Form Integration
|
|
731
|
+
|
|
732
|
+
Works with native HTML forms.
|
|
733
|
+
|
|
734
|
+
```tsx
|
|
735
|
+
<Select
|
|
736
|
+
name="framework"
|
|
737
|
+
defaultValue="react"
|
|
738
|
+
>
|
|
739
|
+
...
|
|
740
|
+
</Select>
|
|
741
|
+
```
|
|
742
|
+
|
|
743
|
+
A hidden input is rendered automatically.
|
|
744
|
+
|
|
745
|
+
---
|
|
746
|
+
|
|
747
|
+
## React Hook Form
|
|
748
|
+
|
|
749
|
+
```tsx
|
|
750
|
+
<Controller
|
|
751
|
+
control={control}
|
|
752
|
+
name="framework"
|
|
753
|
+
render={({ field }) => (
|
|
754
|
+
<Select
|
|
755
|
+
value={field.value}
|
|
756
|
+
onValueChange={field.onChange}
|
|
757
|
+
>
|
|
758
|
+
<Select.Trigger>
|
|
759
|
+
<Select.Value />
|
|
760
|
+
</Select.Trigger>
|
|
761
|
+
|
|
762
|
+
<Select.Content>
|
|
763
|
+
...
|
|
764
|
+
</Select.Content>
|
|
765
|
+
</Select>
|
|
766
|
+
)}
|
|
767
|
+
/>
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
---
|
|
771
|
+
|
|
772
|
+
## Keyboard Support
|
|
773
|
+
|
|
774
|
+
| Key | Action |
|
|
775
|
+
|------|--------|
|
|
776
|
+
| β | Previous option |
|
|
777
|
+
| β | Next option |
|
|
778
|
+
| Enter | Select highlighted option |
|
|
779
|
+
| Space | Open / Select option |
|
|
780
|
+
| Home | First option |
|
|
781
|
+
| End | Last option |
|
|
782
|
+
| Esc | Close dropdown |
|
|
783
|
+
| Backspace | Clear selection (when `clearable`) |
|
|
784
|
+
| Delete | Clear selection (when `clearable`) |
|
|
785
|
+
|
|
786
|
+
---
|
|
787
|
+
|
|
788
|
+
# API
|
|
789
|
+
|
|
790
|
+
## Select
|
|
791
|
+
|
|
792
|
+
| Prop | Type | Default | Description |
|
|
793
|
+
|------|------|---------|-------------|
|
|
794
|
+
| value | string | β | Controlled value |
|
|
795
|
+
| defaultValue | string | β | Initial value |
|
|
796
|
+
| onValueChange | `(value?: string) => void` | β | Called when value changes |
|
|
797
|
+
| placeholder | string | β | Placeholder text |
|
|
798
|
+
| clearable | boolean | false | Allows clearing the selection |
|
|
799
|
+
| disabled | boolean | false | Disables the component |
|
|
800
|
+
| required | boolean | false | Marks the field as required |
|
|
801
|
+
| name | string | β | Hidden input name |
|
|
802
|
+
| variant | Variant | `"outline"` | Visual style |
|
|
803
|
+
| size | Size | `"md"` | Component size |
|
|
804
|
+
| error | boolean | false | Shows error state |
|
|
805
|
+
| success | boolean | false | Shows success state |
|
|
806
|
+
| className | string | β | Additional classes |
|
|
807
|
+
|
|
808
|
+
---
|
|
809
|
+
|
|
810
|
+
## Select.Trigger
|
|
811
|
+
|
|
812
|
+
The interactive trigger that opens the dropdown.
|
|
813
|
+
|
|
814
|
+
---
|
|
815
|
+
|
|
816
|
+
## Select.Value
|
|
817
|
+
|
|
818
|
+
Displays the selected option or placeholder.
|
|
819
|
+
|
|
820
|
+
---
|
|
821
|
+
|
|
822
|
+
## Select.Content
|
|
823
|
+
|
|
824
|
+
Container for dropdown items.
|
|
825
|
+
|
|
826
|
+
---
|
|
827
|
+
|
|
828
|
+
## Select.Item
|
|
829
|
+
|
|
830
|
+
| Prop | Type | Description |
|
|
831
|
+
|------|------|-------------|
|
|
832
|
+
| value | string | Item value |
|
|
833
|
+
| disabled | boolean | Disables the option |
|
|
834
|
+
|
|
835
|
+
---
|
|
836
|
+
|
|
837
|
+
## Select.Group
|
|
838
|
+
|
|
839
|
+
Groups related options.
|
|
840
|
+
|
|
841
|
+
---
|
|
842
|
+
|
|
843
|
+
## Select.Label
|
|
844
|
+
|
|
845
|
+
Heading for a group of options.
|
|
846
|
+
|
|
847
|
+
---
|
|
848
|
+
|
|
849
|
+
## Accessibility
|
|
850
|
+
|
|
851
|
+
- Uses the WAI-ARIA Combobox pattern
|
|
852
|
+
- Supports screen readers
|
|
853
|
+
- Keyboard accessible
|
|
854
|
+
- Focus management
|
|
855
|
+
- Proper ARIA attributes
|
|
856
|
+
- Native form submission support
|
|
857
|
+
|
|
858
|
+
---
|
|
859
|
+
|
|
860
|
+
## Component Structure
|
|
861
|
+
|
|
862
|
+
```tsx
|
|
863
|
+
<Select>
|
|
864
|
+
<Select.Trigger>
|
|
865
|
+
<Select.Value />
|
|
866
|
+
</Select.Trigger>
|
|
867
|
+
|
|
868
|
+
<Select.Content>
|
|
869
|
+
<Select.Group>
|
|
870
|
+
<Select.Label />
|
|
871
|
+
<Select.Item />
|
|
872
|
+
</Select.Group>
|
|
873
|
+
</Select.Content>
|
|
874
|
+
</Select>
|
|
875
|
+
```
|
|
876
|
+
|
|
877
|
+
---
|
|
878
|
+
|
|
879
|
+
## Textarea
|
|
880
|
+
|
|
881
|
+
A flexible textarea with variant, size, autoβresize, character counter, validation, clearable, and `FormField` integration.
|
|
882
|
+
|
|
883
|
+
### Basic Usage
|
|
884
|
+
|
|
885
|
+
```tsx
|
|
886
|
+
import { Textarea } from "kreativ-ui";
|
|
887
|
+
|
|
888
|
+
<Textarea placeholder="Write a message..." />
|
|
889
|
+
```
|
|
890
|
+
|
|
891
|
+
### Variants
|
|
892
|
+
|
|
893
|
+
The `variant` prop controls the visual style of the textarea wrapper.
|
|
894
|
+
|
|
895
|
+
```tsx
|
|
896
|
+
<Textarea variant="outline" />
|
|
897
|
+
<Textarea variant="filled" />
|
|
898
|
+
<Textarea variant="ghost" />
|
|
899
|
+
```
|
|
900
|
+
|
|
901
|
+
### Sizes
|
|
902
|
+
|
|
903
|
+
```tsx
|
|
904
|
+
<Textarea size="sm" />
|
|
905
|
+
<Textarea size="md" />
|
|
906
|
+
<Textarea size="lg" />
|
|
907
|
+
```
|
|
908
|
+
|
|
909
|
+
### Resize Behavior
|
|
910
|
+
|
|
911
|
+
```tsx
|
|
912
|
+
<Textarea resize="both" />
|
|
913
|
+
<Textarea resize="none" />
|
|
914
|
+
<Textarea resize="horizontal" />
|
|
915
|
+
<Textarea resize="vertical" /> // default
|
|
916
|
+
```
|
|
917
|
+
|
|
918
|
+
### Auto Resize
|
|
919
|
+
|
|
920
|
+
```tsx
|
|
921
|
+
<Textarea autoResize minRows={2} maxRows={6} />
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
### Character Counter
|
|
925
|
+
|
|
926
|
+
```tsx
|
|
927
|
+
<Textarea characterCounter maxLength={200} />
|
|
928
|
+
```
|
|
929
|
+
|
|
930
|
+
### Clearable
|
|
931
|
+
|
|
932
|
+
```tsx
|
|
933
|
+
<Textarea clearable onClear={() => console.log("cleared")} />
|
|
934
|
+
```
|
|
935
|
+
|
|
936
|
+
### Validation
|
|
937
|
+
|
|
938
|
+
```tsx
|
|
939
|
+
<Textarea
|
|
940
|
+
onValidate={(value) => value.length >= 3 || "Must be at least 3 characters"}
|
|
941
|
+
/>
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
### Trim on Blur
|
|
945
|
+
|
|
946
|
+
```tsx
|
|
947
|
+
<Textarea trimOnBlur />
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
### With FormField
|
|
951
|
+
|
|
952
|
+
```tsx
|
|
953
|
+
<FormField label="Message" required>
|
|
954
|
+
<FormField.Control>
|
|
955
|
+
<Textarea
|
|
956
|
+
placeholder="Your message..."
|
|
957
|
+
characterCounter
|
|
958
|
+
maxLength={500}
|
|
959
|
+
/>
|
|
960
|
+
</FormField.Control>
|
|
961
|
+
</FormField>
|
|
962
|
+
```
|
|
963
|
+
|
|
964
|
+
### Props (Textarea)
|
|
965
|
+
|
|
966
|
+
| Prop | Type | Default | Description |
|
|
967
|
+
|------|------|---------|-------------|
|
|
968
|
+
| `variant` | InputVariant | `"outline"` | Visual style of the wrapper |
|
|
969
|
+
| `size` | InputSize | `"md"` | Height, padding, font size |
|
|
970
|
+
| `fullWidth` | `boolean` | `true` | Stretch to container width |
|
|
971
|
+
| `resize` | `"none" \| "both" \| "horizontal" \| "vertical"` | `"vertical"` | CSS `resize` behavior |
|
|
972
|
+
| `autoResize` | `boolean` | `false` | Automatically grow/shrink with content |
|
|
973
|
+
| `minRows` | `number` | β | Minimum rows (when `autoResize` is `true`) |
|
|
974
|
+
| `maxRows` | `number` | β | Maximum rows (when `autoResize` is `true`) |
|
|
975
|
+
| `clearable` | `boolean` | `false` | Shows a clear button when value is present |
|
|
976
|
+
| `onClear` | `() => void` | β | Called after clear |
|
|
977
|
+
| `characterCounter` | `boolean` | `false` | Shows character count and optional `maxLength` |
|
|
978
|
+
| `trimOnBlur` | `boolean` | `false` | Trim whitespace on blur |
|
|
979
|
+
| `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
|
|
980
|
+
| `success` | `boolean` | `false` | Success styling |
|
|
981
|
+
| `disabled` | `boolean` | `false` | Disables the textarea |
|
|
982
|
+
| `required` | `boolean` | `false` | Marks as required and sets `aria-required` |
|
|
983
|
+
| `onValidate` | `(value: string) => boolean \| string` | β | Custom validation, returns `true` (valid), `false` (invalid), or a string (error message) |
|
|
984
|
+
| `value` / `defaultValue` | `string` | β | Controlled / uncontrolled value |
|
|
985
|
+
| `onChange` / `onBlur` | `(event) => void` | β | Standard event handlers |
|
|
986
|
+
|
|
987
|
+
```
|
|
988
|
+
All standard `<textarea>` attributes (except `size`) are forwarded.
|
|
989
|
+
|
|
990
|
+
```
|
|
991
|
+
|
|
992
|
+
---
|
|
993
|
+
|
|
994
|
+
### Updated README (Checkbox section only β dropβin)
|
|
995
|
+
|
|
996
|
+
```markdown
|
|
997
|
+
## Checkbox
|
|
998
|
+
|
|
999
|
+
A customizable checkbox with label, description, validation states, and support for indeterminate state. Works seamlessly with `FormField` for automatic ARIA wiring.
|
|
1000
|
+
|
|
1001
|
+
### Basic Usage
|
|
1002
|
+
|
|
1003
|
+
```tsx
|
|
1004
|
+
import { Checkbox } from "kreativ-ui";
|
|
1005
|
+
|
|
1006
|
+
<Checkbox label="Accept terms" />
|
|
1007
|
+
```
|
|
1008
|
+
|
|
1009
|
+
### Sizes
|
|
1010
|
+
|
|
1011
|
+
```tsx
|
|
1012
|
+
<Checkbox size="sm" />
|
|
1013
|
+
<Checkbox size="md" />
|
|
1014
|
+
<Checkbox size="lg" />
|
|
1015
|
+
```
|
|
1016
|
+
|
|
1017
|
+
### Validation States
|
|
1018
|
+
|
|
1019
|
+
```tsx
|
|
1020
|
+
<Checkbox error />
|
|
1021
|
+
<Checkbox success />
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
### Indeterminate
|
|
1025
|
+
|
|
1026
|
+
```tsx
|
|
1027
|
+
<Checkbox indeterminate />
|
|
1028
|
+
```
|
|
1029
|
+
|
|
1030
|
+
### With Description
|
|
1031
|
+
|
|
1032
|
+
```tsx
|
|
1033
|
+
<Checkbox
|
|
1034
|
+
label="Accept terms"
|
|
1035
|
+
description="You must agree to continue."
|
|
1036
|
+
/>
|
|
1037
|
+
```
|
|
1038
|
+
|
|
1039
|
+
### Disabled & Required
|
|
1040
|
+
|
|
1041
|
+
```tsx
|
|
1042
|
+
<Checkbox disabled required />
|
|
1043
|
+
```
|
|
1044
|
+
|
|
1045
|
+
### With FormField
|
|
1046
|
+
|
|
1047
|
+
```tsx
|
|
1048
|
+
<FormField error="This field is required" required>
|
|
1049
|
+
<Checkbox label="I agree to the terms" />
|
|
1050
|
+
</FormField>
|
|
1051
|
+
```
|
|
1052
|
+
|
|
1053
|
+
### Props
|
|
1054
|
+
|
|
1055
|
+
| Prop | Type | Default | Description |
|
|
1056
|
+
|------|------|---------|-------------|
|
|
1057
|
+
| `checked` | `boolean` | β | Controlled checked state |
|
|
1058
|
+
| `defaultChecked` | `boolean` | `false` | Uncontrolled initial state |
|
|
1059
|
+
| `onCheckedChange` | `(checked: boolean) => void` | β | Callback when checked state changes |
|
|
1060
|
+
| `indeterminate` | `boolean` | `false` | Visually indeterminate state (parent checkbox) |
|
|
1061
|
+
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size of the box |
|
|
1062
|
+
| `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
|
|
1063
|
+
| `success` | `boolean` | `false` | Success styling |
|
|
1064
|
+
| `disabled` | `boolean` | `false` | Disables the checkbox |
|
|
1065
|
+
| `required` | `boolean` | `false` | Sets `aria-required` |
|
|
1066
|
+
| `label` | `ReactNode` | β | Label text or element (wired to input via `htmlFor`) |
|
|
1067
|
+
| `description` | `ReactNode` | β | Help text, wired via `aria-describedby` |
|
|
1068
|
+
| `className` | `string` | β | Additional wrapper class |
|
|
1069
|
+
|
|
1070
|
+
All standard `<input type="checkbox">` attributes (except `type`, `size`, `checked`, `defaultChecked`) are forwarded.
|
|
1071
|
+
|
|
1072
|
+
---
|
|
1073
|
+
|
|
1074
|
+
## RadioGroup & Radio
|
|
1075
|
+
|
|
1076
|
+
A controlled group of radio buttons with labels, descriptions, validation states, and support for horizontal/vertical orientation. `RadioGroup` manages the selected value and shared props; `Radio` items are its children.
|
|
1077
|
+
|
|
1078
|
+
### Basic Usage
|
|
1079
|
+
|
|
1080
|
+
```tsx
|
|
1081
|
+
import { RadioGroup, Radio } from "kreativ-ui";
|
|
1082
|
+
|
|
1083
|
+
function App() {
|
|
1084
|
+
const [value, setValue] = useState("option1");
|
|
1085
|
+
|
|
1086
|
+
return (
|
|
1087
|
+
<RadioGroup value={value} onValueChange={setValue}>
|
|
1088
|
+
<Radio value="option1" label="Option 1" />
|
|
1089
|
+
<Radio value="option2" label="Option 2" />
|
|
1090
|
+
<Radio value="option3" label="Option 3" />
|
|
1091
|
+
</RadioGroup>
|
|
1092
|
+
);
|
|
1093
|
+
}
|
|
1094
|
+
```
|
|
1095
|
+
|
|
1096
|
+
### With Descriptions
|
|
1097
|
+
|
|
1098
|
+
```tsx
|
|
1099
|
+
<RadioGroup value={value} onValueChange={setValue}>
|
|
1100
|
+
<Radio value="option1" label="Option 1" description="First choice" />
|
|
1101
|
+
<Radio value="option2" label="Option 2" description="Second choice" />
|
|
1102
|
+
</RadioGroup>
|
|
1103
|
+
```
|
|
1104
|
+
|
|
1105
|
+
### Sizes
|
|
1106
|
+
|
|
1107
|
+
```tsx
|
|
1108
|
+
<RadioGroup size="sm">...</RadioGroup>
|
|
1109
|
+
<RadioGroup size="md">...</RadioGroup>
|
|
1110
|
+
<RadioGroup size="lg">...</RadioGroup>
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
### Orientation
|
|
1114
|
+
|
|
1115
|
+
```tsx
|
|
1116
|
+
<RadioGroup orientation="horizontal">
|
|
1117
|
+
<Radio value="opt1" label="Option 1" />
|
|
1118
|
+
<Radio value="opt2" label="Option 2" />
|
|
1119
|
+
</RadioGroup>
|
|
1120
|
+
```
|
|
1121
|
+
|
|
1122
|
+
### Validation States
|
|
1123
|
+
|
|
1124
|
+
```tsx
|
|
1125
|
+
<RadioGroup error>...</RadioGroup>
|
|
1126
|
+
<RadioGroup success>...</RadioGroup>
|
|
1127
|
+
```
|
|
1128
|
+
|
|
1129
|
+
### Disabled & Required
|
|
1130
|
+
|
|
1131
|
+
```tsx
|
|
1132
|
+
<RadioGroup disabled required>...</RadioGroup>
|
|
1133
|
+
```
|
|
1134
|
+
|
|
1135
|
+
### With FormField
|
|
1136
|
+
|
|
1137
|
+
```tsx
|
|
1138
|
+
<FormField label="Choose your preference" error="Please select an option" required>
|
|
1139
|
+
<RadioGroup value={value} onValueChange={setValue}>
|
|
1140
|
+
<Radio value="opt1" label="Option 1" />
|
|
1141
|
+
<Radio value="opt2" label="Option 2" />
|
|
1142
|
+
</RadioGroup>
|
|
1143
|
+
</FormField>
|
|
1144
|
+
```
|
|
1145
|
+
|
|
1146
|
+
### Individual Radio Disabling
|
|
1147
|
+
|
|
1148
|
+
You can also disable individual radios via the `disabled` prop on `Radio`, which overrides the groupβs `disabled` state for that item.
|
|
1149
|
+
|
|
1150
|
+
```tsx
|
|
1151
|
+
<RadioGroup disabled={false}>
|
|
1152
|
+
<Radio value="opt1" label="Enabled" />
|
|
1153
|
+
<Radio value="opt2" label="Disabled" disabled />
|
|
1154
|
+
</RadioGroup>
|
|
1155
|
+
```
|
|
1156
|
+
|
|
1157
|
+
### Props (RadioGroup)
|
|
1158
|
+
|
|
1159
|
+
| Prop | Type | Default | Description |
|
|
1160
|
+
|------|------|---------|-------------|
|
|
1161
|
+
| `value` | `string` | β | Controlled selected value |
|
|
1162
|
+
| `defaultValue` | `string` | β | Uncontrolled initial value |
|
|
1163
|
+
| `onValueChange` | `(value: string) => void` | β | Callback when selection changes |
|
|
1164
|
+
| `name` | `string` | autoβgenerated | Shared `name` for all radio inputs |
|
|
1165
|
+
| `disabled` | `boolean` | `false` | Disables all radios in the group |
|
|
1166
|
+
| `required` | `boolean` | `false` | Sets `aria-required` on the group |
|
|
1167
|
+
| `orientation` | `"horizontal" \| "vertical"` | `"vertical"` | Layout direction |
|
|
1168
|
+
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size of all radio bubbles |
|
|
1169
|
+
| `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
|
|
1170
|
+
| `success` | `boolean` | `false` | Success styling |
|
|
1171
|
+
| `className` | `string` | β | Additional wrapper class |
|
|
1172
|
+
| `children` | `ReactNode` | β | `Radio` components |
|
|
1173
|
+
|
|
1174
|
+
### Props (Radio)
|
|
1175
|
+
|
|
1176
|
+
| Prop | Type | Default | Description |
|
|
1177
|
+
|------|------|---------|-------------|
|
|
1178
|
+
| `value` | `string` | **required** | Unique value for this option |
|
|
1179
|
+
| `disabled` | `boolean` | `false` | Disables this specific radio |
|
|
1180
|
+
| `label` | `ReactNode` | β | Label text or element |
|
|
1181
|
+
| `description` | `ReactNode` | β | Help text, wired via `aria-describedby` |
|
|
1182
|
+
| `className` | `string` | β | Additional wrapper class |
|
|
1183
|
+
|
|
1184
|
+
All standard `<input type="radio">` attributes (except `type`, `size`, `checked`, `defaultChecked`, `onChange`, `name`, `value`) are forwarded to the underlying `<input>`.
|
|
1185
|
+
```
|
|
1186
|
+
|
|
1187
|
+
---
|
|
1188
|
+
|
|
1189
|
+
### Updated Roadmap (Form section)
|
|
1190
|
+
|
|
1191
|
+
```markdown
|
|
1192
|
+
## Form
|
|
1193
|
+
- β
Input (with kind, clearable, loading, adornments)
|
|
1194
|
+
- β
Select (compound, groups, clearable)
|
|
1195
|
+
- β
Textarea (autoβresize, counter, validation)
|
|
1196
|
+
- β
Checkbox (indeterminate, label, description)
|
|
1197
|
+
- β
RadioGroup (horizontal/vertical, validation)
|
|
1198
|
+
- β
FormField (automatic ARIA wiring)
|
|
1199
|
+
- β³ Switch
|
|
1200
|
+
- β³ Slider
|
|
1201
|
+
- β³ Combobox
|
|
1202
|
+
```
|
|
1203
|
+
|
|
1204
|
+
---
|
|
1205
|
+
|
|
1206
|
+
# Built-in Animations
|
|
1207
|
+
|
|
1208
|
+
Kreativ UI includes Tailwindβcompatible animation utilities.
|
|
1209
|
+
|
|
1210
|
+
```tsx
|
|
1211
|
+
<div className="animate-kui-fade-in" />
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
### Available Animations
|
|
1215
|
+
|
|
1216
|
+
```
|
|
1217
|
+
animate-kui-spin
|
|
1218
|
+
animate-kui-pulse
|
|
1219
|
+
animate-kui-ping
|
|
1220
|
+
animate-kui-bounce
|
|
1221
|
+
|
|
1222
|
+
animate-kui-fade-in
|
|
1223
|
+
animate-kui-fade-out
|
|
1224
|
+
|
|
1225
|
+
animate-kui-scale-in
|
|
1226
|
+
animate-kui-scale-out
|
|
1227
|
+
|
|
1228
|
+
animate-kui-slide-up
|
|
1229
|
+
animate-kui-slide-down
|
|
1230
|
+
animate-kui-slide-left
|
|
1231
|
+
animate-kui-slide-right
|
|
1232
|
+
|
|
1233
|
+
animate-kui-shake
|
|
1234
|
+
|
|
1235
|
+
animate-kui-expand
|
|
1236
|
+
animate-kui-collapse
|
|
1237
|
+
|
|
1238
|
+
animate-kui-shimmer
|
|
1239
|
+
```
|
|
1240
|
+
|
|
1241
|
+
---
|
|
1242
|
+
|
|
1243
|
+
# Project Structure
|
|
1244
|
+
|
|
1245
|
+
```
|
|
1246
|
+
src/
|
|
1247
|
+
β
|
|
1248
|
+
βββ components/
|
|
1249
|
+
β βββ Button/
|
|
1250
|
+
β β βββ Button.tsx
|
|
1251
|
+
β β βββ Button.styles.ts
|
|
1252
|
+
β β βββ Button.types.ts
|
|
1253
|
+
β β βββ index.ts
|
|
1254
|
+
β βββ Input/
|
|
1255
|
+
β β βββ ...
|
|
1256
|
+
β βββ FormField/
|
|
1257
|
+
β β βββ ...
|
|
1258
|
+
β βββ ThemeToggler/
|
|
1259
|
+
β βββ ...
|
|
1260
|
+
β
|
|
1261
|
+
βββ context/ (UIProvider, ThemeContext)
|
|
1262
|
+
βββ hooks/ (useTheme, useSizeStyle)
|
|
1263
|
+
βββ styles/ (base CSS, animation utilities)
|
|
1264
|
+
βββ theme/ (default tokens, color schemas)
|
|
1265
|
+
βββ types/ (shared types: Size, Variant, etc.)
|
|
1266
|
+
βββ utils/ (cn, merge, etc.)
|
|
1267
|
+
β
|
|
1268
|
+
βββ index.ts
|
|
1269
|
+
```
|
|
1270
|
+
|
|
1271
|
+
---
|
|
1272
|
+
|
|
1273
|
+
# Creating a New Component
|
|
1274
|
+
|
|
1275
|
+
Every component follows the same pattern:
|
|
1276
|
+
|
|
1277
|
+
```
|
|
1278
|
+
Component/
|
|
1279
|
+
βββ Component.tsx
|
|
1280
|
+
βββ Component.styles.ts
|
|
1281
|
+
βββ Component.types.ts
|
|
1282
|
+
βββ index.ts
|
|
1283
|
+
```
|
|
1284
|
+
|
|
1285
|
+
Guidelines:
|
|
1286
|
+
|
|
1287
|
+
1. **Types** β Define props and style maps in `*.types.ts`.
|
|
1288
|
+
2. **Styles** β Define reusable `cn` style maps in `*.styles.ts`.
|
|
1289
|
+
3. **Component** β Use `useTheme()` to merge component overrides. Merge styles with `cn()`.
|
|
1290
|
+
4. **Exports** β Export the component and its types from `index.ts`.
|
|
1291
|
+
|
|
1292
|
+
---
|
|
1293
|
+
|
|
1294
|
+
# Development
|
|
1295
|
+
|
|
1296
|
+
```bash
|
|
1297
|
+
npm install # install dependencies
|
|
1298
|
+
npm run dev # start playground (Vite)
|
|
1299
|
+
npm run build # build the library
|
|
1300
|
+
npm run typecheck # run TypeScript type checking
|
|
1301
|
+
```
|
|
1302
|
+
|
|
1303
|
+
---
|
|
1304
|
+
|
|
1305
|
+
# Publishing
|
|
1306
|
+
|
|
1307
|
+
```bash
|
|
1308
|
+
npm version patch # or minor/major
|
|
1309
|
+
npm run build
|
|
1310
|
+
npm publish
|
|
1311
|
+
```
|
|
1312
|
+
|
|
1313
|
+
---
|
|
1314
|
+
|
|
1315
|
+
# Roadmap
|
|
1316
|
+
|
|
1317
|
+
## Core
|
|
1318
|
+
- β
Runtime theme engine
|
|
1319
|
+
- β
CSS variable tokens
|
|
1320
|
+
- β
Light / Dark / System modes
|
|
1321
|
+
- β
Tailwind v4 integration
|
|
1322
|
+
- β
Animation utilities
|
|
1323
|
+
- β
ThemeToggler with transitions
|
|
1324
|
+
|
|
1325
|
+
## Form
|
|
1326
|
+
- β
Input (with kind, clearable, loading, adornments)
|
|
1327
|
+
- β
FormField (automatic ARIA wiring)
|
|
1328
|
+
- β³ Textarea
|
|
1329
|
+
- β³ Select
|
|
1330
|
+
- β³ Checkbox
|
|
1331
|
+
- β³ Radio
|
|
1332
|
+
- β³ Switch
|
|
1333
|
+
- β³ Slider
|
|
1334
|
+
- β³ Combobox
|
|
1335
|
+
|
|
1336
|
+
## Feedback
|
|
1337
|
+
- β³ Alert
|
|
1338
|
+
- β³ Toast
|
|
1339
|
+
- β³ Progress
|
|
1340
|
+
- β³ Spinner
|
|
1341
|
+
- β³ Skeleton
|
|
1342
|
+
|
|
1343
|
+
## Data Display
|
|
1344
|
+
- β³ Badge
|
|
1345
|
+
- β³ Avatar
|
|
1346
|
+
- β³ Card
|
|
1347
|
+
- β³ Table
|
|
1348
|
+
- β³ Data Grid
|
|
1349
|
+
|
|
1350
|
+
## Navigation
|
|
1351
|
+
- β³ Tabs
|
|
1352
|
+
- β³ Accordion
|
|
1353
|
+
- β³ Breadcrumb
|
|
1354
|
+
- β³ Pagination
|
|
1355
|
+
|
|
1356
|
+
## Overlay
|
|
1357
|
+
- β³ Dialog
|
|
1358
|
+
- β³ Drawer
|
|
1359
|
+
- β³ Popover
|
|
1360
|
+
- β³ Tooltip
|
|
1361
|
+
- β³ Dropdown Menu
|
|
1362
|
+
|
|
1363
|
+
---
|
|
1364
|
+
|
|
1365
|
+
Happy building with **Kreativ UI**! π¨β¨
|