@handled-ai/design-system 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -4
- package/dist/charts/bar-chart-component.d.ts +24 -0
- package/dist/charts/bar-chart-component.js +123 -0
- package/dist/charts/bar-chart-component.js.map +1 -0
- package/dist/charts/chart-tooltip.d.ts +26 -0
- package/dist/charts/chart-tooltip.js +69 -0
- package/dist/charts/chart-tooltip.js.map +1 -0
- package/dist/charts/chart.d.ts +64 -0
- package/dist/charts/chart.js +285 -0
- package/dist/charts/chart.js.map +1 -0
- package/dist/charts/donut-chart.d.ts +21 -0
- package/dist/charts/donut-chart.js +96 -0
- package/dist/charts/donut-chart.js.map +1 -0
- package/dist/charts/index.d.ts +11 -0
- package/dist/charts/index.js +10 -0
- package/dist/charts/index.js.map +1 -0
- package/dist/charts/pipeline-overview.d.ts +76 -0
- package/dist/charts/pipeline-overview.js +372 -0
- package/dist/charts/pipeline-overview.js.map +1 -0
- package/dist/charts/sankey-chart.d.ts +52 -0
- package/dist/charts/sankey-chart.js +219 -0
- package/dist/charts/sankey-chart.js.map +1 -0
- package/dist/charts/top-line-metrics.d.ts +26 -0
- package/dist/charts/top-line-metrics.js +224 -0
- package/dist/charts/top-line-metrics.js.map +1 -0
- package/dist/charts/trend-area-chart.d.ts +21 -0
- package/dist/charts/trend-area-chart.js +150 -0
- package/dist/charts/trend-area-chart.js.map +1 -0
- package/dist/charts/volume-analysis-chart.d.ts +19 -0
- package/dist/charts/volume-analysis-chart.js +121 -0
- package/dist/charts/volume-analysis-chart.js.map +1 -0
- package/dist/components/activity-detail.d.ts +38 -0
- package/dist/components/activity-detail.js +163 -0
- package/dist/components/activity-detail.js.map +1 -0
- package/dist/components/activity-log.d.ts +21 -0
- package/dist/components/activity-log.js +61 -0
- package/dist/components/activity-log.js.map +1 -0
- package/dist/components/agent-popover.d.ts +71 -0
- package/dist/components/agent-popover.js +282 -0
- package/dist/components/agent-popover.js.map +1 -0
- package/dist/components/agent-widget.d.ts +24 -0
- package/dist/components/agent-widget.js +117 -0
- package/dist/components/agent-widget.js.map +1 -0
- package/dist/components/avatar.d.ts +13 -0
- package/dist/components/avatar.js +140 -0
- package/dist/components/avatar.js.map +1 -0
- package/dist/components/badge.d.ts +12 -0
- package/dist/components/badge.js +75 -0
- package/dist/components/badge.js.map +1 -0
- package/dist/components/button.d.ts +13 -0
- package/dist/components/button.js +83 -0
- package/dist/components/button.js.map +1 -0
- package/dist/components/card.d.ts +11 -0
- package/dist/components/card.js +119 -0
- package/dist/components/card.js.map +1 -0
- package/dist/components/contact-list.d.ts +34 -0
- package/dist/components/contact-list.js +84 -0
- package/dist/components/contact-list.js.map +1 -0
- package/dist/components/dashboard-cards.d.ts +10 -0
- package/dist/components/dashboard-cards.js +164 -0
- package/dist/components/dashboard-cards.js.map +1 -0
- package/dist/components/data-table-display.d.ts +19 -0
- package/dist/components/data-table-display.js +109 -0
- package/dist/components/data-table-display.js.map +1 -0
- package/dist/components/data-table-filter.d.ts +18 -0
- package/dist/components/data-table-filter.js +107 -0
- package/dist/components/data-table-filter.js.map +1 -0
- package/dist/components/data-table-quick-views.d.ts +13 -0
- package/dist/components/data-table-quick-views.js +90 -0
- package/dist/components/data-table-quick-views.js.map +1 -0
- package/dist/components/data-table-toolbar.d.ts +18 -0
- package/dist/components/data-table-toolbar.js +45 -0
- package/dist/components/data-table-toolbar.js.map +1 -0
- package/dist/components/data-table.d.ts +39 -0
- package/dist/components/data-table.js +821 -0
- package/dist/components/data-table.js.map +1 -0
- package/dist/components/detail-view.d.ts +44 -0
- package/dist/components/detail-view.js +165 -0
- package/dist/components/detail-view.js.map +1 -0
- package/dist/components/dialog.d.ts +19 -0
- package/dist/components/dialog.js +188 -0
- package/dist/components/dialog.js.map +1 -0
- package/dist/components/dropdown-menu.d.ts +27 -0
- package/dist/components/dropdown-menu.js +279 -0
- package/dist/components/dropdown-menu.js.map +1 -0
- package/dist/components/entity-panel.d.ts +69 -0
- package/dist/components/entity-panel.js +584 -0
- package/dist/components/entity-panel.js.map +1 -0
- package/dist/components/inbox-row.d.ts +27 -0
- package/dist/components/inbox-row.js +139 -0
- package/dist/components/inbox-row.js.map +1 -0
- package/dist/components/inbox-toolbar.d.ts +21 -0
- package/dist/components/inbox-toolbar.js +203 -0
- package/dist/components/inbox-toolbar.js.map +1 -0
- package/dist/components/input.d.ts +5 -0
- package/dist/components/input.js +50 -0
- package/dist/components/input.js.map +1 -0
- package/dist/components/insights-filter-bar.d.ts +21 -0
- package/dist/components/insights-filter-bar.js +99 -0
- package/dist/components/insights-filter-bar.js.map +1 -0
- package/dist/components/item-list-display.d.ts +22 -0
- package/dist/components/item-list-display.js +240 -0
- package/dist/components/item-list-display.js.map +1 -0
- package/dist/components/item-list-filter.d.ts +16 -0
- package/dist/components/item-list-filter.js +87 -0
- package/dist/components/item-list-filter.js.map +1 -0
- package/dist/components/item-list-toolbar.d.ts +25 -0
- package/dist/components/item-list-toolbar.js +79 -0
- package/dist/components/item-list-toolbar.js.map +1 -0
- package/dist/components/item-list.d.ts +20 -0
- package/dist/components/item-list.js +702 -0
- package/dist/components/item-list.js.map +1 -0
- package/dist/components/label.d.ts +6 -0
- package/dist/components/label.js +55 -0
- package/dist/components/label.js.map +1 -0
- package/dist/components/message.d.ts +23 -0
- package/dist/components/message.js +117 -0
- package/dist/components/message.js.map +1 -0
- package/dist/components/metric-card.d.ts +25 -0
- package/dist/components/metric-card.js +107 -0
- package/dist/components/metric-card.js.map +1 -0
- package/dist/components/performance-metrics-table.d.ts +38 -0
- package/dist/components/performance-metrics-table.js +342 -0
- package/dist/components/performance-metrics-table.js.map +1 -0
- package/dist/components/preview-list.d.ts +14 -0
- package/dist/components/preview-list.js +83 -0
- package/dist/components/preview-list.js.map +1 -0
- package/dist/components/progress.d.ts +6 -0
- package/dist/components/progress.js +69 -0
- package/dist/components/progress.js.map +1 -0
- package/dist/components/quick-action-chat-area.d.ts +24 -0
- package/dist/components/quick-action-chat-area.js +178 -0
- package/dist/components/quick-action-chat-area.js.map +1 -0
- package/dist/components/quick-action-modal.d.ts +30 -0
- package/dist/components/quick-action-modal.js +288 -0
- package/dist/components/quick-action-modal.js.map +1 -0
- package/dist/components/quick-action-sidebar-nav.d.ts +51 -0
- package/dist/components/quick-action-sidebar-nav.js +528 -0
- package/dist/components/quick-action-sidebar-nav.js.map +1 -0
- package/dist/components/recommended-actions-section.d.ts +23 -0
- package/dist/components/recommended-actions-section.js +215 -0
- package/dist/components/recommended-actions-section.js.map +1 -0
- package/dist/components/report-card.d.ts +26 -0
- package/dist/components/report-card.js +69 -0
- package/dist/components/report-card.js.map +1 -0
- package/dist/components/score-analysis-modal.d.ts +26 -0
- package/dist/components/score-analysis-modal.js +141 -0
- package/dist/components/score-analysis-modal.js.map +1 -0
- package/dist/components/score-breakdown.d.ts +17 -0
- package/dist/components/score-breakdown.js +162 -0
- package/dist/components/score-breakdown.js.map +1 -0
- package/dist/components/score-feedback.d.ts +40 -0
- package/dist/components/score-feedback.js +209 -0
- package/dist/components/score-feedback.js.map +1 -0
- package/dist/components/score-ring.d.ts +14 -0
- package/dist/components/score-ring.js +79 -0
- package/dist/components/score-ring.js.map +1 -0
- package/dist/components/scroll-area.d.ts +7 -0
- package/dist/components/scroll-area.js +101 -0
- package/dist/components/scroll-area.js.map +1 -0
- package/dist/components/select.d.ts +17 -0
- package/dist/components/select.js +228 -0
- package/dist/components/select.js.map +1 -0
- package/dist/components/separator.d.ts +6 -0
- package/dist/components/separator.js +61 -0
- package/dist/components/separator.js.map +1 -0
- package/dist/components/sheet.d.ts +16 -0
- package/dist/components/sheet.js +168 -0
- package/dist/components/sheet.js.map +1 -0
- package/dist/components/sidebar.d.ts +73 -0
- package/dist/components/sidebar.js +723 -0
- package/dist/components/sidebar.js.map +1 -0
- package/dist/components/signal-feedback-inline.d.ts +51 -0
- package/dist/components/signal-feedback-inline.js +548 -0
- package/dist/components/signal-feedback-inline.js.map +1 -0
- package/dist/components/simple-data-table.d.ts +15 -0
- package/dist/components/simple-data-table.js +91 -0
- package/dist/components/simple-data-table.js.map +1 -0
- package/dist/components/skeleton.d.ts +5 -0
- package/dist/components/skeleton.js +44 -0
- package/dist/components/skeleton.js.map +1 -0
- package/dist/components/status-badge.d.ts +10 -0
- package/dist/components/status-badge.js +82 -0
- package/dist/components/status-badge.js.map +1 -0
- package/dist/components/styled-bar-list.d.ts +20 -0
- package/dist/components/styled-bar-list.js +59 -0
- package/dist/components/styled-bar-list.js.map +1 -0
- package/dist/components/suggested-actions.d.ts +110 -0
- package/dist/components/suggested-actions.js +1538 -0
- package/dist/components/suggested-actions.js.map +1 -0
- package/dist/components/table.d.ts +12 -0
- package/dist/components/table.js +147 -0
- package/dist/components/table.js.map +1 -0
- package/dist/components/tabs.d.ts +14 -0
- package/dist/components/tabs.js +129 -0
- package/dist/components/tabs.js.map +1 -0
- package/dist/components/textarea.d.ts +5 -0
- package/dist/components/textarea.js +47 -0
- package/dist/components/textarea.js.map +1 -0
- package/dist/components/timeline-activity.d.ts +34 -0
- package/dist/components/timeline-activity.js +181 -0
- package/dist/components/timeline-activity.js.map +1 -0
- package/dist/components/tooltip.d.ts +9 -0
- package/dist/components/tooltip.js +93 -0
- package/dist/components/tooltip.js.map +1 -0
- package/dist/components/view-mode-toggle.d.ts +16 -0
- package/dist/components/view-mode-toggle.js +24 -0
- package/dist/components/view-mode-toggle.js.map +1 -0
- package/dist/hooks/use-mobile.d.ts +3 -0
- package/dist/hooks/use-mobile.js +21 -0
- package/dist/hooks/use-mobile.js.map +1 -0
- package/dist/index.d.ts +68 -1878
- package/dist/index.js +69 -10918
- package/dist/index.js.map +1 -1
- package/dist/lib/icons.d.ts +18 -0
- package/dist/lib/icons.js +21 -0
- package/dist/lib/icons.js.map +1 -0
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.js +9 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/prototype/index.d.ts +20 -0
- package/dist/prototype/index.js +8 -0
- package/dist/prototype/index.js.map +1 -0
- package/dist/prototype/prototype-accounts-view.d.ts +22 -0
- package/dist/prototype/prototype-accounts-view.js +70 -0
- package/dist/prototype/prototype-accounts-view.js.map +1 -0
- package/dist/prototype/prototype-admin-view.d.ts +21 -0
- package/dist/prototype/prototype-admin-view.js +53 -0
- package/dist/prototype/prototype-admin-view.js.map +1 -0
- package/dist/prototype/prototype-config.d.ts +226 -0
- package/dist/prototype/prototype-config.js +1 -0
- package/dist/prototype/prototype-config.js.map +1 -0
- package/dist/prototype/prototype-inbox-view.d.ts +48 -0
- package/dist/prototype/prototype-inbox-view.js +701 -0
- package/dist/prototype/prototype-inbox-view.js.map +1 -0
- package/dist/prototype/prototype-insights-view.d.ts +23 -0
- package/dist/prototype/prototype-insights-view.js +335 -0
- package/dist/prototype/prototype-insights-view.js.map +1 -0
- package/dist/prototype/prototype-shell.d.ts +40 -0
- package/dist/prototype/prototype-shell.js +190 -0
- package/dist/prototype/prototype-shell.js.map +1 -0
- package/dist/prototype/prototype-work-queue-view.d.ts +8 -0
- package/dist/prototype/prototype-work-queue-view.js +17 -0
- package/dist/prototype/prototype-work-queue-view.js.map +1 -0
- package/dist/three/agent-orb.d.ts +39 -0
- package/dist/three/agent-orb.js +500 -0
- package/dist/three/agent-orb.js.map +1 -0
- package/dist/three/index.d.ts +2 -0
- package/dist/three/index.js +2 -0
- package/dist/three/index.js.map +1 -0
- package/package.json +98 -17
- package/src/charts/bar-chart-component.tsx +150 -0
- package/src/charts/chart-tooltip.tsx +86 -0
- package/src/charts/chart.tsx +371 -0
- package/src/charts/donut-chart.tsx +112 -0
- package/src/charts/index.ts +13 -0
- package/src/charts/pipeline-overview.tsx +476 -0
- package/src/charts/sankey-chart.tsx +290 -0
- package/src/charts/top-line-metrics.tsx +261 -0
- package/src/charts/trend-area-chart.tsx +150 -0
- package/src/charts/volume-analysis-chart.tsx +124 -0
- package/src/components/activity-detail.tsx +233 -0
- package/src/components/activity-log.tsx +89 -0
- package/src/components/agent-popover.tsx +373 -0
- package/src/components/agent-widget.tsx +163 -0
- package/src/components/avatar.tsx +109 -0
- package/src/components/badge.tsx +48 -0
- package/src/components/button.tsx +59 -0
- package/src/components/card.tsx +92 -0
- package/src/components/contact-list.tsx +121 -0
- package/src/components/dashboard-cards.tsx +170 -0
- package/src/components/data-table-display.tsx +139 -0
- package/src/components/data-table-filter.tsx +138 -0
- package/src/components/data-table-quick-views.tsx +103 -0
- package/src/components/data-table-toolbar.tsx +56 -0
- package/src/components/data-table.tsx +915 -0
- package/src/components/detail-view.tsx +237 -0
- package/src/components/dialog.tsx +158 -0
- package/src/components/dropdown-menu.tsx +257 -0
- package/src/components/entity-panel.tsx +767 -0
- package/src/components/inbox-row.tsx +132 -0
- package/src/components/inbox-toolbar.tsx +213 -0
- package/src/components/input.tsx +21 -0
- package/src/components/insights-filter-bar.tsx +132 -0
- package/src/components/item-list-display.tsx +278 -0
- package/src/components/item-list-filter.tsx +118 -0
- package/src/components/item-list-toolbar.tsx +97 -0
- package/src/components/item-list.tsx +843 -0
- package/src/components/label.tsx +24 -0
- package/src/components/message.tsx +83 -0
- package/src/components/metric-card.tsx +178 -0
- package/src/components/performance-metrics-table.tsx +442 -0
- package/src/components/preview-list.tsx +62 -0
- package/src/components/progress.tsx +31 -0
- package/src/components/quick-action-chat-area.tsx +156 -0
- package/src/components/quick-action-modal.tsx +331 -0
- package/src/components/quick-action-sidebar-nav.tsx +592 -0
- package/src/components/recommended-actions-section.tsx +258 -0
- package/src/components/report-card.tsx +106 -0
- package/src/components/score-analysis-modal.tsx +172 -0
- package/src/components/score-breakdown.tsx +179 -0
- package/src/components/score-feedback.tsx +288 -0
- package/src/components/score-ring.tsx +87 -0
- package/src/components/scroll-area.tsx +58 -0
- package/src/components/select.tsx +190 -0
- package/src/components/separator.tsx +28 -0
- package/src/components/sheet.tsx +143 -0
- package/src/components/sidebar.tsx +726 -0
- package/src/components/signal-feedback-inline.tsx +591 -0
- package/src/components/simple-data-table.tsx +124 -0
- package/src/components/skeleton.tsx +15 -0
- package/src/components/status-badge.tsx +63 -0
- package/src/components/styled-bar-list.tsx +70 -0
- package/src/components/suggested-actions.tsx +1985 -0
- package/src/components/table.tsx +116 -0
- package/src/components/tabs.tsx +91 -0
- package/src/components/textarea.tsx +18 -0
- package/src/components/timeline-activity.tsx +234 -0
- package/src/components/tooltip.tsx +57 -0
- package/src/components/view-mode-toggle.tsx +39 -0
- package/src/hooks/use-mobile.ts +21 -0
- package/src/index.ts +77 -0
- package/src/lib/icons.ts +18 -0
- package/src/lib/utils.ts +6 -0
- package/src/prototype/index.ts +11 -0
- package/src/prototype/prototype-accounts-view.tsx +112 -0
- package/src/prototype/prototype-admin-view.tsx +67 -0
- package/src/prototype/prototype-config.ts +243 -0
- package/src/prototype/prototype-inbox-view.tsx +810 -0
- package/src/prototype/prototype-insights-view.tsx +379 -0
- package/src/prototype/prototype-shell.tsx +219 -0
- package/src/prototype/prototype-work-queue-view.tsx +30 -0
- package/src/styles/globals.css +299 -0
- package/src/three/agent-orb.tsx +557 -0
- package/src/three/index.ts +5 -0
- package/src/types/r3f.d.ts +8 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import * as RechartsPrimitive from "recharts";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
|
|
8
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
9
|
+
const THEMES = { light: "", dark: ".dark" } as const;
|
|
10
|
+
|
|
11
|
+
export type ChartConfig = {
|
|
12
|
+
[k in string]: {
|
|
13
|
+
label?: React.ReactNode;
|
|
14
|
+
icon?: React.ComponentType;
|
|
15
|
+
} & (
|
|
16
|
+
| { color?: string; theme?: never }
|
|
17
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
18
|
+
);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type ChartContextProps = {
|
|
22
|
+
config: ChartConfig;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null);
|
|
26
|
+
|
|
27
|
+
function useChart() {
|
|
28
|
+
const context = React.useContext(ChartContext);
|
|
29
|
+
|
|
30
|
+
if (!context) {
|
|
31
|
+
throw new Error("useChart must be used within a <ChartContainer />");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return context;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function ChartContainer({
|
|
38
|
+
id,
|
|
39
|
+
className,
|
|
40
|
+
children,
|
|
41
|
+
config,
|
|
42
|
+
...props
|
|
43
|
+
}: React.ComponentProps<"div"> & {
|
|
44
|
+
config: ChartConfig;
|
|
45
|
+
children: React.ComponentProps<
|
|
46
|
+
typeof RechartsPrimitive.ResponsiveContainer
|
|
47
|
+
>["children"];
|
|
48
|
+
}) {
|
|
49
|
+
const uniqueId = React.useId();
|
|
50
|
+
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<ChartContext.Provider value={{ config }}>
|
|
54
|
+
<div
|
|
55
|
+
data-slot="chart"
|
|
56
|
+
data-chart={chartId}
|
|
57
|
+
className={cn(
|
|
58
|
+
"[&_.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-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 flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
|
|
59
|
+
className,
|
|
60
|
+
)}
|
|
61
|
+
{...props}
|
|
62
|
+
>
|
|
63
|
+
<ChartStyle id={chartId} config={config} />
|
|
64
|
+
<RechartsPrimitive.ResponsiveContainer>
|
|
65
|
+
{children}
|
|
66
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
67
|
+
</div>
|
|
68
|
+
</ChartContext.Provider>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
73
|
+
const colorConfig = Object.entries(config).filter(
|
|
74
|
+
([, config]) => config.theme || config.color,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
if (!colorConfig.length) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<style
|
|
83
|
+
dangerouslySetInnerHTML={{
|
|
84
|
+
__html: Object.entries(THEMES)
|
|
85
|
+
.map(
|
|
86
|
+
([theme, prefix]) => `
|
|
87
|
+
${prefix} [data-chart=${id}] {
|
|
88
|
+
${colorConfig
|
|
89
|
+
.map(([key, itemConfig]) => {
|
|
90
|
+
const color =
|
|
91
|
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ||
|
|
92
|
+
itemConfig.color;
|
|
93
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
94
|
+
})
|
|
95
|
+
.join("\n")}
|
|
96
|
+
}
|
|
97
|
+
`,
|
|
98
|
+
)
|
|
99
|
+
.join("\n"),
|
|
100
|
+
}}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
106
|
+
|
|
107
|
+
type TooltipPayloadItem = {
|
|
108
|
+
name?: string;
|
|
109
|
+
value?: number | string;
|
|
110
|
+
dataKey?: string;
|
|
111
|
+
payload?: Record<string, unknown>;
|
|
112
|
+
color?: string;
|
|
113
|
+
fill?: string;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
function ChartTooltipContent({
|
|
117
|
+
active,
|
|
118
|
+
payload,
|
|
119
|
+
className,
|
|
120
|
+
indicator = "dot",
|
|
121
|
+
hideLabel = false,
|
|
122
|
+
hideIndicator = false,
|
|
123
|
+
label,
|
|
124
|
+
labelFormatter,
|
|
125
|
+
labelClassName,
|
|
126
|
+
formatter,
|
|
127
|
+
color,
|
|
128
|
+
nameKey,
|
|
129
|
+
labelKey,
|
|
130
|
+
}: React.ComponentProps<"div"> & {
|
|
131
|
+
active?: boolean;
|
|
132
|
+
payload?: TooltipPayloadItem[];
|
|
133
|
+
label?: string;
|
|
134
|
+
labelFormatter?: (value: unknown, payload: TooltipPayloadItem[]) => React.ReactNode;
|
|
135
|
+
formatter?: (value: unknown, name: string, item: TooltipPayloadItem, index: number, payload: Record<string, unknown>) => React.ReactNode;
|
|
136
|
+
hideLabel?: boolean;
|
|
137
|
+
hideIndicator?: boolean;
|
|
138
|
+
indicator?: "line" | "dot" | "dashed";
|
|
139
|
+
nameKey?: string;
|
|
140
|
+
labelKey?: string;
|
|
141
|
+
labelClassName?: string;
|
|
142
|
+
color?: string;
|
|
143
|
+
}) {
|
|
144
|
+
const { config } = useChart();
|
|
145
|
+
|
|
146
|
+
const tooltipLabel = React.useMemo(() => {
|
|
147
|
+
if (hideLabel || !payload?.length) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const [item] = payload;
|
|
152
|
+
const key = `${labelKey || item?.dataKey || item?.name || "value"}`;
|
|
153
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
154
|
+
const value =
|
|
155
|
+
!labelKey && typeof label === "string"
|
|
156
|
+
? config[label as keyof typeof config]?.label || label
|
|
157
|
+
: itemConfig?.label;
|
|
158
|
+
|
|
159
|
+
if (labelFormatter) {
|
|
160
|
+
return (
|
|
161
|
+
<div className={cn("font-medium", labelClassName)}>
|
|
162
|
+
{labelFormatter(value, payload)}
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!value) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
|
172
|
+
}, [
|
|
173
|
+
label,
|
|
174
|
+
labelFormatter,
|
|
175
|
+
payload,
|
|
176
|
+
hideLabel,
|
|
177
|
+
labelClassName,
|
|
178
|
+
config,
|
|
179
|
+
labelKey,
|
|
180
|
+
]);
|
|
181
|
+
|
|
182
|
+
if (!active || !payload?.length) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<div
|
|
190
|
+
className={cn(
|
|
191
|
+
"border-border/50 bg-background grid min-w-[8rem] items-start gap-1.5 rounded-lg border px-2.5 py-1.5 text-xs shadow-xl",
|
|
192
|
+
className,
|
|
193
|
+
)}
|
|
194
|
+
>
|
|
195
|
+
{!nestLabel ? tooltipLabel : null}
|
|
196
|
+
<div className="grid gap-1.5">
|
|
197
|
+
{payload.map((item: TooltipPayloadItem, index: number) => {
|
|
198
|
+
const key = `${nameKey || item.name || item.dataKey || "value"}`;
|
|
199
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
200
|
+
const indicatorColor = color || item.payload?.fill || item.color;
|
|
201
|
+
|
|
202
|
+
return (
|
|
203
|
+
<div
|
|
204
|
+
key={item.dataKey}
|
|
205
|
+
className={cn(
|
|
206
|
+
"[&>svg]:text-muted-foreground flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5",
|
|
207
|
+
indicator === "dot" && "items-center",
|
|
208
|
+
)}
|
|
209
|
+
>
|
|
210
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
211
|
+
formatter(item.value, item.name, item, index, item.payload ?? {})
|
|
212
|
+
) : (
|
|
213
|
+
<>
|
|
214
|
+
{itemConfig?.icon ? (
|
|
215
|
+
<itemConfig.icon />
|
|
216
|
+
) : (
|
|
217
|
+
!hideIndicator && (
|
|
218
|
+
<div
|
|
219
|
+
className={cn(
|
|
220
|
+
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
221
|
+
{
|
|
222
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
223
|
+
"w-1": indicator === "line",
|
|
224
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
225
|
+
indicator === "dashed",
|
|
226
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
227
|
+
},
|
|
228
|
+
)}
|
|
229
|
+
style={
|
|
230
|
+
{
|
|
231
|
+
"--color-bg": indicatorColor,
|
|
232
|
+
"--color-border": indicatorColor,
|
|
233
|
+
} as React.CSSProperties
|
|
234
|
+
}
|
|
235
|
+
/>
|
|
236
|
+
)
|
|
237
|
+
)}
|
|
238
|
+
<div
|
|
239
|
+
className={cn(
|
|
240
|
+
"flex flex-1 justify-between leading-none",
|
|
241
|
+
nestLabel ? "items-end" : "items-center",
|
|
242
|
+
)}
|
|
243
|
+
>
|
|
244
|
+
<div className="grid gap-1.5">
|
|
245
|
+
{nestLabel ? tooltipLabel : null}
|
|
246
|
+
<span className="text-muted-foreground">
|
|
247
|
+
{itemConfig?.label || item.name}
|
|
248
|
+
</span>
|
|
249
|
+
</div>
|
|
250
|
+
{item.value && (
|
|
251
|
+
<span className="text-foreground font-mono font-medium tabular-nums">
|
|
252
|
+
{item.value.toLocaleString()}
|
|
253
|
+
</span>
|
|
254
|
+
)}
|
|
255
|
+
</div>
|
|
256
|
+
</>
|
|
257
|
+
)}
|
|
258
|
+
</div>
|
|
259
|
+
);
|
|
260
|
+
})}
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const ChartLegend = RechartsPrimitive.Legend;
|
|
267
|
+
|
|
268
|
+
type LegendPayloadItem = { value?: string; dataKey?: string; [key: string]: unknown };
|
|
269
|
+
|
|
270
|
+
function ChartLegendContent({
|
|
271
|
+
className,
|
|
272
|
+
hideIcon = false,
|
|
273
|
+
payload,
|
|
274
|
+
verticalAlign = "bottom",
|
|
275
|
+
nameKey,
|
|
276
|
+
}: React.ComponentProps<"div"> & {
|
|
277
|
+
payload?: LegendPayloadItem[];
|
|
278
|
+
verticalAlign?: "top" | "bottom";
|
|
279
|
+
hideIcon?: boolean;
|
|
280
|
+
nameKey?: string;
|
|
281
|
+
}) {
|
|
282
|
+
const { config } = useChart();
|
|
283
|
+
|
|
284
|
+
if (!payload?.length) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return (
|
|
289
|
+
<div
|
|
290
|
+
className={cn(
|
|
291
|
+
"flex items-center justify-center gap-4",
|
|
292
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
293
|
+
className,
|
|
294
|
+
)}
|
|
295
|
+
>
|
|
296
|
+
{payload.map((item: LegendPayloadItem) => {
|
|
297
|
+
const key = `${nameKey || item.dataKey || "value"}`;
|
|
298
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<div
|
|
302
|
+
key={item.value}
|
|
303
|
+
className={cn(
|
|
304
|
+
"[&>svg]:text-muted-foreground flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3",
|
|
305
|
+
)}
|
|
306
|
+
>
|
|
307
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
308
|
+
<itemConfig.icon />
|
|
309
|
+
) : (
|
|
310
|
+
<div
|
|
311
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
312
|
+
style={{
|
|
313
|
+
backgroundColor: item.color as string | undefined,
|
|
314
|
+
}}
|
|
315
|
+
/>
|
|
316
|
+
)}
|
|
317
|
+
{itemConfig?.label}
|
|
318
|
+
</div>
|
|
319
|
+
);
|
|
320
|
+
})}
|
|
321
|
+
</div>
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Helper to extract item config from a payload.
|
|
326
|
+
function getPayloadConfigFromPayload(
|
|
327
|
+
config: ChartConfig,
|
|
328
|
+
payload: unknown,
|
|
329
|
+
key: string,
|
|
330
|
+
) {
|
|
331
|
+
if (typeof payload !== "object" || payload === null) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const payloadPayload =
|
|
336
|
+
"payload" in payload &&
|
|
337
|
+
typeof payload.payload === "object" &&
|
|
338
|
+
payload.payload !== null
|
|
339
|
+
? payload.payload
|
|
340
|
+
: undefined;
|
|
341
|
+
|
|
342
|
+
let configLabelKey: string = key;
|
|
343
|
+
|
|
344
|
+
if (
|
|
345
|
+
key in payload &&
|
|
346
|
+
typeof payload[key as keyof typeof payload] === "string"
|
|
347
|
+
) {
|
|
348
|
+
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
349
|
+
} else if (
|
|
350
|
+
payloadPayload &&
|
|
351
|
+
key in payloadPayload &&
|
|
352
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
353
|
+
) {
|
|
354
|
+
configLabelKey = payloadPayload[
|
|
355
|
+
key as keyof typeof payloadPayload
|
|
356
|
+
] as string;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return configLabelKey in config
|
|
360
|
+
? config[configLabelKey]
|
|
361
|
+
: config[key as keyof typeof config];
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export {
|
|
365
|
+
ChartContainer,
|
|
366
|
+
ChartTooltip,
|
|
367
|
+
ChartTooltipContent,
|
|
368
|
+
ChartLegend,
|
|
369
|
+
ChartLegendContent,
|
|
370
|
+
ChartStyle,
|
|
371
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import {
|
|
5
|
+
PieChart,
|
|
6
|
+
Pie,
|
|
7
|
+
Cell,
|
|
8
|
+
Label,
|
|
9
|
+
Tooltip,
|
|
10
|
+
ResponsiveContainer,
|
|
11
|
+
} from "recharts"
|
|
12
|
+
|
|
13
|
+
import { cn } from "../lib/utils"
|
|
14
|
+
import { CHART_TOOLTIP_STYLE } from "./chart-tooltip"
|
|
15
|
+
|
|
16
|
+
export interface DonutSegment {
|
|
17
|
+
name: string
|
|
18
|
+
value: number
|
|
19
|
+
color: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DonutChartProps {
|
|
23
|
+
data: DonutSegment[]
|
|
24
|
+
centerLabel?: string | number
|
|
25
|
+
size?: number
|
|
26
|
+
innerRadius?: number
|
|
27
|
+
outerRadius?: number
|
|
28
|
+
paddingAngle?: number
|
|
29
|
+
showTooltip?: boolean
|
|
30
|
+
showLegend?: boolean
|
|
31
|
+
className?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function DonutChart({
|
|
35
|
+
data,
|
|
36
|
+
centerLabel,
|
|
37
|
+
size = 80,
|
|
38
|
+
innerRadius,
|
|
39
|
+
outerRadius,
|
|
40
|
+
paddingAngle = 2,
|
|
41
|
+
showTooltip = true,
|
|
42
|
+
showLegend = false,
|
|
43
|
+
className,
|
|
44
|
+
}: DonutChartProps) {
|
|
45
|
+
const computedInner = innerRadius ?? Math.round(size * 0.325)
|
|
46
|
+
const computedOuter = outerRadius ?? Math.round(size * 0.45)
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<div className={cn("flex items-center gap-3", className)}>
|
|
50
|
+
<div className="shrink-0" style={{ height: size, width: size }}>
|
|
51
|
+
<ResponsiveContainer width="100%" height="100%">
|
|
52
|
+
<PieChart>
|
|
53
|
+
{showTooltip ? (
|
|
54
|
+
<Tooltip
|
|
55
|
+
contentStyle={CHART_TOOLTIP_STYLE}
|
|
56
|
+
itemStyle={{ color: "#0f172a", fontWeight: 600 }}
|
|
57
|
+
formatter={(value: unknown, name: unknown) => [
|
|
58
|
+
`${value}`,
|
|
59
|
+
String(name),
|
|
60
|
+
]}
|
|
61
|
+
/>
|
|
62
|
+
) : null}
|
|
63
|
+
<Pie
|
|
64
|
+
data={data}
|
|
65
|
+
innerRadius={computedInner}
|
|
66
|
+
outerRadius={computedOuter}
|
|
67
|
+
paddingAngle={paddingAngle}
|
|
68
|
+
dataKey="value"
|
|
69
|
+
stroke="none"
|
|
70
|
+
>
|
|
71
|
+
{data.map((entry, index) => (
|
|
72
|
+
<Cell key={`cell-${index}`} fill={entry.color} />
|
|
73
|
+
))}
|
|
74
|
+
{centerLabel != null ? (
|
|
75
|
+
<Label
|
|
76
|
+
value={String(centerLabel)}
|
|
77
|
+
position="center"
|
|
78
|
+
className="fill-foreground text-lg font-bold"
|
|
79
|
+
/>
|
|
80
|
+
) : null}
|
|
81
|
+
</Pie>
|
|
82
|
+
</PieChart>
|
|
83
|
+
</ResponsiveContainer>
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
{showLegend ? (
|
|
87
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1.5 pl-1">
|
|
88
|
+
{data.map((d) => (
|
|
89
|
+
<div
|
|
90
|
+
key={d.name}
|
|
91
|
+
className="flex items-center justify-between text-[10px]"
|
|
92
|
+
>
|
|
93
|
+
<div className="flex min-w-0 items-center gap-1.5">
|
|
94
|
+
<div
|
|
95
|
+
className="h-1.5 w-1.5 shrink-0 rounded-full"
|
|
96
|
+
style={{ backgroundColor: d.color }}
|
|
97
|
+
/>
|
|
98
|
+
<span
|
|
99
|
+
className="whitespace-nowrap font-medium text-muted-foreground"
|
|
100
|
+
title={d.name}
|
|
101
|
+
>
|
|
102
|
+
{d.name}
|
|
103
|
+
</span>
|
|
104
|
+
</div>
|
|
105
|
+
<span className="ml-1.5 font-bold text-foreground">{d.value}</span>
|
|
106
|
+
</div>
|
|
107
|
+
))}
|
|
108
|
+
</div>
|
|
109
|
+
) : null}
|
|
110
|
+
</div>
|
|
111
|
+
)
|
|
112
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @handled-ai/design-system/charts
|
|
3
|
+
* Chart components requiring recharts and @nivo/sankey
|
|
4
|
+
*/
|
|
5
|
+
export * from "./chart"
|
|
6
|
+
export * from "./chart-tooltip"
|
|
7
|
+
export * from "./bar-chart-component"
|
|
8
|
+
export * from "./donut-chart"
|
|
9
|
+
export * from "./trend-area-chart"
|
|
10
|
+
export * from "./volume-analysis-chart"
|
|
11
|
+
export * from "./top-line-metrics"
|
|
12
|
+
export * from "./pipeline-overview"
|
|
13
|
+
export * from "./sankey-chart"
|