@splenddev/kreativ-ui 0.1.0 → 0.2.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 CHANGED
@@ -1,1365 +1,1133 @@
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**! 🎨✨
1
+ # Kreativ UI
2
+
3
+ A modern, themeable React component library built with **React**, **TypeScript**, **Tailwind CSS v4**, and **CSS Variables**.
4
+ Kreativ UI provides a runtime theme engine that lets you customize colors, typography, radius, sizes, and component styles **without rebuilding CSS**.
5
+
6
+ ---
7
+
8
+ ## ✨ Features
9
+
10
+ - Runtime theme switching (`light`, `dark`, `system`)
11
+ - Built‑in `ThemeToggler` with optional animated transitions
12
+ - CSS‑variable‑driven design tokens
13
+ - Primitive + semantic token architecture
14
+ - Component‑level theme overrides
15
+ - Fully accessible (ARIA, keyboard navigation, focus management)
16
+ - TypeScript‑first and tree‑shakable
17
+
18
+ ---
19
+
20
+ ## 📦 Installation
21
+
22
+ ```bash
23
+ npm install @splenddev/kreativ-ui
24
+ ```
25
+
26
+ Import the stylesheet **once** in your application entry:
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:
37
+
38
+ ```tsx
39
+ import { UIProvider, Button } from "@splenddev/kreativ-ui";
40
+ import "@splenddev/kreativ-ui/styles.css";
41
+
42
+ export default function App() {
43
+ return (
44
+ <UIProvider defaultMode="system">
45
+ <Button>Click me</Button>
46
+ </UIProvider>
47
+ );
48
+ }
49
+ ```
50
+
51
+ ---
52
+
53
+ # ☀️ UIProvider
54
+
55
+ The `UIProvider` component provides the theme context and manages the active colour mode. It must wrap any part of your application that uses Kreativ UI components.
56
+
57
+ ### Modes
58
+
59
+ | Mode | Description |
60
+ | -------- | ---------------------------------------------- |
61
+ | `light` | Forces light mode |
62
+ | `dark` | Forces dark mode |
63
+ | `system` | Follows the user’s operating system preference |
64
+
65
+ ```tsx
66
+ <UIProvider defaultMode="system">
67
+ <App />
68
+ </UIProvider>
69
+ ```
70
+
71
+ ### useTheme
72
+
73
+ Access and change the current mode anywhere in your app:
74
+
75
+ ```tsx
76
+ import { useTheme } from "@splenddev/kreativ-ui";
77
+
78
+ function ThemeSwitcher() {
79
+ const { mode, setMode } = useTheme();
80
+
81
+ return (
82
+ <>
83
+ <button onClick={() => setMode("light")}>Light</button>
84
+ <button onClick={() => setMode("dark")}>Dark</button>
85
+ <button onClick={() => setMode("system")}>System</button>
86
+ </>
87
+ );
88
+ }
89
+ ```
90
+
91
+ ---
92
+
93
+ # 🎨 Theming
94
+
95
+ Kreativ UI’s theme system is built around two layers:
96
+
97
+ - **Primitive tokens** – raw values (colours, spacing, radii, fonts, etc.)
98
+ - **Semantic tokens** – role‑based values that adapt to light/dark modes
99
+
100
+ The library ships with a default theme. You can override any part of it using a `ThemeOverride` object.
101
+
102
+ ## Overriding the Theme
103
+
104
+ Pass a `theme` prop to `UIProvider`. Only the properties you provide will be merged with the default theme.
105
+
106
+ ```tsx
107
+ import { UIProvider } from "@splenddev/kreativ-ui";
108
+
109
+ const theme = {
110
+ semanticTokens: {
111
+ colors: {
112
+ brand: {
113
+ value: {
114
+ light: "16 128 224", // RGB channel values
115
+ dark: "71 153 235",
116
+ },
117
+ },
118
+ surface: {
119
+ value: {
120
+ light: "255 255 255",
121
+ dark: "15 23 42",
122
+ },
123
+ },
124
+ text: {
125
+ value: {
126
+ light: "15 23 42",
127
+ dark: "241 245 249",
128
+ },
129
+ },
130
+ },
131
+ },
132
+ };
133
+
134
+ <UIProvider theme={theme}>
135
+ <App />
136
+ </UIProvider>;
137
+ ```
138
+
139
+ ### Primitive vs Semantic Tokens
140
+
141
+ **Primitive tokens** are raw values:
142
+
143
+ ```ts
144
+ tokens.colors.blue.500 // → 59 130 246
145
+ tokens.colors.gray.900 // → 17 24 39
146
+ tokens.spacing.md // → 16px
147
+ ```
148
+
149
+ **Semantic tokens** describe UI meaning and can reference primitive tokens or direct values:
150
+
151
+ ```ts
152
+ semanticTokens.colors.brand = { value: { light: "{colors.blue.500}", dark: "{colors.blue.400}" } }
153
+ semanticTokens.colors.text = { value: { light: "{colors.gray.900}", dark: "{colors.gray.50}" } }
154
+ ```
155
+
156
+ The runtime engine resolves these references and applies the correct values based on the active colour mode.
157
+
158
+ ### Custom Component Sizes
159
+
160
+ You can extend the size system by adding custom size definitions. For example, to add an `xl` button size:
161
+
162
+ ```tsx
163
+ import { defaultTheme } from "@splenddev/kreativ-ui";
164
+
165
+ const theme = {
166
+ ...defaultTheme,
167
+ sizes: {
168
+ xl: {
169
+ height: "4.5rem",
170
+ paddingX: "2.5rem",
171
+ fontSize: "1.125rem",
172
+ gap: "0.75rem",
173
+ radius: "1rem",
174
+ iconSize: "1.5rem",
175
+ },
176
+ },
177
+ };
178
+
179
+ <UIProvider theme={theme}>
180
+ <Button size="xl">Extra Large</Button>
181
+ </UIProvider>;
182
+ ```
183
+
184
+ ---
185
+
186
+ # 🌗 ThemeToggler
187
+
188
+ A ready‑to‑use theme switcher that integrates with `UIProvider`.
189
+
190
+ ## Basic Usage
191
+
192
+ ```tsx
193
+ import { ThemeToggler } from "@splenddev/kreativ-ui";
194
+
195
+ <ThemeToggler />;
196
+ ```
197
+
198
+ ## With System Mode
199
+
200
+ ```tsx
201
+ <ThemeToggler allowSystem />
202
+ ```
203
+
204
+ ## Icon Only
205
+
206
+ ```tsx
207
+ <ThemeToggler iconOnly allowSystem />
208
+ ```
209
+
210
+ ## Custom Variants
211
+
212
+ ```tsx
213
+ <ThemeToggler variant="outline" activeVariant="solid" />
214
+ ```
215
+
216
+ ## Vertical Layout
217
+
218
+ ```tsx
219
+ <ThemeToggler orientation="vertical" allowSystem />
220
+ ```
221
+
222
+ ## Custom Labels & Icons
223
+
224
+ ```tsx
225
+ import { SunMedium, MoonStar, LaptopMinimal } from "lucide-react";
226
+
227
+ <ThemeToggler
228
+ allowSystem
229
+ labels={{ light: "Day", dark: "Night", system: "Auto" }}
230
+ icons={{
231
+ light: <SunMedium size={18} />,
232
+ dark: <MoonStar size={18} />,
233
+ system: <LaptopMinimal size={18} />,
234
+ }}
235
+ />;
236
+ ```
237
+
238
+ ## Cycle Mode with Animation
239
+
240
+ ```tsx
241
+ <ThemeToggler
242
+ display="cycle"
243
+ allowSystem
244
+ transition={{ type: "rotate", duration: 400, easing: "ease-in-out" }}
245
+ />
246
+ ```
247
+
248
+ Supported transition types: `none`, `fade`, `slide`, `scale`, `rotate`.
249
+
250
+ ## Props
251
+
252
+ | Prop | Type | Default | Description |
253
+ | --------------- | ----------------------------------------------------------------- | ------------------- | ------------------------------------------- |
254
+ | `variant` | `ThemeTogglerVariant` | `"ghost"` | Variant for inactive buttons |
255
+ | `activeVariant` | `ThemeTogglerVariant` | `"solid"` | Variant for active button |
256
+ | `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"sm"` | Button size |
257
+ | `iconOnly` | `boolean` | `false` | Hide labels, show only icons |
258
+ | `allowSystem` | `boolean` | `false` | Show system theme option |
259
+ | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Layout direction |
260
+ | `rounded` | `boolean` | `true` | Rounded container corners |
261
+ | `unstyled` | `boolean` | `false` | Remove wrapper styles |
262
+ | `display` | `"buttons" \| "cycle"` | `"buttons"` | Show all buttons or a single cycling button |
263
+ | `transition` | `{ type?: TransitionType; duration?: number; easing?: string }` | `{ type: "none" }` | Animation configuration for cycle mode |
264
+ | `labels` | `Partial<Record<"light" \| "dark" \| "system", string>>` | – | Override labels |
265
+ | `icons` | `Partial<Record<"light" \| "dark" \| "system", ReactNode>>` | – | Override icons |
266
+ | `buttonProps` | `Partial<ButtonProps>` | – | Props passed to every internal button |
267
+ | `className` | `string` | – | Additional wrapper class |
268
+
269
+ ---
270
+
271
+ # Button
272
+
273
+ A versatile button with support for variants, sizes, loading states, icons, and full‑width.
274
+
275
+ ## Basic Usage
276
+
277
+ ```tsx
278
+ <Button>Click me</Button>
279
+ ```
280
+
281
+ ## Variants
282
+
283
+ ```tsx
284
+ <Button variant="solid">Solid</Button>
285
+ <Button variant="outline">Outline</Button>
286
+ <Button variant="ghost">Ghost</Button>
287
+ <Button variant="soft">Soft</Button>
288
+ <Button variant="destructive">Delete</Button>
289
+ <Button variant="success">Success</Button>
290
+ <Button variant="link">Learn more</Button>
291
+ ```
292
+
293
+ ## Sizes
294
+
295
+ ```tsx
296
+ <Button size="xs">Extra Small</Button>
297
+ <Button size="sm">Small</Button>
298
+ <Button size="md">Medium</Button>
299
+ <Button size="lg">Large</Button>
300
+ <Button size="xl">Extra Large</Button>
301
+ ```
302
+
303
+ ## Loading State
304
+
305
+ ```tsx
306
+ <Button isLoading>Saving...</Button>
307
+ ```
308
+
309
+ ## Icons
310
+
311
+ ```tsx
312
+ <Button leftIcon={<SearchIcon />}>Search</Button>
313
+ <Button rightIcon={<ArrowRightIcon />}>Continue</Button>
314
+ ```
315
+
316
+ ## Icon Only
317
+
318
+ ```tsx
319
+ <Button iconOnly aria-label="Search">
320
+ <SearchIcon />
321
+ </Button>
322
+ ```
323
+
324
+ ## Full Width
325
+
326
+ ```tsx
327
+ <Button fullWidth>Continue</Button>
328
+ ```
329
+
330
+ ## Custom Sizes via Theme
331
+
332
+ Define additional sizes in the theme (as shown in the Theming section) and use them with `size` prop.
333
+
334
+ ## Props
335
+
336
+ | Prop | Type | Default | Description |
337
+ | ------------------------ | ------------------------------------------------------ | -------- | ------------------------------------------- |
338
+ | `variant` | `"solid" \| "outline" \| "ghost" \| "soft" \| "destructive" \| "success" \| "link"` | `"solid"` | Visual style |
339
+ | `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl" \| string` | `"md"` | Size (theme‑driven; custom strings allowed) |
340
+ | `isLoading` | `boolean` | `false` | Shows spinner and disables |
341
+ | `leftIcon` / `rightIcon` | `ReactNode` | – | Icon elements |
342
+ | `fullWidth` | `boolean` | `false` | Stretch to container width |
343
+ | `disabled` | `boolean` | `false` | Disables interactions |
344
+ | `iconOnly` | `boolean` | `false` | Remove padding for icon‑only layout |
345
+
346
+ All standard `<button>` props are forwarded.
347
+
348
+ ---
349
+
350
+ # 🧩 Input & FormField
351
+
352
+ This section covers the `Input` component and the `FormField` composition system for building accessible, validated form controls.
353
+
354
+ ---
355
+
356
+ ## Input
357
+
358
+ A flexible text input with support for variants, sizes, validation states, adornments, password visibility, clearing, and loading states.
359
+
360
+ ### Basic Usage
361
+
362
+ ```tsx
363
+ import { Input } from "@splenddev/kreativ-ui";
364
+
365
+ <Input placeholder="Enter your name" />
366
+ ```
367
+
368
+ ### Variants
369
+
370
+ ```tsx
371
+ <Input variant="outline" />
372
+ <Input variant="filled" />
373
+ <Input variant="ghost" />
374
+ ```
375
+
376
+ ### Sizes
377
+
378
+ ```tsx
379
+ <Input inputSize="sm" />
380
+ <Input inputSize="md" />
381
+ <Input inputSize="lg" />
382
+ ```
383
+
384
+ ### Input Kinds
385
+
386
+ The `kind` prop sets sensible defaults for `type`, `inputMode`, `autoComplete`, and sometimes a placeholder and icon. Any explicit prop overrides the kind default.
387
+
388
+ ```tsx
389
+ <Input kind="email" />
390
+ <Input kind="tel" />
391
+ <Input kind="url" />
392
+ <Input kind="search" />
393
+ <Input kind="numeric" />
394
+ <Input kind="password-current" /> // autoComplete="current-password" + show/hide toggle
395
+ <Input kind="password-new" /> // autoComplete="new-password" + show/hide toggle
396
+ ```
397
+
398
+ To suppress the icon that comes with certain kinds (e.g., `email`, `search`):
399
+
400
+ ```tsx
401
+ <Input kind="email" hideKindIcon />
402
+ ```
403
+
404
+ ### Validation States
405
+
406
+ ```tsx
407
+ <Input error />
408
+ <Input success />
409
+ ```
410
+
411
+ The `error` state also sets `aria-invalid="true"`.
412
+
413
+ ### Disabled & Loading
414
+
415
+ ```tsx
416
+ <Input disabled />
417
+ <Input isLoading /> // shows a spinner, makes the field read‑only (not disabled)
418
+ ```
419
+
420
+ ### Adornments (Icons)
421
+
422
+ ```tsx
423
+ <Input startIcon={<SearchIcon />} />
424
+ <Input endIcon={<MailIcon />} />
425
+ ```
426
+
427
+ ### Clearable
428
+
429
+ ```tsx
430
+ <Input clearable onClear={() => console.log("cleared")} />
431
+ ```
432
+
433
+ A clear button appears when the field has a value. Clicking it clears the value and calls `onClear`.
434
+
435
+ ### Password Input
436
+
437
+ With `kind="password-current"` or `kind="password-new"`, a toggle button is shown to reveal/hide the password.
438
+
439
+ ### Full Width & Rounded
440
+
441
+ ```tsx
442
+ <Input fullWidth /> // default: true
443
+ <Input rounded /> // fully rounded corners
444
+ ```
445
+
446
+ ### Controlled & Uncontrolled
447
+
448
+ ```tsx
449
+ // Controlled
450
+ const [value, setValue] = useState("");
451
+ <Input value={value} onChange={(e) => setValue(e.target.value)} />
452
+
453
+ // Uncontrolled
454
+ <Input defaultValue="Initial value" />
455
+ ```
456
+
457
+ ### Ref Forwarding
458
+
459
+ `Input` forwards refs to the underlying `<input>` element.
460
+
461
+ ### Native Props
462
+
463
+ All standard `<input>` attributes (except `size`) are forwarded to the native input element.
464
+
465
+ ### Size-Aware Styling
466
+
467
+ The component uses `useSizeStyle` to apply theme‑aware sizing from the `sizes` object in the theme.
468
+
469
+ ---
470
+
471
+ ## FormField
472
+
473
+ `FormField` is a higher‑level component that composes a label, description, control, and validation message into an accessible form field. It automatically wires `id`, `aria-describedby`, `aria-invalid`, and `aria-required` – no manual ID juggling.
474
+
475
+ ### Basic Structure
476
+
477
+ ```tsx
478
+ import { FormField, Input } from "@splenddev/kreativ-ui";
479
+
480
+ <FormField>
481
+ <FormField.Label>Email address</FormField.Label>
482
+ <FormField.Description>We'll only send receipts here.</FormField.Description>
483
+ <FormField.Control>
484
+ <Input kind="email" placeholder="you@company.com" />
485
+ </FormField.Control>
486
+ <FormField.Message>Enter a valid email.</FormField.Message>
487
+ </FormField>
488
+ ```
489
+
490
+ ### Subcomponents
491
+
492
+ | Component | Purpose |
493
+ | -------------------- | ------------------------------------------------------------- |
494
+ | `FormField` | Provides context, manages `id` and accessibility relationships |
495
+ | `FormField.Label` | Renders a label associated with the control via `htmlFor` |
496
+ | `FormField.Description` | Renders helper text, linked via `aria-describedby` |
497
+ | `FormField.Control` | Injects the field ID and accessibility props into its child |
498
+ | `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
499
+
500
+ ### Field‑Level Props
501
+
502
+ `FormField` accepts:
503
+
504
+ | Prop | Type | Default | Description |
505
+ | ------------- | ----------- | -------------- | ------------------------------------------------- |
506
+ | `id` | `string` | auto‑generated | Explicit `id` for the control |
507
+ | `error` | `string` | – | Validation error message (overrides description) |
508
+ | `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
509
+ | `className` | `string` | – | Additional wrapper classes |
510
+ | `children` | `ReactNode` | – | The field content (typically subcomponents) |
511
+
512
+ ### Error Handling
513
+
514
+ When `error` is provided:
515
+
516
+ - The error message is displayed (replacing any `Description`).
517
+ - The control receives `aria-invalid="true"`.
518
+ - The error message is linked via `aria-describedby`.
519
+
520
+ ### Required Indicator
521
+
522
+ When `required` is `true`, the label gets a `*` suffix and the control receives `aria-required="true"`.
523
+
524
+ ### Auto‑Generated IDs
525
+
526
+ If no `id` is provided, `FormField` generates a unique ID using `useId` (React 18+) and passes it to the control via `FormField.Control`.
527
+
528
+ ---
529
+
530
+ ## FormField + Input Integration
531
+
532
+ This is the recommended way to build accessible forms with Kreativ UI.
533
+
534
+ ```tsx
535
+ import { FormField, Input } from "@splenddev/kreativ-ui";
536
+
537
+ function EmailField() {
538
+ const [error, setError] = useState("");
539
+
540
+ const handleBlur = (e: React.FocusEvent<HTMLInputElement>) => {
541
+ const value = e.target.value;
542
+ if (!value) setError("Email is required");
543
+ else if (!/\S+@\S+\.\S+/.test(value)) setError("Enter a valid email");
544
+ else setError("");
545
+ };
546
+
547
+ return (
548
+ <FormField id="email" required error={error}>
549
+ <FormField.Label>Email address</FormField.Label>
550
+ <FormField.Description>We'll only send receipts here.</FormField.Description>
551
+ <FormField.Control>
552
+ <Input
553
+ kind="email"
554
+ placeholder="you@company.com"
555
+ onBlur={handleBlur}
556
+ />
557
+ </FormField.Control>
558
+ {error && <FormField.Message>{error}</FormField.Message>}
559
+ </FormField>
560
+ );
561
+ }
562
+ ```
563
+
564
+ **Responsibilities**:
565
+
566
+ - `FormField` – owns field‑level state and accessibility relationships.
567
+ - `FormField.Label` – provides the accessible label.
568
+ - `FormField.Description` – provides supporting text (hidden when `error` exists).
569
+ - `FormField.Control` – connects the actual control to the field context.
570
+ - `Input` – handles the input behavior and presentation.
571
+ - `FormField.Message` – displays validation feedback.
572
+
573
+ ---
574
+
575
+ ## Accessibility
576
+
577
+ The library ensures the following relationships are automatically established:
578
+
579
+ ```
580
+ Label
581
+ ↓
582
+ for → input[id]
583
+
584
+ Description
585
+ ↓
586
+ aria-describedby → description id
587
+
588
+ Validation message
589
+ ↓
590
+ aria-describedby → message id (appended to description ids)
591
+
592
+ Validation state
593
+ ↓
594
+ aria-invalid="true" (when error is present)
595
+ ```
596
+
597
+ When using `FormField`, consumers **should** wrap the input with `FormField.Control` to benefit from these automatic connections.
598
+
599
+ ---
600
+
601
+ ## Validation Behavior
602
+
603
+ ### Field‑Level vs. Input‑Level
604
+
605
+ ```tsx
606
+ // Field-level validation (manages error message and aria state)
607
+ <FormField error="Invalid email">
608
+ <FormField.Control>
609
+ <Input />
610
+ </FormField.Control>
611
+ </FormField>
612
+
613
+ // Input-level error (only visual style and aria-invalid)
614
+ <Input error />
615
+ ```
616
+
617
+ `FormField` manages the error message and overall accessibility, while `Input` controls its own visual presentation. Using both together gives full feedback.
618
+
619
+ ### State‑Transition Feedback
620
+
621
+ When the `error` or `success` state changes on an `Input`, the component briefly animates the change (e.g., a subtle colour transition) rather than continuously animating the validation state. This provides a smooth user experience without being distracting.
622
+
623
+ ---
624
+
625
+ ## Standalone vs. FormField Usage
626
+
627
+ - **Standalone `Input`**: Use when you need a simple input without label/description/validation relationships. Ideal for search bars, inline inputs, or custom layouts.
628
+ - **`FormField` + `Input`**: Use for labeled, described, or validated form controls. This ensures proper accessibility and reduces manual ARIA management.
629
+
630
+ ---
631
+
632
+ ## API Reference
633
+
634
+ ### Input Props
635
+
636
+ | Prop | Type | Default | Description |
637
+ | ----------------- | ----------------------------------- | ----------- | --------------------------------------------------------------------------- |
638
+ | `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
639
+ | `inputSize` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding, font size |
640
+ | `kind` | `InputKind` | `"text"` | Sets defaults for `type`, `inputMode`, `autoComplete`, placeholder, and icon|
641
+ | `hideKindIcon` | `boolean` | `false` | Suppress the default icon from `kind` |
642
+ | `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
643
+ | `success` | `boolean` | `false` | Success styling |
644
+ | `disabled` | `boolean` | `false` | Disables the input |
645
+ | `isLoading` | `boolean` | `false` | Shows spinner and marks read‑only |
646
+ | `clearable` | `boolean` | `false` | Shows clear button when value is present |
647
+ | `onClear` | `() => void` | – | Called after clear |
648
+ | `rounded` | `boolean` | `false` | Fully rounded wrapper |
649
+ | `fullWidth` | `boolean` | `true` | Stretch to container width |
650
+ | `startIcon` | `ReactNode` | – | Content before the input (e.g., icon) |
651
+ | `endIcon` | `ReactNode` | – | Content after the input (e.g., icon) |
652
+ | `className` | `string` | – | Additional wrapper class |
653
+ | `inputClassName` | `string` | – | Additional class for the native input element |
654
+
655
+ All standard `<input>` attributes (except `size`) are forwarded to the underlying `<input>`.
656
+
657
+ ### FormField Props
658
+
659
+ | Prop | Type | Default | Description |
660
+ | ------------- | ----------- | -------------- | ------------------------------------------------- |
661
+ | `id` | `string` | auto‑generated | Explicit `id` for the control |
662
+ | `error` | `string` | – | Validation error message (overrides description) |
663
+ | `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
664
+ | `className` | `string` | – | Additional wrapper classes |
665
+ | `children` | `ReactNode` | – | The field content (typically subcomponents) |
666
+
667
+ ### FormField Subcomponents
668
+
669
+ | Component | Description |
670
+ | -------------------- | ----------------------------------------------------------------- |
671
+ | `FormField.Label` | Renders a label associated with the control via `htmlFor` |
672
+ | `FormField.Description` | Renders helper text, linked via `aria-describedby` |
673
+ | `FormField.Control` | Injects the field ID and accessibility props into its child |
674
+ | `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
675
+
676
+ ---
677
+
678
+ For more advanced usage (e.g., integrating with `react-hook-form`), see the [GitHub repository examples](https://github.com/Vincentvirtuoso/kreativ-ui).
679
+
680
+ ---
681
+
682
+ # 🧩 Select
683
+
684
+ A fully accessible, customizable select component with keyboard navigation, grouped options, clearable selections, and optional integration with `FormField`. Built as a compound component for maximum flexibility.
685
+
686
+ ---
687
+
688
+ ## Overview
689
+
690
+ `Select` is a headless‑style compound component that implements the WAI‑ARIA combobox pattern. It consists of:
691
+
692
+ - `Select` – root container, manages state and context
693
+ - `Select.Trigger` – interactive button that opens/closes the dropdown
694
+ - `Select.Value` – displays the selected option or a placeholder
695
+ - `Select.Content` – dropdown container for options
696
+ - `Select.Item` – an individual selectable option
697
+ - `Select.Group` – groups related options
698
+ - `Select.Label` – heading for a group
699
+
700
+ Supports both **controlled** (`value`/`onValueChange`) and **uncontrolled** (`defaultValue`) usage.
701
+
702
+ ---
703
+
704
+ ## Import
705
+
706
+ ```tsx
707
+ import { Select } from "@splenddev/kreativ-ui";
708
+ ```
709
+
710
+ ---
711
+
712
+ ## Basic Usage
713
+
714
+ ```tsx
715
+ <Select placeholder="Select a country">
716
+ <Select.Trigger>
717
+ <Select.Value />
718
+ </Select.Trigger>
719
+
720
+ <Select.Content>
721
+ <Select.Item value="us">United States</Select.Item>
722
+ <Select.Item value="ca">Canada</Select.Item>
723
+ <Select.Item value="mx">Mexico</Select.Item>
724
+ </Select.Content>
725
+ </Select>
726
+ ```
727
+
728
+ ---
729
+
730
+ ## Controlled Select
731
+
732
+ Use `value` and `onValueChange` to control the selection from a parent component.
733
+
734
+ ```tsx
735
+ import { useState } from "react";
736
+
737
+ function ControlledSelect() {
738
+ const [value, setValue] = useState<string | undefined>("");
739
+
740
+ return (
741
+ <Select value={value} onValueChange={setValue}>
742
+ <Select.Trigger>
743
+ <Select.Value placeholder="Choose a framework" />
744
+ </Select.Trigger>
745
+
746
+ <Select.Content>
747
+ <Select.Item value="react">React</Select.Item>
748
+ <Select.Item value="vue">Vue</Select.Item>
749
+ <Select.Item value="svelte">Svelte</Select.Item>
750
+ </Select.Content>
751
+ </Select>
752
+ );
753
+ }
754
+ ```
755
+
756
+ > When `clearable` is enabled, clearing the value will call `onValueChange(undefined)`. The parent must handle this state change accordingly.
757
+
758
+ ---
759
+
760
+ ## Uncontrolled Select
761
+
762
+ Use `defaultValue` for an uncontrolled component.
763
+
764
+ ```tsx
765
+ <Select defaultValue="react">
766
+ <Select.Trigger>
767
+ <Select.Value placeholder="Choose a framework" />
768
+ </Select.Trigger>
769
+
770
+ <Select.Content>
771
+ <Select.Item value="react">React</Select.Item>
772
+ <Select.Item value="vue">Vue</Select.Item>
773
+ <Select.Item value="angular">Angular</Select.Item>
774
+ </Select.Content>
775
+ </Select>
776
+ ```
777
+
778
+ ---
779
+
780
+ ## Props
781
+
782
+ | Prop | Type | Default | Description |
783
+ | --------------- | ------------------------------------------ | ----------- | ---------------------------------------------------------------- |
784
+ | `value` | `string` | – | Controlled selected value |
785
+ | `defaultValue` | `string` | – | Uncontrolled initial value |
786
+ | `onValueChange` | `(value?: string) => void` | – | Called when selection changes |
787
+ | `placeholder` | `string` | – | Text shown when no value is selected |
788
+ | `required` | `boolean` | `false` | Marks the field as required (`aria-required`) |
789
+ | `name` | `string` | – | Name for the hidden input used in form submissions |
790
+ | `disabled` | `boolean` | `false` | Disables the entire select |
791
+ | `clearable` | `boolean` | `false` | Shows a clear button (removes selection) |
792
+ | `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
793
+ | `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size of the trigger and content |
794
+ | `error` | `boolean` | `false` | Shows error state and sets `aria-invalid="true"` |
795
+ | `success` | `boolean` | `false` | Shows success state |
796
+ | `rounded` | `boolean` | `false` | Applies fully rounded corners to the trigger |
797
+ | `className` | `string` | – | Additional class names for the root container |
798
+
799
+ ---
800
+
801
+ ## Compound Components
802
+
803
+ ### `Select.Trigger`
804
+
805
+ The interactive button that toggles the dropdown. It receives all necessary ARIA attributes from the root `Select`.
806
+
807
+ ```tsx
808
+ <Select.Trigger>
809
+ <Select.Value />
810
+ </Select.Trigger>
811
+ ```
812
+
813
+ ### `Select.Value`
814
+
815
+ Renders the current selection or the placeholder. The label is derived from the matching `Select.Item`’s children.
816
+
817
+ ```tsx
818
+ <Select.Value placeholder="Choose an option" />
819
+ ```
820
+
821
+ ### `Select.Content`
822
+
823
+ The dropdown container. Renders its children (items, groups, labels) inside a listbox.
824
+
825
+ ```tsx
826
+ <Select.Content>
827
+ {/* items */}
828
+ </Select.Content>
829
+ ```
830
+
831
+ ### `Select.Item`
832
+
833
+ A single selectable option.
834
+
835
+ | Prop | Type | Default | Description |
836
+ | ---------- | --------- | ------- | --------------------------------- |
837
+ | `value` | `string` | required | Value of the option |
838
+ | `disabled` | `boolean` | `false` | Disables this option |
839
+ | `children` | `ReactNode` | – | Display label |
840
+
841
+ ```tsx
842
+ <Select.Item value="react" disabled>React</Select.Item>
843
+ ```
844
+
845
+ ### `Select.Group`
846
+
847
+ Groups related options, typically used with `Select.Label`.
848
+
849
+ ```tsx
850
+ <Select.Group>
851
+ <Select.Label>Frontend</Select.Label>
852
+ <Select.Item value="react">React</Select.Item>
853
+ <Select.Item value="vue">Vue</Select.Item>
854
+ </Select.Group>
855
+ ```
856
+
857
+ ### `Select.Label`
858
+
859
+ A heading for a group of options. It is rendered as a non‑interactive label inside the listbox.
860
+
861
+ ```tsx
862
+ <Select.Label>Backend</Select.Label>
863
+ ```
864
+
865
+ ---
866
+
867
+ ## Accessibility
868
+
869
+ `Select` implements the WAI‑ARIA combobox pattern and manages all necessary relationships automatically.
870
+
871
+ **Roles & Attributes**:
872
+
873
+ - Trigger: `role="combobox"`, `aria-haspopup="listbox"`, `aria-expanded`, `aria-controls`, `aria-activedescendant`
874
+ - Content: `role="listbox"`
875
+ - Items: `role="option"`, `aria-selected`, `aria-disabled`
876
+
877
+ **Automatic IDs**: The root generates unique IDs for the trigger, content, and each option. These are used to connect the trigger to the listbox and to manage `aria-activedescendant`.
878
+
879
+ **FormField integration**: When placed inside a `FormField`, the Select consumes the following context:
880
+
881
+ - `id` – becomes the trigger’s `id`
882
+ - `labelId` – linked via `aria-labelledby`
883
+ - `descriptionId` / `messageId` – linked via `aria-describedby`
884
+ - `invalid` – sets `aria-invalid`
885
+ - `required` – sets `aria-required`
886
+
887
+ This ensures full ARIA support with no manual configuration.
888
+
889
+ ---
890
+
891
+ ## Keyboard Navigation
892
+
893
+ | Key | Open state | Closed state |
894
+ | ----------- | ---------- | ------------------------------------ |
895
+ | `ArrowDown` | Next item | Opens the dropdown |
896
+ | `ArrowUp` | Previous item | Opens the dropdown (or no-op) |
897
+ | `Home` | First item | Opens and selects first? (implementation) |
898
+ | `End` | Last item | Opens and selects last? |
899
+ | `Enter` | Select active item | Opens the dropdown |
900
+ | `Space` | Select active item | Opens the dropdown |
901
+ | `Escape` | Closes dropdown | – |
902
+ | `Backspace` | – | Clears selection (if `clearable`) |
903
+ | `Delete` | – | Clears selection (if `clearable`) |
904
+
905
+ > When the dropdown is open, `ArrowDown`/`ArrowUp` navigate through items. `Enter`/`Space` select the active (highlighted) item and close the dropdown. `Escape` closes the dropdown without selection.
906
+
907
+ ---
908
+
909
+ ## Clearable Select
910
+
911
+ When `clearable` is `true`, a clear button appears inside the trigger when a value is selected. Clicking it resets the selection to `undefined`.
912
+
913
+ ```tsx
914
+ <Select clearable defaultValue="react">
915
+ <Select.Trigger>
916
+ <Select.Value placeholder="Pick a framework" />
917
+ </Select.Trigger>
918
+
919
+ <Select.Content>
920
+ <Select.Item value="react">React</Select.Item>
921
+ <Select.Item value="vue">Vue</Select.Item>
922
+ </Select.Content>
923
+ </Select>
924
+ ```
925
+
926
+ **Controlled behavior**: The parent must handle `onValueChange(undefined)` to update its own state.
927
+
928
+ **Uncontrolled behavior**: The internal state is cleared automatically.
929
+
930
+ ---
931
+
932
+ ## Disabled Options
933
+
934
+ Individual items can be disabled using the `disabled` prop. They are not selectable via mouse or keyboard navigation and are announced as disabled by screen readers.
935
+
936
+ ```tsx
937
+ <Select.Item value="legacy" disabled>Legacy</Select.Item>
938
+ ```
939
+
940
+ Disabled items are skipped when navigating with arrow keys.
941
+
942
+ ---
943
+
944
+ ## Validation States
945
+
946
+ ### Error
947
+
948
+ ```tsx
949
+ <Select error>
950
+ <Select.Trigger>
951
+ <Select.Value placeholder="Choose" />
952
+ </Select.Trigger>
953
+ <Select.Content>...</Select.Content>
954
+ </Select>
955
+ ```
956
+
957
+ Visually styles the trigger with error colours and sets `aria-invalid="true"`.
958
+
959
+ ### Success
960
+
961
+ ```tsx
962
+ <Select success>...</Select>
963
+ ```
964
+
965
+ Applies success styling.
966
+
967
+ ---
968
+
969
+ ## FormField Integration
970
+
971
+ When used inside a `FormField`, the Select automatically inherits the field’s `id`, `required`, and validation state.
972
+
973
+ ```tsx
974
+ <FormField required error="Please select a country">
975
+ <FormField.Label>Country</FormField.Label>
976
+ <FormField.Description>Select your country of residence.</FormField.Description>
977
+
978
+ <Select>
979
+ <Select.Trigger>
980
+ <Select.Value placeholder="Select a country" />
981
+ </Select.Trigger>
982
+ <Select.Content>
983
+ <Select.Item value="us">United States</Select.Item>
984
+ <Select.Item value="ca">Canada</Select.Item>
985
+ </Select.Content>
986
+ </Select>
987
+
988
+ <FormField.Message />
989
+ </FormField>
990
+ ```
991
+
992
+ > No extra props are needed – the Select picks up the context automatically.
993
+
994
+ ---
995
+
996
+ ## Native Form Submission
997
+
998
+ The `name` prop renders a hidden `<input>` that is included in form submissions. The value submitted is the currently selected `value`.
999
+
1000
+ ```tsx
1001
+ <form onSubmit={handleSubmit}>
1002
+ <Select name="country" defaultValue="us">
1003
+ <Select.Trigger>
1004
+ <Select.Value placeholder="Select a country" />
1005
+ </Select.Trigger>
1006
+ <Select.Content>
1007
+ <Select.Item value="us">United States</Select.Item>
1008
+ <Select.Item value="ca">Canada</Select.Item>
1009
+ </Select.Content>
1010
+ </Select>
1011
+
1012
+ <button type="submit">Submit</button>
1013
+ </form>
1014
+ ```
1015
+
1016
+ ---
1017
+
1018
+ ## Styling and Theming
1019
+
1020
+ Select uses the same theming infrastructure as other Kreativ UI form controls:
1021
+
1022
+ - `theme.recipes.FormControl` defines base, variant, and size styles.
1023
+ - `useSizeStyle` applies height, padding, and font size from the `sizes` token.
1024
+ - Variants (`outline`, `filled`, `ghost`) are resolved via `resolveRecipe`.
1025
+ - Validation states (`error`, `success`) are applied through CSS variables and class names.
1026
+
1027
+ All styling is driven by the runtime theme, so overriding the visual appearance can be done by providing a custom `FormControl` recipe in the theme.
1028
+
1029
+ ---
1030
+
1031
+ ## Data Attributes
1032
+
1033
+ The Select exposes several data attributes for styling or testing:
1034
+
1035
+ | Attribute | Element | Values | Description |
1036
+ | ------------------ | --------------- | -------------------------- | ---------------------------------------- |
1037
+ | `data-state` | `Select.Trigger` | `"open"`, `"closed"` | Current dropdown state |
1038
+ | `data-state` | `Select.Item` | `"selected"`, `"unselected"` | Selection state of the item |
1039
+ | `data-active` | `Select.Item` | present when highlighted | Keyboard‑focused item (active) |
1040
+ | `data-disabled` | `Select.Item` | present when disabled | Disabled state |
1041
+ | `data-invalid` | `Select.Trigger` | present when error | Error state |
1042
+
1043
+ ---
1044
+
1045
+ ## Complete Example
1046
+
1047
+ ```tsx
1048
+ import { useState } from "react";
1049
+ import { FormField, Select } from "@splenddev/kreativ-ui";
1050
+
1051
+ function CountrySelect() {
1052
+ const [country, setCountry] = useState<string | undefined>("");
1053
+ const [error, setError] = useState("");
1054
+
1055
+ const validate = (value?: string) => {
1056
+ if (!value) setError("Please select a country");
1057
+ else setError("");
1058
+ };
1059
+
1060
+ return (
1061
+ <FormField required error={error}>
1062
+ <FormField.Label>Country</FormField.Label>
1063
+ <FormField.Description>Choose your country of residence.</FormField.Description>
1064
+
1065
+ <Select
1066
+ value={country}
1067
+ onValueChange={(val) => {
1068
+ setCountry(val);
1069
+ validate(val);
1070
+ }}
1071
+ clearable
1072
+ name="country"
1073
+ error={!!error}
1074
+ >
1075
+ <Select.Trigger>
1076
+ <Select.Value placeholder="Select a country" />
1077
+ </Select.Trigger>
1078
+
1079
+ <Select.Content>
1080
+ <Select.Group>
1081
+ <Select.Label>North America</Select.Label>
1082
+ <Select.Item value="us">United States</Select.Item>
1083
+ <Select.Item value="ca">Canada</Select.Item>
1084
+ <Select.Item value="mx">Mexico</Select.Item>
1085
+ </Select.Group>
1086
+
1087
+ <Select.Group>
1088
+ <Select.Label>Europe</Select.Label>
1089
+ <Select.Item value="uk">United Kingdom</Select.Item>
1090
+ <Select.Item value="de">Germany</Select.Item>
1091
+ <Select.Item value="fr" disabled>France (disabled)</Select.Item>
1092
+ </Select.Group>
1093
+ </Select.Content>
1094
+ </Select>
1095
+
1096
+ {error && <FormField.Message>{error}</FormField.Message>}
1097
+ </FormField>
1098
+ );
1099
+ }
1100
+ ```
1101
+
1102
+ ---
1103
+
1104
+ For more advanced use cases (e.g., async loading, custom rendering), refer to the [GitHub repository examples](https://github.com/Vincentvirtuoso/kreativ-ui).
1105
+
1106
+ ---
1107
+
1108
+ # ♿ Accessibility
1109
+
1110
+ Kreativ UI components are built with accessibility in mind:
1111
+
1112
+ - All interactive elements support keyboard navigation.
1113
+ - Focus management and visible focus indicators.
1114
+ - ARIA attributes are applied automatically where needed (e.g., `aria-label`, `aria-describedby`, `aria-invalid`).
1115
+ - Colour contrast respects system‑level settings.
1116
+
1117
+ ---
1118
+
1119
+ # 📦 Browser Support
1120
+
1121
+ Kreativ UI works in all modern browsers (Chrome, Firefox, Safari, Edge).
1122
+ Requires React 18 or later.
1123
+
1124
+ ---
1125
+
1126
+ # 📄 License
1127
+
1128
+ MIT
1129
+
1130
+ ---
1131
+
1132
+ **More component documentation (Textarea, Checkbox, RadioGroup, etc.) coming soon.**
1133
+ Visit the [GitHub repository](https://github.com/Vincentvirtuoso/kreativ-ui) for updates.