@splenddev/kreativ-ui 0.2.8 → 0.3.0

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