@theruntime/components 0.0.0 → 0.0.1

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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +113 -4
  3. package/src/accordion.tsx +62 -0
  4. package/src/alert-dialog.tsx +177 -0
  5. package/src/alert.tsx +60 -0
  6. package/src/aspect-ratio.tsx +7 -0
  7. package/src/attachment.tsx +192 -0
  8. package/src/avatar.tsx +94 -0
  9. package/src/badge.tsx +46 -0
  10. package/src/breadcrumb.tsx +102 -0
  11. package/src/bubble.tsx +125 -0
  12. package/src/button-group.tsx +82 -0
  13. package/src/button.tsx +62 -0
  14. package/src/calendar.tsx +178 -0
  15. package/src/card.tsx +75 -0
  16. package/src/carousel.tsx +228 -0
  17. package/src/chart/container.tsx +72 -0
  18. package/src/chart/context.tsx +39 -0
  19. package/src/chart/index.ts +4 -0
  20. package/src/chart/legend.tsx +63 -0
  21. package/src/chart/payload.ts +31 -0
  22. package/src/chart/tooltip.tsx +149 -0
  23. package/src/checkbox.tsx +27 -0
  24. package/src/cn.ts +36 -0
  25. package/src/collapsible.tsx +19 -0
  26. package/src/combobox/chips.tsx +71 -0
  27. package/src/combobox/content.tsx +123 -0
  28. package/src/combobox/index.ts +13 -0
  29. package/src/combobox/input.tsx +39 -0
  30. package/src/combobox/trigger.tsx +44 -0
  31. package/src/command.tsx +153 -0
  32. package/src/context-menu.tsx +222 -0
  33. package/src/dialog.tsx +142 -0
  34. package/src/direction.tsx +18 -0
  35. package/src/drawer.tsx +122 -0
  36. package/src/dropdown-menu.tsx +226 -0
  37. package/src/empty.tsx +94 -0
  38. package/src/field.tsx +232 -0
  39. package/src/form.tsx +153 -0
  40. package/src/hover-card.tsx +36 -0
  41. package/src/index.ts +90 -0
  42. package/src/input-group.tsx +156 -0
  43. package/src/input-otp.tsx +68 -0
  44. package/src/input.tsx +21 -0
  45. package/src/item.tsx +172 -0
  46. package/src/kbd.tsx +28 -0
  47. package/src/label.tsx +19 -0
  48. package/src/marker.tsx +66 -0
  49. package/src/menubar.tsx +250 -0
  50. package/src/message-scroller.tsx +128 -0
  51. package/src/message.tsx +85 -0
  52. package/src/native-select.tsx +56 -0
  53. package/src/navigation-menu.tsx +161 -0
  54. package/src/pagination.tsx +106 -0
  55. package/src/popover.tsx +72 -0
  56. package/src/progress.tsx +26 -0
  57. package/src/questionnaire/actions.tsx +118 -0
  58. package/src/questionnaire/choices.tsx +113 -0
  59. package/src/questionnaire/index.ts +21 -0
  60. package/src/questionnaire/root.tsx +75 -0
  61. package/src/radio-group.tsx +43 -0
  62. package/src/resizable.tsx +45 -0
  63. package/src/scroll-area.tsx +54 -0
  64. package/src/select.tsx +173 -0
  65. package/src/separator.tsx +26 -0
  66. package/src/sheet.tsx +132 -0
  67. package/src/shell/app-tab.tsx +67 -0
  68. package/src/shell/entry-row.tsx +137 -0
  69. package/src/shell/field.tsx +83 -0
  70. package/src/shell/group-head.tsx +19 -0
  71. package/src/shell/scope-chip.tsx +32 -0
  72. package/src/shell/suggest-panel.tsx +92 -0
  73. package/src/sidebar/context.tsx +128 -0
  74. package/src/sidebar/index.ts +23 -0
  75. package/src/sidebar/menu.tsx +239 -0
  76. package/src/sidebar/sections.tsx +118 -0
  77. package/src/sidebar/sidebar.tsx +183 -0
  78. package/src/skeleton.tsx +13 -0
  79. package/src/slider.tsx +56 -0
  80. package/src/sonner.tsx +41 -0
  81. package/src/spinner.tsx +16 -0
  82. package/src/styles.css +149 -0
  83. package/src/switch.tsx +33 -0
  84. package/src/table.tsx +90 -0
  85. package/src/tabs.tsx +79 -0
  86. package/src/textarea.tsx +18 -0
  87. package/src/toggle-group.tsx +81 -0
  88. package/src/toggle.tsx +44 -0
  89. package/src/tooltip.tsx +51 -0
  90. package/src/use-mobile.ts +21 -0
  91. package/README.md +0 -3
package/src/card.tsx ADDED
@@ -0,0 +1,75 @@
1
+ import * as React from "react";
2
+
3
+ import { cn } from "./cn";
4
+
5
+ function Card({ className, ...props }: React.ComponentProps<"div">) {
6
+ return (
7
+ <div
8
+ data-slot="card"
9
+ className={cn(
10
+ "flex flex-col gap-6 rounded-xl border bg-card py-6 text-card-foreground shadow-sm",
11
+ className,
12
+ )}
13
+ {...props}
14
+ />
15
+ );
16
+ }
17
+
18
+ function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
19
+ return (
20
+ <div
21
+ data-slot="card-header"
22
+ className={cn(
23
+ "@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
24
+ className,
25
+ )}
26
+ {...props}
27
+ />
28
+ );
29
+ }
30
+
31
+ function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
32
+ return (
33
+ <div
34
+ data-slot="card-title"
35
+ className={cn("leading-none font-semibold", className)}
36
+ {...props}
37
+ />
38
+ );
39
+ }
40
+
41
+ function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
42
+ return (
43
+ <div
44
+ data-slot="card-description"
45
+ className={cn("text-sm text-muted-foreground", className)}
46
+ {...props}
47
+ />
48
+ );
49
+ }
50
+
51
+ function CardAction({ className, ...props }: React.ComponentProps<"div">) {
52
+ return (
53
+ <div
54
+ data-slot="card-action"
55
+ className={cn("col-start-2 row-span-2 row-start-1 self-start justify-self-end", className)}
56
+ {...props}
57
+ />
58
+ );
59
+ }
60
+
61
+ function CardContent({ className, ...props }: React.ComponentProps<"div">) {
62
+ return <div data-slot="card-content" className={cn("px-6", className)} {...props} />;
63
+ }
64
+
65
+ function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
66
+ return (
67
+ <div
68
+ data-slot="card-footer"
69
+ className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
70
+ {...props}
71
+ />
72
+ );
73
+ }
74
+
75
+ export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent };
@@ -0,0 +1,228 @@
1
+ import * as React from "react";
2
+ import useEmblaCarousel, { type UseEmblaCarouselType } from "embla-carousel-react";
3
+ import { ArrowLeftIcon, ArrowRightIcon } from "@phosphor-icons/react";
4
+
5
+ import { cn } from "./cn";
6
+ import { Button } from "./button";
7
+
8
+ type CarouselApi = UseEmblaCarouselType[1];
9
+ type UseCarouselParameters = Parameters<typeof useEmblaCarousel>;
10
+ type CarouselOptions = UseCarouselParameters[0];
11
+ type CarouselPlugin = UseCarouselParameters[1];
12
+
13
+ type CarouselProps = {
14
+ opts?: CarouselOptions;
15
+ plugins?: CarouselPlugin;
16
+ orientation?: "horizontal" | "vertical";
17
+ setApi?: (api: CarouselApi) => void;
18
+ };
19
+
20
+ type CarouselContextProps = {
21
+ carouselRef: ReturnType<typeof useEmblaCarousel>[0];
22
+ api: ReturnType<typeof useEmblaCarousel>[1];
23
+ scrollPrev: () => void;
24
+ scrollNext: () => void;
25
+ canScrollPrev: boolean;
26
+ canScrollNext: boolean;
27
+ } & CarouselProps;
28
+
29
+ const CarouselContext = React.createContext<CarouselContextProps | null>(null);
30
+
31
+ function useCarousel() {
32
+ const context = React.useContext(CarouselContext);
33
+
34
+ if (!context) {
35
+ throw new Error("useCarousel must be used within a <Carousel />");
36
+ }
37
+
38
+ return context;
39
+ }
40
+
41
+ function Carousel({
42
+ orientation = "horizontal",
43
+ opts,
44
+ setApi,
45
+ plugins,
46
+ className,
47
+ children,
48
+ ...props
49
+ }: React.ComponentProps<"div"> & CarouselProps) {
50
+ const [carouselRef, api] = useEmblaCarousel(
51
+ {
52
+ ...opts,
53
+ axis: orientation === "horizontal" ? "x" : "y",
54
+ },
55
+ plugins,
56
+ );
57
+ const [canScrollPrev, setCanScrollPrev] = React.useState(false);
58
+ const [canScrollNext, setCanScrollNext] = React.useState(false);
59
+
60
+ const onSelect = React.useCallback((api: CarouselApi) => {
61
+ if (!api) return;
62
+ setCanScrollPrev(api.canScrollPrev());
63
+ setCanScrollNext(api.canScrollNext());
64
+ }, []);
65
+
66
+ const scrollPrev = React.useCallback(() => {
67
+ api?.scrollPrev();
68
+ }, [api]);
69
+
70
+ const scrollNext = React.useCallback(() => {
71
+ api?.scrollNext();
72
+ }, [api]);
73
+
74
+ const handleKeyDown = React.useCallback(
75
+ (event: React.KeyboardEvent<HTMLDivElement>) => {
76
+ if (event.key === "ArrowLeft") {
77
+ event.preventDefault();
78
+ scrollPrev();
79
+ } else if (event.key === "ArrowRight") {
80
+ event.preventDefault();
81
+ scrollNext();
82
+ }
83
+ },
84
+ [scrollPrev, scrollNext],
85
+ );
86
+
87
+ React.useEffect(() => {
88
+ if (!api || !setApi) return;
89
+ setApi(api);
90
+ }, [api, setApi]);
91
+
92
+ React.useEffect(() => {
93
+ if (!api) return;
94
+ onSelect(api);
95
+ api.on("reInit", onSelect);
96
+ api.on("select", onSelect);
97
+
98
+ return () => {
99
+ api?.off("select", onSelect);
100
+ };
101
+ }, [api, onSelect]);
102
+
103
+ return (
104
+ <CarouselContext.Provider
105
+ value={{
106
+ carouselRef,
107
+ api: api,
108
+ opts,
109
+ orientation: orientation || (opts?.axis === "y" ? "vertical" : "horizontal"),
110
+ scrollPrev,
111
+ scrollNext,
112
+ canScrollPrev,
113
+ canScrollNext,
114
+ }}
115
+ >
116
+ <div
117
+ onKeyDownCapture={handleKeyDown}
118
+ className={cn("relative", className)}
119
+ role="region"
120
+ aria-roledescription="carousel"
121
+ data-slot="carousel"
122
+ {...props}
123
+ >
124
+ {children}
125
+ </div>
126
+ </CarouselContext.Provider>
127
+ );
128
+ }
129
+
130
+ function CarouselContent({ className, ...props }: React.ComponentProps<"div">) {
131
+ const { carouselRef, orientation } = useCarousel();
132
+
133
+ return (
134
+ <div ref={carouselRef} className="overflow-hidden" data-slot="carousel-content">
135
+ <div
136
+ className={cn("flex", orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col", className)}
137
+ {...props}
138
+ />
139
+ </div>
140
+ );
141
+ }
142
+
143
+ function CarouselItem({ className, ...props }: React.ComponentProps<"div">) {
144
+ const { orientation } = useCarousel();
145
+
146
+ return (
147
+ <div
148
+ role="group"
149
+ aria-roledescription="slide"
150
+ data-slot="carousel-item"
151
+ className={cn(
152
+ "min-w-0 shrink-0 grow-0 basis-full",
153
+ orientation === "horizontal" ? "pl-4" : "pt-4",
154
+ className,
155
+ )}
156
+ {...props}
157
+ />
158
+ );
159
+ }
160
+
161
+ function CarouselPrevious({
162
+ className,
163
+ variant = "outline",
164
+ size = "icon",
165
+ ...props
166
+ }: React.ComponentProps<typeof Button>) {
167
+ const { orientation, scrollPrev, canScrollPrev } = useCarousel();
168
+
169
+ return (
170
+ <Button
171
+ data-slot="carousel-previous"
172
+ variant={variant}
173
+ size={size}
174
+ className={cn(
175
+ "absolute size-8 rounded-full",
176
+ orientation === "horizontal"
177
+ ? "top-1/2 -left-12 -translate-y-1/2"
178
+ : "-top-12 left-1/2 -translate-x-1/2 rotate-90",
179
+ className,
180
+ )}
181
+ disabled={!canScrollPrev}
182
+ onClick={scrollPrev}
183
+ {...props}
184
+ >
185
+ <ArrowLeftIcon />
186
+ <span className="sr-only">Previous slide</span>
187
+ </Button>
188
+ );
189
+ }
190
+
191
+ function CarouselNext({
192
+ className,
193
+ variant = "outline",
194
+ size = "icon",
195
+ ...props
196
+ }: React.ComponentProps<typeof Button>) {
197
+ const { orientation, scrollNext, canScrollNext } = useCarousel();
198
+
199
+ return (
200
+ <Button
201
+ data-slot="carousel-next"
202
+ variant={variant}
203
+ size={size}
204
+ className={cn(
205
+ "absolute size-8 rounded-full",
206
+ orientation === "horizontal"
207
+ ? "top-1/2 -right-12 -translate-y-1/2"
208
+ : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90",
209
+ className,
210
+ )}
211
+ disabled={!canScrollNext}
212
+ onClick={scrollNext}
213
+ {...props}
214
+ >
215
+ <ArrowRightIcon />
216
+ <span className="sr-only">Next slide</span>
217
+ </Button>
218
+ );
219
+ }
220
+
221
+ export {
222
+ type CarouselApi,
223
+ Carousel,
224
+ CarouselContent,
225
+ CarouselItem,
226
+ CarouselPrevious,
227
+ CarouselNext,
228
+ };
@@ -0,0 +1,72 @@
1
+ import * as React from "react";
2
+ import * as RechartsPrimitive from "recharts";
3
+
4
+ import { cn } from "../cn";
5
+ import { ChartContext, THEME_ENTRIES, type ChartConfig } from "./context";
6
+
7
+ const INITIAL_DIMENSION = { width: 320, height: 200 } as const;
8
+
9
+ export function ChartContainer({
10
+ id,
11
+ className,
12
+ children,
13
+ config,
14
+ initialDimension = INITIAL_DIMENSION,
15
+ ...props
16
+ }: React.ComponentProps<"div"> & {
17
+ config: ChartConfig;
18
+ children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
19
+ initialDimension?: {
20
+ width: number;
21
+ height: number;
22
+ };
23
+ }) {
24
+ const uniqueId = React.useId();
25
+ const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;
26
+
27
+ return (
28
+ <ChartContext.Provider value={{ config }}>
29
+ <div
30
+ data-slot="chart"
31
+ data-chart={chartId}
32
+ className={cn(
33
+ "flex aspect-video justify-center text-caption [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
34
+ className,
35
+ )}
36
+ {...props}
37
+ >
38
+ <ChartStyle id={chartId} config={config} />
39
+ <RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}>
40
+ {children}
41
+ </RechartsPrimitive.ResponsiveContainer>
42
+ </div>
43
+ </ChartContext.Provider>
44
+ );
45
+ }
46
+
47
+ export const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
48
+ const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color);
49
+
50
+ if (!colorConfig.length) {
51
+ return null;
52
+ }
53
+
54
+ return (
55
+ <style
56
+ dangerouslySetInnerHTML={{
57
+ __html: THEME_ENTRIES.map(
58
+ ([theme, prefix]) => `
59
+ ${prefix} [data-chart=${id}] {
60
+ ${colorConfig
61
+ .map(([key, itemConfig]) => {
62
+ const color = itemConfig.theme?.[theme] ?? itemConfig.color;
63
+ return color ? ` --color-${key}: ${color};` : null;
64
+ })
65
+ .join("\n")}
66
+ }
67
+ `,
68
+ ).join("\n"),
69
+ }}
70
+ />
71
+ );
72
+ };
@@ -0,0 +1,39 @@
1
+ import * as React from "react";
2
+
3
+ // Format: { THEME_NAME: CSS_SELECTOR }
4
+ export const THEMES = { light: "", dark: ".dark" } as const;
5
+
6
+ // Typed entries of THEMES, so a consumer indexing a per-theme color record by the loop key
7
+ // keeps the literal "light" | "dark" type instead of widening to string (which Object.entries
8
+ // would do).
9
+ export const THEME_ENTRIES: readonly (readonly [keyof typeof THEMES, string])[] = [
10
+ ["light", THEMES.light],
11
+ ["dark", THEMES.dark],
12
+ ];
13
+
14
+ export type ChartConfig = Record<
15
+ string,
16
+ {
17
+ label?: React.ReactNode;
18
+ icon?: React.ComponentType;
19
+ } & (
20
+ | { color?: string; theme?: never }
21
+ | { color?: never; theme: Record<keyof typeof THEMES, string> }
22
+ )
23
+ >;
24
+
25
+ type ChartContextProps = {
26
+ config: ChartConfig;
27
+ };
28
+
29
+ export const ChartContext = React.createContext<ChartContextProps | null>(null);
30
+
31
+ export function useChart() {
32
+ const context = React.useContext(ChartContext);
33
+
34
+ if (!context) {
35
+ throw new Error("useChart must be used within a <ChartContainer />");
36
+ }
37
+
38
+ return context;
39
+ }
@@ -0,0 +1,4 @@
1
+ export type { ChartConfig } from "./context";
2
+ export { ChartContainer, ChartStyle } from "./container";
3
+ export { ChartTooltip, ChartTooltipContent } from "./tooltip";
4
+ export { ChartLegend, ChartLegendContent } from "./legend";
@@ -0,0 +1,63 @@
1
+ import type * as React from "react";
2
+ import * as RechartsPrimitive from "recharts";
3
+
4
+ import { cn } from "../cn";
5
+ import { useChart } from "./context";
6
+ import { getPayloadConfigFromPayload } from "./payload";
7
+
8
+ export const ChartLegend = RechartsPrimitive.Legend;
9
+
10
+ export function ChartLegendContent({
11
+ className,
12
+ hideIcon = false,
13
+ payload,
14
+ verticalAlign = "bottom",
15
+ nameKey,
16
+ }: React.ComponentProps<"div"> & {
17
+ hideIcon?: boolean;
18
+ nameKey?: string;
19
+ } & RechartsPrimitive.DefaultLegendContentProps) {
20
+ const { config } = useChart();
21
+
22
+ if (!payload?.length) {
23
+ return null;
24
+ }
25
+
26
+ return (
27
+ <div
28
+ className={cn(
29
+ "flex items-center justify-center gap-4",
30
+ verticalAlign === "top" ? "pb-3" : "pt-3",
31
+ className,
32
+ )}
33
+ >
34
+ {payload
35
+ .filter((item) => item.type !== "none")
36
+ .map((item, index) => {
37
+ const key = String(nameKey ?? item.dataKey ?? "value");
38
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
39
+
40
+ return (
41
+ <div
42
+ key={index}
43
+ className={cn(
44
+ "flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",
45
+ )}
46
+ >
47
+ {itemConfig?.icon && !hideIcon ? (
48
+ <itemConfig.icon />
49
+ ) : (
50
+ <div
51
+ className="h-2 w-2 shrink-0 rounded-[2px]"
52
+ style={{
53
+ backgroundColor: item.color,
54
+ }}
55
+ />
56
+ )}
57
+ {itemConfig?.label}
58
+ </div>
59
+ );
60
+ })}
61
+ </div>
62
+ );
63
+ }
@@ -0,0 +1,31 @@
1
+ import type { ChartConfig } from "./context";
2
+
3
+ function hasOwn(value: object, key: string): value is Record<string, unknown> {
4
+ return key in value;
5
+ }
6
+
7
+ // Helper to extract item config from a payload.
8
+ export function getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {
9
+ if (typeof payload !== "object" || payload === null) {
10
+ return undefined;
11
+ }
12
+
13
+ const payloadPayload =
14
+ "payload" in payload && typeof payload.payload === "object" && payload.payload !== null
15
+ ? payload.payload
16
+ : undefined;
17
+
18
+ let configLabelKey: string = key;
19
+
20
+ if (hasOwn(payload, key) && typeof payload[key] === "string") {
21
+ configLabelKey = payload[key];
22
+ } else if (
23
+ payloadPayload &&
24
+ hasOwn(payloadPayload, key) &&
25
+ typeof payloadPayload[key] === "string"
26
+ ) {
27
+ configLabelKey = payloadPayload[key];
28
+ }
29
+
30
+ return configLabelKey in config ? config[configLabelKey] : config[key];
31
+ }
@@ -0,0 +1,149 @@
1
+ import * as React from "react";
2
+ import * as RechartsPrimitive from "recharts";
3
+ import type { TooltipValueType } from "recharts";
4
+
5
+ import { cn, type CSSVarStyle } from "../cn";
6
+ import { useChart } from "./context";
7
+ import { getPayloadConfigFromPayload } from "./payload";
8
+
9
+ type TooltipNameType = number | string;
10
+
11
+ export const ChartTooltip = RechartsPrimitive.Tooltip;
12
+
13
+ export function ChartTooltipContent({
14
+ active,
15
+ payload,
16
+ className,
17
+ indicator = "dot",
18
+ hideLabel = false,
19
+ hideIndicator = false,
20
+ label,
21
+ labelFormatter,
22
+ labelClassName,
23
+ formatter,
24
+ color,
25
+ nameKey,
26
+ labelKey,
27
+ }: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
28
+ React.ComponentProps<"div"> & {
29
+ hideLabel?: boolean;
30
+ hideIndicator?: boolean;
31
+ indicator?: "line" | "dot" | "dashed";
32
+ nameKey?: string;
33
+ labelKey?: string;
34
+ } & Omit<
35
+ RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>,
36
+ "accessibilityLayer"
37
+ >) {
38
+ const { config } = useChart();
39
+
40
+ const tooltipLabel = React.useMemo(() => {
41
+ if (hideLabel || !payload?.length) {
42
+ return null;
43
+ }
44
+
45
+ const [item] = payload;
46
+ const key = String(labelKey ?? item?.dataKey ?? item?.name ?? "value");
47
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
48
+ const value =
49
+ !labelKey && typeof label === "string" ? (config[label]?.label ?? label) : itemConfig?.label;
50
+
51
+ if (labelFormatter) {
52
+ return (
53
+ <div className={cn("font-medium", labelClassName)}>{labelFormatter(value, payload)}</div>
54
+ );
55
+ }
56
+
57
+ if (!value) {
58
+ return null;
59
+ }
60
+
61
+ return <div className={cn("font-medium", labelClassName)}>{value}</div>;
62
+ }, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
63
+
64
+ if (!active || !payload?.length) {
65
+ return null;
66
+ }
67
+
68
+ const nestLabel = payload.length === 1 && indicator !== "dot";
69
+
70
+ return (
71
+ <div
72
+ className={cn(
73
+ "grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-caption shadow-xl",
74
+ className,
75
+ )}
76
+ >
77
+ {!nestLabel ? tooltipLabel : null}
78
+ <div className="grid gap-1.5">
79
+ {payload
80
+ .filter((item) => item.type !== "none")
81
+ .map((item, index) => {
82
+ const key = String(nameKey ?? item.name ?? item.dataKey ?? "value");
83
+ const itemConfig = getPayloadConfigFromPayload(config, item, key);
84
+ const indicatorColor = color ?? item.payload?.fill ?? item.color;
85
+ const indicatorStyle: CSSVarStyle = {
86
+ "--color-bg": indicatorColor,
87
+ "--color-border": indicatorColor,
88
+ };
89
+
90
+ return (
91
+ <div
92
+ key={index}
93
+ className={cn(
94
+ "flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
95
+ indicator === "dot" && "items-center",
96
+ )}
97
+ >
98
+ {formatter && item?.value !== undefined && item.name ? (
99
+ formatter(item.value, item.name, item, index, item.payload)
100
+ ) : (
101
+ <>
102
+ {itemConfig?.icon ? (
103
+ <itemConfig.icon />
104
+ ) : (
105
+ !hideIndicator && (
106
+ <div
107
+ className={cn(
108
+ "shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
109
+ {
110
+ "h-2.5 w-2.5": indicator === "dot",
111
+ "w-1": indicator === "line",
112
+ "w-0 border-[1.5px] border-dashed bg-transparent":
113
+ indicator === "dashed",
114
+ "my-0.5": nestLabel && indicator === "dashed",
115
+ },
116
+ )}
117
+ style={indicatorStyle}
118
+ />
119
+ )
120
+ )}
121
+ <div
122
+ className={cn(
123
+ "flex flex-1 justify-between leading-none",
124
+ nestLabel ? "items-end" : "items-center",
125
+ )}
126
+ >
127
+ <div className="grid gap-1.5">
128
+ {nestLabel ? tooltipLabel : null}
129
+ <span className="text-muted-foreground">
130
+ {itemConfig?.label ?? item.name}
131
+ </span>
132
+ </div>
133
+ {item.value != null && (
134
+ <span className="font-mono font-medium text-foreground tabular-nums">
135
+ {typeof item.value === "number"
136
+ ? item.value.toLocaleString()
137
+ : String(item.value)}
138
+ </span>
139
+ )}
140
+ </div>
141
+ </>
142
+ )}
143
+ </div>
144
+ );
145
+ })}
146
+ </div>
147
+ </div>
148
+ );
149
+ }
@@ -0,0 +1,27 @@
1
+ import * as React from "react";
2
+ import { CheckIcon } from "@phosphor-icons/react";
3
+ import { Checkbox as CheckboxPrimitive } from "radix-ui";
4
+
5
+ import { cn } from "./cn";
6
+
7
+ function Checkbox({ className, ...props }: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
8
+ return (
9
+ <CheckboxPrimitive.Root
10
+ data-slot="checkbox"
11
+ className={cn(
12
+ "peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",
13
+ className,
14
+ )}
15
+ {...props}
16
+ >
17
+ <CheckboxPrimitive.Indicator
18
+ data-slot="checkbox-indicator"
19
+ className="grid place-content-center text-current transition-none"
20
+ >
21
+ <CheckIcon className="size-3.5" />
22
+ </CheckboxPrimitive.Indicator>
23
+ </CheckboxPrimitive.Root>
24
+ );
25
+ }
26
+
27
+ export { Checkbox };