@xemahq/ui-kernel 0.11.0 → 0.11.2
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/dist/ui/chrome/page-shell.d.ts +1 -1
- package/dist/ui/chrome/page-shell.d.ts.map +1 -1
- package/dist/ui/chrome/page-shell.js +9 -4
- package/dist/ui/chrome/page-shell.js.map +1 -1
- package/package.json +6 -4
- package/src/index.ts +0 -17
- package/src/lib/biome-host/agent-validation.ts +0 -239
- package/src/lib/biome-host/biome-builders.ts +0 -112
- package/src/lib/biome-host/biome-mode.ts +0 -6
- package/src/lib/biome-host/biome-navigation.ts +0 -37
- package/src/lib/biome-host/biome-registry.ts +0 -299
- package/src/lib/biome-host/biome-scope-hooks.ts +0 -41
- package/src/lib/biome-host/biome-scope.tsx +0 -52
- package/src/lib/biome-host/biome-scoped-query.ts +0 -134
- package/src/lib/biome-host/create-biome-orval-config.ts +0 -82
- package/src/lib/biome-host/define-web-biome.spec.ts +0 -221
- package/src/lib/biome-host/define-web-biome.ts +0 -222
- package/src/lib/biome-host/errors.ts +0 -220
- package/src/lib/biome-host/frontend-biome.ts +0 -256
- package/src/lib/biome-host/host-bridge.ts +0 -281
- package/src/lib/biome-host/host-sources.ts +0 -54
- package/src/lib/biome-host/i18n-hooks.ts +0 -51
- package/src/lib/biome-host/i18n-port.test.ts +0 -50
- package/src/lib/biome-host/i18n-port.ts +0 -96
- package/src/lib/biome-host/index.ts +0 -35
- package/src/lib/biome-host/realtime-hooks.ts +0 -75
- package/src/lib/biome-host/realtime-port.ts +0 -115
- package/src/lib/biome-host/session-contributions.ts +0 -296
- package/src/lib/biome-host/use-mutation-with-error-toast.ts +0 -90
- package/src/lib/biome-host/use-page-state.ts +0 -248
- package/src/lib/capabilities/capability-context.ts +0 -25
- package/src/lib/capabilities/capability-provider.tsx +0 -73
- package/src/lib/capabilities/index.ts +0 -17
- package/src/lib/capabilities/types.ts +0 -69
- package/src/lib/capabilities/use-capability.ts +0 -79
- package/src/lib/contribution-registry/contribution-registry.spec.ts +0 -141
- package/src/lib/contribution-registry/contribution-registry.ts +0 -204
- package/src/lib/contribution-registry/index.ts +0 -9
- package/src/lib/contribution-registry/renderable-registry.ts +0 -142
- package/src/lib/system-bus/capability-invoke.ts +0 -92
- package/src/lib/system-bus/deeplink.ts +0 -210
- package/src/lib/system-bus/enums.ts +0 -86
- package/src/lib/system-bus/host-ports.ts +0 -93
- package/src/lib/system-bus/index.ts +0 -16
- package/src/lib/system-bus/intent-registry.ts +0 -109
- package/src/lib/system-bus/intents.ts +0 -113
- package/src/lib/system-bus/palette.ts +0 -78
- package/src/lib/system-bus/system-bus-builder.ts +0 -159
- package/src/lib/system-bus/system-bus.ts +0 -37
- package/src/lib/system-bus/windows.ts +0 -51
- package/src/offline/id.ts +0 -16
- package/src/offline/index.ts +0 -54
- package/src/offline/mutation.ts +0 -75
- package/src/offline/offline-status-badge.tsx +0 -51
- package/src/offline/online-controller.ts +0 -105
- package/src/offline/outbox.test.ts +0 -172
- package/src/offline/outbox.ts +0 -348
- package/src/offline/react-hooks.ts +0 -40
- package/src/offline/react.tsx +0 -32
- package/src/offline/storage.ts +0 -112
- package/src/offline/types.ts +0 -77
- package/src/org-db/components/DbResultTable.tsx +0 -176
- package/src/org-db/index.ts +0 -1
- package/src/pdf/index.ts +0 -11
- package/src/registry/index.ts +0 -9
- package/src/registry/lib/agent-validation-host.ts +0 -36
- package/src/registry/lib/biome-slot.tsx +0 -50
- package/src/registry/lib/biomes-enabled-context.ts +0 -20
- package/src/registry/lib/extension-points.ts +0 -134
- package/src/registry/lib/primitives/SessionEventCard.tsx +0 -164
- package/src/registry/lib/primitives/SessionEventTimeline.tsx +0 -95
- package/src/registry/lib/primitives/SessionMutationBar.tsx +0 -76
- package/src/registry/lib/primitives/SessionTabbedDrawer.tsx +0 -165
- package/src/registry/lib/primitives/index.ts +0 -18
- package/src/registry/lib/session-context-builder.ts +0 -84
- package/src/registry/lib/session-context-provider.tsx +0 -33
- package/src/registry/lib/session-context.ts +0 -21
- package/src/registry/lib/session-selectors.ts +0 -272
- package/src/session/comments/CommentRail.tsx +0 -164
- package/src/session/index.ts +0 -3
- package/src/session/lib/cn.ts +0 -11
- package/src/session/shell/SessionWorkspaceShell.tsx +0 -147
- package/src/session-kit/approvals/ApprovalButton.tsx +0 -89
- package/src/session-kit/approvals/ApprovalCard.tsx +0 -341
- package/src/session-kit/approvals/ApprovalsCenter.tsx +0 -336
- package/src/session-kit/approvals/CapabilityApprovalStickyBar.tsx +0 -118
- package/src/session-kit/approvals/Obligation.tsx +0 -111
- package/src/session-kit/approvals/ScopedBody.tsx +0 -392
- package/src/session-kit/approvals/approval-icons.ts +0 -31
- package/src/session-kit/approvals/approval-model.ts +0 -204
- package/src/session-kit/approvals/index.ts +0 -22
- package/src/session-kit/approvals/obligation-display.ts +0 -100
- package/src/session-kit/approvals/risk-accent.ts +0 -47
- package/src/session-kit/approvals/scope-icons.ts +0 -19
- package/src/session-kit/combobox/Combobox.tsx +0 -358
- package/src/session-kit/combobox/use-click-outside.ts +0 -21
- package/src/session-kit/display/ContextHeader.tsx +0 -148
- package/src/session-kit/display/FileDiffCard.tsx +0 -140
- package/src/session-kit/display/MD.tsx +0 -162
- package/src/session-kit/display/MessageTurn.tsx +0 -157
- package/src/session-kit/display/ThinkingPanel.tsx +0 -81
- package/src/session-kit/display/TodoChecklist.tsx +0 -120
- package/src/session-kit/display/TokenMeter.tsx +0 -89
- package/src/session-kit/display/ToolStrip.tsx +0 -278
- package/src/session-kit/display/TypingDots.tsx +0 -24
- package/src/session-kit/index.ts +0 -44
- package/src/session-kit/lib/enums.ts +0 -66
- package/src/session-kit/lib/portal-accent.ts +0 -30
- package/src/session-kit/lib/status-dot.ts +0 -68
- package/src/session-kit/primitives/Avatar.tsx +0 -44
- package/src/session-kit/primitives/PortalGlyph.tsx +0 -51
- package/src/session-kit/primitives/RiskPill.tsx +0 -95
- package/src/session-kit/primitives/ScopeDot.tsx +0 -47
- package/src/session-kit/primitives/Segmented.tsx +0 -71
- package/src/ui/branding/app-branding-context.ts +0 -20
- package/src/ui/branding/app-branding-provider.tsx +0 -123
- package/src/ui/branding/sanitize.ts +0 -89
- package/src/ui/breakpoints.ts +0 -14
- package/src/ui/capture/document-preview.tsx +0 -166
- package/src/ui/capture/field-spec-to-zod.test.ts +0 -81
- package/src/ui/capture/field-spec-to-zod.ts +0 -174
- package/src/ui/capture/field-spec-validate.ts +0 -236
- package/src/ui/capture/field-spec.test.ts +0 -49
- package/src/ui/capture/field-spec.ts +0 -274
- package/src/ui/capture/index.ts +0 -51
- package/src/ui/capture/schema-field-input.tsx +0 -620
- package/src/ui/capture/schema-form.tsx +0 -149
- package/src/ui/capture/submit-values.test.ts +0 -70
- package/src/ui/capture/submit-values.ts +0 -63
- package/src/ui/capture/use-prefill.ts +0 -186
- package/src/ui/capture/use-schema-validation.ts +0 -145
- package/src/ui/capture/use-wizard.ts +0 -180
- package/src/ui/capture/value-format.ts +0 -32
- package/src/ui/capture/wizard.tsx +0 -105
- package/src/ui/charts/bar-chart.tsx +0 -139
- package/src/ui/charts/chart-frame.tsx +0 -125
- package/src/ui/charts/chart-types.ts +0 -52
- package/src/ui/charts/chart-utils.ts +0 -190
- package/src/ui/charts/charts.test.tsx +0 -204
- package/src/ui/charts/donut-chart.tsx +0 -129
- package/src/ui/charts/index.ts +0 -27
- package/src/ui/charts/line-chart.tsx +0 -202
- package/src/ui/charts/sparkline.tsx +0 -109
- package/src/ui/chrome/AsyncBoundary.tsx +0 -74
- package/src/ui/chrome/EmptyState.tsx +0 -257
- package/src/ui/chrome/ErrorCard.tsx +0 -63
- package/src/ui/chrome/LoadingState.tsx +0 -61
- package/src/ui/chrome/PageHeader.tsx +0 -137
- package/src/ui/chrome/RecordCardList.tsx +0 -98
- package/src/ui/chrome/StateCard.tsx +0 -150
- package/src/ui/chrome/confirm-delete-dialog.tsx +0 -59
- package/src/ui/chrome/page-shell.tsx +0 -189
- package/src/ui/chrome/scope-badge.tsx +0 -40
- package/src/ui/chrome/status-badge.tsx +0 -79
- package/src/ui/cn.ts +0 -32
- package/src/ui/design-tokens.ts +0 -372
- package/src/ui/hooks/use-debounced-value.ts +0 -16
- package/src/ui/hooks/use-is-mobile.ts +0 -28
- package/src/ui/index.ts +0 -110
- package/src/ui/pdf/pdf-preview.tsx +0 -122
- package/src/ui/primitives/alert-dialog.tsx +0 -104
- package/src/ui/primitives/async-combobox.tsx +0 -182
- package/src/ui/primitives/badge-variants.ts +0 -21
- package/src/ui/primitives/badge.tsx +0 -25
- package/src/ui/primitives/button-variants.ts +0 -31
- package/src/ui/primitives/button.tsx +0 -29
- package/src/ui/primitives/card.tsx +0 -43
- package/src/ui/primitives/checkbox.tsx +0 -26
- package/src/ui/primitives/collapsible.tsx +0 -9
- package/src/ui/primitives/dialog.tsx +0 -103
- package/src/ui/primitives/dropdown-menu.tsx +0 -179
- package/src/ui/primitives/form-stepper.tsx +0 -94
- package/src/ui/primitives/form-stepper.types.ts +0 -15
- package/src/ui/primitives/input.tsx +0 -22
- package/src/ui/primitives/label.tsx +0 -17
- package/src/ui/primitives/overflow-tabs.tsx +0 -331
- package/src/ui/primitives/popover.tsx +0 -33
- package/src/ui/primitives/preview-device-frame.tsx +0 -213
- package/src/ui/primitives/radio-group.tsx +0 -36
- package/src/ui/primitives/resizable.tsx +0 -67
- package/src/ui/primitives/scroll-area.tsx +0 -38
- package/src/ui/primitives/select.tsx +0 -143
- package/src/ui/primitives/separator.tsx +0 -20
- package/src/ui/primitives/sheet.tsx +0 -107
- package/src/ui/primitives/skeleton.tsx +0 -99
- package/src/ui/primitives/switch.tsx +0 -27
- package/src/ui/primitives/table.tsx +0 -72
- package/src/ui/primitives/tabs.tsx +0 -53
- package/src/ui/primitives/tag-multi-select.tsx +0 -261
- package/src/ui/primitives/textarea.tsx +0 -21
- package/src/ui/primitives/tooltip.tsx +0 -30
- package/src/ui/primitives/url-preview-chrome.tsx +0 -103
- package/src/vista/GenericCatalogueSurface.tsx +0 -179
- package/src/vista/SurfaceFallbackCard.tsx +0 -109
- package/src/vista/VistaPanel.tsx +0 -163
- package/src/vista/form-payload.spec.ts +0 -139
- package/src/vista/html/CustomUiFrame.spec.tsx +0 -127
- package/src/vista/html/CustomUiFrame.tsx +0 -206
- package/src/vista/html/custom-ui-frame-bridge.spec.ts +0 -191
- package/src/vista/html/custom-ui-frame-bridge.ts +0 -98
- package/src/vista/html/custom-ui-frame-contract.ts +0 -88
- package/src/vista/html/custom-ui-intents.spec.ts +0 -135
- package/src/vista/html/custom-ui-intents.ts +0 -155
- package/src/vista/html/custom-ui-srcdoc.spec.ts +0 -151
- package/src/vista/html/custom-ui-srcdoc.ts +0 -193
- package/src/vista/html/index.ts +0 -13
- package/src/vista/index.ts +0 -52
- package/src/vista/surface-catalogue.spec.ts +0 -140
- package/src/vista/surface-catalogue.ts +0 -90
- package/src/vista/surface-icons.ts +0 -57
- package/src/vista/surface-registry.ts +0 -56
- package/src/vista/surfaces/ChartSurface.tsx +0 -34
- package/src/vista/surfaces/FilesSurface.tsx +0 -202
- package/src/vista/surfaces/FormSurface.tsx +0 -380
- package/src/vista/surfaces/HtmlSurface.tsx +0 -43
- package/src/vista/surfaces/TableSurface.tsx +0 -100
- package/src/vista/surfaces/UrlSurface.tsx +0 -40
- package/src/vista/surfaces/blob-surfaces.tsx +0 -139
- package/src/vista/surfaces/elicitation-transport.spec.ts +0 -369
- package/src/vista/surfaces/elicitation-transport.ts +0 -367
- package/src/vista/surfaces/file-surface-utils.ts +0 -69
- package/src/vista/surfaces/index.ts +0 -24
- package/src/vista/surfaces/register-surfaces.tsx +0 -139
- package/src/vista/surfaces/text-surfaces.tsx +0 -132
- package/src/vista/use-vista-tabs.ts +0 -196
- package/src/vista/vista-code-renderer-context.ts +0 -16
- package/src/vista/vista-code-renderer.tsx +0 -35
- package/src/vista/vista-file-context.ts +0 -14
- package/src/vista/vista-file-source.tsx +0 -141
- package/src/vista/vista-form-context.ts +0 -20
- package/src/vista/vista-form-host.tsx +0 -48
- package/src/vista/vista-model.ts +0 -137
- package/src/vista/vista-open-context.tsx +0 -27
- package/src/vista/vista-open-state.ts +0 -11
- package/src/vista/vista-payloads.ts +0 -635
- package/src/vista/vista-tabs-manifest.ts +0 -138
- package/src/vista/vista-tools.ts +0 -232
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
// LineChart — one or more line series over shared x-labels, pure SVG (Wave 9.2)
|
|
3
|
-
//
|
|
4
|
-
// Non-finite points break the line (a new segment starts after the gap) rather
|
|
5
|
-
// than emitting a NaN coordinate.
|
|
6
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
7
|
-
|
|
8
|
-
import { ChartEmpty, ChartFrame, type ChartLegendItem } from './chart-frame';
|
|
9
|
-
import {
|
|
10
|
-
buildAriaSummary,
|
|
11
|
-
chartColorAt,
|
|
12
|
-
defaultFormatValue,
|
|
13
|
-
niceScale,
|
|
14
|
-
} from './chart-utils';
|
|
15
|
-
|
|
16
|
-
import type { ChartBaseProps, ChartLineSeries } from './chart-types';
|
|
17
|
-
import type { ReactNode } from 'react';
|
|
18
|
-
|
|
19
|
-
const VIEW_W = 640;
|
|
20
|
-
const VIEW_H = 360;
|
|
21
|
-
const PAD = { top: 12, right: 12, bottom: 44, left: 48 } as const;
|
|
22
|
-
const PLOT_L = PAD.left;
|
|
23
|
-
const PLOT_R = VIEW_W - PAD.right;
|
|
24
|
-
const PLOT_T = PAD.top;
|
|
25
|
-
const PLOT_B = VIEW_H - PAD.bottom;
|
|
26
|
-
const PLOT_W = PLOT_R - PLOT_L;
|
|
27
|
-
const PLOT_H = PLOT_B - PLOT_T;
|
|
28
|
-
|
|
29
|
-
export interface LineChartProps extends ChartBaseProps {
|
|
30
|
-
/** One or more named line series. */
|
|
31
|
-
readonly series: readonly ChartLineSeries[];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Break a series' points into finite segments (a gap ends the current run). */
|
|
35
|
-
function toSegments(
|
|
36
|
-
points: readonly { value: number }[],
|
|
37
|
-
xToPx: (i: number) => number,
|
|
38
|
-
yToPx: (v: number) => number,
|
|
39
|
-
): string[] {
|
|
40
|
-
const segments: string[] = [];
|
|
41
|
-
let current: string[] = [];
|
|
42
|
-
points.forEach((p, i) => {
|
|
43
|
-
if (Number.isFinite(p.value)) {
|
|
44
|
-
current.push(`${xToPx(i)},${yToPx(p.value)}`);
|
|
45
|
-
} else if (current.length > 0) {
|
|
46
|
-
segments.push(current.join(' '));
|
|
47
|
-
current = [];
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
if (current.length > 0) {
|
|
51
|
-
segments.push(current.join(' '));
|
|
52
|
-
}
|
|
53
|
-
return segments;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function LineChart({
|
|
57
|
-
series,
|
|
58
|
-
title,
|
|
59
|
-
ariaLabel,
|
|
60
|
-
formatValue,
|
|
61
|
-
className,
|
|
62
|
-
emptyLabel = 'No data',
|
|
63
|
-
}: LineChartProps): ReactNode {
|
|
64
|
-
const format = formatValue ?? defaultFormatValue;
|
|
65
|
-
|
|
66
|
-
// Every finite value across all series drives the y-domain and the summary.
|
|
67
|
-
const finiteValues: number[] = [];
|
|
68
|
-
let maxLen = 0;
|
|
69
|
-
for (const s of series) {
|
|
70
|
-
maxLen = Math.max(maxLen, s.points.length);
|
|
71
|
-
for (const p of s.points) {
|
|
72
|
-
if (Number.isFinite(p.value)) {
|
|
73
|
-
finiteValues.push(p.value);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (finiteValues.length === 0) {
|
|
79
|
-
return (
|
|
80
|
-
<ChartEmpty title={title} label={emptyLabel} className={className} />
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const scale = niceScale(
|
|
85
|
-
Math.min(...finiteValues),
|
|
86
|
-
Math.max(...finiteValues),
|
|
87
|
-
{
|
|
88
|
-
pinZero: false,
|
|
89
|
-
},
|
|
90
|
-
);
|
|
91
|
-
const span = scale.max - scale.min;
|
|
92
|
-
const yToPx = (v: number): number =>
|
|
93
|
-
PLOT_B - ((v - scale.min) / span) * PLOT_H;
|
|
94
|
-
const xToPx = (i: number): number =>
|
|
95
|
-
maxLen <= 1 ? PLOT_L + PLOT_W / 2 : PLOT_L + (i / (maxLen - 1)) * PLOT_W;
|
|
96
|
-
|
|
97
|
-
// x labels from the longest series (deterministic pick: first of that length).
|
|
98
|
-
const xLabelSource =
|
|
99
|
-
series.find((s) => s.points.length === maxLen)?.points ?? [];
|
|
100
|
-
|
|
101
|
-
const legend: ChartLegendItem[] = series.map((s, i) => ({
|
|
102
|
-
label: s.name,
|
|
103
|
-
color: chartColorAt(i, s.color),
|
|
104
|
-
}));
|
|
105
|
-
|
|
106
|
-
// Summarize the first series' points (or the union count) for the aria label.
|
|
107
|
-
const summaryPoints = series.flatMap((s) =>
|
|
108
|
-
s.points
|
|
109
|
-
.filter((p) => Number.isFinite(p.value))
|
|
110
|
-
.map((p) => ({ label: `${s.name} ${p.label}`, value: p.value })),
|
|
111
|
-
);
|
|
112
|
-
const summary =
|
|
113
|
-
ariaLabel ?? buildAriaSummary(title, summaryPoints, format, 'point');
|
|
114
|
-
|
|
115
|
-
const plot = (
|
|
116
|
-
<svg
|
|
117
|
-
role="img"
|
|
118
|
-
aria-label={summary}
|
|
119
|
-
width="100%"
|
|
120
|
-
viewBox={`0 0 ${VIEW_W} ${VIEW_H}`}
|
|
121
|
-
preserveAspectRatio="xMidYMid meet"
|
|
122
|
-
className="block h-auto w-full overflow-visible text-ink-4"
|
|
123
|
-
>
|
|
124
|
-
{/* y gridlines + tick labels */}
|
|
125
|
-
{scale.ticks.map((t) => {
|
|
126
|
-
const y = yToPx(t);
|
|
127
|
-
return (
|
|
128
|
-
<g key={`y-${t}`}>
|
|
129
|
-
<line
|
|
130
|
-
x1={PLOT_L}
|
|
131
|
-
x2={PLOT_R}
|
|
132
|
-
y1={y}
|
|
133
|
-
y2={y}
|
|
134
|
-
stroke="currentColor"
|
|
135
|
-
strokeOpacity={0.12}
|
|
136
|
-
/>
|
|
137
|
-
<text
|
|
138
|
-
x={PLOT_L - 8}
|
|
139
|
-
y={y}
|
|
140
|
-
textAnchor="end"
|
|
141
|
-
dominantBaseline="middle"
|
|
142
|
-
fontSize={12}
|
|
143
|
-
fill="currentColor"
|
|
144
|
-
>
|
|
145
|
-
{format(t)}
|
|
146
|
-
</text>
|
|
147
|
-
</g>
|
|
148
|
-
);
|
|
149
|
-
})}
|
|
150
|
-
|
|
151
|
-
{/* x labels */}
|
|
152
|
-
{xLabelSource.map((p, i) => (
|
|
153
|
-
<text
|
|
154
|
-
key={`x-${p.label}-${i}`}
|
|
155
|
-
x={xToPx(i)}
|
|
156
|
-
y={PLOT_B + 16}
|
|
157
|
-
textAnchor="middle"
|
|
158
|
-
fontSize={12}
|
|
159
|
-
fill="currentColor"
|
|
160
|
-
>
|
|
161
|
-
{p.label}
|
|
162
|
-
</text>
|
|
163
|
-
))}
|
|
164
|
-
|
|
165
|
-
{/* lines */}
|
|
166
|
-
{series.map((s, si) => {
|
|
167
|
-
const color = chartColorAt(si, s.color);
|
|
168
|
-
const segments = toSegments(s.points, xToPx, yToPx);
|
|
169
|
-
return (
|
|
170
|
-
<g key={`line-${s.name}-${si}`}>
|
|
171
|
-
{segments.map((pts, gi) => (
|
|
172
|
-
<polyline
|
|
173
|
-
key={`seg-${gi}`}
|
|
174
|
-
points={pts}
|
|
175
|
-
fill="none"
|
|
176
|
-
stroke={color}
|
|
177
|
-
strokeWidth={2}
|
|
178
|
-
strokeLinejoin="round"
|
|
179
|
-
strokeLinecap="round"
|
|
180
|
-
/>
|
|
181
|
-
))}
|
|
182
|
-
{s.points.map((p, i) =>
|
|
183
|
-
Number.isFinite(p.value) ? (
|
|
184
|
-
<circle
|
|
185
|
-
key={`pt-${i}`}
|
|
186
|
-
cx={xToPx(i)}
|
|
187
|
-
cy={yToPx(p.value)}
|
|
188
|
-
r={2.5}
|
|
189
|
-
fill={color}
|
|
190
|
-
>
|
|
191
|
-
<title>{`${s.name} — ${p.label}: ${format(p.value)}`}</title>
|
|
192
|
-
</circle>
|
|
193
|
-
) : null,
|
|
194
|
-
)}
|
|
195
|
-
</g>
|
|
196
|
-
);
|
|
197
|
-
})}
|
|
198
|
-
</svg>
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
return <ChartFrame plot={plot} legend={legend} className={className} />;
|
|
202
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
2
|
-
// Sparkline — tiny inline trend line, pure SVG, no axes/legend (Wave 9.2)
|
|
3
|
-
// ═══════════════════════════════════════════════════════════════════════════
|
|
4
|
-
|
|
5
|
-
import { cn } from '../cn';
|
|
6
|
-
import { chartColorAt, defaultFormatValue, niceScale } from './chart-utils';
|
|
7
|
-
|
|
8
|
-
import type { ChartValueFormatter } from './chart-types';
|
|
9
|
-
import type { ReactNode } from 'react';
|
|
10
|
-
|
|
11
|
-
const VIEW_W = 100;
|
|
12
|
-
const VIEW_H = 28;
|
|
13
|
-
const PAD_Y = 3;
|
|
14
|
-
|
|
15
|
-
export interface SparklineProps {
|
|
16
|
-
/** The ordered values. Non-finite entries break the line rather than plotting NaN. */
|
|
17
|
-
readonly values: readonly number[];
|
|
18
|
-
/** Title — the spine of the `aria-label` summary. */
|
|
19
|
-
readonly title: string;
|
|
20
|
-
readonly ariaLabel?: string;
|
|
21
|
-
readonly formatValue?: ChartValueFormatter;
|
|
22
|
-
/** Line color (CSS color / `currentColor` / `var(--…)`). Defaults to the brand palette slot 0. */
|
|
23
|
-
readonly color?: string;
|
|
24
|
-
readonly className?: string;
|
|
25
|
-
readonly emptyLabel?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function Sparkline({
|
|
29
|
-
values,
|
|
30
|
-
title,
|
|
31
|
-
ariaLabel,
|
|
32
|
-
formatValue,
|
|
33
|
-
color,
|
|
34
|
-
className,
|
|
35
|
-
emptyLabel = 'No data',
|
|
36
|
-
}: SparklineProps): ReactNode {
|
|
37
|
-
const format = formatValue ?? defaultFormatValue;
|
|
38
|
-
const finite = values.filter((v) => Number.isFinite(v));
|
|
39
|
-
// Read the endpoints BEFORE the empty guard so the guard itself narrows them:
|
|
40
|
-
// both are `undefined` exactly when `finite` is empty, which is the case the
|
|
41
|
-
// guard already returns for.
|
|
42
|
-
const first = finite[0];
|
|
43
|
-
const last = finite[finite.length - 1];
|
|
44
|
-
|
|
45
|
-
if (first === undefined || last === undefined) {
|
|
46
|
-
return (
|
|
47
|
-
<span
|
|
48
|
-
role="img"
|
|
49
|
-
aria-label={`${title}: ${emptyLabel}`}
|
|
50
|
-
className={cn('inline-block text-body-2 text-ink-4', className)}
|
|
51
|
-
>
|
|
52
|
-
{emptyLabel}
|
|
53
|
-
</span>
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const scale = niceScale(Math.min(...finite), Math.max(...finite), {
|
|
58
|
-
pinZero: false,
|
|
59
|
-
});
|
|
60
|
-
const span = scale.max - scale.min;
|
|
61
|
-
const yToPx = (v: number): number =>
|
|
62
|
-
VIEW_H - PAD_Y - ((v - scale.min) / span) * (VIEW_H - 2 * PAD_Y);
|
|
63
|
-
const xToPx = (i: number): number =>
|
|
64
|
-
values.length <= 1 ? VIEW_W / 2 : (i / (values.length - 1)) * VIEW_W;
|
|
65
|
-
|
|
66
|
-
// Break into finite segments so a gap never yields a NaN coordinate.
|
|
67
|
-
const segments: string[] = [];
|
|
68
|
-
let current: string[] = [];
|
|
69
|
-
values.forEach((v, i) => {
|
|
70
|
-
if (Number.isFinite(v)) {
|
|
71
|
-
current.push(`${xToPx(i)},${yToPx(v)}`);
|
|
72
|
-
} else if (current.length > 0) {
|
|
73
|
-
segments.push(current.join(' '));
|
|
74
|
-
current = [];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
if (current.length > 0) {
|
|
78
|
-
segments.push(current.join(' '));
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const stroke = chartColorAt(0, color);
|
|
82
|
-
const summary =
|
|
83
|
-
ariaLabel ??
|
|
84
|
-
`${title}: trend of ${finite.length} points, from ${format(first)} to ${format(last)}.`;
|
|
85
|
-
|
|
86
|
-
return (
|
|
87
|
-
<svg
|
|
88
|
-
role="img"
|
|
89
|
-
aria-label={summary}
|
|
90
|
-
width="100%"
|
|
91
|
-
viewBox={`0 0 ${VIEW_W} ${VIEW_H}`}
|
|
92
|
-
preserveAspectRatio="none"
|
|
93
|
-
className={cn('block h-auto w-full overflow-visible', className)}
|
|
94
|
-
>
|
|
95
|
-
{segments.map((pts, i) => (
|
|
96
|
-
<polyline
|
|
97
|
-
key={`seg-${i}`}
|
|
98
|
-
points={pts}
|
|
99
|
-
fill="none"
|
|
100
|
-
stroke={stroke}
|
|
101
|
-
strokeWidth={1.5}
|
|
102
|
-
strokeLinejoin="round"
|
|
103
|
-
strokeLinecap="round"
|
|
104
|
-
vectorEffect="non-scaling-stroke"
|
|
105
|
-
/>
|
|
106
|
-
))}
|
|
107
|
-
</svg>
|
|
108
|
-
);
|
|
109
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import EmptyState from './EmptyState';
|
|
2
|
-
import ErrorCard, { type ErrorMessageFormatter } from './ErrorCard';
|
|
3
|
-
import LoadingState, { type LoadingStateVariant } from './LoadingState';
|
|
4
|
-
|
|
5
|
-
import type { LucideIcon } from 'lucide-react';
|
|
6
|
-
import type { ReactNode } from 'react';
|
|
7
|
-
|
|
8
|
-
interface AsyncBoundaryEmpty {
|
|
9
|
-
icon: LucideIcon;
|
|
10
|
-
title: string;
|
|
11
|
-
description?: ReactNode;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface AsyncBoundaryProps {
|
|
15
|
-
/** Async in flight — renders the loading affordance. */
|
|
16
|
-
isLoading: boolean;
|
|
17
|
-
/** Resolved error, if any — renders an `ErrorCard`. */
|
|
18
|
-
error?: Error | string | unknown | null;
|
|
19
|
-
/**
|
|
20
|
-
* When true, the resolved data is empty — renders an `EmptyState`. Only
|
|
21
|
-
* checked when `empty` config is supplied; otherwise children render.
|
|
22
|
-
*/
|
|
23
|
-
isEmpty?: boolean;
|
|
24
|
-
/** Empty-state config; omit to never render an empty state. */
|
|
25
|
-
empty?: AsyncBoundaryEmpty;
|
|
26
|
-
/** Retry handler threaded to `ErrorCard`. */
|
|
27
|
-
onRetry?: () => void;
|
|
28
|
-
/** Loading affordance variant. */
|
|
29
|
-
loadingVariant?: LoadingStateVariant;
|
|
30
|
-
/** Host error decoder threaded to `ErrorCard`. */
|
|
31
|
-
formatError?: ErrorMessageFormatter;
|
|
32
|
-
children: ReactNode;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Declarative loading / error / empty wrapper. Collapses the
|
|
37
|
-
* `if (isLoading) … if (error) … if (empty) … else children` ladder that
|
|
38
|
-
* every biome list/detail surface re-implements into one component built on
|
|
39
|
-
* the shared `LoadingState` / `ErrorCard` / `EmptyState` primitives.
|
|
40
|
-
*
|
|
41
|
-
* Precedence: loading → error → empty → children.
|
|
42
|
-
*/
|
|
43
|
-
export default function AsyncBoundary({
|
|
44
|
-
isLoading,
|
|
45
|
-
error,
|
|
46
|
-
isEmpty,
|
|
47
|
-
empty,
|
|
48
|
-
onRetry,
|
|
49
|
-
loadingVariant,
|
|
50
|
-
formatError,
|
|
51
|
-
children,
|
|
52
|
-
}: Readonly<AsyncBoundaryProps>) {
|
|
53
|
-
if (isLoading) {
|
|
54
|
-
return <LoadingState variant={loadingVariant} />;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (error) {
|
|
58
|
-
return (
|
|
59
|
-
<ErrorCard error={error} onRetry={onRetry} formatError={formatError} />
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (isEmpty && empty) {
|
|
64
|
-
return (
|
|
65
|
-
<EmptyState
|
|
66
|
-
icon={empty.icon}
|
|
67
|
-
title={empty.title}
|
|
68
|
-
description={empty.description}
|
|
69
|
-
/>
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return <>{children}</>;
|
|
74
|
-
}
|
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { cn } from '../cn';
|
|
2
|
-
import { Button } from '../primitives/button';
|
|
3
|
-
import { Card, CardContent } from '../primitives/card';
|
|
4
|
-
|
|
5
|
-
import type { LucideIcon } from 'lucide-react';
|
|
6
|
-
import type { ComponentType, ReactNode } from 'react';
|
|
7
|
-
|
|
8
|
-
export type EmptyStateVariant =
|
|
9
|
-
| 'not-configured'
|
|
10
|
-
| 'no-results'
|
|
11
|
-
| 'disabled-context';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Visual density.
|
|
15
|
-
* - `comfortable` (default): hero empty state for full-page surfaces —
|
|
16
|
-
* big 64px icon, generous padding, hero copy. Use when the page has
|
|
17
|
-
* nothing else to render.
|
|
18
|
-
* - `dense`: inline empty state for surfaces nested inside other
|
|
19
|
-
* content (tabs, sub-panels). Smaller icon, tighter padding, no
|
|
20
|
-
* dashed card frame — reads as a calm placeholder, not a banner.
|
|
21
|
-
* - `inline`: single-line text-only message, no icon, no card. Use
|
|
22
|
-
* inside list sub-sections where even the dense frame is too much.
|
|
23
|
-
*/
|
|
24
|
-
export type EmptyStateSize = 'comfortable' | 'dense' | 'inline';
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Polymorphic link element. The host shell renders Next.js `<Link>`;
|
|
28
|
-
* pass it via `linkComponent` to get client-side routing. Defaults to a
|
|
29
|
-
* plain anchor so the primitive stays host-framework-agnostic.
|
|
30
|
-
*/
|
|
31
|
-
export type EmptyStateLinkComponent = ComponentType<{
|
|
32
|
-
href: string;
|
|
33
|
-
children: ReactNode;
|
|
34
|
-
}>;
|
|
35
|
-
|
|
36
|
-
const DefaultLink: EmptyStateLinkComponent = ({ href, children }) => (
|
|
37
|
-
<a href={href}>{children}</a>
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
interface EmptyStateAction {
|
|
41
|
-
label: string;
|
|
42
|
-
onClick: () => void;
|
|
43
|
-
icon?: LucideIcon;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
interface EmptyStateSecondaryAction {
|
|
47
|
-
label: string;
|
|
48
|
-
href: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
interface EmptyStateCommonProps {
|
|
52
|
-
title: string;
|
|
53
|
-
description?: ReactNode;
|
|
54
|
-
action?: EmptyStateAction;
|
|
55
|
-
secondaryAction?: EmptyStateSecondaryAction;
|
|
56
|
-
/** Host link component for `secondaryAction.href` (defaults to `<a>`). */
|
|
57
|
-
linkComponent?: EmptyStateLinkComponent;
|
|
58
|
-
className?: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** `comfortable` / `dense` render an icon block, so the icon is required. */
|
|
62
|
-
interface EmptyStateIconicProps extends EmptyStateCommonProps {
|
|
63
|
-
size?: Exclude<EmptyStateSize, 'inline'>;
|
|
64
|
-
icon: LucideIcon;
|
|
65
|
-
/** Optional illustration or extra content above the title */
|
|
66
|
-
illustration?: ReactNode;
|
|
67
|
-
/** Visual variant — drives default iconBg/iconColor unless overridden. */
|
|
68
|
-
variant?: EmptyStateVariant;
|
|
69
|
-
/** Icon tint — overrides variant defaults */
|
|
70
|
-
iconBg?: string;
|
|
71
|
-
iconColor?: string;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* `inline` is text-only by definition — no icon block, therefore no icon,
|
|
76
|
-
* illustration, variant or icon tint. They are typed `never` rather than
|
|
77
|
-
* silently ignored: an accepted-but-unrendered prop is how callers ended up
|
|
78
|
-
* importing a lucide icon that renders nowhere.
|
|
79
|
-
*/
|
|
80
|
-
interface EmptyStateInlineProps extends EmptyStateCommonProps {
|
|
81
|
-
size: 'inline';
|
|
82
|
-
icon?: never;
|
|
83
|
-
illustration?: never;
|
|
84
|
-
variant?: never;
|
|
85
|
-
iconBg?: never;
|
|
86
|
-
iconColor?: never;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
type EmptyStateProps = EmptyStateIconicProps | EmptyStateInlineProps;
|
|
90
|
-
|
|
91
|
-
const VARIANT_DEFAULTS: Record<
|
|
92
|
-
EmptyStateVariant,
|
|
93
|
-
{ iconBg: string; iconColor: string }
|
|
94
|
-
> = {
|
|
95
|
-
'not-configured': { iconBg: 'bg-info/10', iconColor: 'text-info' },
|
|
96
|
-
'no-results': { iconBg: 'bg-warning/10', iconColor: 'text-warning' },
|
|
97
|
-
'disabled-context': { iconBg: 'bg-muted', iconColor: 'text-ink-3' },
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export default function EmptyState(props: Readonly<EmptyStateProps>) {
|
|
101
|
-
const { title, description, action, secondaryAction, linkComponent, className } =
|
|
102
|
-
props;
|
|
103
|
-
const Link = linkComponent ?? DefaultLink;
|
|
104
|
-
|
|
105
|
-
if (props.size === 'inline') {
|
|
106
|
-
return (
|
|
107
|
-
<div
|
|
108
|
-
className={cn(
|
|
109
|
-
'flex items-center justify-center px-3 py-6 text-center text-body-2 text-ink-4',
|
|
110
|
-
className,
|
|
111
|
-
)}
|
|
112
|
-
>
|
|
113
|
-
<div className="max-w-sm space-y-1">
|
|
114
|
-
<p className="text-ink-3">{title}</p>
|
|
115
|
-
{description && <p className="text-ink-4">{description}</p>}
|
|
116
|
-
{(action || secondaryAction) && (
|
|
117
|
-
<div className="mt-3 flex items-center justify-center gap-2">
|
|
118
|
-
{action && (
|
|
119
|
-
<Button
|
|
120
|
-
size="sm"
|
|
121
|
-
variant="outline"
|
|
122
|
-
onClick={action.onClick}
|
|
123
|
-
className="h-7 gap-1.5 text-body-2"
|
|
124
|
-
>
|
|
125
|
-
{action.icon && <action.icon className="h-3.5 w-3.5" />}
|
|
126
|
-
{action.label}
|
|
127
|
-
</Button>
|
|
128
|
-
)}
|
|
129
|
-
{secondaryAction && (
|
|
130
|
-
<Button
|
|
131
|
-
asChild
|
|
132
|
-
size="sm"
|
|
133
|
-
variant="ghost"
|
|
134
|
-
className="h-7 px-2 text-body-2"
|
|
135
|
-
>
|
|
136
|
-
<Link href={secondaryAction.href}>
|
|
137
|
-
{secondaryAction.label}
|
|
138
|
-
</Link>
|
|
139
|
-
</Button>
|
|
140
|
-
)}
|
|
141
|
-
</div>
|
|
142
|
-
)}
|
|
143
|
-
</div>
|
|
144
|
-
</div>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const {
|
|
149
|
-
icon: Icon,
|
|
150
|
-
illustration,
|
|
151
|
-
variant = 'not-configured',
|
|
152
|
-
size = 'comfortable',
|
|
153
|
-
iconBg,
|
|
154
|
-
iconColor,
|
|
155
|
-
} = props;
|
|
156
|
-
const defaults = VARIANT_DEFAULTS[variant];
|
|
157
|
-
const resolvedIconBg = iconBg ?? defaults.iconBg;
|
|
158
|
-
const resolvedIconColor = iconColor ?? defaults.iconColor;
|
|
159
|
-
|
|
160
|
-
if (size === 'dense') {
|
|
161
|
-
return (
|
|
162
|
-
<div
|
|
163
|
-
className={cn(
|
|
164
|
-
'flex flex-col items-center justify-center px-4 py-8 text-center',
|
|
165
|
-
className,
|
|
166
|
-
)}
|
|
167
|
-
>
|
|
168
|
-
{illustration ?? (
|
|
169
|
-
<div
|
|
170
|
-
className={cn(
|
|
171
|
-
'h-9 w-9 rounded-xl flex items-center justify-center mb-3',
|
|
172
|
-
resolvedIconBg,
|
|
173
|
-
)}
|
|
174
|
-
>
|
|
175
|
-
<Icon className={cn('h-4 w-4', resolvedIconColor)} />
|
|
176
|
-
</div>
|
|
177
|
-
)}
|
|
178
|
-
<p className="text-body-1 font-semibold text-ink">{title}</p>
|
|
179
|
-
{description && (
|
|
180
|
-
<p className="mt-1 max-w-md text-body-2 leading-snug text-ink-3">
|
|
181
|
-
{description}
|
|
182
|
-
</p>
|
|
183
|
-
)}
|
|
184
|
-
{(action || secondaryAction) && (
|
|
185
|
-
<div className="mt-3 flex items-center gap-2">
|
|
186
|
-
{action && (
|
|
187
|
-
<Button
|
|
188
|
-
size="sm"
|
|
189
|
-
variant="outline"
|
|
190
|
-
onClick={action.onClick}
|
|
191
|
-
className="h-7 gap-1.5 text-body-2"
|
|
192
|
-
>
|
|
193
|
-
{action.icon && <action.icon className="h-3.5 w-3.5" />}
|
|
194
|
-
{action.label}
|
|
195
|
-
</Button>
|
|
196
|
-
)}
|
|
197
|
-
{secondaryAction && (
|
|
198
|
-
<Button
|
|
199
|
-
asChild
|
|
200
|
-
size="sm"
|
|
201
|
-
variant="ghost"
|
|
202
|
-
className="h-7 px-2 text-body-2"
|
|
203
|
-
>
|
|
204
|
-
<Link href={secondaryAction.href}>{secondaryAction.label}</Link>
|
|
205
|
-
</Button>
|
|
206
|
-
)}
|
|
207
|
-
</div>
|
|
208
|
-
)}
|
|
209
|
-
</div>
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return (
|
|
214
|
-
<Card
|
|
215
|
-
className={cn(
|
|
216
|
-
'border-2 border-dashed border-border/50 rounded-xl',
|
|
217
|
-
className,
|
|
218
|
-
)}
|
|
219
|
-
>
|
|
220
|
-
<CardContent className="flex flex-col items-center justify-center py-16 text-center">
|
|
221
|
-
{illustration ?? (
|
|
222
|
-
<div
|
|
223
|
-
className={`h-16 w-16 rounded-2xl flex items-center justify-center mb-5 ${resolvedIconBg}`}
|
|
224
|
-
>
|
|
225
|
-
<Icon className={`h-7 w-7 ${resolvedIconColor}`} />
|
|
226
|
-
</div>
|
|
227
|
-
)}
|
|
228
|
-
<p className="text-subtitle font-semibold text-ink">{title}</p>
|
|
229
|
-
{description && (
|
|
230
|
-
<p className="text-body-1 mt-2 max-w-sm text-ink-3 leading-relaxed">
|
|
231
|
-
{description}
|
|
232
|
-
</p>
|
|
233
|
-
)}
|
|
234
|
-
{(action || secondaryAction) && (
|
|
235
|
-
<div className="mt-6 flex items-center gap-3">
|
|
236
|
-
{action && (
|
|
237
|
-
<Button
|
|
238
|
-
size="sm"
|
|
239
|
-
variant="outline"
|
|
240
|
-
onClick={action.onClick}
|
|
241
|
-
className="gap-2 h-10 px-5"
|
|
242
|
-
>
|
|
243
|
-
{action.icon && <action.icon className="h-4 w-4" />}
|
|
244
|
-
{action.label}
|
|
245
|
-
</Button>
|
|
246
|
-
)}
|
|
247
|
-
{secondaryAction && (
|
|
248
|
-
<Button asChild size="sm" variant="ghost" className="h-10 px-3">
|
|
249
|
-
<Link href={secondaryAction.href}>{secondaryAction.label}</Link>
|
|
250
|
-
</Button>
|
|
251
|
-
)}
|
|
252
|
-
</div>
|
|
253
|
-
)}
|
|
254
|
-
</CardContent>
|
|
255
|
-
</Card>
|
|
256
|
-
);
|
|
257
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { AlertCircle, RefreshCw } from 'lucide-react';
|
|
2
|
-
|
|
3
|
-
import { getUserFacingErrorMessage } from '../../lib/biome-host/errors';
|
|
4
|
-
import { Button } from '../primitives/button';
|
|
5
|
-
import { Card, CardContent } from '../primitives/card';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Host-agnostic error formatter. The default is the canonical, envelope-aware
|
|
9
|
-
* {@link getUserFacingErrorMessage} decoder — biomes get rich error copy with
|
|
10
|
-
* zero wiring. Pass `formatError` only to override with a host-specific decoder
|
|
11
|
-
* (extra codes, i18n); the canonical default already handles Orval envelopes,
|
|
12
|
-
* `ApiClientError`, workflow error codes, and "failed to fetch".
|
|
13
|
-
*/
|
|
14
|
-
export type ErrorMessageFormatter = (error: unknown, fallback: string) => string;
|
|
15
|
-
|
|
16
|
-
const defaultFormatError: ErrorMessageFormatter = (error, fallback) =>
|
|
17
|
-
getUserFacingErrorMessage(error, fallback);
|
|
18
|
-
|
|
19
|
-
interface ErrorCardProps {
|
|
20
|
-
error: Error | string | unknown;
|
|
21
|
-
title?: string;
|
|
22
|
-
onRetry?: () => void;
|
|
23
|
-
/**
|
|
24
|
-
* Optional host error-decoder. Defaults to a plain message extractor.
|
|
25
|
-
* The host shell should pass `getUserFacingErrorMessage` to keep its
|
|
26
|
-
* envelope-aware messaging.
|
|
27
|
-
*/
|
|
28
|
-
formatError?: ErrorMessageFormatter;
|
|
29
|
-
fallbackMessage?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default function ErrorCard({
|
|
33
|
-
error,
|
|
34
|
-
title = 'Something went wrong',
|
|
35
|
-
onRetry,
|
|
36
|
-
formatError = defaultFormatError,
|
|
37
|
-
fallbackMessage = 'Unable to load this content right now.',
|
|
38
|
-
}: ErrorCardProps) {
|
|
39
|
-
const message = formatError(error, fallbackMessage);
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<Card className="border-destructive/25 bg-destructive/[0.03] rounded-xl">
|
|
43
|
-
<CardContent className="flex flex-col items-center py-14 text-center">
|
|
44
|
-
<div className="h-14 w-14 rounded-2xl bg-destructive/10 flex items-center justify-center mb-4">
|
|
45
|
-
<AlertCircle className="h-6 w-6 text-destructive" />
|
|
46
|
-
</div>
|
|
47
|
-
<p className="text-subtitle font-semibold text-ink">{title}</p>
|
|
48
|
-
<p className="text-body-1 text-ink-3 mt-2 max-w-md leading-relaxed">{message}</p>
|
|
49
|
-
{onRetry && (
|
|
50
|
-
<Button
|
|
51
|
-
size="sm"
|
|
52
|
-
variant="outline"
|
|
53
|
-
onClick={onRetry}
|
|
54
|
-
className="mt-5 gap-2 h-10 border-destructive/20 text-destructive hover:bg-destructive/5"
|
|
55
|
-
>
|
|
56
|
-
<RefreshCw className="h-4 w-4" />
|
|
57
|
-
Retry
|
|
58
|
-
</Button>
|
|
59
|
-
)}
|
|
60
|
-
</CardContent>
|
|
61
|
-
</Card>
|
|
62
|
-
);
|
|
63
|
-
}
|