@splenddev/kreativ-ui 0.2.7 → 0.2.8

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
@@ -274,83 +274,781 @@ Supported transition types: `none`, `fade`, `slide`, `scale`, `rotate`.
274
274
 
275
275
  # Button
276
276
 
277
- A versatile button with support for variants, sizes, loading states, icons, and full‑width.
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
+ ---
278
282
 
279
283
  ## Basic Usage
280
284
 
281
285
  ```tsx
286
+ import { Button } from "@splenddev/kreativ-ui";
287
+
282
288
  <Button>Click me</Button>
283
289
  ```
284
290
 
291
+ By default, the Button uses:
292
+
293
+ * `variant="solid"`
294
+ * `color="brand"`
295
+ * `size="md"`
296
+ * `typography="body"`
297
+ * `fullWidth={false}`
298
+ * `isLoading={false}`
299
+ * `disabled={false}`
300
+
301
+ ---
302
+
285
303
  ## Variants
286
304
 
305
+ Use `variant` to control the Button's visual treatment.
306
+
287
307
  ```tsx
288
308
  <Button variant="solid">Solid</Button>
289
- <Button variant="outline">Outline</Button>
290
- <Button variant="ghost">Ghost</Button>
291
- <Button variant="soft">Soft</Button>
292
- <Button variant="destructive">Delete</Button>
293
- <Button variant="success">Success</Button>
294
- <Button variant="link">Learn more</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>
325
+ ```
326
+
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>
344
+
345
+ <Button variant="destructive">
346
+ Delete
347
+ </Button>
348
+
349
+ <Button variant="success">
350
+ Success
351
+ </Button>
295
352
  ```
296
353
 
354
+ Available colors depend on the configured Button recipe and theme.
355
+
356
+ ---
357
+
297
358
  ## Sizes
298
359
 
360
+ Buttons support the standard Kreativ UI size scale:
361
+
299
362
  ```tsx
300
- <Button size="xs">Extra Small</Button>
301
- <Button size="sm">Small</Button>
302
- <Button size="md">Medium</Button>
303
- <Button size="lg">Large</Button>
304
- <Button size="xl">Extra Large</Button>
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>
305
382
  ```
306
383
 
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
+ ---
395
+
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.
401
+
402
+ ```tsx
403
+ <Button size="custom">
404
+ Custom Size
405
+ </Button>
406
+ ```
407
+
408
+ For example:
409
+
410
+ ```ts
411
+ 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
+ },
421
+ },
422
+ };
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
+
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
+
307
471
  ## Loading State
308
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
+
309
508
  ```tsx
310
- <Button isLoading>Saving...</Button>
509
+ <Button leftIcon={<SearchIcon />}>
510
+ Search
511
+ </Button>
311
512
  ```
312
513
 
313
- ## Icons
514
+ ### Right Icon
314
515
 
315
516
  ```tsx
316
- <Button leftIcon={<SearchIcon />}>Search</Button>
317
- <Button rightIcon={<ArrowRightIcon />}>Continue</Button>
517
+ <Button rightIcon={<ArrowRightIcon />}>
518
+ Continue
519
+ </Button>
318
520
  ```
319
521
 
320
- ## Icon Only
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.
321
556
 
322
557
  ```tsx
323
- <Button iconOnly aria-label="Search">
558
+ <Button
559
+ iconOnly
560
+ aria-label="Search"
561
+ >
324
562
  <SearchIcon />
325
563
  </Button>
326
564
  ```
327
565
 
328
- ## Full Width
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:
329
571
 
330
572
  ```tsx
331
- <Button fullWidth>Continue</Button>
573
+ <Button
574
+ iconOnly
575
+ aria-label="Open settings"
576
+ >
577
+ <SettingsIcon />
578
+ </Button>
332
579
  ```
333
580
 
334
- ## Custom Sizes via Theme
581
+ ---
335
582
 
336
- Define additional sizes in the theme (as shown in the Theming section) and use them with `size` prop.
583
+ # Full Width
337
584
 
338
- ## Props
585
+ Use `fullWidth` to make the Button fill its available horizontal space.
339
586
 
340
- | Prop | Type | Default | Description |
341
- | ------------------------ | ----------------------------------------------------------------------------------- | --------- | ------------------------------------------- |
342
- | `variant` | `"solid" \| "outline" \| "ghost" \| "soft" \| "destructive" \| "success" \| "link"` | `"solid"` | Visual style |
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 |
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
+ ```
349
612
 
350
- All standard `<button>` props are forwarded.
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.
351
624
 
352
625
  ---
353
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;
655
+ }
656
+ ```
657
+
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
665
+
666
+ ### Using a Custom Component
667
+
668
+ The same pattern can be used with another component:
669
+
670
+ ```tsx
671
+ <Button
672
+ render={(props) => (
673
+ <CustomLink
674
+ {...props}
675
+ href="/templates"
676
+ />
677
+ )}
678
+ >
679
+ Templates
680
+ </Button>
681
+ ```
682
+
683
+ ---
684
+
685
+ ## Next.js Server Component Note
686
+
687
+ The `render` prop contains a function.
688
+
689
+ Because functions cannot cross the Next.js Server Component → Client Component boundary, `render` should be used from a Client Component.
690
+
691
+ ### ❌ This can fail
692
+
693
+ ```tsx
694
+ // page.tsx
695
+
696
+ import { Button } from "@splenddev/kreativ-ui";
697
+
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
+ }
711
+ ```
712
+
713
+ ### ✅ Create the render function in a Client Component
714
+
715
+ ```tsx
716
+ "use client";
717
+
718
+ import { Button } from "@splenddev/kreativ-ui";
719
+
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
+ ```
734
+
735
+ The Client Component can then be rendered from your Server Component:
736
+
737
+ ```tsx
738
+ import { TemplatesButton } from "./TemplatesButton";
739
+
740
+ export default function Page() {
741
+ return <TemplatesButton />;
742
+ }
743
+ ```
744
+
745
+ > **Note:** `render` is intentionally retained as an advanced rendering API. For ordinary Buttons, simply use `<Button>`.
746
+
747
+ ---
748
+
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:
767
+
768
+ ```tsx
769
+ <Button
770
+ variant="solid"
771
+ size="sm"
772
+ typography="bodySmall"
773
+ isLoading
774
+ >
775
+ Processing...
776
+ </Button>
777
+ ```
778
+
779
+ ---
780
+
781
+ # Theming
782
+
783
+ Button behavior and appearance are driven by the active Kreativ UI theme.
784
+
785
+ The Button recipe controls visual variants:
786
+
787
+ ```ts
788
+ const theme = {
789
+ recipes: {
790
+ Button: {
791
+ // recipe configuration
792
+ },
793
+ },
794
+ };
795
+ ```
796
+
797
+ The size system controls dimensions:
798
+
799
+ ```ts
800
+ const theme = {
801
+ sizes: {
802
+ // ...
803
+ },
804
+ };
805
+ ```
806
+
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
+
354
1052
  # 🧩 Input & FormField
355
1053
 
356
1054
  This section covers the `Input` component and the `FormField` composition system for building accessible, validated form controls.