@caqophony/ui 0.6.3 → 0.6.5

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 CHANGED
@@ -8,7 +8,7 @@ export { Chart as ChartJS } from 'chart.js';
8
8
  */
9
9
  interface ChartDataPoint {
10
10
  label: string;
11
- value: number;
11
+ value: number | null;
12
12
  }
13
13
  interface TimeSeriesDataPoint {
14
14
  date: string | Date;
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 = CHART_COLORS.primary,
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 labels = data.map((d) => d.label);
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: colors,
207
- borderColor: colors.map((c) => c.replace("0.8", "1")),
208
- borderWidth: 1
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 ?? 0 : context.parsed.y ?? 0;
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
- x: {
232
- beginAtZero: true,
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-gray-500 ${className ?? ""}`,
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
- () => data.reduce((sum, d) => sum + d.value, 0),
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-gray-500 ${className ?? ""}`,
351
+ className: `flex items-center justify-center text-muted-foreground ${className ?? ""}`,
329
352
  style: { height },
330
353
  children: emptyMessage
331
354
  }
package/dist/index.js CHANGED
@@ -4500,10 +4500,11 @@ PageContent.displayName = "PageContent";
4500
4500
  import * as React37 from "react";
4501
4501
  import { jsx as jsx51, jsxs as jsxs40 } from "react/jsx-runtime";
4502
4502
  var MEDIA_SIZE = {
4503
- sm: "h-8 w-8",
4504
- md: "h-10 w-10",
4505
- lg: "h-12 w-12"
4503
+ sm: "min-h-8 min-w-8",
4504
+ md: "min-h-10 min-w-10",
4505
+ lg: "min-h-12 min-w-12"
4506
4506
  };
4507
+ var MEDIA_SLOT = "flex flex-shrink-0 items-center justify-center";
4507
4508
  var MediaObject = React37.forwardRef(
4508
4509
  ({
4509
4510
  className,
@@ -4527,7 +4528,7 @@ var MediaObject = React37.forwardRef(
4527
4528
  ),
4528
4529
  ...props,
4529
4530
  children: [
4530
- /* @__PURE__ */ jsx51("div", { className: cn("flex-shrink-0", MEDIA_SIZE[mediaSize]), children: media }),
4531
+ /* @__PURE__ */ jsx51("div", { className: cn(MEDIA_SLOT, MEDIA_SIZE[mediaSize]), children: media }),
4531
4532
  /* @__PURE__ */ jsxs40("div", { className: "min-w-0", children: [
4532
4533
  title && /* @__PURE__ */ jsx51("p", { className: "font-medium text-foreground", children: title }),
4533
4534
  description && /* @__PURE__ */ jsx51("p", { className: "text-sm text-muted-foreground", children: description })
@@ -4548,7 +4549,7 @@ var MediaObject = React37.forwardRef(
4548
4549
  ),
4549
4550
  ...props,
4550
4551
  children: [
4551
- /* @__PURE__ */ jsx51("div", { className: cn("flex-shrink-0", MEDIA_SIZE[mediaSize]), children: media }),
4552
+ /* @__PURE__ */ jsx51("div", { className: cn(MEDIA_SLOT, MEDIA_SIZE[mediaSize]), children: media }),
4552
4553
  /* @__PURE__ */ jsxs40("div", { className: "min-w-0 flex-1", children: [
4553
4554
  title && /* @__PURE__ */ jsx51("p", { className: "font-medium text-foreground", children: title }),
4554
4555
  description && /* @__PURE__ */ jsx51("p", { className: "text-sm text-muted-foreground", children: description })
@@ -4597,7 +4598,14 @@ var PageHeading = React38.forwardRef(
4597
4598
  ...props,
4598
4599
  children: [
4599
4600
  /* @__PURE__ */ jsxs41("div", { className: "flex min-w-0 flex-1 flex-col gap-1 sm:basis-80", children: [
4600
- /* @__PURE__ */ jsx52("h1", { className: "break-words text-2xl font-semibold tracking-tight text-foreground sm:text-3xl", children: title }),
4601
+ /* @__PURE__ */ jsx52(
4602
+ "h1",
4603
+ {
4604
+ className: "line-clamp-2 break-words text-2xl font-semibold tracking-tight text-foreground sm:text-3xl",
4605
+ title: typeof title === "string" ? title : void 0,
4606
+ children: title
4607
+ }
4608
+ ),
4601
4609
  description && /* @__PURE__ */ jsx52("p", { className: "break-words text-sm text-muted-foreground sm:text-base", children: description }),
4602
4610
  meta && /* @__PURE__ */ jsx52("div", { className: "mt-2 flex flex-wrap gap-2", children: meta })
4603
4611
  ] }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caqophony/ui",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "Generic, optional React UI reuse library (Gossamer tokens). Centrally maintained by Caqophony.",
5
5
  "license": "MIT",
6
6
  "author": "Caqophony",