@brightlocal/ui-components 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/README.md +6 -1
  2. package/component-meta.json +663 -38
  3. package/deprecations.json +1 -1
  4. package/dist/alert-dialog.cjs +1 -1
  5. package/dist/alert-dialog.d.ts +32 -3
  6. package/dist/alert-dialog.d.ts.map +1 -1
  7. package/dist/alert-dialog.js +61 -58
  8. package/dist/alert.cjs +1 -1
  9. package/dist/alert.d.ts.map +1 -1
  10. package/dist/alert.js +58 -57
  11. package/dist/badge.cjs +1 -1
  12. package/dist/badge.d.ts +9 -0
  13. package/dist/badge.d.ts.map +1 -1
  14. package/dist/badge.js +50 -30
  15. package/dist/banner.cjs +1 -0
  16. package/dist/banner.d.ts +81 -0
  17. package/dist/banner.d.ts.map +1 -0
  18. package/dist/banner.js +176 -0
  19. package/dist/blocks/empty-state.cjs +1 -1
  20. package/dist/blocks/empty-state.d.ts +4 -3
  21. package/dist/blocks/empty-state.d.ts.map +1 -1
  22. package/dist/blocks/empty-state.js +21 -20
  23. package/dist/blocks/progress-state.d.ts +2 -2
  24. package/dist/blocks/sidebar.cjs +1 -1
  25. package/dist/blocks/sidebar.d.ts +17 -0
  26. package/dist/blocks/sidebar.d.ts.map +1 -1
  27. package/dist/blocks/sidebar.js +8 -2
  28. package/dist/brand-illustration-motif.d.ts +1 -1
  29. package/dist/card.cjs +1 -1
  30. package/dist/card.d.ts +86 -6
  31. package/dist/card.d.ts.map +1 -1
  32. package/dist/card.js +185 -96
  33. package/dist/chart.cjs +3 -3
  34. package/dist/chart.d.ts +231 -13
  35. package/dist/chart.d.ts.map +1 -1
  36. package/dist/chart.js +466 -306
  37. package/dist/checkbox.cjs +1 -1
  38. package/dist/checkbox.d.ts +1 -1
  39. package/dist/checkbox.d.ts.map +1 -1
  40. package/dist/checkbox.js +2 -1
  41. package/dist/combobox.cjs +1 -1
  42. package/dist/combobox.js +2 -2
  43. package/dist/command.cjs +1 -1
  44. package/dist/command.js +1 -1
  45. package/dist/data-table.cjs +1 -1
  46. package/dist/data-table.d.ts +169 -22
  47. package/dist/data-table.d.ts.map +1 -1
  48. package/dist/data-table.js +695 -561
  49. package/dist/grid.d.ts +24 -1
  50. package/dist/grid.d.ts.map +1 -1
  51. package/dist/hooks/use-breakpoint.cjs +1 -1
  52. package/dist/hooks/use-breakpoint.d.ts +1 -1
  53. package/dist/hooks/use-breakpoint.d.ts.map +1 -1
  54. package/dist/hooks/use-breakpoint.js +1 -0
  55. package/dist/index.cjs +1 -1
  56. package/dist/index.d.ts +5 -0
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +593 -561
  59. package/dist/info-tooltip.cjs +1 -0
  60. package/dist/info-tooltip.d.ts +39 -0
  61. package/dist/info-tooltip.d.ts.map +1 -0
  62. package/dist/info-tooltip.js +41 -0
  63. package/dist/input-chip.cjs +1 -1
  64. package/dist/input-chip.js +1 -1
  65. package/dist/input-group.cjs +1 -1
  66. package/dist/input-group.d.ts +33 -2
  67. package/dist/input-group.d.ts.map +1 -1
  68. package/dist/input-group.js +167 -54
  69. package/dist/input-otp.cjs +1 -1
  70. package/dist/input-otp.js +9 -9
  71. package/dist/input-password.cjs +1 -1
  72. package/dist/input-password.d.ts +28 -6
  73. package/dist/input-password.d.ts.map +1 -1
  74. package/dist/input-password.js +5 -5
  75. package/dist/input.cjs +1 -1
  76. package/dist/input.js +10 -10
  77. package/dist/lib/block-illustration.cjs +1 -1
  78. package/dist/lib/block-illustration.d.ts +4 -1
  79. package/dist/lib/block-illustration.d.ts.map +1 -1
  80. package/dist/lib/block-illustration.js +12 -11
  81. package/dist/lib/utils.cjs +1 -1
  82. package/dist/lib/utils.d.ts.map +1 -1
  83. package/dist/lib/utils.js +4 -3
  84. package/dist/list.cjs +1 -1
  85. package/dist/list.js +1 -1
  86. package/dist/multi-select-filter.cjs +1 -0
  87. package/dist/multi-select-filter.d.ts +178 -0
  88. package/dist/multi-select-filter.d.ts.map +1 -0
  89. package/dist/multi-select-filter.js +463 -0
  90. package/dist/progress.cjs +1 -1
  91. package/dist/progress.d.ts +123 -16
  92. package/dist/progress.d.ts.map +1 -1
  93. package/dist/progress.js +89 -75
  94. package/dist/rating.cjs +1 -1
  95. package/dist/rating.js +18 -18
  96. package/dist/relative-date.cjs +1 -0
  97. package/dist/relative-date.d.ts +65 -0
  98. package/dist/relative-date.d.ts.map +1 -0
  99. package/dist/relative-date.js +128 -0
  100. package/dist/select.cjs +2 -2
  101. package/dist/select.d.ts +11 -1
  102. package/dist/select.d.ts.map +1 -1
  103. package/dist/select.js +97 -81
  104. package/dist/sheet.cjs +1 -1
  105. package/dist/sheet.d.ts +78 -2
  106. package/dist/sheet.d.ts.map +1 -1
  107. package/dist/sheet.js +192 -85
  108. package/dist/single-select-filter.cjs +1 -0
  109. package/dist/single-select-filter.d.ts +81 -0
  110. package/dist/single-select-filter.d.ts.map +1 -0
  111. package/dist/single-select-filter.js +226 -0
  112. package/dist/sonner.cjs +1 -1
  113. package/dist/sonner.d.ts.map +1 -1
  114. package/dist/sonner.js +22 -22
  115. package/dist/split-layout.cjs +1 -1
  116. package/dist/split-layout.d.ts +1 -1
  117. package/dist/split-layout.js +13 -13
  118. package/dist/table.cjs +1 -1
  119. package/dist/table.d.ts +45 -4
  120. package/dist/table.d.ts.map +1 -1
  121. package/dist/table.js +90 -73
  122. package/dist/tabs.cjs +1 -1
  123. package/dist/tabs.d.ts +12 -1
  124. package/dist/tabs.d.ts.map +1 -1
  125. package/dist/tabs.js +148 -126
  126. package/dist/textarea.cjs +1 -1
  127. package/dist/textarea.js +1 -1
  128. package/dist/tooltip.cjs +1 -1
  129. package/dist/tooltip.d.ts +38 -36
  130. package/dist/tooltip.d.ts.map +1 -1
  131. package/dist/tooltip.js +262 -73
  132. package/dist/typography-text.d.ts +1 -2
  133. package/dist/typography-text.d.ts.map +1 -1
  134. package/dist/typography.d.ts +1 -1
  135. package/package.json +5 -6
  136. package/src/blocks/empty-state.tsx +8 -3
  137. package/src/blocks/progress-state.tsx +2 -2
  138. package/src/blocks/sidebar.tsx +26 -2
  139. package/src/components/alert-dialog.tsx +50 -5
  140. package/src/components/alert.tsx +16 -8
  141. package/src/components/badge.tsx +40 -3
  142. package/src/components/banner.tsx +288 -0
  143. package/src/components/brand-illustration-motif.tsx +1 -1
  144. package/src/components/card.tsx +211 -24
  145. package/src/components/chart.tsx +523 -35
  146. package/src/components/checkbox.tsx +1 -1
  147. package/src/components/combobox.tsx +2 -2
  148. package/src/components/command.tsx +1 -1
  149. package/src/components/data-table.tsx +778 -195
  150. package/src/components/grid.tsx +32 -1
  151. package/src/components/info-tooltip.tsx +94 -0
  152. package/src/components/input-chip.tsx +1 -1
  153. package/src/components/input-group.tsx +246 -11
  154. package/src/components/input-otp.tsx +1 -1
  155. package/src/components/input-password.tsx +33 -11
  156. package/src/components/input.tsx +1 -1
  157. package/src/components/list.tsx +1 -1
  158. package/src/components/multi-select-filter.tsx +912 -0
  159. package/src/components/progress.tsx +190 -31
  160. package/src/components/rating.tsx +1 -1
  161. package/src/components/relative-date.tsx +230 -0
  162. package/src/components/select.tsx +35 -5
  163. package/src/components/sheet.tsx +240 -4
  164. package/src/components/single-select-filter.tsx +443 -0
  165. package/src/components/sonner.tsx +16 -5
  166. package/src/components/split-layout.tsx +2 -2
  167. package/src/components/table.tsx +71 -11
  168. package/src/components/tabs.tsx +93 -46
  169. package/src/components/textarea.tsx +1 -1
  170. package/src/components/tooltip.tsx +440 -68
  171. package/src/components/typography-text.tsx +1 -2
  172. package/src/components/typography.tsx +1 -1
  173. package/src/hooks/use-breakpoint.ts +2 -1
  174. package/src/index.ts +5 -0
  175. package/src/lib/block-illustration.tsx +5 -1
  176. package/src/lib/utils.ts +1 -0
@@ -2,6 +2,8 @@
2
2
 
3
3
  import * as React from "react";
4
4
  import * as RechartsPrimitive from "recharts";
5
+ import { Slot, Slottable } from "@radix-ui/react-slot";
6
+ import { cva } from "class-variance-authority";
5
7
  import { cn } from "@brightlocal/ui-components/lib/utils";
6
8
 
7
9
  // ============================================================================
@@ -22,7 +24,13 @@ type ChartContextProps = {
22
24
  config: ChartConfig;
23
25
  };
24
26
 
25
- const ChartContext = React.createContext<ChartContextProps | null>(null);
27
+ /** What the context carries — the public props plus internal provenance. */
28
+ type ChartContextValue = ChartContextProps & {
29
+ /** True when the config comes from a `ChartLegendList` rather than a `ChartContainer` — no `ChartStyle` variables exist there. */
30
+ standalone?: boolean;
31
+ };
32
+
33
+ const ChartContext = React.createContext<ChartContextValue | null>(null);
26
34
 
27
35
  function useChart() {
28
36
  const context = React.useContext(ChartContext);
@@ -34,6 +42,15 @@ function useChart() {
34
42
  return context;
35
43
  }
36
44
 
45
+ /**
46
+ * The chart config when rendered inside a `ChartContainer` (or a
47
+ * `ChartLegendList` given a `config`), otherwise `null`. Lets legend parts
48
+ * render beside a chart as well as inside one.
49
+ */
50
+ function useChartOptional() {
51
+ return React.useContext(ChartContext);
52
+ }
53
+
37
54
  // ============================================================================
38
55
  // Chart Container
39
56
  // ============================================================================
@@ -483,7 +500,12 @@ interface ChartLegendProps extends React.ComponentProps<
483
500
  }
484
501
 
485
502
  /**
486
- * ChartLegend displays a legend for the chart series.
503
+ * ChartLegend positions a legend inside a Recharts chart. Pass
504
+ * `content={<ChartLegendContent />}` to render it with DS styling.
505
+ *
506
+ * For a legend that lives *beside* a chart (next to a donut, or shared by
507
+ * several charts) compose {@link ChartLegendList} and {@link ChartLegendItem}
508
+ * directly instead — Recharts' Legend takes its room from the plot area.
487
509
  */
488
510
  function ChartLegend({ ...props }: ChartLegendProps) {
489
511
  return <RechartsPrimitive.Legend {...props} />;
@@ -491,36 +513,456 @@ function ChartLegend({ ...props }: ChartLegendProps) {
491
513
 
492
514
  ChartLegend.displayName = "ChartLegend";
493
515
 
516
+ // ----------------------------------------------------------------------------
517
+ // Chart Legend Item
518
+ // ----------------------------------------------------------------------------
519
+
520
+ /**
521
+ * Layout direction of a {@link ChartLegendList}.
522
+ */
523
+ type ChartLegendOrientation = "horizontal" | "vertical";
524
+
525
+ /**
526
+ * Scale of a {@link ChartLegendList} and its items.
527
+ * - `sm` — 12/16 text, 8px swatch: chart chrome, next to axis ticks and the tooltip.
528
+ * - `md` — 14/20 text, 10px swatch: a key read as content, beside a donut or under a report chart.
529
+ */
530
+ type ChartLegendSize = "sm" | "md";
531
+
532
+ /**
533
+ * Props for the ChartLegendItem component.
534
+ */
535
+ interface ChartLegendItemProps extends React.ComponentPropsWithoutRef<"div"> {
536
+ /**
537
+ * Data hook for automated testing (required)
538
+ * @example "sources-legend-google"
539
+ */
540
+ dataHook: string;
541
+ /**
542
+ * Key into the chart config. Resolves the swatch colour, the custom icon and
543
+ * the default label. Reads the config from the nearest `ChartContainer` or
544
+ * `ChartLegendList config={…}`; outside both, pass `color` and a label.
545
+ */
546
+ seriesKey?: string;
547
+ /**
548
+ * Swatch colour. Wins over the config colour — the way to colour an item
549
+ * that renders beside a chart rather than inside one.
550
+ * @example "var(--chart-blue)"
551
+ */
552
+ color?: string;
553
+ /**
554
+ * Hide the series icon from the config and draw the colour swatch instead.
555
+ * @default false
556
+ */
557
+ hideIcon?: boolean;
558
+ /**
559
+ * Trailing value (a count, a percentage), rendered in tabular figures and
560
+ * pushed to the far edge in a vertical list.
561
+ */
562
+ value?: React.ReactNode;
563
+ /**
564
+ * De-emphasised: the swatch dims and the text turns muted. The series is
565
+ * still drawn and still counts — it is just not what the reader is looking
566
+ * at (e.g. sources a filter has not chosen). Figma `Visibility=Muted`.
567
+ * @default false
568
+ */
569
+ muted?: boolean;
570
+ /**
571
+ * Switched off: the muted look plus a strike through the label (the value
572
+ * stays legible), so a hidden series reads as hidden in greyscale and in a
573
+ * screenshot — never by colour alone. The strike also reaches a nested
574
+ * button or link used as the label. Use it for a toggled-off series in an
575
+ * interactive legend. Wins over `muted`. Figma `Visibility=Hidden`.
576
+ * @default false
577
+ */
578
+ hidden?: boolean;
579
+ /**
580
+ * Render the child element instead of a `div`, merging the item's props
581
+ * into it — so the item can be a `PopoverTrigger` or a `<button
582
+ * aria-pressed>`. The child's own content becomes the label; the swatch
583
+ * and value are placed around it.
584
+ * @default false
585
+ */
586
+ asChild?: boolean;
587
+ /** Analytics element identifier */
588
+ trackingEl?: string;
589
+ /** Analytics label */
590
+ trackingLabel?: string;
591
+ /**
592
+ * The label. Defaults to the config label for `seriesKey`, then to the key
593
+ * itself. Required when `asChild` is set (it is the element to render).
594
+ */
595
+ children?: React.ReactNode;
596
+ }
597
+
598
+ /**
599
+ * One legend entry: a colour swatch (or the series icon), a label and an
600
+ * optional value. Composable — it renders inside a chart via
601
+ * {@link ChartLegendContent}, or anywhere else inside a
602
+ * {@link ChartLegendList}.
603
+ *
604
+ * @example
605
+ * ```tsx
606
+ * <ChartLegendList dataHook="sources-legend" orientation="vertical" config={config}>
607
+ * <ChartLegendItem dataHook="sources-legend-google" seriesKey="google" value={1240} />
608
+ * <ChartLegendItem dataHook="sources-legend-other" seriesKey="other" value={88} asChild>
609
+ * <PopoverTrigger>Other</PopoverTrigger>
610
+ * </ChartLegendItem>
611
+ * </ChartLegendList>
612
+ * ```
613
+ */
614
+ const ChartLegendItem = React.forwardRef<HTMLDivElement, ChartLegendItemProps>(
615
+ (
616
+ {
617
+ asChild = false,
618
+ children,
619
+ className,
620
+ color,
621
+ dataHook,
622
+ hidden = false,
623
+ hideIcon = false,
624
+ muted = false,
625
+ seriesKey,
626
+ trackingEl,
627
+ trackingLabel,
628
+ value,
629
+ ...props
630
+ },
631
+ ref
632
+ ) => {
633
+ const chart = useChartOptional();
634
+ const itemConfig = seriesKey ? chart?.config[seriesKey] : undefined;
635
+ /* Colour order: explicit prop → config colour → the `--color-<key>`
636
+ variable ChartStyle defines inside a ChartContainer (the only place a
637
+ `theme` config resolves). */
638
+ const swatchColor =
639
+ color ??
640
+ itemConfig?.color ??
641
+ (seriesKey ? `var(--color-${seriesKey})` : undefined);
642
+
643
+ const unresolved =
644
+ !!seriesKey &&
645
+ !color &&
646
+ (!chart || (!!chart.standalone && !itemConfig?.color));
647
+ React.useEffect(() => {
648
+ if (process.env.NODE_ENV !== "production" && unresolved) {
649
+ console.warn(
650
+ `ChartLegendItem: seriesKey="${seriesKey}" has no colour to resolve — render it inside a ChartContainer, give the ChartLegendList config a \`color\` for this key (a \`theme\` only resolves inside a container), or set \`color\`.`
651
+ );
652
+ }
653
+ }, [seriesKey, unresolved]);
654
+
655
+ const Comp = asChild ? Slot : "div";
656
+ const label = children ?? itemConfig?.label ?? seriesKey;
657
+
658
+ return (
659
+ <Comp
660
+ ref={ref}
661
+ className={cn(
662
+ /* The focus ring is here rather than at each call site, so an
663
+ `asChild` button gets it without remembering to. */
664
+ "[&>svg]:text-muted-foreground focus-visible:shadow-default flex items-center gap-1.5 rounded-sm outline-none group-data-[size=md]/legend:gap-2 [&>svg]:size-3 group-data-[size=md]/legend:[&>svg]:size-3.5",
665
+ (muted || hidden) && "text-muted-foreground",
666
+ /* text-decoration does not propagate into a nested <button>/<a>
667
+ (atomic inline-level boxes), so a trigger used as the label gets
668
+ the strike explicitly. */
669
+ hidden && "line-through [&_:is(button,a)]:line-through",
670
+ className
671
+ )}
672
+ data-hidden={hidden || undefined}
673
+ data-hook={dataHook}
674
+ data-muted={muted || hidden || undefined}
675
+ data-slot="chart-legend-item"
676
+ data-tracking-el={trackingEl}
677
+ data-tracking-label={trackingLabel}
678
+ {...props}
679
+ >
680
+ {itemConfig?.icon && !hideIcon ? (
681
+ <itemConfig.icon size={12} />
682
+ ) : (
683
+ /* A span, not a div: with `asChild` the item is often a button,
684
+ which only allows phrasing content. */
685
+ <span
686
+ aria-hidden="true"
687
+ className={cn(
688
+ "duration-fast block size-2 shrink-0 rounded-[2px] transition-opacity ease-out group-data-[size=md]/legend:size-2.5",
689
+ (muted || hidden) && "opacity-40"
690
+ )}
691
+ data-slot="chart-legend-item-swatch"
692
+ style={{ backgroundColor: swatchColor }}
693
+ />
694
+ )}
695
+ <Slottable>{label}</Slottable>
696
+ {value != null && (
697
+ <span
698
+ className="ml-auto pl-0.5 tabular-nums"
699
+ data-slot="chart-legend-item-value"
700
+ >
701
+ {/* inline-block stops the hidden strike propagating from the item:
702
+ the label is struck, the value stays legible — as in Figma and
703
+ the Chart Legend pattern spec. */}
704
+ <span className="inline-block">{value}</span>
705
+ </span>
706
+ )}
707
+ </Comp>
708
+ );
709
+ }
710
+ );
711
+
712
+ ChartLegendItem.displayName = "ChartLegendItem";
713
+
714
+ // ----------------------------------------------------------------------------
715
+ // Chart Legend List
716
+ // ----------------------------------------------------------------------------
717
+
718
+ const chartLegendListVariants = cva("group/legend flex", {
719
+ variants: {
720
+ size: {
721
+ sm: "text-body-xs",
722
+ md: "text-body-sm",
723
+ },
724
+ orientation: {
725
+ /* Wraps: six or seven series do not fit one line on a phone, and
726
+ without wrapping the tail is simply clipped. */
727
+ horizontal: "flex-wrap items-center justify-center gap-x-4 gap-y-1",
728
+ /* Items stretch to the list's width so a value can sit at the far edge. */
729
+ vertical: "flex-col items-stretch gap-3",
730
+ },
731
+ },
732
+ defaultVariants: {
733
+ orientation: "horizontal",
734
+ size: "sm",
735
+ },
736
+ });
737
+
738
+ /**
739
+ * Props for the ChartLegendList component.
740
+ */
741
+ interface ChartLegendListProps extends React.ComponentPropsWithoutRef<"div"> {
742
+ /**
743
+ * Data hook for automated testing (required)
744
+ * @example "sources-legend"
745
+ */
746
+ dataHook: string;
747
+ /**
748
+ * Layout direction. Horizontal wraps under or above a plot; vertical stacks
749
+ * beside a donut, label left and value right.
750
+ * @default "horizontal"
751
+ */
752
+ orientation?: ChartLegendOrientation;
753
+ /**
754
+ * Scale of the list and its items. `sm` matches the chart's axis ticks and
755
+ * tooltip; `md` is for a key read as content beside a donut or under a
756
+ * report chart (14px text, 10px swatch).
757
+ * @default "sm"
758
+ */
759
+ size?: ChartLegendSize;
760
+ /**
761
+ * Accessible name of the legend group.
762
+ * @default "Chart legend"
763
+ */
764
+ ariaLabel?: string;
765
+ /**
766
+ * Chart config for the items, when the list renders outside a
767
+ * `ChartContainer`. Replaces (does not merge with) a surrounding
768
+ * container's config. Give each key a `color` — a `theme` only resolves
769
+ * inside a container.
770
+ */
771
+ config?: ChartConfig;
772
+ /** Analytics element identifier */
773
+ trackingEl?: string;
774
+ /** Analytics label */
775
+ trackingLabel?: string;
776
+ }
777
+
778
+ /**
779
+ * A legend as a standalone list of {@link ChartLegendItem}s — the key beside
780
+ * a donut, a shared key under several charts, or a row of series toggles.
781
+ * {@link ChartLegendContent} renders one of these inside a chart.
782
+ *
783
+ * It is a labelled `role="group"`, not a list: the same container holds
784
+ * static keys and rows of toggle buttons, and a group with a name reads
785
+ * correctly for both ("Chart legend, group"). A static key therefore no
786
+ * longer announces its item count — accepted trade-off (DS-1026 review).
787
+ */
788
+ const ChartLegendList = React.forwardRef<HTMLDivElement, ChartLegendListProps>(
789
+ (
790
+ {
791
+ ariaLabel,
792
+ children,
793
+ className,
794
+ config,
795
+ dataHook,
796
+ orientation = "horizontal",
797
+ size = "sm",
798
+ trackingEl,
799
+ trackingLabel,
800
+ ...props
801
+ },
802
+ ref
803
+ ) => {
804
+ const contextValue = React.useMemo<ChartContextValue | null>(
805
+ () => (config ? { config, standalone: true } : null),
806
+ [config]
807
+ );
808
+ const list = (
809
+ <div
810
+ ref={ref}
811
+ aria-label={ariaLabel ?? "Chart legend"}
812
+ className={cn(
813
+ chartLegendListVariants({ orientation, size }),
814
+ className
815
+ )}
816
+ data-hook={dataHook}
817
+ data-orientation={orientation}
818
+ data-size={size}
819
+ data-slot="chart-legend-list"
820
+ data-tracking-el={trackingEl}
821
+ data-tracking-label={trackingLabel}
822
+ role="group"
823
+ {...props}
824
+ >
825
+ {children}
826
+ </div>
827
+ );
828
+
829
+ return contextValue ? (
830
+ <ChartContext.Provider value={contextValue}>{list}</ChartContext.Provider>
831
+ ) : (
832
+ list
833
+ );
834
+ }
835
+ );
836
+
837
+ ChartLegendList.displayName = "ChartLegendList";
838
+
839
+ // ----------------------------------------------------------------------------
840
+ // Chart Legend Content (Recharts adapter)
841
+ // ----------------------------------------------------------------------------
842
+
843
+ /** `data-hook` segment from an entry key: lower-case, non-alphanumerics to `-`. */
844
+ const slug = (key: string) =>
845
+ key
846
+ .toLowerCase()
847
+ .replace(/[^a-z0-9]+/g, "-")
848
+ .replace(/^-|-$/g, "");
849
+
850
+ /**
851
+ * One entry of the legend payload Recharts hands to `ChartLegend`'s content.
852
+ */
853
+ interface ChartLegendPayloadItem {
854
+ /** Display name — the series name for Bar/Line, the sector name for Pie. */
855
+ value: string;
856
+ /** Series key. Present for Bar/Line/Area series; Pie entries have none. */
857
+ dataKey?: string;
858
+ color?: string;
859
+ /** The series' or sector's raw datum. */
860
+ payload: Record<string, unknown>;
861
+ }
862
+
494
863
  /**
495
864
  * Props for the ChartLegendContent component.
496
865
  */
497
866
  interface ChartLegendContentProps
498
867
  extends React.ComponentProps<"div">, Pick<ChartLegendProps, "nameKey"> {
868
+ /**
869
+ * Data hook for automated testing. Items derive theirs from it
870
+ * (`<dataHook>-<entry key>`, where the entry key is the series `dataKey`,
871
+ * or the Pie entry's `nameKey` value, slugified).
872
+ * @default "chart-legend"
873
+ */
874
+ dataHook?: string;
499
875
  /** Hide the series icon in the legend */
500
876
  hideIcon?: boolean;
501
877
  /** Legend payload from Recharts (automatically provided) */
502
- payload?: Array<{
503
- value: string;
504
- dataKey: string;
505
- color?: string;
506
- payload: Record<string, unknown>;
507
- }>;
878
+ payload?: Array<ChartLegendPayloadItem>;
508
879
  /**
509
- * Vertical alignment of the legend relative to the chart
880
+ * Vertical alignment of the legend relative to the chart — sets the gap
881
+ * to the plot. Pass the same value to `ChartLegend`.
510
882
  * @default "bottom"
511
883
  */
512
- verticalAlign?: "top" | "bottom";
884
+ verticalAlign?: "top" | "middle" | "bottom";
885
+ /**
886
+ * Layout direction. Pair `vertical` with
887
+ * `<ChartLegend layout="vertical" align="right" verticalAlign="middle" />`.
888
+ * @default "horizontal"
889
+ */
890
+ orientation?: ChartLegendOrientation;
891
+ /**
892
+ * Accessible name of the legend group.
893
+ * @default "Chart legend"
894
+ */
895
+ ariaLabel?: string;
896
+ /**
897
+ * Scale of the legend. Keep `sm` inside a chart — it matches the axis
898
+ * ticks and the tooltip; `md` is for a key read as content.
899
+ * @default "sm"
900
+ */
901
+ size?: ChartLegendSize;
902
+ /**
903
+ * Show each entry's value after its label, read from `payload[valueKey]`.
904
+ * Meaningful for Pie/Donut, whose payload is the sector's datum — for Bar
905
+ * and Line series the payload carries no total, so render a
906
+ * `ChartLegendList` beside the chart with your own values instead.
907
+ * @default false
908
+ */
909
+ showValue?: boolean;
910
+ /**
911
+ * Field of each entry's datum that holds its value — for a Pie, its
912
+ * `dataKey` (e.g. `"visitors"`). Defaults to the series `dataKey`, then
913
+ * `"value"`.
914
+ */
915
+ valueKey?: string;
916
+ /**
917
+ * Formats the value shown by `showValue`. Receives the payload entry;
918
+ * read the number from `item.payload`.
919
+ * @example (item) => `${item.payload.visitors} visitors`
920
+ */
921
+ valueFormatter?: (item: ChartLegendPayloadItem) => React.ReactNode;
922
+ /**
923
+ * Order of the entries. Recharts sorts the payload alphabetically by
924
+ * default; pass the entry keys (series `dataKey`s, or Pie `nameKey`
925
+ * values) in the order the chart declares them, or a comparator. Keys not
926
+ * listed go last. Legend order should match series order and tooltip
927
+ * order.
928
+ * @example ["google", "facebook", "other"]
929
+ */
930
+ sortBy?:
931
+ | string[]
932
+ | ((a: ChartLegendPayloadItem, b: ChartLegendPayloadItem) => number);
933
+ /**
934
+ * Replace the rendering of one entry — e.g. wrap "Other" in a popover
935
+ * trigger. Receives the entry and the default item. Recharts positions the
936
+ * legend inside the chart's box, so floating content opened from here can
937
+ * be clipped by it; for an interactive legend prefer a `ChartLegendList`
938
+ * beside the chart.
939
+ */
940
+ renderItem?: (
941
+ item: ChartLegendPayloadItem,
942
+ defaultNode: React.ReactNode
943
+ ) => React.ReactNode;
513
944
  }
514
945
 
515
946
  /**
516
- * ChartLegendContent renders the content inside the legend.
947
+ * ChartLegendContent renders Recharts' legend payload as a
948
+ * {@link ChartLegendList} of {@link ChartLegendItem}s. Use as
949
+ * `<ChartLegend content={<ChartLegendContent />} />`.
517
950
  */
518
951
  function ChartLegendContent({
952
+ ariaLabel,
519
953
  className,
954
+ dataHook = "chart-legend",
520
955
  hideIcon = false,
956
+ nameKey,
957
+ orientation = "horizontal",
521
958
  payload,
959
+ renderItem,
960
+ showValue = false,
961
+ size = "sm",
962
+ sortBy,
963
+ valueFormatter,
964
+ valueKey,
522
965
  verticalAlign = "bottom",
523
- nameKey,
524
966
  }: ChartLegendContentProps) {
525
967
  const { config } = useChart();
526
968
 
@@ -528,41 +970,80 @@ function ChartLegendContent({
528
970
  return null;
529
971
  }
530
972
 
973
+ /* The key an entry is known by: the series dataKey (Bar/Line/Area), or
974
+ for a Pie — whose entries carry no dataKey — the datum's nameKey value,
975
+ then the display name. Drives the config lookup, sortBy and the hook. */
976
+ const entryKey = (item: ChartLegendPayloadItem) =>
977
+ String(
978
+ item.dataKey ??
979
+ (nameKey ? item.payload?.[nameKey] : undefined) ??
980
+ item.value
981
+ );
982
+ /* Keys absent from a `sortBy` array go last, in their incoming order. */
983
+ const rank = (item: ChartLegendPayloadItem) => {
984
+ const index = Array.isArray(sortBy) ? sortBy.indexOf(entryKey(item)) : -1;
985
+ return index === -1 ? Number.POSITIVE_INFINITY : index;
986
+ };
987
+ const sorted = sortBy
988
+ ? [...payload].sort(
989
+ Array.isArray(sortBy)
990
+ ? (a, b) => {
991
+ const ra = rank(a);
992
+ const rb = rank(b);
993
+ return ra === rb ? 0 : ra - rb;
994
+ }
995
+ : sortBy
996
+ )
997
+ : payload;
998
+
531
999
  return (
532
- <div
1000
+ <ChartLegendList
1001
+ ariaLabel={ariaLabel}
533
1002
  className={cn(
534
- "flex items-center justify-center gap-4",
535
- verticalAlign === "top" ? "pb-4" : "pt-4",
1003
+ verticalAlign === "top" && "pb-4",
1004
+ verticalAlign === "bottom" && "pt-4",
536
1005
  className
537
1006
  )}
1007
+ /* Intentional: inside a chart the root keeps the slot name consumers
1008
+ have selected since before the list existed. */
538
1009
  data-slot="chart-legend-content"
1010
+ dataHook={dataHook}
1011
+ orientation={orientation}
1012
+ size={size}
539
1013
  >
540
- {payload.map((item) => {
541
- const key = `${nameKey || item.dataKey || "value"}`;
1014
+ {sorted.map((item) => {
1015
+ const key = entryKey(item);
542
1016
  const itemConfig = config[key];
543
-
544
- return (
545
- <div
1017
+ const value = showValue
1018
+ ? valueFormatter
1019
+ ? valueFormatter(item)
1020
+ : (item.payload?.[valueKey ?? item.dataKey ?? "value"] as
1021
+ | React.ReactNode
1022
+ | undefined)
1023
+ : undefined;
1024
+
1025
+ const node = (
1026
+ <ChartLegendItem
546
1027
  key={item.value}
547
- className={cn(
548
- "[&>svg]:text-muted-foreground flex items-center gap-1.5"
549
- )}
1028
+ color={item.color}
1029
+ dataHook={`${dataHook}-${slug(key)}`}
1030
+ hideIcon={hideIcon}
1031
+ seriesKey={key}
1032
+ value={value}
550
1033
  >
551
- {itemConfig?.icon && !hideIcon ? (
552
- <itemConfig.icon size={12} />
553
- ) : (
554
- <div
555
- className="h-2 w-2 shrink-0 rounded-[2px]"
556
- style={{
557
- backgroundColor: item.color,
558
- }}
559
- />
560
- )}
561
1034
  {itemConfig?.label || item.value}
562
- </div>
1035
+ </ChartLegendItem>
1036
+ );
1037
+
1038
+ return renderItem ? (
1039
+ <React.Fragment key={item.value}>
1040
+ {renderItem(item, node)}
1041
+ </React.Fragment>
1042
+ ) : (
1043
+ node
563
1044
  );
564
1045
  })}
565
- </div>
1046
+ </ChartLegendList>
566
1047
  );
567
1048
  }
568
1049
 
@@ -1194,6 +1675,8 @@ export {
1194
1675
  ChartTooltipContent,
1195
1676
  ChartLegend,
1196
1677
  ChartLegendContent,
1678
+ ChartLegendList,
1679
+ ChartLegendItem,
1197
1680
  ChartStyle,
1198
1681
  ChartDot,
1199
1682
  ChartDotOnStroke,
@@ -1211,6 +1694,11 @@ export type {
1211
1694
  ChartTooltipPayloadItem,
1212
1695
  ChartLegendProps,
1213
1696
  ChartLegendContentProps,
1697
+ ChartLegendListProps,
1698
+ ChartLegendItemProps,
1699
+ ChartLegendOrientation,
1700
+ ChartLegendPayloadItem,
1701
+ ChartLegendSize,
1214
1702
  ChartDotProps,
1215
1703
  ChartDotOnStrokeProps,
1216
1704
  ChartDotSize,
@@ -90,4 +90,4 @@ const Checkbox = React.forwardRef<HTMLButtonElement, CheckboxProps>(
90
90
 
91
91
  Checkbox.displayName = "Checkbox";
92
92
 
93
- export { Checkbox };
93
+ export { Checkbox, checkboxVariants };
@@ -384,7 +384,7 @@ const comboboxTriggerVariants = cva([
384
384
  "dark:bg-white/5 dark:border-white/15",
385
385
 
386
386
  // Typography
387
- "text-body text-foreground",
387
+ "text-field text-foreground",
388
388
 
389
389
  // Placeholder state
390
390
  "data-[placeholder=true]:text-muted-foreground",
@@ -620,7 +620,7 @@ function ComboboxValue<T>({
620
620
  return (
621
621
  <span
622
622
  className={cn(
623
- "text-body overflow-hidden text-ellipsis whitespace-nowrap",
623
+ "text-field overflow-hidden text-ellipsis whitespace-nowrap",
624
624
  className
625
625
  )}
626
626
  data-slot="combobox-value"
@@ -251,7 +251,7 @@ const CommandInput = React.forwardRef<
251
251
  <CommandPrimitive.Input
252
252
  ref={inputRef}
253
253
  className={cn(
254
- "placeholder:text-muted-foreground text-body flex w-full bg-transparent outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
254
+ "placeholder:text-muted-foreground text-field flex w-full bg-transparent outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
255
255
  className
256
256
  )}
257
257
  data-slot="command-input"