@momoi-labs/kiso-react 0.21.0 → 0.22.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.
- package/dist/bar-gauge.d.ts +7 -1
- package/dist/bar-gauge.js +5 -3
- package/dist/chart-data.d.ts +0 -1
- package/dist/chart-data.js +0 -1
- package/dist/chart-legend.d.ts +16 -1
- package/dist/chart-legend.js +10 -5
- package/dist/chart.d.ts +13 -1
- package/dist/chart.js +14 -6
- package/dist/generated/status-badge.d.ts +18 -0
- package/dist/generated/status-badge.js +2 -0
- package/dist/meter.d.ts +12 -3
- package/dist/meter.js +6 -4
- package/dist/status-badge.d.ts +3 -5
- package/package.json +2 -2
package/dist/bar-gauge.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
declare const defaultLabels: {
|
|
3
|
+
notCollected: string;
|
|
4
|
+
empty: string;
|
|
5
|
+
};
|
|
2
6
|
export type BarGaugeProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
3
7
|
label: string;
|
|
4
8
|
rows: readonly {
|
|
@@ -8,5 +12,7 @@ export type BarGaugeProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
|
8
12
|
}[];
|
|
9
13
|
max: number;
|
|
10
14
|
formatValue?: (value: number) => string;
|
|
15
|
+
labels?: Partial<typeof defaultLabels>;
|
|
11
16
|
};
|
|
12
|
-
export declare function BarGauge({ label, rows, max, formatValue, className, ...props }: BarGaugeProps): React.JSX.Element;
|
|
17
|
+
export declare function BarGauge({ label, rows, max, formatValue, labels, className, ...props }: BarGaugeProps): React.JSX.Element;
|
|
18
|
+
export {};
|
package/dist/bar-gauge.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { clsx as cn } from "clsx";
|
|
3
3
|
import { Meter } from "./meter.js";
|
|
4
|
-
|
|
4
|
+
const defaultLabels = { notCollected: "Not collected", empty: "No measurements." };
|
|
5
|
+
export function BarGauge({ label, rows, max, formatValue = String, labels, className, ...props }) {
|
|
5
6
|
if (!Number.isFinite(max) || max <= 0)
|
|
6
7
|
throw new RangeError("Bar gauge max must be positive.");
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const text = { ...defaultLabels, ...labels };
|
|
9
|
+
return _jsx("div", { ...props, role: "group", "aria-label": label, "data-slot": "bar-gauge", className: cn("bar-gauge", className), children: rows.length ? rows.map(row => _jsx(Meter, { label: row.label, value: row.value, max: max, valueText: row.value !== null && Number.isFinite(row.value) ? formatValue(row.value) : text.notCollected }, row.key))
|
|
10
|
+
: _jsx("p", { children: text.empty }) });
|
|
9
11
|
}
|
package/dist/chart-data.d.ts
CHANGED
|
@@ -17,7 +17,6 @@ export declare function validateChart(data: readonly ChartSample[], series: read
|
|
|
17
17
|
export type ChartSummaryStat = "min" | "max" | "avg" | "current" | "p50" | "p75" | "p90" | "p95" | "p99";
|
|
18
18
|
export declare const chartSummaryStats: readonly ChartSummaryStat[];
|
|
19
19
|
export declare const defaultChartSummary: readonly ChartSummaryStat[];
|
|
20
|
-
export declare const chartSummaryLabel: (stat: ChartSummaryStat) => string;
|
|
21
20
|
export declare function seriesSummary(data: readonly ChartSample[], key: string, stats?: readonly ChartSummaryStat[]): Record<ChartSummaryStat, number | null>;
|
|
22
21
|
export declare const formatChartTime: (timestamp: number) => string;
|
|
23
22
|
export declare const formatChartValue: (value: number) => string;
|
package/dist/chart-data.js
CHANGED
|
@@ -37,7 +37,6 @@ export function validateChart(data, series) {
|
|
|
37
37
|
}
|
|
38
38
|
export const chartSummaryStats = ["min", "max", "avg", "current", "p50", "p75", "p90", "p95", "p99"];
|
|
39
39
|
export const defaultChartSummary = ["min", "max", "avg", "current"];
|
|
40
|
-
export const chartSummaryLabel = (stat) => stat.startsWith("p") ? stat : stat[0].toUpperCase() + stat.slice(1);
|
|
41
40
|
/** Linear interpolation between the closest ranks of sorted values. */
|
|
42
41
|
function percentile(sorted, fraction) {
|
|
43
42
|
const rank = (sorted.length - 1) * fraction;
|
package/dist/chart-legend.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { type ChartSample, type ChartSeries, type ChartSummaryStat } from "./chart-data.js";
|
|
3
3
|
export type { ChartSummaryStat } from "./chart-data.js";
|
|
4
|
+
declare const defaultLabels: {
|
|
5
|
+
series: string;
|
|
6
|
+
current: string;
|
|
7
|
+
notCollected: string;
|
|
8
|
+
min: string;
|
|
9
|
+
max: string;
|
|
10
|
+
avg: string;
|
|
11
|
+
p50: string;
|
|
12
|
+
p75: string;
|
|
13
|
+
p90: string;
|
|
14
|
+
p95: string;
|
|
15
|
+
p99: string;
|
|
16
|
+
};
|
|
4
17
|
export type ChartLegendProps = React.ComponentProps<"div"> & {
|
|
5
18
|
data: readonly ChartSample[];
|
|
6
19
|
series: readonly ChartSeries[];
|
|
@@ -13,9 +26,11 @@ export type ChartLegendProps = React.ComponentProps<"div"> & {
|
|
|
13
26
|
formatTime?: (timestamp: number) => string;
|
|
14
27
|
highlightSeries?: string | null;
|
|
15
28
|
onHighlightSeriesChange?: (key: string | null) => void;
|
|
29
|
+
/** Localizes the fixed text. `current` names both the current column and the inline caption. */
|
|
30
|
+
labels?: Partial<typeof defaultLabels>;
|
|
16
31
|
};
|
|
17
32
|
export declare function ChartSeriesLabel({ series, index }: {
|
|
18
33
|
series: ChartSeries;
|
|
19
34
|
index: number;
|
|
20
35
|
}): React.JSX.Element;
|
|
21
|
-
export declare function ChartLegend({ data, series, label, formatValue, variant, summary: stats, activeTimestamp, formatTime, highlightSeries, onHighlightSeriesChange, className, ...props }: ChartLegendProps): React.JSX.Element;
|
|
36
|
+
export declare function ChartLegend({ data, series, label, formatValue, variant, summary: stats, activeTimestamp, formatTime, highlightSeries, onHighlightSeriesChange, labels, className, ...props }: ChartLegendProps): React.JSX.Element;
|
package/dist/chart-legend.js
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { clsx as cn } from "clsx";
|
|
4
|
-
import { chartColor, chartSlot,
|
|
4
|
+
import { chartColor, chartSlot, defaultChartSummary, formatChartTime, formatChartValue, measured, seriesSummary, validateChart } from "./chart-data.js";
|
|
5
|
+
const defaultLabels = {
|
|
6
|
+
series: "Series", current: "Current", notCollected: "Not collected",
|
|
7
|
+
min: "Min", max: "Max", avg: "Avg", p50: "p50", p75: "p75", p90: "p90", p95: "p95", p99: "p99",
|
|
8
|
+
};
|
|
5
9
|
export function ChartSeriesLabel({ series, index }) {
|
|
6
10
|
const slot = chartSlot(series, index);
|
|
7
11
|
return _jsxs("span", { className: "chart-series-label", children: [_jsx("svg", { className: "chart-series-swatch", "aria-hidden": "true", width: "28", height: "12", viewBox: "0 0 28 12", children: _jsx("path", { d: "M0 6H28", stroke: chartColor(slot), strokeWidth: "2" }) }), _jsxs("span", { children: [slot, ". ", series.label] })] });
|
|
8
12
|
}
|
|
9
|
-
export function ChartLegend({ data, series, label, formatValue = formatChartValue, variant = "table", summary: stats = defaultChartSummary, activeTimestamp, formatTime = formatChartTime, highlightSeries, onHighlightSeriesChange, className, ...props }) {
|
|
13
|
+
export function ChartLegend({ data, series, label, formatValue = formatChartValue, variant = "table", summary: stats = defaultChartSummary, activeTimestamp, formatTime = formatChartTime, highlightSeries, onHighlightSeriesChange, labels, className, ...props }) {
|
|
10
14
|
validateChart(data, series);
|
|
15
|
+
const text = { ...defaultLabels, ...labels };
|
|
11
16
|
const seriesLabel = (item, index) => onHighlightSeriesChange
|
|
12
17
|
? _jsx("button", { type: "button", className: "chart-series-button", "aria-pressed": highlightSeries === item.key, onClick: () => onHighlightSeriesChange(highlightSeries === item.key ? null : item.key), children: _jsx(ChartSeriesLabel, { series: item, index: index }) })
|
|
13
18
|
: _jsx(ChartSeriesLabel, { series: item, index: index });
|
|
14
19
|
if (variant !== "table") {
|
|
15
20
|
const sample = activeTimestamp == null ? data.at(-1) : data.find(item => item.timestamp === activeTimestamp);
|
|
16
21
|
return _jsxs("div", { ...props, "data-slot": "chart-legend", "data-variant": variant, className: cn("chart-legend", `chart-legend-${variant}`, className), "aria-label": label, "aria-live": variant === "sidebar" ? "polite" : undefined, children: [_jsx("span", { className: "chart-legend-caption", children: variant === "sidebar" && activeTimestamp != null
|
|
17
|
-
? formatTime(activeTimestamp) :
|
|
22
|
+
? formatTime(activeTimestamp) : text.current }), _jsx("dl", { children: series.map((item, index) => _jsxs("div", { children: [_jsx("dt", { children: seriesLabel(item, index) }), _jsx("dd", { children: measured(sample?.values[item.key]) ? formatValue(sample.values[item.key]) : text.notCollected })] }, item.key)) })] });
|
|
18
23
|
}
|
|
19
|
-
return _jsx("div", { ...props, "data-slot": "chart-legend", "data-variant": "table", className: cn("chart-table-scroll", className), children: _jsxs("table", { className: "chart-table", children: [_jsx("caption", { children: label }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children:
|
|
24
|
+
return _jsx("div", { ...props, "data-slot": "chart-legend", "data-variant": "table", className: cn("chart-table-scroll", className), children: _jsxs("table", { className: "chart-table", children: [_jsx("caption", { children: label }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: text.series }), stats.map(stat => _jsx("th", { scope: "col", children: text[stat] }, stat))] }) }), _jsx("tbody", { children: series.map((item, index) => {
|
|
20
25
|
const summary = seriesSummary(data, item.key, stats);
|
|
21
|
-
return _jsxs("tr", { children: [_jsx("th", { scope: "row", children: seriesLabel(item, index) }), stats.map(stat => _jsx("td", { children: summary[stat] === null ?
|
|
26
|
+
return _jsxs("tr", { children: [_jsx("th", { scope: "row", children: seriesLabel(item, index) }), stats.map(stat => _jsx("td", { children: summary[stat] === null ? text.notCollected : formatValue(summary[stat]) }, stat))] }, item.key);
|
|
22
27
|
}) })] }) });
|
|
23
28
|
}
|
package/dist/chart.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { type ChartLegendProps } from "./chart-legend.js";
|
|
2
3
|
import { type ChartLayout, type ChartLegendPlacement, type ChartTreatmentProps } from "./chart-style.js";
|
|
3
4
|
import { type ChartSample, type ChartSeries, type ChartSummaryStat } from "./chart-data.js";
|
|
4
5
|
import type { TimeRange } from "./time-range-control.js";
|
|
5
6
|
export type { ChartSample, ChartSeries } from "./chart-data.js";
|
|
7
|
+
declare const defaultLabels: {
|
|
8
|
+
notCollected: string;
|
|
9
|
+
empty: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
values: string;
|
|
12
|
+
help: string;
|
|
13
|
+
summary: (label: string) => string;
|
|
14
|
+
samples: (label: string) => string;
|
|
15
|
+
};
|
|
6
16
|
export type ChartProps = Omit<React.ComponentProps<"figure">, "children"> & {
|
|
7
17
|
data: readonly ChartSample[];
|
|
8
18
|
series: readonly ChartSeries[];
|
|
@@ -27,5 +37,7 @@ export type ChartProps = Omit<React.ComponentProps<"figure">, "children"> & {
|
|
|
27
37
|
/** Drag across the plot with a mouse or pen to select samples from one
|
|
28
38
|
timestamp to another. TimeRangeControl stays the keyboard and touch path. */
|
|
29
39
|
onRangeSelect?: (range: TimeRange) => void;
|
|
40
|
+
/** Localizes the fixed text. Chart passes the legend's keys on to ChartLegend. */
|
|
41
|
+
labels?: Partial<typeof defaultLabels> & NonNullable<ChartLegendProps["labels"]>;
|
|
30
42
|
} & ChartTreatmentProps;
|
|
31
|
-
export declare function Chart({ data, series, label, variant, layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime, formatValue, min, max, onRangeSelect, chartStyle, chartLine, chartFill, ref, className, onKeyDown, ...props }: ChartProps): React.JSX.Element;
|
|
43
|
+
export declare function Chart({ data, series, label, variant, layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime, formatValue, min, max, onRangeSelect, labels, chartStyle, chartLine, chartFill, ref, className, onKeyDown, ...props }: ChartProps): React.JSX.Element;
|
package/dist/chart.js
CHANGED
|
@@ -9,8 +9,16 @@ import { ChartDot, ChartPattern, pixelCurve, useChartPresentation, useChartStyle
|
|
|
9
9
|
import { useChartFill } from "./chart-fill.js";
|
|
10
10
|
import { chartPinned, clearChartPin, setChartHover, toggleChartPin, useChartSync } from "./chart-sync.js";
|
|
11
11
|
import { chartColor, chartSlot, formatChartTime, formatChartValue, measured, validateChart } from "./chart-data.js";
|
|
12
|
-
|
|
12
|
+
const defaultLabels = {
|
|
13
|
+
notCollected: "Not collected", empty: "No collected samples in this window.",
|
|
14
|
+
timestamp: "Timestamp", values: "View exact values",
|
|
15
|
+
help: "Focus the chart and use Left and Right to inspect samples. Press Enter to mark the inspected sample in every synchronized chart, and Escape to clear it. Select a series in the legend to highlight it. Exact values are available below.",
|
|
16
|
+
summary: (label) => `${label}: summary`,
|
|
17
|
+
samples: (label) => `${label}: collected samples, timestamps in UTC`,
|
|
18
|
+
};
|
|
19
|
+
export function Chart({ data, series, label, variant = "line", layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime = formatChartTime, formatValue = formatChartValue, min, max, onRangeSelect, labels, chartStyle, chartLine, chartFill, ref, className, onKeyDown, ...props }) {
|
|
13
20
|
const id = React.useId();
|
|
21
|
+
const text = { ...defaultLabels, ...labels };
|
|
14
22
|
const frame = React.useRef(null);
|
|
15
23
|
const { line, fill } = useChartStyle(frame, { chartStyle, chartLine, chartFill });
|
|
16
24
|
const presentation = useChartPresentation(frame, layoutProp, legendProp);
|
|
@@ -73,7 +81,7 @@ export function Chart({ data, series, label, variant = "line", layout: layoutPro
|
|
|
73
81
|
return { timestamp: sample.timestamp, values: series.map(item => !gap && measured(sample.values[item.key]) ? sample.values[item.key] : null) };
|
|
74
82
|
});
|
|
75
83
|
const hasData = plot.some(sample => sample.values.some(measured));
|
|
76
|
-
const displayValue = (value) => measured(value) ? formatValue(value) :
|
|
84
|
+
const displayValue = (value) => measured(value) ? formatValue(value) : text.notCollected;
|
|
77
85
|
const known = plot.flatMap(sample => sample.values).filter(measured);
|
|
78
86
|
let splitMin = min ?? Math.min(0, ...known);
|
|
79
87
|
let splitMax = max ?? Math.max(0, ...known);
|
|
@@ -159,8 +167,8 @@ export function Chart({ data, series, label, variant = "line", layout: layoutPro
|
|
|
159
167
|
? _jsx(Area, { ...common, type: curve, stackId: variant === "stacked-area" ? "total" : undefined, fill: textured ? `url(#${id}-fill-${index})` : chartColor(slot), fillOpacity: dimmed ? 0.06 : 0.2 }, item.key)
|
|
160
168
|
: _jsx(Line, { ...common, type: curve }, item.key);
|
|
161
169
|
}), _jsx(ChartSyncMarker, { group: group, source: source, plot: plot, data: data, series: series, indices: indices, stacked: variant === "stacked-area", line: line, highlighted: highlighted, pick: !lane || indices[0] === 0 ? pick : undefined, readout: legend !== "sidebar" && (!lane || indices[0] === 0), formatTime: formatTime, displayValue: displayValue })] }) }), selectRange && _jsx("div", { className: "chart-range-band", hidden: true, "aria-hidden": "true" })] });
|
|
162
|
-
const legendProps = { data, series, label:
|
|
163
|
-
highlightSeries: highlighted, onHighlightSeriesChange: highlight };
|
|
170
|
+
const legendProps = { data, series, label: text.summary(label), variant: legend, summary, formatValue, formatTime,
|
|
171
|
+
highlightSeries: highlighted, onHighlightSeriesChange: highlight, labels };
|
|
164
172
|
// Only a sidebar follows the inspected timestamp, so only it subscribes.
|
|
165
173
|
const legendContent = legend === "sidebar"
|
|
166
174
|
? _jsx(ChartSidebarLegend, { group: group, ...legendProps })
|
|
@@ -184,8 +192,8 @@ export function Chart({ data, series, label, variant = "line", layout: layoutPro
|
|
|
184
192
|
event.preventDefault();
|
|
185
193
|
toggleChartPin(group, inspected.current);
|
|
186
194
|
}
|
|
187
|
-
}, children: [_jsx("figcaption", { id: `${id}-title`, className: "t-h3", children: label }), _jsx("p", { id: `${id}-help`, className: "chart-help", children:
|
|
188
|
-
: _jsx("div", { className: "chart-empty hatch", style: { minHeight: height }, children:
|
|
195
|
+
}, children: [_jsx("figcaption", { id: `${id}-title`, className: "t-h3", children: label }), _jsx("p", { id: `${id}-help`, className: "chart-help", children: text.help }), _jsxs("div", { className: "chart-body", children: [_jsx("div", { className: "chart-plots", children: hasData ? layout === "split" ? series.map((item, index) => _jsxs("div", { className: "chart-lane", children: [_jsxs("div", { className: "chart-lane-heading", children: [_jsx(ChartSeriesLabel, { series: item, index: index }), _jsx("span", { children: displayValue(data.at(-1)?.values[item.key]) })] }), renderPlot([index], item)] }, item.key)) : renderPlot(series.map((_, index) => index))
|
|
196
|
+
: _jsx("div", { className: "chart-empty hatch", style: { minHeight: height }, children: text.empty }) }), legend === "sidebar" && legendContent] }), legend !== "sidebar" && legendContent, _jsxs("details", { className: "disclosure chart-values", children: [_jsx("summary", { children: text.values }), _jsx("div", { className: "chart-table-scroll", children: _jsxs("table", { className: "chart-table", children: [_jsx("caption", { children: text.samples(label) }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: text.timestamp }), series.map(item => _jsx("th", { scope: "col", children: item.label }, item.key))] }) }), _jsx("tbody", { children: data.map(sample => _jsxs("tr", { children: [_jsx("th", { scope: "row", children: formatChartTime(sample.timestamp) }), series.map(item => _jsx("td", { children: measured(sample.values[item.key]) ? String(sample.values[item.key]) : text.notCollected }, item.key))] }, sample.timestamp)) })] }) })] })] });
|
|
189
197
|
}
|
|
190
198
|
// Observe Recharts' synchronized tooltip state after render. This keeps the
|
|
191
199
|
// sidebar on the same timestamp for mouse, keyboard, touch, and sibling panels.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The state of one record: a mark and a label. The label always names the
|
|
3
|
+
* state, so color never carries it alone.
|
|
4
|
+
*/
|
|
5
|
+
export type StatusBadgeSpec = {
|
|
6
|
+
tone: StatusTone;
|
|
7
|
+
/**
|
|
8
|
+
* Work is going, such as a build. A thing that is merely up holds
|
|
9
|
+
* still.
|
|
10
|
+
*/
|
|
11
|
+
pulse?: boolean;
|
|
12
|
+
label: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Green is alive, red is failed, neutral is what is not happening. No
|
|
16
|
+
* fourth color: a status reads like a light on a device.
|
|
17
|
+
*/
|
|
18
|
+
export type StatusTone = "success" | "danger" | "neutral";
|
package/dist/meter.d.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
declare const defaultMeterLabels: {
|
|
3
|
+
notCollected: string;
|
|
4
|
+
};
|
|
5
|
+
declare const defaultProgressLabels: {
|
|
6
|
+
inProgress: string;
|
|
7
|
+
};
|
|
2
8
|
export type MeterProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
3
9
|
label: string;
|
|
4
10
|
value: number | null;
|
|
5
11
|
min?: number;
|
|
6
12
|
max?: number;
|
|
7
13
|
valueText?: string;
|
|
14
|
+
labels?: Partial<typeof defaultMeterLabels>;
|
|
8
15
|
};
|
|
9
|
-
export declare function Meter({ label, value, min, max, valueText, className, ...props }: MeterProps): React.JSX.Element;
|
|
10
|
-
export type ProgressProps = Omit<MeterProps, "min" | "value"> & {
|
|
16
|
+
export declare function Meter({ label, value, min, max, valueText, labels, className, ...props }: MeterProps): React.JSX.Element;
|
|
17
|
+
export type ProgressProps = Omit<MeterProps, "min" | "value" | "labels"> & {
|
|
11
18
|
value?: number | null;
|
|
19
|
+
labels?: Partial<typeof defaultProgressLabels>;
|
|
12
20
|
};
|
|
13
|
-
export declare function Progress({ label, value, max, valueText, className, ...props }: ProgressProps): React.JSX.Element;
|
|
21
|
+
export declare function Progress({ label, value, max, valueText, labels, className, ...props }: ProgressProps): React.JSX.Element;
|
|
22
|
+
export {};
|
package/dist/meter.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { clsx as cn } from "clsx";
|
|
3
|
-
|
|
3
|
+
const defaultMeterLabels = { notCollected: "Not collected" };
|
|
4
|
+
const defaultProgressLabels = { inProgress: "In progress" };
|
|
5
|
+
export function Meter({ label, value, min = 0, max = 100, valueText, labels, className, ...props }) {
|
|
4
6
|
if (!Number.isFinite(min) || !Number.isFinite(max) || max <= min)
|
|
5
7
|
throw new RangeError("Meter max must exceed min.");
|
|
6
8
|
const known = value !== null && Number.isFinite(value);
|
|
7
9
|
const bounded = known ? Math.min(max, Math.max(min, value)) : undefined;
|
|
8
|
-
const text = valueText ?? (known ? `${value} / ${max}` :
|
|
10
|
+
const text = valueText ?? (known ? `${value} / ${max}` : { ...defaultMeterLabels, ...labels }.notCollected);
|
|
9
11
|
return _jsxs("div", { ...props, "data-slot": "meter", className: cn("meter", className), children: [_jsxs("div", { className: "meter-label", children: [_jsx("span", { children: label }), _jsx("span", { children: text })] }), _jsx("div", { role: known ? "meter" : undefined, "aria-label": label, "aria-valuemin": known ? min : undefined, "aria-valuemax": known ? max : undefined, "aria-valuenow": bounded, "aria-valuetext": known ? text : undefined, className: cn("meter-track", !known && "hatch"), children: bounded !== undefined && _jsx("span", { style: { width: `${(bounded - min) / (max - min) * 100}%` } }) })] });
|
|
10
12
|
}
|
|
11
|
-
export function Progress({ label, value, max = 100, valueText, className, ...props }) {
|
|
13
|
+
export function Progress({ label, value, max = 100, valueText, labels, className, ...props }) {
|
|
12
14
|
if (!Number.isFinite(max) || max <= 0)
|
|
13
15
|
throw new RangeError("Progress max must be positive.");
|
|
14
16
|
const known = value != null && Number.isFinite(value);
|
|
15
|
-
const text = valueText ?? (known ? `${value} / ${max}` :
|
|
17
|
+
const text = valueText ?? (known ? `${value} / ${max}` : { ...defaultProgressLabels, ...labels }.inProgress);
|
|
16
18
|
return _jsxs("div", { ...props, "data-slot": "progress", className: cn("meter", className), children: [_jsxs("div", { className: "meter-label", children: [_jsx("span", { children: label }), _jsx("span", { children: text })] }), _jsx("div", { role: "progressbar", "aria-label": label, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuenow": known ? Math.min(max, Math.max(0, value)) : undefined, "aria-valuetext": text, className: cn("meter-track", !known && "hatch"), children: known && _jsx("span", { style: { width: `${Math.min(1, Math.max(0, value / max)) * 100}%` } }) })] });
|
|
17
19
|
}
|
package/dist/status-badge.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { Badge } from "./badge.js";
|
|
3
|
-
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
pulse?: boolean;
|
|
7
|
-
};
|
|
3
|
+
import type { StatusBadgeSpec, StatusTone } from "./generated/status-badge.js";
|
|
4
|
+
export type { StatusTone };
|
|
5
|
+
export type StatusBadgeProps = Omit<React.ComponentProps<typeof Badge>, "variant" | "asChild"> & Omit<StatusBadgeSpec, "label">;
|
|
8
6
|
export declare function StatusBadge({ tone, pulse, children, ...props }: StatusBadgeProps): React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momoi-labs/kiso-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Kiso React components built with shadcn/ui and Radix",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"prepack": "npm run build"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@momoi-labs/kiso": "^0.
|
|
35
|
+
"@momoi-labs/kiso": "^1.0.0",
|
|
36
36
|
"class-variance-authority": "0.7.1",
|
|
37
37
|
"clsx": "2.1.1",
|
|
38
38
|
"radix-ui": "1.6.7",
|