@caqophony/ui 0.6.2 → 0.6.4
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/charts.d.mts +1 -1
- package/dist/charts.js +65 -42
- package/dist/index.d.mts +7 -1
- package/dist/index.js +79 -46
- package/package.json +1 -1
package/dist/charts.d.mts
CHANGED
package/dist/charts.js
CHANGED
|
@@ -181,38 +181,81 @@ function LineChart({
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
// src/charts/bar-chart.tsx
|
|
184
|
-
import { useMemo as useMemo2 } from "react";
|
|
184
|
+
import { useEffect, useMemo as useMemo2, useRef, useState } from "react";
|
|
185
185
|
import { Bar } from "react-chartjs-2";
|
|
186
186
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
187
|
+
var BAR_TOKENS = {
|
|
188
|
+
bar: "--primary",
|
|
189
|
+
text: "--muted-foreground",
|
|
190
|
+
grid: "--border"
|
|
191
|
+
};
|
|
192
|
+
function paletteOf(el) {
|
|
193
|
+
const style = getComputedStyle(el);
|
|
194
|
+
const read = (name) => {
|
|
195
|
+
const value = style.getPropertyValue(name).trim();
|
|
196
|
+
if (value === "")
|
|
197
|
+
throw new Error(
|
|
198
|
+
`BarChart: the token ${name} is not set on the page: the chart draws in the kit's tokens, so the page loads @caqophony/ui/styles.css`
|
|
199
|
+
);
|
|
200
|
+
return `hsl(${value})`;
|
|
201
|
+
};
|
|
202
|
+
return {
|
|
203
|
+
bar: read(BAR_TOKENS.bar),
|
|
204
|
+
text: read(BAR_TOKENS.text),
|
|
205
|
+
grid: read(BAR_TOKENS.grid)
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
var valueTick = (tickValue) => formatNumber(
|
|
209
|
+
typeof tickValue === "number" ? tickValue : parseFloat(String(tickValue))
|
|
210
|
+
);
|
|
187
211
|
function BarChart({
|
|
188
212
|
data,
|
|
189
213
|
label = "Value",
|
|
190
|
-
color
|
|
214
|
+
color,
|
|
191
215
|
horizontal = false,
|
|
192
216
|
showLegend = false,
|
|
193
217
|
height = 256,
|
|
194
218
|
emptyMessage = "No data available",
|
|
195
219
|
className
|
|
196
220
|
}) {
|
|
221
|
+
const box = useRef(null);
|
|
222
|
+
const [palette, setPalette] = useState(null);
|
|
223
|
+
const empty = data.length === 0;
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
if (!empty && box.current !== null) setPalette(paletteOf(box.current));
|
|
226
|
+
}, [empty]);
|
|
197
227
|
const chartData = useMemo2(() => {
|
|
198
|
-
const
|
|
199
|
-
const colors = data.length > 1 ? generateColors(data.length) : [color];
|
|
228
|
+
const fill = color ?? palette?.bar;
|
|
200
229
|
return {
|
|
201
|
-
labels,
|
|
230
|
+
labels: data.map((d) => d.label),
|
|
202
231
|
datasets: [
|
|
203
232
|
{
|
|
204
233
|
label,
|
|
205
234
|
data: data.map((d) => d.value),
|
|
206
|
-
backgroundColor:
|
|
207
|
-
|
|
208
|
-
|
|
235
|
+
backgroundColor: fill,
|
|
236
|
+
borderWidth: 0,
|
|
237
|
+
borderRadius: 4
|
|
209
238
|
}
|
|
210
239
|
]
|
|
211
240
|
};
|
|
212
|
-
}, [data, label, color]);
|
|
213
|
-
const options = useMemo2(
|
|
214
|
-
|
|
241
|
+
}, [data, label, color, palette]);
|
|
242
|
+
const options = useMemo2(() => {
|
|
243
|
+
const valueAxis = {
|
|
244
|
+
beginAtZero: true,
|
|
245
|
+
ticks: { callback: valueTick, color: palette?.text },
|
|
246
|
+
grid: { color: palette?.grid },
|
|
247
|
+
border: { display: false }
|
|
248
|
+
};
|
|
249
|
+
const categoryAxis = {
|
|
250
|
+
ticks: { color: palette?.text },
|
|
251
|
+
grid: { display: false },
|
|
252
|
+
border: { color: palette?.grid }
|
|
253
|
+
};
|
|
254
|
+
return {
|
|
215
255
|
...BASE_CHART_OPTIONS,
|
|
256
|
+
// #6326: the bars are drawn at their values at once: a reader (or a
|
|
257
|
+
// capture of the page) never sees a bar part-way to its value
|
|
258
|
+
animation: false,
|
|
216
259
|
indexAxis: horizontal ? "y" : "x",
|
|
217
260
|
plugins: {
|
|
218
261
|
legend: {
|
|
@@ -221,48 +264,26 @@ function BarChart({
|
|
|
221
264
|
tooltip: {
|
|
222
265
|
callbacks: {
|
|
223
266
|
label: (context) => {
|
|
224
|
-
const val = horizontal ? context.parsed.x
|
|
225
|
-
return `${context.dataset.label}: ${formatNumber(val)}`;
|
|
267
|
+
const val = horizontal ? context.parsed.x : context.parsed.y;
|
|
268
|
+
return val === null ? `${context.dataset.label}: no value` : `${context.dataset.label}: ${formatNumber(val)}`;
|
|
226
269
|
}
|
|
227
270
|
}
|
|
228
271
|
}
|
|
229
272
|
},
|
|
230
|
-
scales: {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
ticks: horizontal ? {
|
|
234
|
-
callback: (tickValue) => {
|
|
235
|
-
if (tickValue === null) return "";
|
|
236
|
-
const value = typeof tickValue === "number" ? tickValue : parseFloat(String(tickValue));
|
|
237
|
-
return formatNumber(value);
|
|
238
|
-
}
|
|
239
|
-
} : void 0
|
|
240
|
-
},
|
|
241
|
-
y: {
|
|
242
|
-
beginAtZero: true,
|
|
243
|
-
ticks: !horizontal ? {
|
|
244
|
-
callback: (tickValue) => {
|
|
245
|
-
if (tickValue === null) return "";
|
|
246
|
-
const value = typeof tickValue === "number" ? tickValue : parseFloat(String(tickValue));
|
|
247
|
-
return formatNumber(value);
|
|
248
|
-
}
|
|
249
|
-
} : void 0
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}),
|
|
253
|
-
[horizontal, showLegend]
|
|
254
|
-
);
|
|
273
|
+
scales: horizontal ? { x: valueAxis, y: categoryAxis } : { x: categoryAxis, y: valueAxis }
|
|
274
|
+
};
|
|
275
|
+
}, [horizontal, showLegend, palette]);
|
|
255
276
|
if (data.length === 0) {
|
|
256
277
|
return /* @__PURE__ */ jsx2(
|
|
257
278
|
"div",
|
|
258
279
|
{
|
|
259
|
-
className: `flex items-center justify-center text-
|
|
280
|
+
className: `flex items-center justify-center text-muted-foreground ${className ?? ""}`,
|
|
260
281
|
style: { height },
|
|
261
282
|
children: emptyMessage
|
|
262
283
|
}
|
|
263
284
|
);
|
|
264
285
|
}
|
|
265
|
-
return /* @__PURE__ */ jsx2("div", { className, style: { height }, children: /* @__PURE__ */ jsx2(Bar, { data: chartData, options }) });
|
|
286
|
+
return /* @__PURE__ */ jsx2("div", { ref: box, className, style: { height }, children: palette !== null ? /* @__PURE__ */ jsx2(Bar, { data: chartData, options }) : null });
|
|
266
287
|
}
|
|
267
288
|
|
|
268
289
|
// src/charts/doughnut-chart.tsx
|
|
@@ -279,7 +300,8 @@ function DoughnutChart({
|
|
|
279
300
|
className
|
|
280
301
|
}) {
|
|
281
302
|
const total = useMemo3(
|
|
282
|
-
|
|
303
|
+
// #6326: the total of the values the data holds; a null point is not 0
|
|
304
|
+
() => data.reduce((sum, d) => d.value === null ? sum : sum + d.value, 0),
|
|
283
305
|
[data]
|
|
284
306
|
);
|
|
285
307
|
const chartData = useMemo3(() => {
|
|
@@ -309,6 +331,7 @@ function DoughnutChart({
|
|
|
309
331
|
callbacks: {
|
|
310
332
|
label: (context) => {
|
|
311
333
|
const val = context.parsed;
|
|
334
|
+
if (val === null) return `${context.label}: no value`;
|
|
312
335
|
const percentage = total > 0 ? Math.round(val / total * 100) : 0;
|
|
313
336
|
if (showPercentage) {
|
|
314
337
|
return `${context.label}: ${formatNumber(val)} (${percentage}%)`;
|
|
@@ -325,7 +348,7 @@ function DoughnutChart({
|
|
|
325
348
|
return /* @__PURE__ */ jsx3(
|
|
326
349
|
"div",
|
|
327
350
|
{
|
|
328
|
-
className: `flex items-center justify-center text-
|
|
351
|
+
className: `flex items-center justify-center text-muted-foreground ${className ?? ""}`,
|
|
329
352
|
style: { height },
|
|
330
353
|
children: emptyMessage
|
|
331
354
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -1703,6 +1703,12 @@ declare const Container: React.ForwardRefExoticComponent<ContainerProps & React.
|
|
|
1703
1703
|
* The shell provides the structural frame (sidebar, header, breadcrumb).
|
|
1704
1704
|
* PageContent provides the content padding every page needs.
|
|
1705
1705
|
*
|
|
1706
|
+
* #6254 — the children are spaced by a flex column's `gap`, never by
|
|
1707
|
+
* `space-y-*`: that margin sits on each direct child, and a generated page
|
|
1708
|
+
* wraps each state's sections in `<div className="contents">`, which has no
|
|
1709
|
+
* box to carry it (the page header sat flush on the card). A flex gap spaces
|
|
1710
|
+
* the items a `display: contents` child lays out, as it spaces its own.
|
|
1711
|
+
*
|
|
1706
1712
|
* Usage:
|
|
1707
1713
|
* import { PageContent } from '@caqophony/ui';
|
|
1708
1714
|
* <PageContent>
|
|
@@ -1714,7 +1720,7 @@ declare const Container: React.ForwardRefExoticComponent<ContainerProps & React.
|
|
|
1714
1720
|
*/
|
|
1715
1721
|
|
|
1716
1722
|
interface PageContentProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
1717
|
-
/** Vertical gap between
|
|
1723
|
+
/** Vertical gap between the sections. Default: 'md' (gap-6) */
|
|
1718
1724
|
gap?: 'sm' | 'md' | 'lg' | 'none';
|
|
1719
1725
|
/** Whether to include page-level padding. Default: true */
|
|
1720
1726
|
padded?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -112,7 +112,7 @@ var CardHeader = React2.forwardRef(({ className, ...props }, ref) => /* @__PURE_
|
|
|
112
112
|
"div",
|
|
113
113
|
{
|
|
114
114
|
ref,
|
|
115
|
-
className: cn("flex flex-col
|
|
115
|
+
className: cn("flex flex-col gap-1.5 p-6", className),
|
|
116
116
|
...props
|
|
117
117
|
}
|
|
118
118
|
));
|
|
@@ -346,7 +346,7 @@ function FormSection({
|
|
|
346
346
|
title && /* @__PURE__ */ jsx6("legend", { className: "text-base font-medium text-foreground dark:text-foreground", children: title }),
|
|
347
347
|
description && /* @__PURE__ */ jsx6("p", { className: "text-sm text-muted-foreground dark:text-muted-foreground", children: description })
|
|
348
348
|
] }),
|
|
349
|
-
/* @__PURE__ */ jsx6("div", { className: "
|
|
349
|
+
/* @__PURE__ */ jsx6("div", { className: "flex flex-col gap-4", children })
|
|
350
350
|
] });
|
|
351
351
|
}
|
|
352
352
|
function FormError({ error, className }) {
|
|
@@ -881,7 +881,14 @@ function AccordionSingle({
|
|
|
881
881
|
value,
|
|
882
882
|
onValueChange: handleValueChange
|
|
883
883
|
},
|
|
884
|
-
children: /* @__PURE__ */ jsx9(
|
|
884
|
+
children: /* @__PURE__ */ jsx9(
|
|
885
|
+
"div",
|
|
886
|
+
{
|
|
887
|
+
className: cn("flex flex-col gap-2", className),
|
|
888
|
+
"data-accordion-root": "",
|
|
889
|
+
children
|
|
890
|
+
}
|
|
891
|
+
)
|
|
885
892
|
}
|
|
886
893
|
);
|
|
887
894
|
}
|
|
@@ -913,7 +920,14 @@ function AccordionMultiple({
|
|
|
913
920
|
value,
|
|
914
921
|
onValueChange: handleValueChange
|
|
915
922
|
},
|
|
916
|
-
children: /* @__PURE__ */ jsx9(
|
|
923
|
+
children: /* @__PURE__ */ jsx9(
|
|
924
|
+
"div",
|
|
925
|
+
{
|
|
926
|
+
className: cn("flex flex-col gap-2", className),
|
|
927
|
+
"data-accordion-root": "",
|
|
928
|
+
children
|
|
929
|
+
}
|
|
930
|
+
)
|
|
917
931
|
}
|
|
918
932
|
);
|
|
919
933
|
}
|
|
@@ -1517,15 +1531,27 @@ function SkeletonRow({ className = "" }) {
|
|
|
1517
1531
|
import * as React8 from "react";
|
|
1518
1532
|
import { jsx as jsx19, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1519
1533
|
var StackedList = React8.forwardRef(
|
|
1520
|
-
({ className, divided = true, density = "default", ...props }, ref) =>
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1534
|
+
({ className, divided = true, density = "default", ...props }, ref) => (
|
|
1535
|
+
// #6255: one grid for the list, an `auto` avatar column and the rest:
|
|
1536
|
+
// each item lays itself on it (`subgrid`), so the widest avatar sets one
|
|
1537
|
+
// column for every row and the titles start at one x. Every child spans
|
|
1538
|
+
// both columns, so a row that is not a StackedListItem stays a full row.
|
|
1539
|
+
// The column gap is the avatar's own margin: a list with no avatar has a
|
|
1540
|
+
// 0px column and no gap.
|
|
1541
|
+
/* @__PURE__ */ jsx19(
|
|
1542
|
+
"ul",
|
|
1543
|
+
{
|
|
1544
|
+
ref,
|
|
1545
|
+
role: "list",
|
|
1546
|
+
className: cn(
|
|
1547
|
+
"grid w-full grid-cols-[auto_minmax(0,1fr)] [&>*]:col-span-full",
|
|
1548
|
+
divided && "divide-y divide-border",
|
|
1549
|
+
className
|
|
1550
|
+
),
|
|
1551
|
+
"data-density": density,
|
|
1552
|
+
...props
|
|
1553
|
+
}
|
|
1554
|
+
)
|
|
1529
1555
|
)
|
|
1530
1556
|
);
|
|
1531
1557
|
StackedList.displayName = "StackedList";
|
|
@@ -1544,37 +1570,39 @@ var StackedListItem = React8.forwardRef(
|
|
|
1544
1570
|
{
|
|
1545
1571
|
ref,
|
|
1546
1572
|
className: cn(
|
|
1547
|
-
"
|
|
1573
|
+
"grid grid-cols-subgrid items-center",
|
|
1548
1574
|
density === "compact" ? "px-3 py-2" : "px-4 py-4",
|
|
1549
1575
|
className
|
|
1550
1576
|
),
|
|
1551
1577
|
...props,
|
|
1552
1578
|
children: [
|
|
1553
|
-
avatar && /* @__PURE__ */ jsx19("div", { className: "
|
|
1554
|
-
/* @__PURE__ */ jsxs13("div", { className: "min-w-0 flex-1", children: [
|
|
1555
|
-
/* @__PURE__ */
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1579
|
+
avatar && /* @__PURE__ */ jsx19("div", { className: "col-start-1 mr-4", children: avatar }),
|
|
1580
|
+
/* @__PURE__ */ jsxs13("div", { className: "col-start-2 flex min-w-0 flex-wrap items-center gap-x-4 gap-y-1", children: [
|
|
1581
|
+
/* @__PURE__ */ jsxs13("div", { className: "min-w-0 grow basis-40", children: [
|
|
1582
|
+
/* @__PURE__ */ jsx19(
|
|
1583
|
+
"p",
|
|
1584
|
+
{
|
|
1585
|
+
className: cn(
|
|
1586
|
+
"break-words font-medium text-foreground",
|
|
1587
|
+
density === "compact" ? "text-sm" : "text-base"
|
|
1588
|
+
),
|
|
1589
|
+
children: title
|
|
1590
|
+
}
|
|
1591
|
+
),
|
|
1592
|
+
description && /* @__PURE__ */ jsx19(
|
|
1593
|
+
"p",
|
|
1594
|
+
{
|
|
1595
|
+
className: cn(
|
|
1596
|
+
"truncate text-muted-foreground",
|
|
1597
|
+
density === "compact" ? "text-xs" : "text-sm"
|
|
1598
|
+
),
|
|
1599
|
+
children: description
|
|
1600
|
+
}
|
|
1601
|
+
)
|
|
1602
|
+
] }),
|
|
1603
|
+
meta && /* @__PURE__ */ jsx19("span", { className: "flex-shrink-0 text-sm text-muted-foreground", children: meta }),
|
|
1604
|
+
action && /* @__PURE__ */ jsx19("div", { className: "flex-shrink-0", children: action })
|
|
1605
|
+
] })
|
|
1578
1606
|
]
|
|
1579
1607
|
}
|
|
1580
1608
|
)
|
|
@@ -3149,7 +3177,7 @@ var FormLayout = React20.forwardRef(
|
|
|
3149
3177
|
{
|
|
3150
3178
|
ref,
|
|
3151
3179
|
className: cn(
|
|
3152
|
-
layout === "stacked" && "
|
|
3180
|
+
layout === "stacked" && "flex flex-col gap-6",
|
|
3153
3181
|
layout === "inline" && "flex flex-wrap items-end gap-4",
|
|
3154
3182
|
layout === "two-column" && "grid grid-cols-1 gap-6 lg:grid-cols-2",
|
|
3155
3183
|
className
|
|
@@ -3170,7 +3198,7 @@ var FormLayoutSection = React20.forwardRef(({ className, title, description, chi
|
|
|
3170
3198
|
title && /* @__PURE__ */ jsx31("h3", { className: "text-base font-semibold text-foreground", children: title }),
|
|
3171
3199
|
description && /* @__PURE__ */ jsx31("p", { className: "mt-1 text-sm text-muted-foreground", children: description })
|
|
3172
3200
|
] }),
|
|
3173
|
-
/* @__PURE__ */ jsx31("div", { className: "
|
|
3201
|
+
/* @__PURE__ */ jsx31("div", { className: "flex flex-col gap-4", children })
|
|
3174
3202
|
]
|
|
3175
3203
|
}
|
|
3176
3204
|
));
|
|
@@ -4161,7 +4189,7 @@ var DescriptionList = React32.forwardRef(({ className, layout = "stacked", ...pr
|
|
|
4161
4189
|
className: cn(
|
|
4162
4190
|
layout === "grid" && "grid grid-cols-1 gap-x-6 gap-y-4 sm:grid-cols-2",
|
|
4163
4191
|
layout === "side-by-side" && "divide-y divide-border",
|
|
4164
|
-
layout === "stacked" && "
|
|
4192
|
+
layout === "stacked" && "flex flex-col gap-4",
|
|
4165
4193
|
className
|
|
4166
4194
|
),
|
|
4167
4195
|
...props
|
|
@@ -4445,9 +4473,9 @@ Divider.displayName = "Divider";
|
|
|
4445
4473
|
import * as React36 from "react";
|
|
4446
4474
|
import { jsx as jsx50 } from "react/jsx-runtime";
|
|
4447
4475
|
var GAP_CLASSES2 = {
|
|
4448
|
-
sm: "
|
|
4449
|
-
md: "
|
|
4450
|
-
lg: "
|
|
4476
|
+
sm: "gap-4",
|
|
4477
|
+
md: "gap-6",
|
|
4478
|
+
lg: "gap-8",
|
|
4451
4479
|
none: ""
|
|
4452
4480
|
};
|
|
4453
4481
|
var PageContent = React36.forwardRef(
|
|
@@ -4455,7 +4483,12 @@ var PageContent = React36.forwardRef(
|
|
|
4455
4483
|
"div",
|
|
4456
4484
|
{
|
|
4457
4485
|
ref,
|
|
4458
|
-
className: cn(
|
|
4486
|
+
className: cn(
|
|
4487
|
+
"flex min-w-0 flex-col",
|
|
4488
|
+
GAP_CLASSES2[gap],
|
|
4489
|
+
padded && "p-4 sm:p-6",
|
|
4490
|
+
className
|
|
4491
|
+
),
|
|
4459
4492
|
...props,
|
|
4460
4493
|
children
|
|
4461
4494
|
}
|