@durablex/react-ui 0.1.0-beta.3
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/LICENSE +202 -0
- package/NOTICE +5 -0
- package/dist/index.d.ts +1078 -0
- package/dist/index.js +6407 -0
- package/dist/index.js.map +1 -0
- package/package.json +86 -0
- package/src/components/AnimatedDurablexMark.tsx +35 -0
- package/src/components/AppStatusBadge.tsx +17 -0
- package/src/components/AppTag.tsx +17 -0
- package/src/components/AppsView.tsx +226 -0
- package/src/components/BulkReplayButton.tsx +52 -0
- package/src/components/CursorPager.tsx +50 -0
- package/src/components/DeliveriesSplit.tsx +187 -0
- package/src/components/DeliveryDetail.tsx +188 -0
- package/src/components/DurablexLogo.tsx +12 -0
- package/src/components/EndpointFormDialog.tsx +153 -0
- package/src/components/EndpointRow.tsx +172 -0
- package/src/components/EndpointsTab.tsx +83 -0
- package/src/components/EventsList.tsx +170 -0
- package/src/components/EventsView.tsx +24 -0
- package/src/components/Facts.tsx +14 -0
- package/src/components/FlowControlBadge.tsx +23 -0
- package/src/components/FlowControlSection.tsx +82 -0
- package/src/components/FlowSummary.tsx +47 -0
- package/src/components/FormField.tsx +10 -0
- package/src/components/GlyphBadge.tsx +41 -0
- package/src/components/JsonBlock.tsx +48 -0
- package/src/components/JsonEditor.tsx +91 -0
- package/src/components/LogList.tsx +45 -0
- package/src/components/Meta.tsx +31 -0
- package/src/components/OverviewView.tsx +39 -0
- package/src/components/PayloadTabs.tsx +70 -0
- package/src/components/ReceiverFormDialog.tsx +123 -0
- package/src/components/ReceiversTab.tsx +194 -0
- package/src/components/ReplayRunDialog.tsx +112 -0
- package/src/components/ResumeMark.tsx +38 -0
- package/src/components/RetryFromStepButton.tsx +44 -0
- package/src/components/RunCancelButton.tsx +23 -0
- package/src/components/RunControlHistory.tsx +71 -0
- package/src/components/RunInspector.test.tsx +78 -0
- package/src/components/RunInspector.tsx +297 -0
- package/src/components/RunInspectorActions.tsx +40 -0
- package/src/components/RunPauseButton.tsx +34 -0
- package/src/components/RunnerLiveBadge.tsx +11 -0
- package/src/components/RunsFilterBar.tsx +180 -0
- package/src/components/RunsTable.tsx +110 -0
- package/src/components/RunsTableHead.tsx +19 -0
- package/src/components/RunsTableLoader.tsx +10 -0
- package/src/components/RunsTablePlaceholder.tsx +19 -0
- package/src/components/RunsTableRow.tsx +103 -0
- package/src/components/RunsView.test.tsx +46 -0
- package/src/components/RunsView.tsx +243 -0
- package/src/components/ScheduledBadge.tsx +15 -0
- package/src/components/SecretReveal.tsx +45 -0
- package/src/components/SectionHeader.tsx +10 -0
- package/src/components/StatTileGrid.tsx +71 -0
- package/src/components/StatsTiles.tsx +66 -0
- package/src/components/StatusBadge.tsx +50 -0
- package/src/components/StepFlow.tsx +105 -0
- package/src/components/StepGlyph.tsx +25 -0
- package/src/components/StepInspector.tsx +44 -0
- package/src/components/StepRow.tsx +69 -0
- package/src/components/StepTabsView.tsx +51 -0
- package/src/components/StepTimeline.tsx +87 -0
- package/src/components/TableStatusRows.tsx +54 -0
- package/src/components/TriggerEventDialog.tsx +180 -0
- package/src/components/TriggerEventResult.tsx +61 -0
- package/src/components/WebhookBadges.tsx +69 -0
- package/src/components/WebhookStatusBadge.tsx +25 -0
- package/src/components/WebhooksView.tsx +69 -0
- package/src/components/WorkflowDetail.tsx +149 -0
- package/src/components/WorkflowRunAction.tsx +46 -0
- package/src/components/WorkflowRunDialog.tsx +187 -0
- package/src/components/WorkflowsView.tsx +168 -0
- package/src/components/charts/ChartCard.tsx +19 -0
- package/src/components/charts/RunCharts.tsx +31 -0
- package/src/components/charts/RunLatencyChart.tsx +71 -0
- package/src/components/charts/RunsOverTimeChart.tsx +60 -0
- package/src/components/filters/AppFilter.tsx +65 -0
- package/src/components/filters/FilterDropdown.tsx +33 -0
- package/src/components/filters/FilterDropdownButton.tsx +31 -0
- package/src/components/filters/FilterDropdownItem.tsx +37 -0
- package/src/components/filters/TimeRangeFilter.tsx +43 -0
- package/src/components/filters/TimeZoneFilter.tsx +40 -0
- package/src/components/filters/use-click-outside.ts +18 -0
- package/src/components/filters-pager.test.tsx +94 -0
- package/src/components/marks-geometry.ts +10 -0
- package/src/components/replay-dialog.test.tsx +18 -0
- package/src/components/run-components.test.tsx +126 -0
- package/src/components/run-controls.test.tsx +97 -0
- package/src/hooks/use-confirm-action.ts +19 -0
- package/src/hooks/use-copy.ts +22 -0
- package/src/hooks/use-keyset-pager.ts +34 -0
- package/src/hooks/use-mobile.ts +16 -0
- package/src/index.ts +165 -0
- package/src/lib/app-color.test.ts +32 -0
- package/src/lib/app-color.ts +8 -0
- package/src/lib/control-action.ts +36 -0
- package/src/lib/flow-control.ts +77 -0
- package/src/lib/format.test.ts +102 -0
- package/src/lib/format.ts +45 -0
- package/src/lib/json-highlight.test.ts +36 -0
- package/src/lib/json-highlight.ts +64 -0
- package/src/lib/run-filters.ts +8 -0
- package/src/lib/run-logs.test.ts +80 -0
- package/src/lib/run-logs.ts +34 -0
- package/src/lib/run-progress.test.ts +109 -0
- package/src/lib/run-progress.ts +44 -0
- package/src/lib/run-sort.test.ts +40 -0
- package/src/lib/run-sort.ts +19 -0
- package/src/lib/status-label.test.ts +35 -0
- package/src/lib/status-label.ts +13 -0
- package/src/lib/step-detail.test.ts +122 -0
- package/src/lib/step-detail.ts +35 -0
- package/src/lib/step-display.test.ts +19 -0
- package/src/lib/step-display.ts +13 -0
- package/src/lib/step-timeline.test.ts +89 -0
- package/src/lib/step-timeline.ts +50 -0
- package/src/lib/table.ts +2 -0
- package/src/lib/theme.ts +35 -0
- package/src/lib/time-range.ts +81 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/webhook-view.test.ts +176 -0
- package/src/lib/webhook-view.ts +113 -0
- package/src/lib/workflow-run.test.ts +55 -0
- package/src/lib/workflow-run.ts +45 -0
- package/src/shell/AppShell.tsx +34 -0
- package/src/shell/Sidebar.tsx +78 -0
- package/src/shell/Topbar.tsx +22 -0
- package/src/styles.css +2204 -0
- package/src/test-utils.tsx +130 -0
- package/src/ui/button.tsx +67 -0
- package/src/ui/chart.tsx +337 -0
- package/src/ui/dialog.tsx +145 -0
- package/src/ui/input.tsx +19 -0
- package/src/ui/resizable.tsx +40 -0
- package/src/ui/separator.tsx +28 -0
- package/src/ui/sheet.tsx +128 -0
- package/src/ui/sidebar.tsx +665 -0
- package/src/ui/skeleton.tsx +15 -0
- package/src/ui/sonner.tsx +35 -0
- package/src/ui/table.tsx +87 -0
- package/src/ui/tooltip.tsx +51 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
import {
|
|
5
|
+
DurablexProvider,
|
|
6
|
+
type BulkReplayResult,
|
|
7
|
+
type ControlAction,
|
|
8
|
+
type DurablexClient,
|
|
9
|
+
type Run,
|
|
10
|
+
type RunStats,
|
|
11
|
+
type Step,
|
|
12
|
+
type TimelineFrame,
|
|
13
|
+
type WorkflowDef,
|
|
14
|
+
} from "@durablex/react";
|
|
15
|
+
import { TooltipProvider } from "./ui/tooltip";
|
|
16
|
+
|
|
17
|
+
export function makeRun(overrides: Partial<Run> = {}): Run {
|
|
18
|
+
return {
|
|
19
|
+
id: "run_1",
|
|
20
|
+
workflowName: "sendEmail",
|
|
21
|
+
app: "default",
|
|
22
|
+
status: "succeeded",
|
|
23
|
+
errorCount: 0,
|
|
24
|
+
attempt: 1,
|
|
25
|
+
triggerKind: "event",
|
|
26
|
+
stepCount: 0,
|
|
27
|
+
currentStepIndex: -1,
|
|
28
|
+
startedAt: "2026-07-01T00:00:00.000Z",
|
|
29
|
+
...overrides,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function makeStep(overrides: Partial<Step> = {}): Step {
|
|
34
|
+
return {
|
|
35
|
+
name: "validate",
|
|
36
|
+
index: 0,
|
|
37
|
+
attempt: 1,
|
|
38
|
+
status: "succeeded",
|
|
39
|
+
...overrides,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function makeStats(overrides: Partial<RunStats> = {}): RunStats {
|
|
44
|
+
return {
|
|
45
|
+
total: 0,
|
|
46
|
+
active: 0,
|
|
47
|
+
queued: 0,
|
|
48
|
+
running: 0,
|
|
49
|
+
succeeded: 0,
|
|
50
|
+
failed: 0,
|
|
51
|
+
successRate: 0,
|
|
52
|
+
...overrides,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function* framesOf(frames: TimelineFrame[]): AsyncGenerator<TimelineFrame> {
|
|
57
|
+
for (const f of frames) yield f;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function makeControlAction(overrides: Partial<ControlAction> = {}): ControlAction {
|
|
61
|
+
return {
|
|
62
|
+
id: "act_1",
|
|
63
|
+
action: "replay",
|
|
64
|
+
createdAt: "2026-07-01T00:00:00.000Z",
|
|
65
|
+
...overrides,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const DEFAULT_BULK: BulkReplayResult = {
|
|
70
|
+
matched: 0,
|
|
71
|
+
replayed: 0,
|
|
72
|
+
skipped: 0,
|
|
73
|
+
failed: 0,
|
|
74
|
+
capped: false,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export interface FakeClientOptions {
|
|
78
|
+
run?: Run;
|
|
79
|
+
getError?: Error;
|
|
80
|
+
steps?: Step[];
|
|
81
|
+
stats?: RunStats;
|
|
82
|
+
workflows?: WorkflowDef[];
|
|
83
|
+
frames?: TimelineFrame[];
|
|
84
|
+
controlActions?: ControlAction[];
|
|
85
|
+
cancel?: (id: string) => Promise<Run>;
|
|
86
|
+
pause?: (id: string) => Promise<Run>;
|
|
87
|
+
resume?: (id: string) => Promise<Run>;
|
|
88
|
+
replay?: (id: string, input?: unknown) => Promise<Run>;
|
|
89
|
+
retryFromStep?: (id: string, step: string) => Promise<Run>;
|
|
90
|
+
bulkReplay?: (filter: unknown) => Promise<BulkReplayResult>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// A DurablexClient stub carrying only the methods the run views touch. Control
|
|
94
|
+
// methods default to resolving a run; pass spies to assert a mutation fired. Cast
|
|
95
|
+
// through unknown since tests never exercise the rest of the surface.
|
|
96
|
+
export function fakeClient(opts: FakeClientOptions = {}): DurablexClient {
|
|
97
|
+
const run = async () => opts.run ?? makeRun();
|
|
98
|
+
return {
|
|
99
|
+
runs: {
|
|
100
|
+
get: async () => {
|
|
101
|
+
if (opts.getError) throw opts.getError;
|
|
102
|
+
return opts.run ?? makeRun();
|
|
103
|
+
},
|
|
104
|
+
steps: async () => opts.steps ?? [],
|
|
105
|
+
stats: async () => opts.stats ?? makeStats(),
|
|
106
|
+
list: async () => ({ runs: [], nextCursor: null }),
|
|
107
|
+
watch: () => framesOf(opts.frames ?? []),
|
|
108
|
+
watchAll: () => framesOf([]),
|
|
109
|
+
cancel: opts.cancel ?? run,
|
|
110
|
+
pause: opts.pause ?? run,
|
|
111
|
+
resume: opts.resume ?? run,
|
|
112
|
+
replay: opts.replay ?? run,
|
|
113
|
+
retryFromStep: opts.retryFromStep ?? run,
|
|
114
|
+
bulkReplay: opts.bulkReplay ?? (async () => DEFAULT_BULK),
|
|
115
|
+
controlActions: async () => opts.controlActions ?? [],
|
|
116
|
+
},
|
|
117
|
+
workflows: { list: async () => opts.workflows ?? [] },
|
|
118
|
+
} as unknown as DurablexClient;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function renderWithClient(ui: ReactElement, client: DurablexClient) {
|
|
122
|
+
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
123
|
+
return render(
|
|
124
|
+
<QueryClientProvider client={qc}>
|
|
125
|
+
<DurablexProvider client={client}>
|
|
126
|
+
<TooltipProvider>{ui}</TooltipProvider>
|
|
127
|
+
</DurablexProvider>
|
|
128
|
+
</QueryClientProvider>,
|
|
129
|
+
);
|
|
130
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
3
|
+
import { Slot } from "radix-ui";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../lib/utils";
|
|
6
|
+
|
|
7
|
+
const buttonVariants = cva(
|
|
8
|
+
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
9
|
+
{
|
|
10
|
+
variants: {
|
|
11
|
+
variant: {
|
|
12
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
13
|
+
outline:
|
|
14
|
+
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
15
|
+
secondary:
|
|
16
|
+
"bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
17
|
+
ghost:
|
|
18
|
+
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
19
|
+
destructive:
|
|
20
|
+
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
21
|
+
link: "text-primary underline-offset-4 hover:underline",
|
|
22
|
+
},
|
|
23
|
+
size: {
|
|
24
|
+
default:
|
|
25
|
+
"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
26
|
+
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
27
|
+
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
|
28
|
+
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
29
|
+
icon: "size-8",
|
|
30
|
+
"icon-xs":
|
|
31
|
+
"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
|
32
|
+
"icon-sm":
|
|
33
|
+
"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
|
|
34
|
+
"icon-lg": "size-9",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
defaultVariants: {
|
|
38
|
+
variant: "default",
|
|
39
|
+
size: "default",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
function Button({
|
|
45
|
+
className,
|
|
46
|
+
variant = "default",
|
|
47
|
+
size = "default",
|
|
48
|
+
asChild = false,
|
|
49
|
+
...props
|
|
50
|
+
}: React.ComponentProps<"button"> &
|
|
51
|
+
VariantProps<typeof buttonVariants> & {
|
|
52
|
+
asChild?: boolean;
|
|
53
|
+
}) {
|
|
54
|
+
const Comp = asChild ? Slot.Root : "button";
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Comp
|
|
58
|
+
data-slot="button"
|
|
59
|
+
data-variant={variant}
|
|
60
|
+
data-size={size}
|
|
61
|
+
className={cn(buttonVariants({ variant, size, className }))}
|
|
62
|
+
{...props}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { Button, buttonVariants };
|
package/src/ui/chart.tsx
ADDED
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as RechartsPrimitive from "recharts";
|
|
3
|
+
import type { TooltipValueType } from "recharts";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../lib/utils";
|
|
6
|
+
|
|
7
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
8
|
+
const THEMES = { light: "", dark: ".dark" } as const;
|
|
9
|
+
|
|
10
|
+
const INITIAL_DIMENSION = { width: 320, height: 200 } as const;
|
|
11
|
+
type TooltipNameType = number | string;
|
|
12
|
+
|
|
13
|
+
export type ChartConfig = Record<
|
|
14
|
+
string,
|
|
15
|
+
{
|
|
16
|
+
label?: React.ReactNode;
|
|
17
|
+
icon?: React.ComponentType;
|
|
18
|
+
} & (
|
|
19
|
+
| { color?: string; theme?: never }
|
|
20
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
21
|
+
)
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
type ChartContextProps = {
|
|
25
|
+
config: ChartConfig;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null);
|
|
29
|
+
|
|
30
|
+
function useChart() {
|
|
31
|
+
const context = React.useContext(ChartContext);
|
|
32
|
+
|
|
33
|
+
if (!context) {
|
|
34
|
+
throw new Error("useChart must be used within a <ChartContainer />");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return context;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function ChartContainer({
|
|
41
|
+
id,
|
|
42
|
+
className,
|
|
43
|
+
children,
|
|
44
|
+
config,
|
|
45
|
+
initialDimension = INITIAL_DIMENSION,
|
|
46
|
+
...props
|
|
47
|
+
}: React.ComponentProps<"div"> & {
|
|
48
|
+
config: ChartConfig;
|
|
49
|
+
children: React.ComponentProps<typeof RechartsPrimitive.ResponsiveContainer>["children"];
|
|
50
|
+
initialDimension?: {
|
|
51
|
+
width: number;
|
|
52
|
+
height: number;
|
|
53
|
+
};
|
|
54
|
+
}) {
|
|
55
|
+
const uniqueId = React.useId();
|
|
56
|
+
const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<ChartContext.Provider value={{ config }}>
|
|
60
|
+
<div
|
|
61
|
+
data-slot="chart"
|
|
62
|
+
data-chart={chartId}
|
|
63
|
+
className={cn(
|
|
64
|
+
"flex aspect-video justify-center text-xs [&_.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",
|
|
65
|
+
className,
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
>
|
|
69
|
+
<ChartStyle id={chartId} config={config} />
|
|
70
|
+
<RechartsPrimitive.ResponsiveContainer initialDimension={initialDimension}>
|
|
71
|
+
{children}
|
|
72
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
73
|
+
</div>
|
|
74
|
+
</ChartContext.Provider>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
79
|
+
const colorConfig = Object.entries(config).filter(([, config]) => config.theme ?? config.color);
|
|
80
|
+
|
|
81
|
+
if (!colorConfig.length) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<style
|
|
87
|
+
dangerouslySetInnerHTML={{
|
|
88
|
+
__html: Object.entries(THEMES)
|
|
89
|
+
.map(
|
|
90
|
+
([theme, prefix]) => `
|
|
91
|
+
${prefix} [data-chart=${id}] {
|
|
92
|
+
${colorConfig
|
|
93
|
+
.map(([key, itemConfig]) => {
|
|
94
|
+
const color = itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ?? itemConfig.color;
|
|
95
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
96
|
+
})
|
|
97
|
+
.join("\n")}
|
|
98
|
+
}
|
|
99
|
+
`,
|
|
100
|
+
)
|
|
101
|
+
.join("\n"),
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
108
|
+
|
|
109
|
+
function ChartTooltipContent({
|
|
110
|
+
active,
|
|
111
|
+
payload,
|
|
112
|
+
className,
|
|
113
|
+
indicator = "dot",
|
|
114
|
+
hideLabel = false,
|
|
115
|
+
hideIndicator = false,
|
|
116
|
+
label,
|
|
117
|
+
labelFormatter,
|
|
118
|
+
labelClassName,
|
|
119
|
+
formatter,
|
|
120
|
+
color,
|
|
121
|
+
nameKey,
|
|
122
|
+
labelKey,
|
|
123
|
+
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
124
|
+
React.ComponentProps<"div"> & {
|
|
125
|
+
hideLabel?: boolean;
|
|
126
|
+
hideIndicator?: boolean;
|
|
127
|
+
indicator?: "line" | "dot" | "dashed";
|
|
128
|
+
nameKey?: string;
|
|
129
|
+
labelKey?: string;
|
|
130
|
+
} & Omit<
|
|
131
|
+
RechartsPrimitive.DefaultTooltipContentProps<TooltipValueType, TooltipNameType>,
|
|
132
|
+
"accessibilityLayer"
|
|
133
|
+
>) {
|
|
134
|
+
const { config } = useChart();
|
|
135
|
+
|
|
136
|
+
const tooltipLabel = React.useMemo(() => {
|
|
137
|
+
if (hideLabel || !payload?.length) {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const [item] = payload;
|
|
142
|
+
const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
|
|
143
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
144
|
+
const value =
|
|
145
|
+
!labelKey && typeof label === "string" ? (config[label]?.label ?? label) : itemConfig?.label;
|
|
146
|
+
|
|
147
|
+
if (labelFormatter) {
|
|
148
|
+
return (
|
|
149
|
+
<div className={cn("font-medium", labelClassName)}>{labelFormatter(value, payload)}</div>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!value) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
|
158
|
+
}, [label, labelFormatter, payload, hideLabel, labelClassName, config, labelKey]);
|
|
159
|
+
|
|
160
|
+
if (!active || !payload?.length) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<div
|
|
168
|
+
className={cn(
|
|
169
|
+
"grid min-w-32 items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",
|
|
170
|
+
className,
|
|
171
|
+
)}
|
|
172
|
+
>
|
|
173
|
+
{!nestLabel ? tooltipLabel : null}
|
|
174
|
+
<div className="grid gap-1.5">
|
|
175
|
+
{payload
|
|
176
|
+
.filter((item) => item.type !== "none")
|
|
177
|
+
.map((item, index) => {
|
|
178
|
+
const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`;
|
|
179
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
180
|
+
const indicatorColor = color ?? item.payload?.fill ?? item.color;
|
|
181
|
+
|
|
182
|
+
return (
|
|
183
|
+
<div
|
|
184
|
+
key={index}
|
|
185
|
+
className={cn(
|
|
186
|
+
"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
|
|
187
|
+
indicator === "dot" && "items-center",
|
|
188
|
+
)}
|
|
189
|
+
>
|
|
190
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
191
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
192
|
+
) : (
|
|
193
|
+
<>
|
|
194
|
+
{itemConfig?.icon ? (
|
|
195
|
+
<itemConfig.icon />
|
|
196
|
+
) : (
|
|
197
|
+
!hideIndicator && (
|
|
198
|
+
<div
|
|
199
|
+
className={cn(
|
|
200
|
+
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
201
|
+
{
|
|
202
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
203
|
+
"w-1": indicator === "line",
|
|
204
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
205
|
+
indicator === "dashed",
|
|
206
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
207
|
+
},
|
|
208
|
+
)}
|
|
209
|
+
style={
|
|
210
|
+
{
|
|
211
|
+
"--color-bg": indicatorColor,
|
|
212
|
+
"--color-border": indicatorColor,
|
|
213
|
+
} as React.CSSProperties
|
|
214
|
+
}
|
|
215
|
+
/>
|
|
216
|
+
)
|
|
217
|
+
)}
|
|
218
|
+
<div
|
|
219
|
+
className={cn(
|
|
220
|
+
"flex flex-1 justify-between leading-none",
|
|
221
|
+
nestLabel ? "items-end" : "items-center",
|
|
222
|
+
)}
|
|
223
|
+
>
|
|
224
|
+
<div className="grid gap-1.5">
|
|
225
|
+
{nestLabel ? tooltipLabel : null}
|
|
226
|
+
<span className="text-muted-foreground">
|
|
227
|
+
{itemConfig?.label ?? item.name}
|
|
228
|
+
</span>
|
|
229
|
+
</div>
|
|
230
|
+
{item.value != null && (
|
|
231
|
+
<span className="font-mono font-medium text-foreground tabular-nums">
|
|
232
|
+
{typeof item.value === "number"
|
|
233
|
+
? item.value.toLocaleString()
|
|
234
|
+
: String(item.value)}
|
|
235
|
+
</span>
|
|
236
|
+
)}
|
|
237
|
+
</div>
|
|
238
|
+
</>
|
|
239
|
+
)}
|
|
240
|
+
</div>
|
|
241
|
+
);
|
|
242
|
+
})}
|
|
243
|
+
</div>
|
|
244
|
+
</div>
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const ChartLegend = RechartsPrimitive.Legend;
|
|
249
|
+
|
|
250
|
+
function ChartLegendContent({
|
|
251
|
+
className,
|
|
252
|
+
hideIcon = false,
|
|
253
|
+
payload,
|
|
254
|
+
verticalAlign = "bottom",
|
|
255
|
+
nameKey,
|
|
256
|
+
}: React.ComponentProps<"div"> & {
|
|
257
|
+
hideIcon?: boolean;
|
|
258
|
+
nameKey?: string;
|
|
259
|
+
} & RechartsPrimitive.DefaultLegendContentProps) {
|
|
260
|
+
const { config } = useChart();
|
|
261
|
+
|
|
262
|
+
if (!payload?.length) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<div
|
|
268
|
+
className={cn(
|
|
269
|
+
"flex flex-wrap items-center justify-center gap-x-2.5 gap-y-1",
|
|
270
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
271
|
+
className,
|
|
272
|
+
)}
|
|
273
|
+
>
|
|
274
|
+
{payload
|
|
275
|
+
.filter((item) => item.type !== "none")
|
|
276
|
+
.map((item, index) => {
|
|
277
|
+
const key = `${nameKey ?? item.dataKey ?? "value"}`;
|
|
278
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
279
|
+
|
|
280
|
+
return (
|
|
281
|
+
<div
|
|
282
|
+
key={index}
|
|
283
|
+
className={cn(
|
|
284
|
+
"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",
|
|
285
|
+
)}
|
|
286
|
+
>
|
|
287
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
288
|
+
<itemConfig.icon />
|
|
289
|
+
) : (
|
|
290
|
+
<div
|
|
291
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
292
|
+
style={{
|
|
293
|
+
backgroundColor: item.color,
|
|
294
|
+
}}
|
|
295
|
+
/>
|
|
296
|
+
)}
|
|
297
|
+
{itemConfig?.label}
|
|
298
|
+
</div>
|
|
299
|
+
);
|
|
300
|
+
})}
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: string) {
|
|
306
|
+
if (typeof payload !== "object" || payload === null) {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const payloadPayload =
|
|
311
|
+
"payload" in payload && typeof payload.payload === "object" && payload.payload !== null
|
|
312
|
+
? payload.payload
|
|
313
|
+
: undefined;
|
|
314
|
+
|
|
315
|
+
let configLabelKey: string = key;
|
|
316
|
+
|
|
317
|
+
if (key in payload && typeof payload[key as keyof typeof payload] === "string") {
|
|
318
|
+
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
319
|
+
} else if (
|
|
320
|
+
payloadPayload &&
|
|
321
|
+
key in payloadPayload &&
|
|
322
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
323
|
+
) {
|
|
324
|
+
configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return configLabelKey in config ? config[configLabelKey] : config[key];
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export {
|
|
331
|
+
ChartContainer,
|
|
332
|
+
ChartTooltip,
|
|
333
|
+
ChartTooltipContent,
|
|
334
|
+
ChartLegend,
|
|
335
|
+
ChartLegendContent,
|
|
336
|
+
ChartStyle,
|
|
337
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Dialog as DialogPrimitive } from "radix-ui";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import { Button } from "./button";
|
|
8
|
+
import { XIcon } from "lucide-react";
|
|
9
|
+
|
|
10
|
+
function Dialog({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
|
11
|
+
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function DialogTrigger({ ...props }: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
|
15
|
+
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function DialogPortal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
|
19
|
+
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function DialogClose({ ...props }: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
|
23
|
+
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function DialogOverlay({
|
|
27
|
+
className,
|
|
28
|
+
...props
|
|
29
|
+
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
|
30
|
+
return (
|
|
31
|
+
<DialogPrimitive.Overlay
|
|
32
|
+
data-slot="dialog-overlay"
|
|
33
|
+
className={cn(
|
|
34
|
+
"fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
|
|
35
|
+
className,
|
|
36
|
+
)}
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function DialogContent({
|
|
43
|
+
className,
|
|
44
|
+
children,
|
|
45
|
+
showCloseButton = true,
|
|
46
|
+
...props
|
|
47
|
+
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
|
48
|
+
showCloseButton?: boolean;
|
|
49
|
+
}) {
|
|
50
|
+
return (
|
|
51
|
+
<DialogPortal>
|
|
52
|
+
<DialogOverlay />
|
|
53
|
+
<DialogPrimitive.Content
|
|
54
|
+
data-slot="dialog-content"
|
|
55
|
+
className={cn(
|
|
56
|
+
"fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
|
57
|
+
className,
|
|
58
|
+
)}
|
|
59
|
+
{...props}
|
|
60
|
+
>
|
|
61
|
+
{children}
|
|
62
|
+
{showCloseButton && (
|
|
63
|
+
<DialogPrimitive.Close data-slot="dialog-close" asChild>
|
|
64
|
+
<Button variant="ghost" className="absolute top-2 right-2" size="icon-sm">
|
|
65
|
+
<XIcon />
|
|
66
|
+
<span className="sr-only">Close</span>
|
|
67
|
+
</Button>
|
|
68
|
+
</DialogPrimitive.Close>
|
|
69
|
+
)}
|
|
70
|
+
</DialogPrimitive.Content>
|
|
71
|
+
</DialogPortal>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
76
|
+
return (
|
|
77
|
+
<div data-slot="dialog-header" className={cn("flex flex-col gap-2", className)} {...props} />
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function DialogFooter({
|
|
82
|
+
className,
|
|
83
|
+
showCloseButton = false,
|
|
84
|
+
children,
|
|
85
|
+
...props
|
|
86
|
+
}: React.ComponentProps<"div"> & {
|
|
87
|
+
showCloseButton?: boolean;
|
|
88
|
+
}) {
|
|
89
|
+
return (
|
|
90
|
+
<div
|
|
91
|
+
data-slot="dialog-footer"
|
|
92
|
+
className={cn(
|
|
93
|
+
"-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end",
|
|
94
|
+
className,
|
|
95
|
+
)}
|
|
96
|
+
{...props}
|
|
97
|
+
>
|
|
98
|
+
{children}
|
|
99
|
+
{showCloseButton && (
|
|
100
|
+
<DialogPrimitive.Close asChild>
|
|
101
|
+
<Button variant="outline">Close</Button>
|
|
102
|
+
</DialogPrimitive.Close>
|
|
103
|
+
)}
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
|
109
|
+
return (
|
|
110
|
+
<DialogPrimitive.Title
|
|
111
|
+
data-slot="dialog-title"
|
|
112
|
+
className={cn("font-heading text-base leading-none font-medium", className)}
|
|
113
|
+
{...props}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function DialogDescription({
|
|
119
|
+
className,
|
|
120
|
+
...props
|
|
121
|
+
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
|
122
|
+
return (
|
|
123
|
+
<DialogPrimitive.Description
|
|
124
|
+
data-slot="dialog-description"
|
|
125
|
+
className={cn(
|
|
126
|
+
"text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
|
|
127
|
+
className,
|
|
128
|
+
)}
|
|
129
|
+
{...props}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
Dialog,
|
|
136
|
+
DialogClose,
|
|
137
|
+
DialogContent,
|
|
138
|
+
DialogDescription,
|
|
139
|
+
DialogFooter,
|
|
140
|
+
DialogHeader,
|
|
141
|
+
DialogOverlay,
|
|
142
|
+
DialogPortal,
|
|
143
|
+
DialogTitle,
|
|
144
|
+
DialogTrigger,
|
|
145
|
+
};
|
package/src/ui/input.tsx
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "../lib/utils";
|
|
4
|
+
|
|
5
|
+
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
|
6
|
+
return (
|
|
7
|
+
<input
|
|
8
|
+
type={type}
|
|
9
|
+
data-slot="input"
|
|
10
|
+
className={cn(
|
|
11
|
+
"h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
12
|
+
className,
|
|
13
|
+
)}
|
|
14
|
+
{...props}
|
|
15
|
+
/>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { Input };
|