@richardmcquiston01/dashboard-widgets-toolkit 0.1.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.
@@ -0,0 +1,203 @@
1
+ import { ReactNode } from 'react';
2
+ import { D as DashboardWidget, W as WidgetSize, G as GraphWidgetData, N as NiceDomain, L as Locale, a as DashboardLayout, A as AlertListWidgetData, B as BarListWidgetData, b as GaugeWidgetData, K as KpiWidgetData, T as TableWidgetData, c as TextWidgetData, d as WidgetData } from './scale-WlRozDCf.js';
3
+
4
+ interface WidgetCardProps {
5
+ readonly title: string;
6
+ readonly description?: string;
7
+ /** Extra controls in the header (move, hide...), before the minimise toggle. */
8
+ readonly actions?: ReactNode;
9
+ readonly minimized?: boolean;
10
+ /** Shows the minimise/expand toggle when given. */
11
+ readonly onToggleMinimized?: () => void;
12
+ /** Default 'ok', which renders `children`. */
13
+ readonly status?: 'ok' | 'loading' | 'empty' | 'error';
14
+ readonly emptyText?: string;
15
+ readonly error?: string;
16
+ /** Shows a Retry button on the error state when given. */
17
+ readonly onRetry?: () => void;
18
+ readonly footer?: ReactNode;
19
+ readonly size?: WidgetSize;
20
+ /** 2 to 6; default 2. */
21
+ readonly headingLevel?: 2 | 3 | 4 | 5 | 6;
22
+ readonly className?: string;
23
+ readonly children?: ReactNode;
24
+ }
25
+ /**
26
+ * The frame every widget sits in: title, optional description and actions,
27
+ * a minimise toggle, and loading, empty and error states.
28
+ */
29
+ declare function WidgetCard({ title, description, actions, minimized, onToggleMinimized, status, emptyText, error, onRetry, footer, size, headingLevel, className, children, }: WidgetCardProps): ReactNode;
30
+ /** The title to show: alert lists add their total, e.g. "Low stock (3)". */
31
+ declare function widgetTitle(widget: DashboardWidget): string;
32
+ interface ResolvedWidgetCardProps {
33
+ readonly widget: DashboardWidget;
34
+ readonly actions?: ReactNode;
35
+ readonly minimized?: boolean;
36
+ readonly onToggleMinimized?: () => void;
37
+ readonly onRetry?: () => void;
38
+ readonly headingLevel?: 2 | 3 | 4 | 5 | 6;
39
+ readonly className?: string;
40
+ }
41
+ /** A WidgetCard for a resolved (or loading) widget, with its renderer. */
42
+ declare function ResolvedWidgetCard({ widget, ...props }: ResolvedWidgetCardProps): ReactNode;
43
+
44
+ /** A bar with a rounded data end and a square end on the baseline. */
45
+ declare function barPath(x: number, y: number, width: number, height: number, roundedEnd: 'top' | 'bottom'): string;
46
+ interface ChartModel {
47
+ readonly labels: readonly string[];
48
+ /** values[series][index]; null where a series has no point. */
49
+ readonly values: readonly (readonly (number | null)[])[];
50
+ readonly domain: NiceDomain;
51
+ }
52
+ /** Labels by position (first series that has one) and a value matrix. */
53
+ declare function buildChartModel(data: GraphWidgetData): ChartModel;
54
+ /** A plain-language summary of the chart, for its SVG <desc>. */
55
+ declare function describeChart(data: GraphWidgetData, model: ChartModel, format: (value: number) => string): string;
56
+ declare function GraphWidget({ data, title, }: {
57
+ readonly data: GraphWidgetData;
58
+ /** The accessible name; defaults to the series names. */
59
+ readonly title?: string;
60
+ }): ReactNode;
61
+
62
+ /** Every element that carries a stable `dwt-*` class, for `classNames`. */
63
+ type DashboardClassSlot = 'dashboard' | 'hiddenBar' | 'grid' | 'card' | 'cardHeader' | 'cardTitle' | 'cardDescription' | 'cardActions' | 'cardBody' | 'cardFooter' | 'button' | 'status' | 'empty' | 'error' | 'text' | 'kpi' | 'gauge' | 'table' | 'barList' | 'alertList' | 'chart' | 'legend' | 'tooltip' | 'tableTwin';
64
+ /**
65
+ * Extra classes per slot, appended to the `dwt-*` class (never replacing
66
+ * it), e.g. `{ card: 'rounded-lg shadow-sm' }` for Tailwind.
67
+ */
68
+ type DashboardClassNames = Partial<Record<DashboardClassSlot, string>>;
69
+ /** Interface text, overridable for other languages or house style. */
70
+ interface DashboardLabels {
71
+ readonly loading: string;
72
+ readonly retry: string;
73
+ readonly viewAsTable: string;
74
+ readonly hide: (title: string) => string;
75
+ readonly show: (title: string) => string;
76
+ readonly minimize: (title: string) => string;
77
+ readonly expand: (title: string) => string;
78
+ readonly moveEarlier: (title: string) => string;
79
+ readonly moveLater: (title: string) => string;
80
+ readonly hiddenWidgets: string;
81
+ readonly allHidden: string;
82
+ readonly noWidgets: string;
83
+ readonly andMore: (count: number) => string;
84
+ /** The comparison in KPI deltas, e.g. "previous period". */
85
+ readonly comparison: string;
86
+ }
87
+ declare const DEFAULT_LABELS: DashboardLabels;
88
+ interface WidgetSettings {
89
+ /** BCP 47 locale for numbers; undefined uses the runtime default. */
90
+ readonly locale?: Locale;
91
+ /** e.g. "_blank". Links always get rel="noreferrer". */
92
+ readonly linkTarget?: string;
93
+ readonly classNames?: DashboardClassNames;
94
+ readonly labels?: Partial<DashboardLabels>;
95
+ }
96
+ interface ResolvedSettings {
97
+ readonly locale: Locale;
98
+ readonly linkTarget: string | undefined;
99
+ readonly classNames: DashboardClassNames;
100
+ readonly labels: DashboardLabels;
101
+ }
102
+ /** Sets locale, link target, extra classes and labels for widgets inside it. */
103
+ declare function WidgetSettingsProvider({ children, ...settings }: WidgetSettings & {
104
+ readonly children?: ReactNode;
105
+ }): ReactNode;
106
+ declare function useWidgetSettings(): ResolvedSettings;
107
+ /** Joins class names, skipping empty ones. */
108
+ declare function joinClassNames(...names: readonly (string | false | null | undefined)[]): string;
109
+
110
+ interface WidgetGridProps {
111
+ /** Rendered in the order given. */
112
+ readonly widgets: readonly DashboardWidget[];
113
+ readonly onRetry?: (key: string) => void;
114
+ readonly headingLevel?: 2 | 3 | 4 | 5 | 6;
115
+ readonly className?: string;
116
+ }
117
+ /** A plain grid of widget cards, no layout controls. */
118
+ declare function WidgetGrid({ widgets, onRetry, headingLevel, className, }: WidgetGridProps): ReactNode;
119
+ interface DashboardProps extends WidgetSettings {
120
+ /** Resolved (or loading) widgets, any order: the layout orders them. */
121
+ readonly widgets: readonly DashboardWidget[];
122
+ /** The viewer's saved layout. Default: none saved. */
123
+ readonly layout?: DashboardLayout;
124
+ /**
125
+ * Called with the next layout after a move, hide, show, minimise or
126
+ * restore; persist it. Without it the layout is read-only (no controls).
127
+ */
128
+ readonly onLayoutChange?: (layout: DashboardLayout) => void;
129
+ readonly onRetry?: (key: string) => void;
130
+ readonly headingLevel?: 2 | 3 | 4 | 5 | 6;
131
+ readonly className?: string;
132
+ }
133
+ /**
134
+ * A full dashboard: widgets ordered by the viewer's layout, with move,
135
+ * hide/show and minimise controls when `onLayoutChange` is given. Settings
136
+ * (locale, link target, classNames, labels) apply to every widget inside.
137
+ */
138
+ declare function Dashboard({ locale, linkTarget, classNames, labels, ...props }: DashboardProps): ReactNode;
139
+
140
+ /**
141
+ * Default colours, used as `var(--dwt-*, fallback)` so charts read correctly
142
+ * without the stylesheet. `styles.css` redefines them for dark mode, and an
143
+ * app can override any of them with its own CSS custom properties.
144
+ *
145
+ * The categorical order is the dataviz reference palette, validated for
146
+ * colour-vision deficiency on adjacent pairs in light and dark modes. Slots
147
+ * are assigned in this fixed order, never cycled, and follow the series
148
+ * (its position in the payload), never its rank.
149
+ */
150
+ declare const DEFAULT_SERIES_COLORS: readonly string[];
151
+ /** `var(--dwt-series-N, #hex)` for the series at `index` (0-based). */
152
+ declare function seriesColor(index: number): string;
153
+
154
+ /**
155
+ * An anchor with rel="noreferrer", or plain text when there is no href or
156
+ * it isn't a safe scheme (http, https, mailto, relative). Never fetches.
157
+ */
158
+ declare function WidgetLink({ href, className, children, }: {
159
+ readonly href: string | undefined;
160
+ readonly className?: string;
161
+ readonly children: ReactNode;
162
+ }): ReactNode;
163
+ /** A decorative square thumbnail; nothing for an unsafe or missing URL. */
164
+ declare function Thumbnail({ url, }: {
165
+ readonly url: string | undefined;
166
+ }): ReactNode;
167
+
168
+ /** TEXT: a headline value and its label. */
169
+ declare function TextWidget({ data, }: {
170
+ readonly data: TextWidgetData;
171
+ }): ReactNode;
172
+ /**
173
+ * KPI: a stat tile. The change against the previous period carries an arrow
174
+ * and signed text as well as colour, so it never relies on colour alone.
175
+ */
176
+ declare function KpiWidget({ data, }: {
177
+ readonly data: KpiWidgetData;
178
+ }): ReactNode;
179
+ /** GAUGE: a meter whose track is a lighter step of the fill's own hue. */
180
+ declare function GaugeWidget({ data, }: {
181
+ readonly data: GaugeWidgetData;
182
+ }): ReactNode;
183
+ /** TABLE: a data table; cells with a safe `href` become links. */
184
+ declare function TableWidget({ data, }: {
185
+ readonly data: TableWidgetData;
186
+ }): ReactNode;
187
+ /**
188
+ * BAR_LIST: labelled horizontal bars. One series, so one colour (slot 1)
189
+ * for every bar; the value text sits beside the bar, never inside it.
190
+ */
191
+ declare function BarListWidget({ data, }: {
192
+ readonly data: BarListWidgetData;
193
+ }): ReactNode;
194
+ /** ALERT_LIST: rows needing attention, with thumbnail, link and value. */
195
+ declare function AlertListWidget({ data, }: {
196
+ readonly data: AlertListWidgetData;
197
+ }): ReactNode;
198
+ /** Renders any payload with the renderer for its kind. */
199
+ declare function WidgetContent({ data, }: {
200
+ readonly data: WidgetData;
201
+ }): ReactNode;
202
+
203
+ export { AlertListWidget, BarListWidget, DEFAULT_LABELS, DEFAULT_SERIES_COLORS, Dashboard, type DashboardClassNames, type DashboardClassSlot, type DashboardLabels, type DashboardProps, GaugeWidget, GraphWidget, KpiWidget, ResolvedWidgetCard, type ResolvedWidgetCardProps, TableWidget, TextWidget, Thumbnail, WidgetCard, type WidgetCardProps, WidgetContent, WidgetGrid, type WidgetGridProps, WidgetLink, type WidgetSettings, WidgetSettingsProvider, barPath, buildChartModel, describeChart, joinClassNames, seriesColor, useWidgetSettings, widgetTitle };