@splenddev/kreativ-ui 0.2.4 → 0.2.6

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
@@ -149,8 +149,12 @@ tokens.spacing.md // → 16px
149
149
  **Semantic tokens** describe UI meaning and can reference primitive tokens or direct values:
150
150
 
151
151
  ```ts
152
- semanticTokens.colors.brand = { value: { light: "{colors.blue.500}", dark: "{colors.blue.400}" } }
153
- semanticTokens.colors.text = { value: { light: "{colors.gray.900}", dark: "{colors.gray.50}" } }
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
+ };
154
158
  ```
155
159
 
156
160
  The runtime engine resolves these references and applies the correct values based on the active colour mode.
@@ -249,26 +253,26 @@ Supported transition types: `none`, `fade`, `slide`, `scale`, `rotate`.
249
253
 
250
254
  ## Props
251
255
 
252
- | Prop | Type | Default | Description |
253
- | --------------- | ----------------------------------------------------------------- | ------------------- | ------------------------------------------- |
254
- | `variant` | `ThemeTogglerVariant` | `"ghost"` | Variant for inactive buttons |
255
- | `activeVariant` | `ThemeTogglerVariant` | `"solid"` | Variant for active button |
256
- | `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl"` | `"sm"` | Button size |
257
- | `iconOnly` | `boolean` | `false` | Hide labels, show only icons |
258
- | `allowSystem` | `boolean` | `false` | Show system theme option |
259
- | `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Layout direction |
260
- | `rounded` | `boolean` | `true` | Rounded container corners |
261
- | `unstyled` | `boolean` | `false` | Remove wrapper styles |
262
- | `display` | `"buttons" \| "cycle"` | `"buttons"` | Show all buttons or a single cycling button |
263
- | `transition` | `{ type?: TransitionType; duration?: number; easing?: string }` | `{ type: "none" }` | Animation configuration for cycle mode |
264
- | `labels` | `Partial<Record<"light" \| "dark" \| "system", string>>` | – | Override labels |
265
- | `icons` | `Partial<Record<"light" \| "dark" \| "system", ReactNode>>` | – | Override icons |
266
- | `buttonProps` | `Partial<ButtonProps>` | – | Props passed to every internal button |
267
- | `className` | `string` | – | Additional wrapper class |
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 |
268
272
 
269
273
  ---
270
274
 
271
- # Button
275
+ # Button
272
276
 
273
277
  A versatile button with support for variants, sizes, loading states, icons, and full‑width.
274
278
 
@@ -333,15 +337,15 @@ Define additional sizes in the theme (as shown in the Theming section) and use t
333
337
 
334
338
  ## Props
335
339
 
336
- | Prop | Type | Default | Description |
337
- | ------------------------ | ------------------------------------------------------ | -------- | ------------------------------------------- |
340
+ | Prop | Type | Default | Description |
341
+ | ------------------------ | ----------------------------------------------------------------------------------- | --------- | ------------------------------------------- |
338
342
  | `variant` | `"solid" \| "outline" \| "ghost" \| "soft" \| "destructive" \| "success" \| "link"` | `"solid"` | Visual style |
339
- | `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl" \| string` | `"md"` | Size (theme‑driven; custom strings allowed) |
340
- | `isLoading` | `boolean` | `false` | Shows spinner and disables |
341
- | `leftIcon` / `rightIcon` | `ReactNode` | – | Icon elements |
342
- | `fullWidth` | `boolean` | `false` | Stretch to container width |
343
- | `disabled` | `boolean` | `false` | Disables interactions |
344
- | `iconOnly` | `boolean` | `false` | Remove padding for icon‑only layout |
343
+ | `size` | `"xs" \| "sm" \| "md" \| "lg" \| "xl" \| string` | `"md"` | Size (theme‑driven; custom strings allowed) |
344
+ | `isLoading` | `boolean` | `false` | Shows spinner and disables |
345
+ | `leftIcon` / `rightIcon` | `ReactNode` | – | Icon elements |
346
+ | `fullWidth` | `boolean` | `false` | Stretch to container width |
347
+ | `disabled` | `boolean` | `false` | Disables interactions |
348
+ | `iconOnly` | `boolean` | `false` | Remove padding for icon‑only layout |
345
349
 
346
350
  All standard `<button>` props are forwarded.
347
351
 
@@ -362,7 +366,7 @@ A flexible text input with support for variants, sizes, validation states, adorn
362
366
  ```tsx
363
367
  import { Input } from "@splenddev/kreativ-ui";
364
368
 
365
- <Input placeholder="Enter your name" />
369
+ <Input placeholder="Enter your name" />;
366
370
  ```
367
371
 
368
372
  ### Variants
@@ -484,30 +488,30 @@ import { FormField, Input } from "@splenddev/kreativ-ui";
484
488
  <Input kind="email" placeholder="you@company.com" />
485
489
  </FormField.Control>
486
490
  <FormField.Message>Enter a valid email.</FormField.Message>
487
- </FormField>
491
+ </FormField>;
488
492
  ```
489
493
 
490
494
  ### Subcomponents
491
495
 
492
- | Component | Purpose |
493
- | -------------------- | ------------------------------------------------------------- |
494
- | `FormField` | Provides context, manages `id` and accessibility relationships |
495
- | `FormField.Label` | Renders a label associated with the control via `htmlFor` |
496
- | `FormField.Description` | Renders helper text, linked via `aria-describedby` |
497
- | `FormField.Control` | Injects the field ID and accessibility props into its child |
498
- | `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
496
+ | Component | Purpose |
497
+ | ----------------------- | -------------------------------------------------------------- |
498
+ | `FormField` | Provides context, manages `id` and accessibility relationships |
499
+ | `FormField.Label` | Renders a label associated with the control via `htmlFor` |
500
+ | `FormField.Description` | Renders helper text, linked via `aria-describedby` |
501
+ | `FormField.Control` | Injects the field ID and accessibility props into its child |
502
+ | `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
499
503
 
500
504
  ### Field‑Level Props
501
505
 
502
506
  `FormField` accepts:
503
507
 
504
- | Prop | Type | Default | Description |
505
- | ------------- | ----------- | -------------- | ------------------------------------------------- |
506
- | `id` | `string` | auto‑generated | Explicit `id` for the control |
507
- | `error` | `string` | – | Validation error message (overrides description) |
508
- | `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
509
- | `className` | `string` | – | Additional wrapper classes |
510
- | `children` | `ReactNode` | – | The field content (typically subcomponents) |
508
+ | Prop | Type | Default | Description |
509
+ | ----------- | ----------- | -------------- | ------------------------------------------------- |
510
+ | `id` | `string` | auto‑generated | Explicit `id` for the control |
511
+ | `error` | `string` | – | Validation error message (overrides description) |
512
+ | `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
513
+ | `className` | `string` | – | Additional wrapper classes |
514
+ | `children` | `ReactNode` | – | The field content (typically subcomponents) |
511
515
 
512
516
  ### Error Handling
513
517
 
@@ -547,13 +551,11 @@ function EmailField() {
547
551
  return (
548
552
  <FormField id="email" required error={error}>
549
553
  <FormField.Label>Email address</FormField.Label>
550
- <FormField.Description>We'll only send receipts here.</FormField.Description>
554
+ <FormField.Description>
555
+ We'll only send receipts here.
556
+ </FormField.Description>
551
557
  <FormField.Control>
552
- <Input
553
- kind="email"
554
- placeholder="you@company.com"
555
- onBlur={handleBlur}
556
- />
558
+ <Input kind="email" placeholder="you@company.com" onBlur={handleBlur} />
557
559
  </FormField.Control>
558
560
  {error && <FormField.Message>{error}</FormField.Message>}
559
561
  </FormField>
@@ -633,45 +635,45 @@ When the `error` or `success` state changes on an `Input`, the component briefly
633
635
 
634
636
  ### Input Props
635
637
 
636
- | Prop | Type | Default | Description |
637
- | ----------------- | ----------------------------------- | ----------- | --------------------------------------------------------------------------- |
638
- | `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
639
- | `inputSize` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding, font size |
640
- | `kind` | `InputKind` | `"text"` | Sets defaults for `type`, `inputMode`, `autoComplete`, placeholder, and icon|
641
- | `hideKindIcon` | `boolean` | `false` | Suppress the default icon from `kind` |
642
- | `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
643
- | `success` | `boolean` | `false` | Success styling |
644
- | `disabled` | `boolean` | `false` | Disables the input |
645
- | `isLoading` | `boolean` | `false` | Shows spinner and marks read‑only |
646
- | `clearable` | `boolean` | `false` | Shows clear button when value is present |
647
- | `onClear` | `() => void` | – | Called after clear |
648
- | `rounded` | `boolean` | `false` | Fully rounded wrapper |
649
- | `fullWidth` | `boolean` | `true` | Stretch to container width |
650
- | `startIcon` | `ReactNode` | – | Content before the input (e.g., icon) |
651
- | `endIcon` | `ReactNode` | – | Content after the input (e.g., icon) |
652
- | `className` | `string` | – | Additional wrapper class |
653
- | `inputClassName` | `string` | – | Additional class for the native input element |
638
+ | Prop | Type | Default | Description |
639
+ | ---------------- | ---------------------------------- | ----------- | ---------------------------------------------------------------------------- |
640
+ | `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
641
+ | `inputSize` | `"sm" \| "md" \| "lg"` | `"md"` | Height, padding, font size |
642
+ | `kind` | `InputKind` | `"text"` | Sets defaults for `type`, `inputMode`, `autoComplete`, placeholder, and icon |
643
+ | `hideKindIcon` | `boolean` | `false` | Suppress the default icon from `kind` |
644
+ | `error` | `boolean` | `false` | Danger styling and `aria-invalid` |
645
+ | `success` | `boolean` | `false` | Success styling |
646
+ | `disabled` | `boolean` | `false` | Disables the input |
647
+ | `isLoading` | `boolean` | `false` | Shows spinner and marks read‑only |
648
+ | `clearable` | `boolean` | `false` | Shows clear button when value is present |
649
+ | `onClear` | `() => void` | – | Called after clear |
650
+ | `rounded` | `boolean` | `false` | Fully rounded wrapper |
651
+ | `fullWidth` | `boolean` | `true` | Stretch to container width |
652
+ | `startIcon` | `ReactNode` | – | Content before the input (e.g., icon) |
653
+ | `endIcon` | `ReactNode` | – | Content after the input (e.g., icon) |
654
+ | `className` | `string` | – | Additional wrapper class |
655
+ | `inputClassName` | `string` | – | Additional class for the native input element |
654
656
 
655
657
  All standard `<input>` attributes (except `size`) are forwarded to the underlying `<input>`.
656
658
 
657
659
  ### FormField Props
658
660
 
659
- | Prop | Type | Default | Description |
660
- | ------------- | ----------- | -------------- | ------------------------------------------------- |
661
- | `id` | `string` | auto‑generated | Explicit `id` for the control |
662
- | `error` | `string` | – | Validation error message (overrides description) |
663
- | `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
664
- | `className` | `string` | – | Additional wrapper classes |
665
- | `children` | `ReactNode` | – | The field content (typically subcomponents) |
661
+ | Prop | Type | Default | Description |
662
+ | ----------- | ----------- | -------------- | ------------------------------------------------- |
663
+ | `id` | `string` | auto‑generated | Explicit `id` for the control |
664
+ | `error` | `string` | – | Validation error message (overrides description) |
665
+ | `required` | `boolean` | `false` | Shows required indicator and sets `aria-required` |
666
+ | `className` | `string` | – | Additional wrapper classes |
667
+ | `children` | `ReactNode` | – | The field content (typically subcomponents) |
666
668
 
667
669
  ### FormField Subcomponents
668
670
 
669
- | Component | Description |
670
- | -------------------- | ----------------------------------------------------------------- |
671
- | `FormField.Label` | Renders a label associated with the control via `htmlFor` |
672
- | `FormField.Description` | Renders helper text, linked via `aria-describedby` |
673
- | `FormField.Control` | Injects the field ID and accessibility props into its child |
674
- | `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
671
+ | Component | Description |
672
+ | ----------------------- | ------------------------------------------------------------ |
673
+ | `FormField.Label` | Renders a label associated with the control via `htmlFor` |
674
+ | `FormField.Description` | Renders helper text, linked via `aria-describedby` |
675
+ | `FormField.Control` | Injects the field ID and accessibility props into its child |
676
+ | `FormField.Message` | Displays a validation message, linked via `aria-describedby` |
675
677
 
676
678
  ---
677
679
 
@@ -779,22 +781,22 @@ Use `defaultValue` for an uncontrolled component.
779
781
 
780
782
  ## Props
781
783
 
782
- | Prop | Type | Default | Description |
783
- | --------------- | ------------------------------------------ | ----------- | ---------------------------------------------------------------- |
784
- | `value` | `string` | – | Controlled selected value |
785
- | `defaultValue` | `string` | – | Uncontrolled initial value |
786
- | `onValueChange` | `(value?: string) => void` | – | Called when selection changes |
787
- | `placeholder` | `string` | – | Text shown when no value is selected |
788
- | `required` | `boolean` | `false` | Marks the field as required (`aria-required`) |
789
- | `name` | `string` | – | Name for the hidden input used in form submissions |
790
- | `disabled` | `boolean` | `false` | Disables the entire select |
791
- | `clearable` | `boolean` | `false` | Shows a clear button (removes selection) |
792
- | `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
793
- | `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size of the trigger and content |
794
- | `error` | `boolean` | `false` | Shows error state and sets `aria-invalid="true"` |
795
- | `success` | `boolean` | `false` | Shows success state |
796
- | `rounded` | `boolean` | `false` | Applies fully rounded corners to the trigger |
797
- | `className` | `string` | – | Additional class names for the root container |
784
+ | Prop | Type | Default | Description |
785
+ | --------------- | ---------------------------------- | ----------- | -------------------------------------------------- |
786
+ | `value` | `string` | – | Controlled selected value |
787
+ | `defaultValue` | `string` | – | Uncontrolled initial value |
788
+ | `onValueChange` | `(value?: string) => void` | – | Called when selection changes |
789
+ | `placeholder` | `string` | – | Text shown when no value is selected |
790
+ | `required` | `boolean` | `false` | Marks the field as required (`aria-required`) |
791
+ | `name` | `string` | – | Name for the hidden input used in form submissions |
792
+ | `disabled` | `boolean` | `false` | Disables the entire select |
793
+ | `clearable` | `boolean` | `false` | Shows a clear button (removes selection) |
794
+ | `variant` | `"outline" \| "filled" \| "ghost"` | `"outline"` | Visual style |
795
+ | `size` | `"sm" \| "md" \| "lg"` | `"md"` | Size of the trigger and content |
796
+ | `error` | `boolean` | `false` | Shows error state and sets `aria-invalid="true"` |
797
+ | `success` | `boolean` | `false` | Shows success state |
798
+ | `rounded` | `boolean` | `false` | Applies fully rounded corners to the trigger |
799
+ | `className` | `string` | – | Additional class names for the root container |
798
800
 
799
801
  ---
800
802
 
@@ -823,23 +825,23 @@ Renders the current selection or the placeholder. The label is derived from the
823
825
  The dropdown container. Renders its children (items, groups, labels) inside a listbox.
824
826
 
825
827
  ```tsx
826
- <Select.Content>
827
- {/* items */}
828
- </Select.Content>
828
+ <Select.Content>{/* items */}</Select.Content>
829
829
  ```
830
830
 
831
831
  ### `Select.Item`
832
832
 
833
833
  A single selectable option.
834
834
 
835
- | Prop | Type | Default | Description |
836
- | ---------- | --------- | ------- | --------------------------------- |
837
- | `value` | `string` | required | Value of the option |
838
- | `disabled` | `boolean` | `false` | Disables this option |
839
- | `children` | `ReactNode` | – | Display label |
835
+ | Prop | Type | Default | Description |
836
+ | ---------- | ----------- | -------- | -------------------- |
837
+ | `value` | `string` | required | Value of the option |
838
+ | `disabled` | `boolean` | `false` | Disables this option |
839
+ | `children` | `ReactNode` | – | Display label |
840
840
 
841
841
  ```tsx
842
- <Select.Item value="react" disabled>React</Select.Item>
842
+ <Select.Item value="react" disabled>
843
+ React
844
+ </Select.Item>
843
845
  ```
844
846
 
845
847
  ### `Select.Group`
@@ -890,17 +892,17 @@ This ensures full ARIA support with no manual configuration.
890
892
 
891
893
  ## Keyboard Navigation
892
894
 
893
- | Key | Open state | Closed state |
894
- | ----------- | ---------- | ------------------------------------ |
895
- | `ArrowDown` | Next item | Opens the dropdown |
896
- | `ArrowUp` | Previous item | Opens the dropdown (or no-op) |
897
- | `Home` | First item | Opens and selects first? (implementation) |
898
- | `End` | Last item | Opens and selects last? |
899
- | `Enter` | Select active item | Opens the dropdown |
900
- | `Space` | Select active item | Opens the dropdown |
901
- | `Escape` | Closes dropdown | – |
902
- | `Backspace` | – | Clears selection (if `clearable`) |
903
- | `Delete` | – | Clears selection (if `clearable`) |
895
+ | Key | Open state | Closed state |
896
+ | ----------- | ------------------ | ----------------------------------------- |
897
+ | `ArrowDown` | Next item | Opens the dropdown |
898
+ | `ArrowUp` | Previous item | Opens the dropdown (or no-op) |
899
+ | `Home` | First item | Opens and selects first? (implementation) |
900
+ | `End` | Last item | Opens and selects last? |
901
+ | `Enter` | Select active item | Opens the dropdown |
902
+ | `Space` | Select active item | Opens the dropdown |
903
+ | `Escape` | Closes dropdown | – |
904
+ | `Backspace` | – | Clears selection (if `clearable`) |
905
+ | `Delete` | – | Clears selection (if `clearable`) |
904
906
 
905
907
  > When the dropdown is open, `ArrowDown`/`ArrowUp` navigate through items. `Enter`/`Space` select the active (highlighted) item and close the dropdown. `Escape` closes the dropdown without selection.
906
908
 
@@ -934,7 +936,9 @@ When `clearable` is `true`, a clear button appears inside the trigger when a val
934
936
  Individual items can be disabled using the `disabled` prop. They are not selectable via mouse or keyboard navigation and are announced as disabled by screen readers.
935
937
 
936
938
  ```tsx
937
- <Select.Item value="legacy" disabled>Legacy</Select.Item>
939
+ <Select.Item value="legacy" disabled>
940
+ Legacy
941
+ </Select.Item>
938
942
  ```
939
943
 
940
944
  Disabled items are skipped when navigating with arrow keys.
@@ -973,7 +977,9 @@ When used inside a `FormField`, the Select automatically inherits the field’s
973
977
  ```tsx
974
978
  <FormField required error="Please select a country">
975
979
  <FormField.Label>Country</FormField.Label>
976
- <FormField.Description>Select your country of residence.</FormField.Description>
980
+ <FormField.Description>
981
+ Select your country of residence.
982
+ </FormField.Description>
977
983
 
978
984
  <Select>
979
985
  <Select.Trigger>
@@ -1032,13 +1038,13 @@ All styling is driven by the runtime theme, so overriding the visual appearance
1032
1038
 
1033
1039
  The Select exposes several data attributes for styling or testing:
1034
1040
 
1035
- | Attribute | Element | Values | Description |
1036
- | ------------------ | --------------- | -------------------------- | ---------------------------------------- |
1037
- | `data-state` | `Select.Trigger` | `"open"`, `"closed"` | Current dropdown state |
1038
- | `data-state` | `Select.Item` | `"selected"`, `"unselected"` | Selection state of the item |
1039
- | `data-active` | `Select.Item` | present when highlighted | Keyboard‑focused item (active) |
1040
- | `data-disabled` | `Select.Item` | present when disabled | Disabled state |
1041
- | `data-invalid` | `Select.Trigger` | present when error | Error state |
1041
+ | Attribute | Element | Values | Description |
1042
+ | --------------- | ---------------- | ---------------------------- | ------------------------------ |
1043
+ | `data-state` | `Select.Trigger` | `"open"`, `"closed"` | Current dropdown state |
1044
+ | `data-state` | `Select.Item` | `"selected"`, `"unselected"` | Selection state of the item |
1045
+ | `data-active` | `Select.Item` | present when highlighted | Keyboard‑focused item (active) |
1046
+ | `data-disabled` | `Select.Item` | present when disabled | Disabled state |
1047
+ | `data-invalid` | `Select.Trigger` | present when error | Error state |
1042
1048
 
1043
1049
  ---
1044
1050
 
@@ -1060,7 +1066,9 @@ function CountrySelect() {
1060
1066
  return (
1061
1067
  <FormField required error={error}>
1062
1068
  <FormField.Label>Country</FormField.Label>
1063
- <FormField.Description>Choose your country of residence.</FormField.Description>
1069
+ <FormField.Description>
1070
+ Choose your country of residence.
1071
+ </FormField.Description>
1064
1072
 
1065
1073
  <Select
1066
1074
  value={country}
@@ -1088,7 +1096,9 @@ function CountrySelect() {
1088
1096
  <Select.Label>Europe</Select.Label>
1089
1097
  <Select.Item value="uk">United Kingdom</Select.Item>
1090
1098
  <Select.Item value="de">Germany</Select.Item>
1091
- <Select.Item value="fr" disabled>France (disabled)</Select.Item>
1099
+ <Select.Item value="fr" disabled>
1100
+ France (disabled)
1101
+ </Select.Item>
1092
1102
  </Select.Group>
1093
1103
  </Select.Content>
1094
1104
  </Select>
@@ -1105,6 +1115,1454 @@ For more advanced use cases (e.g., async loading, custom rendering), refer to th
1105
1115
 
1106
1116
  ---
1107
1117
 
1118
+ # Typography System
1119
+
1120
+ Kreativ UI provides a centralized, theme-aware typography system for controlling how text is rendered across your application and component library.
1121
+
1122
+ 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.
1123
+
1124
+ The system supports:
1125
+
1126
+ * Reusable typography presets
1127
+ * Primitive design tokens
1128
+ * Semantic tokens
1129
+ * Custom font families
1130
+ * `next/font`
1131
+ * CSS custom properties
1132
+ * Local fonts
1133
+ * Runtime theme customization
1134
+ * Custom typography presets
1135
+ * Component-level typography selection
1136
+ * Custom component integration
1137
+ * Type-safe token definitions
1138
+ * Direct CSS value overrides
1139
+
1140
+ ---
1141
+
1142
+ ## How It Works
1143
+
1144
+ Kreativ UI typography is built around four layers:
1145
+
1146
+ ```text
1147
+ Primitive Tokens
1148
+ ↓
1149
+ Semantic Tokens
1150
+ ↓
1151
+ Typography Presets
1152
+ ↓
1153
+ useTypography()
1154
+ ↓
1155
+ React.CSSProperties
1156
+ ↓
1157
+ Component
1158
+ ```
1159
+
1160
+ ### Primitive Tokens
1161
+
1162
+ Primitive tokens contain reusable values such as:
1163
+
1164
+ ```ts
1165
+ fonts.body
1166
+ fonts.heading
1167
+ fonts.mono
1168
+
1169
+ fontSizes.sm
1170
+ fontSizes.md
1171
+ fontSizes.lg
1172
+
1173
+ fontWeights.normal
1174
+ fontWeights.medium
1175
+ fontWeights.bold
1176
+
1177
+ lineHeights.tight
1178
+ lineHeights.normal
1179
+ lineHeights.relaxed
1180
+ ```
1181
+
1182
+ They are defined with `defineToken()`.
1183
+
1184
+ ```ts
1185
+ const fonts = {
1186
+ body: defineToken("Inter, sans-serif"),
1187
+ heading: defineToken("Poppins, sans-serif"),
1188
+ };
1189
+ ```
1190
+
1191
+ ---
1192
+
1193
+ ### Semantic Tokens
1194
+
1195
+ Semantic tokens represent values that can change depending on the active theme or color mode.
1196
+
1197
+ They are defined with `defineSemanticToken()`.
1198
+
1199
+ ```ts
1200
+ const colors = {
1201
+ text: defineSemanticToken(
1202
+ "{colors.gray.900}",
1203
+ "{colors.gray.100}",
1204
+ ),
1205
+ };
1206
+ ```
1207
+
1208
+ Typography itself is generally not mode-dependent, but typography definitions can reference semantic tokens when appropriate.
1209
+
1210
+ ---
1211
+
1212
+ ### Typography Presets
1213
+
1214
+ Typography presets combine tokens into meaningful styles.
1215
+
1216
+ ```ts
1217
+ const typography = {
1218
+ body: {
1219
+ fontFamily: "{fonts.body}",
1220
+ fontSize: "{fontSizes.md}",
1221
+ fontWeight: "{fontWeights.normal}",
1222
+ lineHeight: "{lineHeights.normal}",
1223
+ },
1224
+
1225
+ heading: {
1226
+ fontFamily: "{fonts.heading}",
1227
+ fontSize: "{fontSizes.2xl}",
1228
+ fontWeight: "{fontWeights.bold}",
1229
+ lineHeight: "{lineHeights.tight}",
1230
+ },
1231
+ };
1232
+ ```
1233
+
1234
+ A preset is referenced by name:
1235
+
1236
+ ```tsx
1237
+ <Button typography="body" />
1238
+ ```
1239
+
1240
+ ---
1241
+
1242
+ ### `useTypography()`
1243
+
1244
+ The `useTypography()` hook retrieves the typography preset from the active theme and resolves all token references into CSS values.
1245
+
1246
+ ```tsx
1247
+ const styles = useTypography("heading");
1248
+ ```
1249
+
1250
+ The result is suitable for React's `style` prop:
1251
+
1252
+ ```tsx
1253
+ <h1 style={styles}>Welcome</h1>
1254
+ ```
1255
+
1256
+ ---
1257
+
1258
+ # Typography Architecture
1259
+
1260
+ A typical Kreativ UI theme contains:
1261
+
1262
+ ```ts
1263
+ const theme = {
1264
+ tokens: {
1265
+ fonts: {
1266
+ body: defineToken("Inter, sans-serif"),
1267
+ heading: defineToken("Poppins, sans-serif"),
1268
+ mono: defineToken("JetBrains Mono, monospace"),
1269
+ },
1270
+
1271
+ fontSizes: {
1272
+ sm: defineToken("0.875rem"),
1273
+ md: defineToken("1rem"),
1274
+ lg: defineToken("1.125rem"),
1275
+ },
1276
+
1277
+ fontWeights: {
1278
+ normal: defineToken(400),
1279
+ medium: defineToken(500),
1280
+ semibold: defineToken(600),
1281
+ bold: defineToken(700),
1282
+ },
1283
+
1284
+ lineHeights: {
1285
+ tight: defineToken(1.2),
1286
+ normal: defineToken(1.5),
1287
+ relaxed: defineToken(1.75),
1288
+ },
1289
+ },
1290
+
1291
+ typography: {
1292
+ body: {
1293
+ fontFamily: "{fonts.body}",
1294
+ fontSize: "{fontSizes.md}",
1295
+ fontWeight: "{fontWeights.normal}",
1296
+ lineHeight: "{lineHeights.normal}",
1297
+ },
1298
+
1299
+ heading: {
1300
+ fontFamily: "{fonts.heading}",
1301
+ fontSize: "{fontSizes.lg}",
1302
+ fontWeight: "{fontWeights.bold}",
1303
+ lineHeight: "{lineHeights.tight}",
1304
+ },
1305
+ },
1306
+ };
1307
+ ```
1308
+
1309
+ This creates a clear separation between **what a value is** and **how that value is used**.
1310
+
1311
+ For example:
1312
+
1313
+ ```text
1314
+ "Inter, sans-serif"
1315
+ ↓
1316
+ fonts.body
1317
+ ↓
1318
+ typography.body
1319
+ ↓
1320
+ useTypography("body")
1321
+ ↓
1322
+ CSSProperties
1323
+ ```
1324
+
1325
+ ---
1326
+
1327
+ # Using Typography in Components
1328
+
1329
+ There are several ways to consume the typography system.
1330
+
1331
+ ---
1332
+
1333
+ ## 1. Using `useTypography()` Directly
1334
+
1335
+ Use the hook when you are creating a custom component or need direct access to resolved typography styles.
1336
+
1337
+ ```tsx
1338
+ import { useTypography } from "@splenddev/kreativ-ui";
1339
+
1340
+ function MyCustomCard() {
1341
+ const headingStyles = useTypography("heading");
1342
+ const bodyStyles = useTypography("body");
1343
+
1344
+ return (
1345
+ <div>
1346
+ <h2 style={headingStyles}>
1347
+ Card Title
1348
+ </h2>
1349
+
1350
+ <p style={bodyStyles}>
1351
+ This is the card content.
1352
+ </p>
1353
+ </div>
1354
+ );
1355
+ }
1356
+ ```
1357
+
1358
+ The component does not need to know what font family, size, weight, or line height is currently configured.
1359
+
1360
+ ---
1361
+
1362
+ # 2. Creating a Reusable Component with `TypographyProps`
1363
+
1364
+ Kreativ UI exposes `TypographyProps` so custom components can participate in the same typography system.
1365
+
1366
+ ```ts
1367
+ export interface TypographyProps {
1368
+ /**
1369
+ * Defines the typography style to apply to the component.
1370
+ * The value must match a typography style registered in the theme.
1371
+ */
1372
+ typography?: string;
1373
+ }
1374
+ ```
1375
+
1376
+ A custom component can extend this interface:
1377
+
1378
+ ```tsx
1379
+ import {
1380
+ TypographyProps,
1381
+ useTypography,
1382
+ } from "@splenddev/kreativ-ui";
1383
+
1384
+ interface MyTextProps extends TypographyProps {
1385
+ children: React.ReactNode;
1386
+ }
1387
+
1388
+ function MyText({
1389
+ typography = "body",
1390
+ children,
1391
+ }: MyTextProps) {
1392
+ const styles = useTypography(typography);
1393
+
1394
+ return (
1395
+ <p style={styles}>
1396
+ {children}
1397
+ </p>
1398
+ );
1399
+ }
1400
+ ```
1401
+
1402
+ Usage:
1403
+
1404
+ ```tsx
1405
+ <MyText>
1406
+ Default body text
1407
+ </MyText>
1408
+
1409
+ <MyText typography="heading">
1410
+ Heading text
1411
+ </MyText>
1412
+
1413
+ <MyText typography="caption">
1414
+ Caption text
1415
+ </MyText>
1416
+ ```
1417
+
1418
+ This allows custom components to behave consistently with Kreativ UI's built-in components.
1419
+
1420
+ ---
1421
+
1422
+ # 3. Using Typography with Built-in Components
1423
+
1424
+ Built-in components that render text can expose the `typography` prop.
1425
+
1426
+ ```tsx
1427
+ <Button typography="bodySmall">
1428
+ Small Button
1429
+ </Button>
1430
+
1431
+ <Input typography="body" />
1432
+
1433
+ <Select typography="body" />
1434
+ ```
1435
+
1436
+ The typography prop controls typography-related properties while component-specific layout remains independent.
1437
+
1438
+ For example:
1439
+
1440
+ ```text
1441
+ Typography
1442
+ ├── fontFamily
1443
+ ├── fontSize
1444
+ ├── fontWeight
1445
+ ├── lineHeight
1446
+ └── letterSpacing
1447
+
1448
+ Component Size
1449
+ ├── height
1450
+ ├── padding
1451
+ ├── gap
1452
+ ├── iconSize
1453
+ └── radius
1454
+ ```
1455
+
1456
+ This separation prevents changing a typography preset from unexpectedly changing component dimensions.
1457
+
1458
+ ---
1459
+
1460
+ # 4. Typography and Component Size
1461
+
1462
+ Components such as `Button` often have their own size system:
1463
+
1464
+ ```ts
1465
+ sizes: {
1466
+ sm: {
1467
+ height: "2rem",
1468
+ paddingX: "0.75rem",
1469
+ gap: "0.375rem",
1470
+ iconSize: "1rem",
1471
+ radius: "0.8rem",
1472
+ },
1473
+
1474
+ md: {
1475
+ height: "2.5rem",
1476
+ paddingX: "1rem",
1477
+ gap: "0.5rem",
1478
+ iconSize: "1.125rem",
1479
+ radius: "1rem",
1480
+ },
1481
+ }
1482
+ ```
1483
+
1484
+ Typography should remain responsible for text properties.
1485
+
1486
+ For example:
1487
+
1488
+ ```tsx
1489
+ <Button
1490
+ size="lg"
1491
+ typography="bodySmall"
1492
+ >
1493
+ Continue
1494
+ </Button>
1495
+ ```
1496
+
1497
+ The button can use the large component dimensions while using the `bodySmall` typography preset.
1498
+
1499
+ Recommended responsibility:
1500
+
1501
+ ```text
1502
+ size
1503
+ → dimensions and component geometry
1504
+
1505
+ typography
1506
+ → text presentation
1507
+
1508
+ style
1509
+ → final consumer override
1510
+ ```
1511
+
1512
+ ---
1513
+
1514
+ # Loading Fonts
1515
+
1516
+ Kreativ UI does **not need to load fonts itself**.
1517
+
1518
+ Instead, your application is responsible for loading the font.
1519
+
1520
+ Kreativ UI only needs to know which font family should be used.
1521
+
1522
+ This allows Kreativ UI to work with:
1523
+
1524
+ * `next/font`
1525
+ * Google Fonts
1526
+ * local fonts
1527
+ * CSS `@font-face`
1528
+ * system fonts
1529
+ * CSS variables
1530
+ * external font providers
1531
+
1532
+ This separation makes the library framework-agnostic.
1533
+
1534
+ ---
1535
+
1536
+ # 5. Using Next.js `next/font`
1537
+
1538
+ This is one of the most common setups for a Next.js application.
1539
+
1540
+ For example:
1541
+
1542
+ ```tsx
1543
+ import { Geist, Geist_Mono } from "next/font/google";
1544
+
1545
+ const geistSans = Geist({
1546
+ variable: "--font-geist-sans",
1547
+ subsets: ["latin"],
1548
+ });
1549
+
1550
+ const geistMono = Geist_Mono({
1551
+ variable: "--font-geist-mono",
1552
+ subsets: ["latin"],
1553
+ });
1554
+ ```
1555
+
1556
+ Apply the generated variables to the document:
1557
+
1558
+ ```tsx
1559
+ <html
1560
+ lang="en"
1561
+ className={`${geistSans.variable} ${geistMono.variable}`}
1562
+ >
1563
+ ```
1564
+
1565
+ The CSS variables are now available to your application.
1566
+
1567
+ You can register them with Kreativ UI:
1568
+
1569
+ ```tsx
1570
+ import {
1571
+ UIProvider,
1572
+ defineToken,
1573
+ } from "@splenddev/kreativ-ui";
1574
+
1575
+ <UIProvider
1576
+ theme={{
1577
+ tokens: {
1578
+ fonts: {
1579
+ body: defineToken("var(--font-geist-sans)"),
1580
+ heading: defineToken("var(--font-geist-sans)"),
1581
+ mono: defineToken("var(--font-geist-mono)"),
1582
+ },
1583
+ },
1584
+ }}
1585
+ >
1586
+ {children}
1587
+ </UIProvider>
1588
+ ```
1589
+
1590
+ Your typography presets can continue to reference semantic font roles:
1591
+
1592
+ ```ts
1593
+ const typography = {
1594
+ body: {
1595
+ fontFamily: "{fonts.body}",
1596
+ fontSize: "{fontSizes.md}",
1597
+ fontWeight: "{fontWeights.normal}",
1598
+ lineHeight: "{lineHeights.normal}",
1599
+ },
1600
+
1601
+ code: {
1602
+ fontFamily: "{fonts.mono}",
1603
+ fontSize: "{fontSizes.sm}",
1604
+ lineHeight: "{lineHeights.normal}",
1605
+ },
1606
+ };
1607
+ ```
1608
+
1609
+ This produces the following flow:
1610
+
1611
+ ```text
1612
+ next/font
1613
+ ↓
1614
+ --font-geist-sans
1615
+ ↓
1616
+ fonts.body
1617
+ ↓
1618
+ typography.body
1619
+ ↓
1620
+ useTypography("body")
1621
+ ↓
1622
+ fontFamily: var(--font-geist-sans)
1623
+ ```
1624
+
1625
+ ### Why this approach is recommended
1626
+
1627
+ Kreativ UI does not need to know that the font came from Next.js.
1628
+
1629
+ It only consumes:
1630
+
1631
+ ```css
1632
+ var(--font-geist-sans)
1633
+ ```
1634
+
1635
+ This keeps the design system independent from the framework responsible for loading the font.
1636
+
1637
+ ---
1638
+
1639
+ # 6. Using Google Fonts Without `next/font`
1640
+
1641
+ If your application loads a font through CSS or another font provider, you can register it directly.
1642
+
1643
+ ```ts
1644
+ const theme = {
1645
+ tokens: {
1646
+ fonts: {
1647
+ body: defineToken("Inter, sans-serif"),
1648
+ heading: defineToken("Poppins, sans-serif"),
1649
+ },
1650
+ },
1651
+ };
1652
+ ```
1653
+
1654
+ Your typography definitions remain unchanged:
1655
+
1656
+ ```ts
1657
+ const typography = {
1658
+ body: {
1659
+ fontFamily: "{fonts.body}",
1660
+ fontSize: "{fontSizes.md}",
1661
+ lineHeight: "{lineHeights.normal}",
1662
+ },
1663
+ };
1664
+ ```
1665
+
1666
+ The typography system does not care how the font was loaded.
1667
+
1668
+ ---
1669
+
1670
+ # 7. Using Local Fonts
1671
+
1672
+ If your application defines a local font using `@font-face`:
1673
+
1674
+ ```css
1675
+ @font-face {
1676
+ font-family: "MyBrandFont";
1677
+ src: url("/fonts/my-brand-font.woff2") format("woff2");
1678
+ }
1679
+ ```
1680
+
1681
+ Register it:
1682
+
1683
+ ```ts
1684
+ const theme = {
1685
+ tokens: {
1686
+ fonts: {
1687
+ body: defineToken("MyBrandFont, sans-serif"),
1688
+ },
1689
+ },
1690
+ };
1691
+ ```
1692
+
1693
+ Then reference it from typography:
1694
+
1695
+ ```ts
1696
+ const typography = {
1697
+ body: {
1698
+ fontFamily: "{fonts.body}",
1699
+ fontSize: "{fontSizes.md}",
1700
+ lineHeight: "{lineHeights.normal}",
1701
+ },
1702
+ };
1703
+ ```
1704
+
1705
+ ---
1706
+
1707
+ # 8. Using CSS Variables for Fonts
1708
+
1709
+ CSS variables are particularly useful when the application already has a global font system.
1710
+
1711
+ ```css
1712
+ :root {
1713
+ --app-font-body: "Inter", sans-serif;
1714
+ --app-font-heading: "Poppins", sans-serif;
1715
+ }
1716
+ ```
1717
+
1718
+ Register them:
1719
+
1720
+ ```ts
1721
+ const theme = {
1722
+ tokens: {
1723
+ fonts: {
1724
+ body: defineToken("var(--app-font-body)"),
1725
+ heading: defineToken("var(--app-font-heading)"),
1726
+ },
1727
+ },
1728
+ };
1729
+ ```
1730
+
1731
+ This also allows the font to be changed without changing the typography definitions themselves.
1732
+
1733
+ ---
1734
+
1735
+ # 9. Using a System Font Stack
1736
+
1737
+ You do not need a custom font.
1738
+
1739
+ ```ts
1740
+ const theme = {
1741
+ tokens: {
1742
+ fonts: {
1743
+ body: defineToken(
1744
+ "ui-sans-serif, system-ui, sans-serif",
1745
+ ),
1746
+
1747
+ heading: defineToken(
1748
+ "ui-sans-serif, system-ui, sans-serif",
1749
+ ),
1750
+
1751
+ mono: defineToken(
1752
+ "ui-monospace, SFMono-Regular, Menlo, monospace",
1753
+ ),
1754
+ },
1755
+ },
1756
+ };
1757
+ ```
1758
+
1759
+ ---
1760
+
1761
+ # Customising Typography
1762
+
1763
+ ## 10. Extending the Default Presets
1764
+
1765
+ You can add custom typography presets while retaining the defaults.
1766
+
1767
+ ```tsx
1768
+ import {
1769
+ UIProvider,
1770
+ defaultTheme,
1771
+ } from "@splenddev/kreativ-ui";
1772
+
1773
+ const typography = {
1774
+ ...defaultTheme.typography,
1775
+
1776
+ display: {
1777
+ fontFamily: "{fonts.heading}",
1778
+ fontSize: "4rem",
1779
+ fontWeight: 700,
1780
+ lineHeight: "1",
1781
+ letterSpacing: "-0.04em",
1782
+ },
1783
+
1784
+ label: {
1785
+ fontFamily: "{fonts.body}",
1786
+ fontSize: "0.75rem",
1787
+ fontWeight: 600,
1788
+ lineHeight: "1.2",
1789
+ },
1790
+ };
1791
+
1792
+ const theme = {
1793
+ ...defaultTheme,
1794
+ typography,
1795
+ };
1796
+
1797
+ <UIProvider theme={theme}>
1798
+ <App />
1799
+ </UIProvider>;
1800
+ ```
1801
+
1802
+ You can now use:
1803
+
1804
+ ```tsx
1805
+ <Button typography="label">
1806
+ Continue
1807
+ </Button>
1808
+
1809
+ <MyText typography="display">
1810
+ Welcome
1811
+ </MyText>
1812
+ ```
1813
+
1814
+ ---
1815
+
1816
+ # 11. Overriding an Existing Typography Preset
1817
+
1818
+ You can also modify a built-in preset.
1819
+
1820
+ ```ts
1821
+ const typography = {
1822
+ ...defaultTheme.typography,
1823
+
1824
+ body: {
1825
+ ...defaultTheme.typography.body,
1826
+ fontSize: "{fontSizes.lg}",
1827
+ },
1828
+ };
1829
+ ```
1830
+
1831
+ Every component using:
1832
+
1833
+ ```tsx
1834
+ typography="body"
1835
+ ```
1836
+
1837
+ will now use the customized definition.
1838
+
1839
+ This is useful when you want to change the application's typography globally without modifying every component.
1840
+
1841
+ ---
1842
+
1843
+ # 12. Creating Typography with `defineTypography()`
1844
+
1845
+ For design-system authors, Kreativ UI provides `defineTypography()`.
1846
+
1847
+ ```ts
1848
+ import {
1849
+ defineTypography,
1850
+ } from "@splenddev/kreativ-ui";
1851
+
1852
+ const typography = {
1853
+ display: defineTypography({
1854
+ fontFamily: "{fonts.heading}",
1855
+ fontSize: "{fontSizes.4xl}",
1856
+ fontWeight: "{fontWeights.bold}",
1857
+ lineHeight: "{lineHeights.tight}",
1858
+ letterSpacing: "-0.04em",
1859
+ }),
1860
+ };
1861
+ ```
1862
+
1863
+ `defineTypography()` provides a consistent definition API and ensures the typography object conforms to the expected typography structure.
1864
+
1865
+ It is especially useful when creating reusable theme configurations.
1866
+
1867
+ ---
1868
+
1869
+ # 13. Defining Custom Tokens with `defineToken()`
1870
+
1871
+ Use `defineToken()` for primitive values.
1872
+
1873
+ ```ts
1874
+ import { defineToken } from "@splenddev/kreativ-ui";
1875
+
1876
+ const tokens = {
1877
+ fonts: {
1878
+ serif: defineToken("Georgia, serif"),
1879
+ },
1880
+
1881
+ fontSizes: {
1882
+ "5xl": defineToken("3rem"),
1883
+ },
1884
+
1885
+ fontWeights: {
1886
+ black: defineToken(900),
1887
+ },
1888
+ };
1889
+ ```
1890
+
1891
+ These tokens can then be referenced by typography:
1892
+
1893
+ ```ts
1894
+ const typography = {
1895
+ serifDisplay: defineTypography({
1896
+ fontFamily: "{fonts.serif}",
1897
+ fontSize: "{fontSizes.5xl}",
1898
+ fontWeight: "{fontWeights.black}",
1899
+ lineHeight: "{lineHeights.tight}",
1900
+ }),
1901
+ };
1902
+ ```
1903
+
1904
+ Using `defineToken()` ensures the values follow the token structure expected by the theme engine.
1905
+
1906
+ ---
1907
+
1908
+ # 14. Semantic Tokens
1909
+
1910
+ Semantic tokens are useful when a value needs to change according to the active theme or color mode.
1911
+
1912
+ ```ts
1913
+ const tokens = {
1914
+ colors: {
1915
+ brandText: defineSemanticToken(
1916
+ "{colors.blue.700}",
1917
+ "{colors.blue.200}",
1918
+ ),
1919
+ },
1920
+ };
1921
+ ```
1922
+
1923
+ Typography itself generally does not need separate light and dark definitions.
1924
+
1925
+ Instead, semantic tokens are most useful when typography is combined with color or other semantic styling.
1926
+
1927
+ For example:
1928
+
1929
+ ```ts
1930
+ const semanticTokens = {
1931
+ text: {
1932
+ primary: defineSemanticToken(
1933
+ "{colors.gray.900}",
1934
+ "{colors.gray.100}",
1935
+ ),
1936
+ },
1937
+ };
1938
+ ```
1939
+
1940
+ A component can then combine typography with the semantic text color.
1941
+
1942
+ ---
1943
+
1944
+ # 15. Direct CSS Values
1945
+
1946
+ Typography values do not have to reference tokens.
1947
+
1948
+ You can use literal CSS values:
1949
+
1950
+ ```ts
1951
+ const typography = {
1952
+ custom: defineTypography({
1953
+ fontFamily: "Georgia, serif",
1954
+ fontSize: "1.125rem",
1955
+ fontWeight: 600,
1956
+ lineHeight: 1.6,
1957
+ letterSpacing: "-0.01em",
1958
+ }),
1959
+ };
1960
+ ```
1961
+
1962
+ This is useful for typography that is intentionally unique.
1963
+
1964
+ However, reusable design-system values should generally be represented as tokens.
1965
+
1966
+ ---
1967
+
1968
+ # 16. Combining Typography with Component Overrides
1969
+
1970
+ Typography provides the baseline text styling, while consumers can still make one-off overrides.
1971
+
1972
+ For example:
1973
+
1974
+ ```tsx
1975
+ <Button
1976
+ typography="body"
1977
+ style={{
1978
+ fontWeight: 700,
1979
+ }}
1980
+ >
1981
+ Continue
1982
+ </Button>
1983
+ ```
1984
+
1985
+ The recommended precedence is:
1986
+
1987
+ ```text
1988
+ Component defaults
1989
+ ↓
1990
+ Component size/layout
1991
+ ↓
1992
+ Typography preset
1993
+ ↓
1994
+ Explicit style prop
1995
+ ```
1996
+
1997
+ This means the `style` prop remains an escape hatch for application-specific cases.
1998
+
1999
+ Avoid using it repeatedly for values that should actually become part of your theme.
2000
+
2001
+ ---
2002
+
2003
+ # 17. Creating a Typography-Aware Custom Component
2004
+
2005
+ A complete custom component might look like this:
2006
+
2007
+ ```tsx
2008
+ import {
2009
+ TypographyProps,
2010
+ useTypography,
2011
+ } from "@splenddev/kreativ-ui";
2012
+
2013
+ interface CardTitleProps extends TypographyProps {
2014
+ children: React.ReactNode;
2015
+ }
2016
+
2017
+ function CardTitle({
2018
+ typography = "headingSmall",
2019
+ children,
2020
+ }: CardTitleProps) {
2021
+ const typographyStyles = useTypography(typography);
2022
+
2023
+ return (
2024
+ <h3 style={typographyStyles}>
2025
+ {children}
2026
+ </h3>
2027
+ );
2028
+ }
2029
+ ```
2030
+
2031
+ Usage:
2032
+
2033
+ ```tsx
2034
+ <CardTitle>
2035
+ Default title
2036
+ </CardTitle>
2037
+
2038
+ <CardTitle typography="heading">
2039
+ Large title
2040
+ </CardTitle>
2041
+
2042
+ <CardTitle typography="display">
2043
+ Custom display title
2044
+ </CardTitle>
2045
+ ```
2046
+
2047
+ The component remains completely independent of the actual font values.
2048
+
2049
+ ---
2050
+
2051
+ # 18. Using Typography Without a Preset Name
2052
+
2053
+ If a component needs to use typography dynamically, it can simply pass the name received from its props:
2054
+
2055
+ ```tsx
2056
+ function MyComponent({
2057
+ typography = "body",
2058
+ }: TypographyProps) {
2059
+ const styles = useTypography(typography);
2060
+
2061
+ return (
2062
+ <div style={styles}>
2063
+ Content
2064
+ </div>
2065
+ );
2066
+ }
2067
+ ```
2068
+
2069
+ The component does not need to maintain its own list of typography styles.
2070
+
2071
+ This allows application-defined styles to work automatically.
2072
+
2073
+ ---
2074
+
2075
+ # Runtime Theme Changes
2076
+
2077
+ Typography is resolved against the active theme.
2078
+
2079
+ For example, suppose the default theme contains:
2080
+
2081
+ ```ts
2082
+ fonts: {
2083
+ body: defineToken("Inter, sans-serif"),
2084
+ }
2085
+ ```
2086
+
2087
+ and a custom theme changes it to:
2088
+
2089
+ ```ts
2090
+ fonts: {
2091
+ body: defineToken("Poppins, sans-serif"),
2092
+ }
2093
+ ```
2094
+
2095
+ A typography preset referencing:
2096
+
2097
+ ```ts
2098
+ fontFamily: "{fonts.body}"
2099
+ ```
2100
+
2101
+ does not need to change.
2102
+
2103
+ It automatically resolves to the active token value.
2104
+
2105
+ ```text
2106
+ Typography
2107
+ ↓
2108
+ {fonts.body}
2109
+ ↓
2110
+ Active theme
2111
+ ↓
2112
+ Poppins, sans-serif
2113
+ ```
2114
+
2115
+ This is one of the primary benefits of the token-based architecture.
2116
+
2117
+ ---
2118
+
2119
+ # Recommended Typography Structure
2120
+
2121
+ For most applications, a semantic typography structure works well:
2122
+
2123
+ ```ts
2124
+ const typography = {
2125
+ body: {},
2126
+ bodySmall: {},
2127
+
2128
+ heading: {},
2129
+ headingSmall: {},
2130
+
2131
+ caption: {},
2132
+
2133
+ label: {},
2134
+
2135
+ code: {},
2136
+
2137
+ display: {},
2138
+ };
2139
+ ```
2140
+
2141
+ The exact names are completely customizable.
2142
+
2143
+ Avoid names such as:
2144
+
2145
+ ```ts
2146
+ small12
2147
+ font14
2148
+ large20
2149
+ bold16
2150
+ ```
2151
+
2152
+ Prefer semantic names:
2153
+
2154
+ ```ts
2155
+ bodySmall
2156
+ body
2157
+ heading
2158
+ caption
2159
+ label
2160
+ display
2161
+ ```
2162
+
2163
+ This makes the design system easier to maintain when the actual values change.
2164
+
2165
+ ---
2166
+
2167
+ # Best Practices
2168
+
2169
+ ### Prefer semantic typography names
2170
+
2171
+ Use:
2172
+
2173
+ ```tsx
2174
+ typography="heading"
2175
+ ```
2176
+
2177
+ instead of:
2178
+
2179
+ ```tsx
2180
+ typography="font24"
2181
+ ```
2182
+
2183
+ ---
2184
+
2185
+ ### Use tokens for reusable values
2186
+
2187
+ Prefer:
2188
+
2189
+ ```ts
2190
+ fontSize: "{fontSizes.md}"
2191
+ ```
2192
+
2193
+ over repeatedly writing:
2194
+
2195
+ ```ts
2196
+ fontSize: "0.875rem"
2197
+ ```
2198
+
2199
+ ---
2200
+
2201
+ ### Let the application load fonts
2202
+
2203
+ Kreativ UI should consume fonts rather than own the font-loading mechanism.
2204
+
2205
+ This allows it to work with:
2206
+
2207
+ * Next.js
2208
+ * Vite
2209
+ * Remix
2210
+ * CRA
2211
+ * plain React
2212
+ * CSS
2213
+ * local fonts
2214
+ * external font providers
2215
+
2216
+ ---
2217
+
2218
+ ### Use `defineToken()`
2219
+
2220
+ Prefer:
2221
+
2222
+ ```ts
2223
+ fonts: {
2224
+ body: defineToken("Inter, sans-serif"),
2225
+ }
2226
+ ```
2227
+
2228
+ over manually constructing:
2229
+
2230
+ ```ts
2231
+ fonts: {
2232
+ body: {
2233
+ value: "Inter, sans-serif",
2234
+ },
2235
+ }
2236
+ ```
2237
+
2238
+ ---
2239
+
2240
+ ### Use `defineTypography()`
2241
+
2242
+ When creating reusable typography definitions:
2243
+
2244
+ ```ts
2245
+ heading: defineTypography({
2246
+ fontFamily: "{fonts.heading}",
2247
+ fontSize: "{fontSizes.2xl}",
2248
+ fontWeight: "{fontWeights.bold}",
2249
+ lineHeight: "{lineHeights.tight}",
2250
+ })
2251
+ ```
2252
+
2253
+ This gives the definition a clear and consistent API.
2254
+
2255
+ ---
2256
+
2257
+ ### Use `useTypography()` in custom components
2258
+
2259
+ Avoid manually accessing:
2260
+
2261
+ ```ts
2262
+ theme.typography
2263
+ ```
2264
+
2265
+ inside every component.
2266
+
2267
+ Prefer:
2268
+
2269
+ ```ts
2270
+ const styles = useTypography("body");
2271
+ ```
2272
+
2273
+ This keeps typography resolution centralized.
2274
+
2275
+ ---
2276
+
2277
+ ### Keep typography separate from layout
2278
+
2279
+ Typography should control:
2280
+
2281
+ ```text
2282
+ fontFamily
2283
+ fontSize
2284
+ fontWeight
2285
+ lineHeight
2286
+ letterSpacing
2287
+ ```
2288
+
2289
+ Component size should control:
2290
+
2291
+ ```text
2292
+ height
2293
+ padding
2294
+ gap
2295
+ radius
2296
+ iconSize
2297
+ ```
2298
+
2299
+ This makes components more predictable.
2300
+
2301
+ ---
2302
+
2303
+ # API Reference
2304
+
2305
+ ## `useTypography()`
2306
+
2307
+ ```ts
2308
+ useTypography(name?: string): React.CSSProperties
2309
+ ```
2310
+
2311
+ Resolves a typography preset from the active theme and returns React-compatible CSS properties.
2312
+
2313
+ ### Parameters
2314
+
2315
+ | Parameter | Type | Description |
2316
+ | --------- | -------- | ----------------------------- |
2317
+ | `name` | `string` | Name of the typography preset |
2318
+
2319
+ ### Example
2320
+
2321
+ ```tsx
2322
+ const styles = useTypography("heading");
2323
+
2324
+ return <h1 style={styles}>Hello</h1>;
2325
+ ```
2326
+
2327
+ ---
2328
+
2329
+ ## `TypographyProps`
2330
+
2331
+ ```ts
2332
+ interface TypographyProps {
2333
+ typography?: string;
2334
+ }
2335
+ ```
2336
+
2337
+ Allows a component to expose the theme's typography presets through a `typography` prop.
2338
+
2339
+ ---
2340
+
2341
+ ## `TypographyStyle`
2342
+
2343
+ ```ts
2344
+ interface TypographyStyle {
2345
+ fontFamily?: string;
2346
+ fontSize?: string;
2347
+ fontWeight?: string | number;
2348
+ lineHeight?: string | number;
2349
+ letterSpacing?: string;
2350
+ }
2351
+ ```
2352
+
2353
+ Defines the typography properties supported by Kreativ UI.
2354
+
2355
+ ---
2356
+
2357
+ ## `Typography`
2358
+
2359
+ ```ts
2360
+ type Typography = Record<string, TypographyStyle>;
2361
+ ```
2362
+
2363
+ Represents the collection of named typography presets available in a theme.
2364
+
2365
+ ---
2366
+
2367
+ ## `defineTypography()`
2368
+
2369
+ ```ts
2370
+ defineTypography(
2371
+ typography: TypographyStyle,
2372
+ ): TypographyStyle
2373
+ ```
2374
+
2375
+ Defines and type-checks a typography preset.
2376
+
2377
+ Example:
2378
+
2379
+ ```ts
2380
+ const heading = defineTypography({
2381
+ fontFamily: "{fonts.heading}",
2382
+ fontSize: "{fontSizes.2xl}",
2383
+ fontWeight: "{fontWeights.bold}",
2384
+ lineHeight: "{lineHeights.tight}",
2385
+ });
2386
+ ```
2387
+
2388
+ ---
2389
+
2390
+ ## `defineToken()`
2391
+
2392
+ ```ts
2393
+ defineToken<T>(value: T): {
2394
+ value: T;
2395
+ }
2396
+ ```
2397
+
2398
+ Creates a primitive design token.
2399
+
2400
+ Example:
2401
+
2402
+ ```ts
2403
+ const bodyFont = defineToken(
2404
+ "Inter, sans-serif",
2405
+ );
2406
+ ```
2407
+
2408
+ ---
2409
+
2410
+ ## `defineSemanticToken()`
2411
+
2412
+ ```ts
2413
+ defineSemanticToken<T>(
2414
+ light: T,
2415
+ dark: T,
2416
+ ): {
2417
+ value: {
2418
+ light: T;
2419
+ dark: T;
2420
+ };
2421
+ }
2422
+ ```
2423
+
2424
+ Creates a theme-aware semantic token.
2425
+
2426
+ ---
2427
+
2428
+ ## `resolveTokenReference()`
2429
+
2430
+ ```ts
2431
+ resolveTokenReference(
2432
+ value: unknown,
2433
+ tokens: DesignTokens,
2434
+ ): string | number
2435
+ ```
2436
+
2437
+ Resolves a token reference such as:
2438
+
2439
+ ```ts
2440
+ "{fonts.body}"
2441
+ ```
2442
+
2443
+ against the active design-token collection.
2444
+
2445
+ ---
2446
+
2447
+ ## `resolveTypography()`
2448
+
2449
+ ```ts
2450
+ resolveTypography(
2451
+ typography: TypographyStyle | undefined,
2452
+ tokens: DesignTokens,
2453
+ ): React.CSSProperties
2454
+ ```
2455
+
2456
+ Converts a typography definition into resolved React CSS properties.
2457
+
2458
+ ---
2459
+
2460
+ # Complete Example
2461
+
2462
+ The following example demonstrates a complete Next.js setup using `next/font`, Kreativ UI tokens, typography, and a custom component.
2463
+
2464
+ ```tsx
2465
+ import { Geist, Geist_Mono } from "next/font/google";
2466
+
2467
+ import {
2468
+ UIProvider,
2469
+ defineToken,
2470
+ defineTypography,
2471
+ defaultTheme,
2472
+ } from "@splenddev/kreativ-ui";
2473
+
2474
+ const geistSans = Geist({
2475
+ variable: "--font-geist-sans",
2476
+ subsets: ["latin"],
2477
+ });
2478
+
2479
+ const geistMono = Geist_Mono({
2480
+ variable: "--font-geist-mono",
2481
+ subsets: ["latin"],
2482
+ });
2483
+
2484
+ const theme = {
2485
+ ...defaultTheme,
2486
+
2487
+ tokens: {
2488
+ ...defaultTheme.tokens,
2489
+
2490
+ fonts: {
2491
+ ...defaultTheme.tokens.fonts,
2492
+
2493
+ body: defineToken(
2494
+ "var(--font-geist-sans)",
2495
+ ),
2496
+
2497
+ heading: defineToken(
2498
+ "var(--font-geist-sans)",
2499
+ ),
2500
+
2501
+ mono: defineToken(
2502
+ "var(--font-geist-mono)",
2503
+ ),
2504
+ },
2505
+ },
2506
+
2507
+ typography: {
2508
+ ...defaultTheme.typography,
2509
+
2510
+ display: defineTypography({
2511
+ fontFamily: "{fonts.heading}",
2512
+ fontSize: "4rem",
2513
+ fontWeight: "{fontWeights.bold}",
2514
+ lineHeight: "1",
2515
+ letterSpacing: "-0.04em",
2516
+ }),
2517
+ },
2518
+ };
2519
+
2520
+ export default function RootLayout({
2521
+ children,
2522
+ }: LayoutProps<"/">) {
2523
+ return (
2524
+ <html
2525
+ lang="en"
2526
+ className={`${geistSans.variable} ${geistMono.variable}`}
2527
+ >
2528
+ <body>
2529
+ <UIProvider theme={theme}>
2530
+ {children}
2531
+ </UIProvider>
2532
+ </body>
2533
+ </html>
2534
+ );
2535
+ }
2536
+ ```
2537
+
2538
+ The important separation is:
2539
+
2540
+ ```text
2541
+ Next.js
2542
+ │
2543
+ └── Loads Geist
2544
+ │
2545
+ └── --font-geist-sans
2546
+ │
2547
+ ▼
2548
+ Kreativ UI font token
2549
+ │
2550
+ └── fonts.body
2551
+ │
2552
+ ▼
2553
+ Typography preset
2554
+ │
2555
+ └── typography.body
2556
+ │
2557
+ ▼
2558
+ useTypography("body")
2559
+ │
2560
+ ▼
2561
+ React.CSSProperties
2562
+ ```
2563
+
2564
+ 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.
2565
+
1108
2566
  # ♿ Accessibility
1109
2567
 
1110
2568
  Kreativ UI components are built with accessibility in mind:
@@ -1130,4 +2588,4 @@ MIT
1130
2588
  ---
1131
2589
 
1132
2590
  **More component documentation (Textarea, Checkbox, RadioGroup, etc.) coming soon.**
1133
- Visit the [GitHub repository](https://github.com/Vincentvirtuoso/kreativ-ui) for updates.
2591
+ Visit the [GitHub repository](https://github.com/Vincentvirtuoso/kreativ-ui) for updates.