@caqophony/ui 0.9.2 → 0.9.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 +11 -2
- package/dist/charts.js +19 -6
- package/dist/{chunk-K2B226HX.js → chunk-A3GODQ6C.js} +2 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.js +1 -1
- package/dist/marketing.js +1 -1
- package/package.json +1 -1
package/dist/charts.d.mts
CHANGED
|
@@ -40,8 +40,13 @@ interface LineChartProps extends BaseChartProps {
|
|
|
40
40
|
/** Date format for labels */
|
|
41
41
|
dateFormat?: Intl.DateTimeFormatOptions;
|
|
42
42
|
}
|
|
43
|
+
interface ChartValueUnit {
|
|
44
|
+
kind: 'percent';
|
|
45
|
+
scale: 1 | 100;
|
|
46
|
+
}
|
|
43
47
|
interface BarChartProps extends BaseChartProps {
|
|
44
48
|
data: ChartDataPoint[];
|
|
49
|
+
unit?: ChartValueUnit;
|
|
45
50
|
/** Label for the dataset */
|
|
46
51
|
label?: string;
|
|
47
52
|
/** Bar color */
|
|
@@ -60,7 +65,7 @@ type NumberFormatMode = 'compact' | 'full' | 'currency';
|
|
|
60
65
|
|
|
61
66
|
declare function LineChart({ data, label, secondaryLabel, color, secondaryColor, fill, showLegend, height, emptyMessage, dateFormat, className, }: LineChartProps): react_jsx_runtime.JSX.Element;
|
|
62
67
|
|
|
63
|
-
declare function BarChart({ data, label, color, horizontal, showLegend, height, emptyMessage, className, }: BarChartProps): react_jsx_runtime.JSX.Element;
|
|
68
|
+
declare function BarChart({ data, label, color, horizontal, showLegend, height, emptyMessage, className, unit, }: BarChartProps): react_jsx_runtime.JSX.Element;
|
|
64
69
|
|
|
65
70
|
declare function DoughnutChart({ data, colors, showPercentage, showLegend, height, emptyMessage, className, }: DoughnutChartProps): react_jsx_runtime.JSX.Element;
|
|
66
71
|
|
|
@@ -92,6 +97,10 @@ declare function ChartSkeleton({ height, className }: ChartSkeletonProps): react
|
|
|
92
97
|
* Format a number for display in charts (compact: 1K, 1M, etc.)
|
|
93
98
|
*/
|
|
94
99
|
declare function formatNumber(value: number, mode?: NumberFormatMode): string;
|
|
100
|
+
/**
|
|
101
|
+
* Format a chart value in its unit: a plain number compact, a percent as `64.6%`
|
|
102
|
+
*/
|
|
103
|
+
declare function formatValue(value: number, unit?: ChartValueUnit): string;
|
|
95
104
|
/**
|
|
96
105
|
* Format a date for chart labels
|
|
97
106
|
*/
|
|
@@ -114,4 +123,4 @@ declare const CHART_COLORS: {
|
|
|
114
123
|
readonly gray: "rgb(107, 114, 128)";
|
|
115
124
|
};
|
|
116
125
|
|
|
117
|
-
export { BarChart, type BarChartProps, type BaseChartProps, CHART_COLORS, type ChartDataPoint, ChartSkeleton, DoughnutChart, type DoughnutChartProps, LineChart, type LineChartProps, type NumberFormatMode, type TimeSeriesDataPoint, formatDateLabel, formatNumber, generateColors };
|
|
126
|
+
export { BarChart, type BarChartProps, type BaseChartProps, CHART_COLORS, type ChartDataPoint, ChartSkeleton, type ChartValueUnit, DoughnutChart, type DoughnutChartProps, LineChart, type LineChartProps, type NumberFormatMode, type TimeSeriesDataPoint, formatDateLabel, formatNumber, formatValue, generateColors };
|
package/dist/charts.js
CHANGED
|
@@ -25,6 +25,14 @@ function formatNumber(value, mode = "compact") {
|
|
|
25
25
|
}
|
|
26
26
|
return value.toString();
|
|
27
27
|
}
|
|
28
|
+
var PERCENT_FRACTION_DIGITS = 1;
|
|
29
|
+
function formatValue(value, unit) {
|
|
30
|
+
if (unit === void 0) return formatNumber(value);
|
|
31
|
+
return new Intl.NumberFormat("en-US", {
|
|
32
|
+
style: "percent",
|
|
33
|
+
maximumFractionDigits: PERCENT_FRACTION_DIGITS
|
|
34
|
+
}).format(unit.scale === 100 ? value / 100 : value);
|
|
35
|
+
}
|
|
28
36
|
function formatDateLabel(date, options = { month: "short", day: "numeric" }) {
|
|
29
37
|
const d = typeof date === "string" ? new Date(date) : date;
|
|
30
38
|
return d.toLocaleDateString("en-US", options);
|
|
@@ -205,8 +213,9 @@ function paletteOf(el) {
|
|
|
205
213
|
grid: read(BAR_TOKENS.grid)
|
|
206
214
|
};
|
|
207
215
|
}
|
|
208
|
-
var valueTick = (tickValue) =>
|
|
209
|
-
typeof tickValue === "number" ? tickValue : parseFloat(String(tickValue))
|
|
216
|
+
var valueTick = (unit) => (tickValue) => formatValue(
|
|
217
|
+
typeof tickValue === "number" ? tickValue : parseFloat(String(tickValue)),
|
|
218
|
+
unit
|
|
210
219
|
);
|
|
211
220
|
function BarChart({
|
|
212
221
|
data,
|
|
@@ -216,7 +225,8 @@ function BarChart({
|
|
|
216
225
|
showLegend = false,
|
|
217
226
|
height = 256,
|
|
218
227
|
emptyMessage = "No data available",
|
|
219
|
-
className
|
|
228
|
+
className,
|
|
229
|
+
unit
|
|
220
230
|
}) {
|
|
221
231
|
const box = useRef(null);
|
|
222
232
|
const [palette, setPalette] = useState(null);
|
|
@@ -239,10 +249,12 @@ function BarChart({
|
|
|
239
249
|
]
|
|
240
250
|
};
|
|
241
251
|
}, [data, label, color, palette]);
|
|
252
|
+
const scale = unit?.scale;
|
|
242
253
|
const options = useMemo2(() => {
|
|
254
|
+
const valueUnit = scale === void 0 ? void 0 : { kind: "percent", scale };
|
|
243
255
|
const valueAxis = {
|
|
244
256
|
beginAtZero: true,
|
|
245
|
-
ticks: { callback: valueTick, color: palette?.text },
|
|
257
|
+
ticks: { callback: valueTick(valueUnit), color: palette?.text },
|
|
246
258
|
grid: { color: palette?.grid },
|
|
247
259
|
border: { display: false }
|
|
248
260
|
};
|
|
@@ -265,14 +277,14 @@ function BarChart({
|
|
|
265
277
|
callbacks: {
|
|
266
278
|
label: (context) => {
|
|
267
279
|
const val = horizontal ? context.parsed.x : context.parsed.y;
|
|
268
|
-
return val === null ? `${context.dataset.label}: no value` : `${context.dataset.label}: ${
|
|
280
|
+
return val === null ? `${context.dataset.label}: no value` : `${context.dataset.label}: ${formatValue(val, valueUnit)}`;
|
|
269
281
|
}
|
|
270
282
|
}
|
|
271
283
|
}
|
|
272
284
|
},
|
|
273
285
|
scales: horizontal ? { x: valueAxis, y: categoryAxis } : { x: categoryAxis, y: valueAxis }
|
|
274
286
|
};
|
|
275
|
-
}, [horizontal, showLegend, palette]);
|
|
287
|
+
}, [horizontal, showLegend, palette, scale]);
|
|
276
288
|
if (data.length === 0) {
|
|
277
289
|
return /* @__PURE__ */ jsx2(
|
|
278
290
|
"div",
|
|
@@ -386,5 +398,6 @@ export {
|
|
|
386
398
|
LineChart,
|
|
387
399
|
formatDateLabel,
|
|
388
400
|
formatNumber,
|
|
401
|
+
formatValue,
|
|
389
402
|
generateColors
|
|
390
403
|
};
|
|
@@ -49,6 +49,8 @@ var buttonVariants = cva(
|
|
|
49
49
|
outline: "border border-border dark:border-border bg-background dark:bg-background text-foreground dark:text-foreground shadow-sm hover:bg-muted dark:hover:bg-muted hover:text-foreground dark:hover:text-foreground",
|
|
50
50
|
secondary: "bg-muted dark:bg-muted text-muted-foreground dark:text-muted-foreground shadow-sm hover:bg-muted/80 dark:hover:bg-muted/80",
|
|
51
51
|
ghost: "hover:bg-muted dark:hover:bg-muted hover:text-foreground dark:hover:text-foreground",
|
|
52
|
+
// #6362: a quiet destructive action (a page's delete): error-toned text, no fill until hover. The solid `destructive` is kept for the confirm's own button.
|
|
53
|
+
"destructive-ghost": "text-intent-error-foreground hover:bg-intent-error hover:text-intent-error-foreground",
|
|
52
54
|
link: "text-primary-text dark:text-primary-text underline-offset-4 hover:underline"
|
|
53
55
|
},
|
|
54
56
|
size: {
|
package/dist/index.d.mts
CHANGED
|
@@ -12,7 +12,7 @@ import { LucideIcon } from 'lucide-react';
|
|
|
12
12
|
import { ClassValue } from 'clsx';
|
|
13
13
|
|
|
14
14
|
declare const buttonVariants: (props?: ({
|
|
15
|
-
variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
|
|
15
|
+
variant?: "link" | "default" | "destructive" | "outline" | "secondary" | "ghost" | "destructive-ghost" | null | undefined;
|
|
16
16
|
size?: "icon" | "default" | "sm" | "lg" | null | undefined;
|
|
17
17
|
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
18
18
|
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
package/dist/index.js
CHANGED
package/dist/marketing.js
CHANGED