@schemavaults/ui 0.108.0 → 0.109.1

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.
Files changed (67) hide show
  1. package/dist/components/hooks/index.d.ts +2 -0
  2. package/dist/components/hooks/index.js +1 -0
  3. package/dist/components/hooks/index.js.map +1 -1
  4. package/dist/components/hooks/use-measured-width.d.ts +33 -0
  5. package/dist/components/hooks/use-measured-width.js +61 -0
  6. package/dist/components/hooks/use-measured-width.js.map +1 -0
  7. package/dist/components/ui/bar-chart/bar-chart.d.ts +71 -13
  8. package/dist/components/ui/bar-chart/bar-chart.js +263 -96
  9. package/dist/components/ui/bar-chart/bar-chart.js.map +1 -1
  10. package/dist/components/ui/bar-list/bar-list.d.ts +63 -0
  11. package/dist/components/ui/bar-list/bar-list.js +39 -0
  12. package/dist/components/ui/bar-list/bar-list.js.map +1 -0
  13. package/dist/components/ui/bar-list/index.d.ts +2 -0
  14. package/dist/components/ui/bar-list/index.js +2 -0
  15. package/dist/components/ui/bar-list/index.js.map +1 -0
  16. package/dist/components/ui/chart-primitives/chart-colors.d.ts +69 -0
  17. package/dist/components/ui/chart-primitives/chart-colors.js +201 -0
  18. package/dist/components/ui/chart-primitives/chart-colors.js.map +1 -0
  19. package/dist/components/ui/chart-primitives/chart-data-table.d.ts +20 -0
  20. package/dist/components/ui/chart-primitives/chart-data-table.js +11 -0
  21. package/dist/components/ui/chart-primitives/chart-data-table.js.map +1 -0
  22. package/dist/components/ui/chart-primitives/chart-format.d.ts +12 -0
  23. package/dist/components/ui/chart-primitives/chart-format.js +40 -0
  24. package/dist/components/ui/chart-primitives/chart-format.js.map +1 -0
  25. package/dist/components/ui/chart-primitives/chart-legend.d.ts +20 -0
  26. package/dist/components/ui/chart-primitives/chart-legend.js +22 -0
  27. package/dist/components/ui/chart-primitives/chart-legend.js.map +1 -0
  28. package/dist/components/ui/chart-primitives/chart-scale.d.ts +59 -0
  29. package/dist/components/ui/chart-primitives/chart-scale.js +178 -0
  30. package/dist/components/ui/chart-primitives/chart-scale.js.map +1 -0
  31. package/dist/components/ui/chart-primitives/chart-tooltip.d.ts +67 -0
  32. package/dist/components/ui/chart-primitives/chart-tooltip.js +57 -0
  33. package/dist/components/ui/chart-primitives/chart-tooltip.js.map +1 -0
  34. package/dist/components/ui/chart-primitives/index.d.ts +12 -0
  35. package/dist/components/ui/chart-primitives/index.js +7 -0
  36. package/dist/components/ui/chart-primitives/index.js.map +1 -0
  37. package/dist/components/ui/chart-primitives/responsive-chart.d.ts +26 -0
  38. package/dist/components/ui/chart-primitives/responsive-chart.js +25 -0
  39. package/dist/components/ui/chart-primitives/responsive-chart.js.map +1 -0
  40. package/dist/components/ui/chart-primitives/use-chart-width.d.ts +30 -0
  41. package/dist/components/ui/chart-primitives/use-chart-width.js +56 -0
  42. package/dist/components/ui/chart-primitives/use-chart-width.js.map +1 -0
  43. package/dist/components/ui/histogram/bin-values.d.ts +53 -0
  44. package/dist/components/ui/histogram/bin-values.js +137 -0
  45. package/dist/components/ui/histogram/bin-values.js.map +1 -0
  46. package/dist/components/ui/histogram/histogram.d.ts +76 -0
  47. package/dist/components/ui/histogram/histogram.js +149 -0
  48. package/dist/components/ui/histogram/histogram.js.map +1 -0
  49. package/dist/components/ui/histogram/index.d.ts +4 -0
  50. package/dist/components/ui/histogram/index.js +3 -0
  51. package/dist/components/ui/histogram/index.js.map +1 -0
  52. package/dist/components/ui/index.d.ts +6 -0
  53. package/dist/components/ui/index.js +3 -0
  54. package/dist/components/ui/index.js.map +1 -1
  55. package/dist/components/ui/line-chart/line-chart.d.ts +104 -20
  56. package/dist/components/ui/line-chart/line-chart.js +290 -151
  57. package/dist/components/ui/line-chart/line-chart.js.map +1 -1
  58. package/dist/components/ui/pie-chart/pie-chart.d.ts +35 -7
  59. package/dist/components/ui/pie-chart/pie-chart.js +200 -88
  60. package/dist/components/ui/pie-chart/pie-chart.js.map +1 -1
  61. package/dist/components/ui/scatter-plot/scatter-plot.d.ts +123 -21
  62. package/dist/components/ui/scatter-plot/scatter-plot.js +507 -243
  63. package/dist/components/ui/scatter-plot/scatter-plot.js.map +1 -1
  64. package/dist/components/ui/sparkline/sparkline.d.ts +15 -5
  65. package/dist/components/ui/sparkline/sparkline.js +21 -37
  66. package/dist/components/ui/sparkline/sparkline.js.map +1 -1
  67. package/package.json +3 -2
@@ -2,3 +2,5 @@ export * from "./use-toast";
2
2
  export type * from "./use-toast";
3
3
  export * from "./use-mobile";
4
4
  export type * from "./use-mobile";
5
+ export * from "./use-measured-width";
6
+ export type * from "./use-measured-width";
@@ -1,3 +1,4 @@
1
1
  export * from "./use-toast";
2
2
  export * from "./use-mobile";
3
+ export * from "./use-measured-width";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAG5B,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAG5B,cAAc,cAAc,CAAC;AAG7B,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { type RefCallback } from "react";
2
+ export interface UseMeasuredWidthResult<T extends HTMLElement> {
3
+ /** Attach to the element whose width should be tracked. */
4
+ ref: RefCallback<T>;
5
+ /**
6
+ * The element's content-box width in whole pixels (rounded down, so a chart
7
+ * drawn at this width never overflows it), or `fallbackWidth` until the
8
+ * first measurement.
9
+ */
10
+ width: number;
11
+ /**
12
+ * `false` for the server render and the first client render, `true` once
13
+ * the element has been laid out with a non-zero width. Render a placeholder
14
+ * until then instead of drawing at the fallback width.
15
+ */
16
+ isMeasured: boolean;
17
+ }
18
+ /**
19
+ * Tracks an element's rendered width with a `ResizeObserver`, for drawing an
20
+ * SVG chart at the width of its container.
21
+ *
22
+ * The server render and the first client render both report
23
+ * `fallbackWidth` with `isMeasured: false`, so hydration stays clean; the
24
+ * element is then measured in a layout effect, before the browser paints,
25
+ * and again whenever it resizes. A width of `0` (an element inside a
26
+ * `display: none` tab, say) is ignored and the last good width kept.
27
+ *
28
+ * The element must get its width from its container (a block, `w-full`),
29
+ * not from its content, or it cannot shrink below what it draws. The chart
30
+ * components also set `contain: inline-size` on it for that reason.
31
+ */
32
+ export declare function useMeasuredWidth<T extends HTMLElement = HTMLDivElement>(fallbackWidth?: number): UseMeasuredWidthResult<T>;
33
+ export default useMeasuredWidth;
@@ -0,0 +1,61 @@
1
+ "use client";
2
+ import { useCallback, useLayoutEffect, useState } from "react";
3
+ /**
4
+ * The content-box width from layout (`clientWidth` minus padding), which,
5
+ * unlike `getBoundingClientRect()`, ignores CSS transforms: a chart inside a
6
+ * dialog that is still zooming in measures its real width, not 95% of it.
7
+ */
8
+ function contentBoxWidth(element) {
9
+ const style = window.getComputedStyle(element);
10
+ const padding = parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
11
+ return element.clientWidth - (Number.isFinite(padding) ? padding : 0);
12
+ }
13
+ /**
14
+ * Tracks an element's rendered width with a `ResizeObserver`, for drawing an
15
+ * SVG chart at the width of its container.
16
+ *
17
+ * The server render and the first client render both report
18
+ * `fallbackWidth` with `isMeasured: false`, so hydration stays clean; the
19
+ * element is then measured in a layout effect, before the browser paints,
20
+ * and again whenever it resizes. A width of `0` (an element inside a
21
+ * `display: none` tab, say) is ignored and the last good width kept.
22
+ *
23
+ * The element must get its width from its container (a block, `w-full`),
24
+ * not from its content, or it cannot shrink below what it draws. The chart
25
+ * components also set `contain: inline-size` on it for that reason.
26
+ */
27
+ export function useMeasuredWidth(fallbackWidth = 0) {
28
+ const [element, setElement] = useState(null);
29
+ const [measuredWidth, setMeasuredWidth] = useState(null);
30
+ const ref = useCallback((node) => {
31
+ setElement(node);
32
+ }, []);
33
+ useLayoutEffect(() => {
34
+ if (!element)
35
+ return undefined;
36
+ const update = (width) => {
37
+ const whole = Math.floor(width);
38
+ if (whole > 0)
39
+ setMeasuredWidth(whole);
40
+ };
41
+ update(contentBoxWidth(element));
42
+ if (typeof ResizeObserver === "undefined")
43
+ return undefined;
44
+ const observer = new ResizeObserver((entries) => {
45
+ const entry = entries[0];
46
+ if (entry)
47
+ update(entry.contentRect.width);
48
+ });
49
+ observer.observe(element);
50
+ return () => {
51
+ observer.disconnect();
52
+ };
53
+ }, [element]);
54
+ return {
55
+ ref,
56
+ width: measuredWidth ?? fallbackWidth,
57
+ isMeasured: measuredWidth !== null,
58
+ };
59
+ }
60
+ export default useMeasuredWidth;
61
+ //# sourceMappingURL=use-measured-width.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-measured-width.js","sourceRoot":"","sources":["../../../src/components/hooks/use-measured-width.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAoB,MAAM,OAAO,CAAC;AAmBjF;;;;GAIG;AACH,SAAS,eAAe,CAAC,OAAoB;IAC3C,MAAM,KAAK,GAAwB,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACpE,MAAM,OAAO,GACX,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACjE,OAAO,OAAO,CAAC,WAAW,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,gBAAgB,CAC9B,gBAAwB,CAAC;IAEzB,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAW,IAAI,CAAC,CAAC;IACvD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAExE,MAAM,GAAG,GAAmB,WAAW,CAAC,CAAC,IAAc,EAAQ,EAAE;QAC/D,UAAU,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,eAAe,CAAC,GAA6B,EAAE;QAC7C,IAAI,CAAC,OAAO;YAAE,OAAO,SAAS,CAAC;QAE/B,MAAM,MAAM,GAAG,CAAC,KAAa,EAAQ,EAAE;YACrC,MAAM,KAAK,GAAW,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACxC,IAAI,KAAK,GAAG,CAAC;gBAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC;QACzC,CAAC,CAAC;QAEF,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;QAEjC,IAAI,OAAO,cAAc,KAAK,WAAW;YAAE,OAAO,SAAS,CAAC;QAC5D,MAAM,QAAQ,GAAG,IAAI,cAAc,CACjC,CAAC,OAA8B,EAAQ,EAAE;YACvC,MAAM,KAAK,GAAoC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC1D,IAAI,KAAK;gBAAE,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC7C,CAAC,CACF,CAAC;QACF,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC1B,OAAO,GAAS,EAAE;YAChB,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO;QACL,GAAG;QACH,KAAK,EAAE,aAAa,IAAI,aAAa;QACrC,UAAU,EAAE,aAAa,KAAK,IAAI;KACnC,CAAC;AACJ,CAAC;AAED,eAAe,gBAAgB,CAAC"}
@@ -1,11 +1,14 @@
1
1
  import { type VariantProps } from "class-variance-authority";
2
2
  import type { HTMLAttributes, KeyboardEvent, MouseEvent, ReactElement, ReactNode, Ref } from "react";
3
+ import { chartPaintSwatchStyle, type ChartColorId } from "../../ui/chart-primitives/chart-colors";
4
+ import { type ChartWidth } from "../../ui/chart-primitives/use-chart-width";
3
5
  export declare const barChartSizeIds: ["sm", "md", "lg", "xl"];
4
6
  export type BarChartSizeId = (typeof barChartSizeIds)[number];
5
7
  export declare const barChartOrientationIds: ["vertical", "horizontal"];
6
8
  export type BarChartOrientationId = (typeof barChartOrientationIds)[number];
7
- export declare const barChartBarColorIds: ["default", "primary", "positive", "warning", "destructive", "muted"];
8
- export type BarChartBarColorId = (typeof barChartBarColorIds)[number];
9
+ /** Preset bar colours; see `chartColorIds`. */
10
+ export declare const barChartBarColorIds: ["chart-1", "chart-2", "chart-3", "chart-4", "chart-5", "chart-6", "chart-7", "chart-8", "other", "default", "brand", "primary", "positive", "warning", "destructive", "muted"];
11
+ export type BarChartBarColorId = ChartColorId;
9
12
  export declare const barChartVariants: (props?: ({
10
13
  size?: "sm" | "lg" | "xl" | "md" | null | undefined;
11
14
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
@@ -19,14 +22,21 @@ export interface BarChartBar {
19
22
  value: number;
20
23
  /** Human-readable category label rendered along the axis. */
21
24
  label?: string;
22
- /** Preset color id from the chart palette. Ignored if `fill` is provided. */
25
+ /**
26
+ * Preset color for this bar. Defaults to the chart's `color` (slot 1):
27
+ * the bars of one series share one colour.
28
+ */
23
29
  color?: BarChartBarColorId;
24
30
  /**
25
31
  * Override the fill with a raw CSS color (e.g. `"#ff0080"` or
26
- * `"hsl(var(--chart-1))"`). Takes precedence over `color`.
32
+ * `"var(--chart-3)"`). Takes precedence over `color`.
27
33
  */
28
34
  fill?: string;
29
- /** Extra classes applied to this bar's `<rect>`. */
35
+ /**
36
+ * Extra classes applied to this bar's painted shape. The shape doesn't
37
+ * take the pointer (its whole column does), so style hover and focus with
38
+ * `data-[active=true]:` rather than `hover:`.
39
+ */
30
40
  className?: string;
31
41
  /** Fired when this bar is clicked or activated via keyboard. */
32
42
  onClick?: (bar: BarChartBar, event: MouseEvent<SVGRectElement> | KeyboardEvent<SVGRectElement>) => void;
@@ -40,7 +50,14 @@ export interface BarChartValueLabelContext {
40
50
  percentage: number;
41
51
  index: number;
42
52
  }
43
- export interface BarChartProps extends Omit<HTMLAttributes<HTMLDivElement>, "onClick">, VariantProps<typeof barChartVariants> {
53
+ export interface BarChartTooltipContext {
54
+ bar: BarChartBar;
55
+ value: number;
56
+ index: number;
57
+ /** `formatValue(value)`. */
58
+ formattedValue: string;
59
+ }
60
+ export interface BarChartProps extends Omit<HTMLAttributes<HTMLDivElement>, "onClick" | "color">, VariantProps<typeof barChartVariants> {
44
61
  /** Bars to render, in order. */
45
62
  bars: ReadonlyArray<BarChartBar>;
46
63
  /** Accessible label describing what the chart represents. */
@@ -49,20 +66,35 @@ export interface BarChartProps extends Omit<HTMLAttributes<HTMLDivElement>, "onC
49
66
  orientation?: BarChartOrientationId;
50
67
  /**
51
68
  * Upper bound of the value scale. Defaults to the largest bar value (or `1`
52
- * when every bar is `0`). Useful for pinning multiple charts to a shared
53
- * scale.
69
+ * when every bar is `0`), rounded up to a nice tick when `showValueAxis`
70
+ * is on. Useful for pinning multiple charts to a shared scale.
54
71
  */
55
72
  max?: number;
56
- /** Override the rendered canvas width in pixels (defaults are size-aware). */
57
- width?: number;
73
+ /**
74
+ * Canvas width in pixels (defaults are size-aware), or `"auto"` to fill the
75
+ * container and redraw when it resizes. An `"auto"` chart renders an empty
76
+ * placeholder at its height until it has been measured, so the server
77
+ * render carries no pixel width.
78
+ */
79
+ width?: ChartWidth;
58
80
  /** Override the rendered canvas height in pixels (defaults are size-aware). */
59
81
  height?: number;
82
+ /**
83
+ * Colour of every bar that names none of its own. Defaults to `"chart-1"`:
84
+ * one series, one colour.
85
+ */
86
+ color?: BarChartBarColorId;
60
87
  /**
61
88
  * Gap between bars as a fraction of each bar's slot (0–0.9). Defaults to
62
89
  * `0.3`.
63
90
  */
64
91
  barGap?: number;
65
- /** Corner radius applied to the free end of every bar. Defaults to `4`. */
92
+ /**
93
+ * Thickest a bar may get, in pixels. Defaults to `24`; the rest of a wide
94
+ * slot stays air. Pass `Infinity` to fill the slot.
95
+ */
96
+ maxBarThickness?: number;
97
+ /** Corner radius of each bar's free end (the baseline end stays square). Defaults to `4`. */
66
98
  cornerRadius?: number;
67
99
  /** Render the baseline axis line. Defaults to `true`. */
68
100
  showAxis?: boolean;
@@ -71,15 +103,36 @@ export interface BarChartProps extends Omit<HTMLAttributes<HTMLDivElement>, "onC
71
103
  * disables gridlines. Defaults to `0`.
72
104
  */
73
105
  gridLineCount?: number;
106
+ /**
107
+ * Render a value axis: nice tick values (0, 20, 40 …) with hairline
108
+ * gridlines, labelled with `formatValue`. Defaults to `false`.
109
+ */
110
+ showValueAxis?: boolean;
111
+ /** About how many intervals the value axis is split into. Defaults to `4`. */
112
+ valueAxisTickCount?: number;
74
113
  /** Render each bar's category `label` along the axis. Defaults to `true`. */
75
114
  showCategoryLabels?: boolean;
76
115
  /** Render a value label at the free end of each bar. Defaults to `false`. */
77
116
  showValueLabels?: boolean;
117
+ /**
118
+ * Format a value for the value axis, the value labels and the tooltip.
119
+ * Defaults to a thousands-separated number.
120
+ */
121
+ formatValue?: (value: number) => string;
78
122
  /**
79
123
  * Customize the value-label text. Return `null` to skip a bar. Defaults to
80
- * the raw value (`String(value)`).
124
+ * `formatValue(value)`.
81
125
  */
82
126
  valueLabelFormatter?: (context: BarChartValueLabelContext) => string | null;
127
+ /** Replace the hover / focus readout's content. */
128
+ formatTooltip?: (context: BarChartTooltipContext) => ReactNode;
129
+ /** Hide the hover / focus readout. Defaults to `true` (shown). */
130
+ showTooltip?: boolean;
131
+ /**
132
+ * Hold the current render at reduced opacity while new data loads, rather
133
+ * than flashing a skeleton.
134
+ */
135
+ loading?: boolean;
83
136
  /**
84
137
  * Fallback handler invoked for any bar that doesn't have its own `onClick`.
85
138
  * Receives the clicked bar.
@@ -98,8 +151,13 @@ export interface BarChartProps extends Omit<HTMLAttributes<HTMLDivElement>, "onC
98
151
  /** Optional ref forwarded to the wrapper element. */
99
152
  ref?: Ref<HTMLDivElement>;
100
153
  }
101
- declare function BarChart({ bars, label, orientation, max, size, width, height, barGap, cornerRadius, showAxis, gridLineCount, showCategoryLabels, showValueLabels, valueLabelFormatter, onBarClick, children, className, overlayClassName, valueLabelClassName, categoryLabelClassName, axisClassName, ref, ...props }: BarChartProps): ReactElement;
154
+ declare function BarChart({ bars, label, orientation, max, size, width, height, color, barGap, maxBarThickness, cornerRadius, showAxis, gridLineCount, showValueAxis, valueAxisTickCount, showCategoryLabels, showValueLabels, formatValue, valueLabelFormatter, formatTooltip, showTooltip, loading, onBarClick, children, className, style, overlayClassName, valueLabelClassName, categoryLabelClassName, axisClassName, ref, ...props }: BarChartProps): ReactElement;
102
155
  declare namespace BarChart {
103
156
  var displayName: string;
104
157
  }
158
+ /** A legend swatch for a bar colour, e.g. for a legend built next to several bar charts. */
159
+ export declare function barChartSwatchProps(colorId: BarChartBarColorId, fill?: string): {
160
+ className: string | undefined;
161
+ style: ReturnType<typeof chartPaintSwatchStyle>;
162
+ };
105
163
  export { BarChart };