@kashi-ui/react 2.11.0 → 2.15.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.
@@ -29,7 +29,7 @@ export function ActivityHeatmap({ data, year = toJalali(new Date()).jy, label, u
29
29
  const box = useRef(null);
30
30
  const [tip, setTip] = useState(null);
31
31
  const name = label ?? H.inYear(unit, n(year));
32
- return (_jsxs("figure", { ref: box, className: cx("k-heatmap", className), style: { margin: 0 }, onPointerLeave: () => setTip(null), children: [_jsx("div", { className: "k-heatmap__scroll", children: _jsxs("div", { role: "img", "aria-label": `${name}: ${num(total)} ${unit}`, children: [_jsx("div", { className: "k-heatmap__months", "aria-hidden": "true", children: monthStarts.map((m) => _jsx("span", { style: { gridColumn: m.col + 1 }, children: m.name }, m.name)) }), _jsxs("div", { className: "k-heatmap__body", "aria-hidden": "true", children: [_jsx("div", { className: "k-heatmap__days", children: H.weekdays.map((w, i) => _jsx("span", { children: w }, i)) }), _jsxs("div", { className: "k-heatmap__grid", onPointerOver: (e) => {
32
+ return (_jsxs("figure", { ref: box, className: cx("k-heatmap", className), style: { margin: 0 }, onPointerLeave: () => setTip(null), children: [_jsx("div", { className: "k-heatmap__scroll", tabIndex: 0, role: "region", "aria-label": name, children: _jsxs("div", { role: "img", "aria-label": `${name}: ${num(total)} ${unit}`, children: [_jsx("div", { className: "k-heatmap__months", "aria-hidden": "true", children: monthStarts.map((m) => _jsx("span", { style: { gridColumn: m.col + 1 }, children: m.name }, m.name)) }), _jsxs("div", { className: "k-heatmap__body", "aria-hidden": "true", children: [_jsx("div", { className: "k-heatmap__days", children: H.weekdays.map((w, i) => _jsx("span", { children: w }, i)) }), _jsxs("div", { className: "k-heatmap__grid", onPointerOver: (e) => {
33
33
  const cell = e.target.closest("[data-i]");
34
34
  if (!cell || !box.current)
35
35
  return setTip(null);
package/dist/Chart.d.ts CHANGED
@@ -5,6 +5,8 @@ export interface TipRow {
5
5
  color?: string;
6
6
  }
7
7
  /** راهنمای شناور مشترک نمودارها؛ x و y نسبت به ظرف نمودار */
8
+ /** هشت رنگ دسته‌ای با ترتیب ثابت (--k-chart-1..8)؛ سری نهم به بعد رنگ خنثی می‌گیرد («سایر») */
9
+ export declare const chartColor: (i: number) => string;
8
10
  export declare function ChartTip({ x, y, title, rows, width }: {
9
11
  x: number;
10
12
  y: number;
package/dist/Chart.js CHANGED
@@ -36,6 +36,8 @@ function niceTicks(max, count = 4) {
36
36
  return Array.from({ length: Math.ceil(max / step) + 1 }, (_, i) => i * step);
37
37
  }
38
38
  /** راهنمای شناور مشترک نمودارها؛ x و y نسبت به ظرف نمودار */
39
+ /** هشت رنگ دسته‌ای با ترتیب ثابت (--k-chart-1..8)؛ سری نهم به بعد رنگ خنثی می‌گیرد («سایر») */
40
+ export const chartColor = (i) => (i < 8 ? `var(--k-chart-${i + 1})` : "var(--k-text-quaternary)");
39
41
  export function ChartTip({ x, y, title, rows, width }) {
40
42
  // داخل ظرف بماند
41
43
  const cx = width ? Math.min(Math.max(x, 80), width - 80) : x;
@@ -74,7 +76,7 @@ export function BarChart({ title, data, series, labels, format, labelMax = true,
74
76
  const ticks = niceTicks(max);
75
77
  const top = ticks[ticks.length - 1] || 1;
76
78
  const maxIndex = totals.indexOf(max);
77
- const color = (i) => ({ "--_c": `var(--k-chart-${i + 1})` });
79
+ const color = (i) => ({ "--_c": chartColor(i) });
78
80
  const describe = (i) => stacked ? `${cats[i]}: ${stacked.map((s) => `${s.name} ${format(s.values[i] ?? 0)}`).join(M.common.list)}${M.common.list}${M.common.total} ${format(totals[i])}` : `${cats[i]}: ${format(totals[i])}`;
79
81
  const box = useRef(null);
80
82
  const [tip, setTip] = useState(null);
@@ -82,7 +84,7 @@ export function BarChart({ title, data, series, labels, format, labelMax = true,
82
84
  if (loading || cats.length === 0)
83
85
  return _jsx(ChartPlaceholder, { title: title, loading: loading, emptyMessage: emptyMessage, className: className });
84
86
  return (_jsxs("figure", { className: cx("k-chart k-chart--bar", className), "aria-labelledby": `${id}-t`, style: { margin: 0, ...(height ? { "--k-chart-height": height } : {}) }, children: [_jsxs("figcaption", { className: "k-chart__head", children: [_jsx("p", { className: "k-chart__title", id: `${id}-t`, children: title }), stacked && stacked.length > 1 && (_jsx("ul", { className: "k-chart__legend", "aria-hidden": "true", children: stacked.map((s, i) => _jsxs("li", { style: color(i), children: [_jsx("span", { className: "k-chart__key k-chart__key--box" }), s.name] }, s.name)) }))] }), _jsxs("div", { className: "k-chart__plot", ref: box, children: [_jsx("div", { className: "k-bars__grid", "aria-hidden": "true", children: ticks.map((t) => _jsx("span", { "data-v": T.compact(t) }, t)) }), _jsx("div", { className: "k-bars", role: "list", "aria-label": title, children: cats.map((label, i) => (_jsxs("div", { className: "k-bars__col", role: "listitem", tabIndex: 0, "aria-label": describe(i), "data-active": tip?.i === i ? "" : undefined, style: { "--_d": `${i * 40}ms` }, onPointerEnter: (e) => show(e, i), onPointerLeave: () => setTip(null), onFocus: (e) => show(e, i), onBlur: () => setTip(null), children: [labelMax && i === maxIndex && _jsx("span", { className: "k-bars__value", "aria-hidden": "true", children: format(totals[i]) }), stacked ? (_jsx("span", { className: "k-bars__stack", style: { blockSize: `${(totals[i] / top) * 100}%` }, "aria-hidden": "true", children: stacked.map((s, si) => (_jsx("span", { className: "k-bars__seg", style: { ...color(si), flexGrow: s.values[i] ?? 0 } }, s.name))) })) : (_jsx("span", { className: "k-bars__bar", style: { blockSize: `${(totals[i] / top) * 100}%` }, "aria-hidden": "true" })), _jsx("span", { className: "k-bars__label", "aria-hidden": "true", children: label })] }, label))) }), tip && (_jsx(ChartTip, { x: tip.x, y: tip.y, width: box.current?.clientWidth, title: cats[tip.i], rows: stacked
85
- ? [...stacked.map((s, si) => ({ name: s.name, value: format(s.values[tip.i] ?? 0), color: `var(--k-chart-${si + 1})` })), { name: M.common.total, value: format(totals[tip.i]) }]
87
+ ? [...stacked.map((s, si) => ({ name: s.name, value: format(s.values[tip.i] ?? 0), color: chartColor(si) })), { name: M.common.total, value: format(totals[tip.i]) }]
86
88
  : [{ value: format(totals[tip.i]) }] }))] })] }));
87
89
  }
88
90
  /** میله‌های افقی برای رتبه‌بندی با نام‌های بلند، مثل پربازدیدترین صفحه‌ها */
@@ -109,12 +111,12 @@ export function ProportionBar({ title, data, percent = true, format, className,
109
111
  const parts = data.slice(0, 4);
110
112
  const total = parts.reduce((n, d) => n + d.value, 0) || 1;
111
113
  const pct = (v) => T.pct(v, total);
112
- const color = (i) => ({ "--_c": `var(--k-chart-${i + 1})` });
114
+ const color = (i) => ({ "--_c": chartColor(i) });
113
115
  const box = useRef(null);
114
116
  const [tip, setTip] = useState(null);
115
117
  if (loading || !data?.length)
116
118
  return _jsx(ChartPlaceholder, { title: title, loading: loading, emptyMessage: emptyMessage, className: className });
117
- return (_jsxs("figure", { className: cx("k-chart", className), "aria-labelledby": `${id}-t`, style: { margin: 0 }, children: [_jsx("figcaption", { className: "k-chart__head", children: _jsx("p", { className: "k-chart__title", id: `${id}-t`, children: title }) }), _jsxs("div", { className: "k-proportion__wrap", ref: box, children: [_jsx("div", { className: "k-proportion", "aria-hidden": "true", children: parts.map((d, i) => (_jsx("span", { className: "k-proportion__seg", "data-active": tip?.i === i ? "" : undefined, style: { ...color(i), flexGrow: d.value }, onPointerEnter: (e) => setTip(tipAt(e.currentTarget, box.current, i)), onPointerLeave: () => setTip(null) }, d.label))) }), tip && _jsx(ChartTip, { x: tip.x, y: tip.y, width: box.current?.clientWidth, rows: [{ name: parts[tip.i].label, value: pct(parts[tip.i].value), color: `var(--k-chart-${tip.i + 1})` }, { name: M.chart.count, value: format(parts[tip.i].value) }] })] }), _jsx("ul", { className: "k-proportion__legend", children: parts.map((d, i) => (_jsxs("li", { style: color(i), "data-active": tip?.i === i ? "" : undefined, children: [_jsx("span", { className: "k-chart__key k-chart__key--box", "aria-hidden": "true" }), _jsx("span", { children: d.label }), _jsx("strong", { children: percent ? pct(d.value) : format(d.value) }), percent && _jsx("span", { className: "k-proportion__abs", children: format(d.value) })] }, d.label))) })] }));
119
+ return (_jsxs("figure", { className: cx("k-chart", className), "aria-labelledby": `${id}-t`, style: { margin: 0 }, children: [_jsx("figcaption", { className: "k-chart__head", children: _jsx("p", { className: "k-chart__title", id: `${id}-t`, children: title }) }), _jsxs("div", { className: "k-proportion__wrap", ref: box, children: [_jsx("div", { className: "k-proportion", "aria-hidden": "true", children: parts.map((d, i) => (_jsx("span", { className: "k-proportion__seg", "data-active": tip?.i === i ? "" : undefined, style: { ...color(i), flexGrow: d.value }, onPointerEnter: (e) => setTip(tipAt(e.currentTarget, box.current, i)), onPointerLeave: () => setTip(null) }, d.label))) }), tip && _jsx(ChartTip, { x: tip.x, y: tip.y, width: box.current?.clientWidth, rows: [{ name: parts[tip.i].label, value: pct(parts[tip.i].value), color: chartColor(tip.i) }, { name: M.chart.count, value: format(parts[tip.i].value) }] })] }), _jsx("ul", { className: "k-proportion__legend", children: parts.map((d, i) => (_jsxs("li", { style: color(i), "data-active": tip?.i === i ? "" : undefined, children: [_jsx("span", { className: "k-chart__key k-chart__key--box", "aria-hidden": "true" }), _jsx("span", { children: d.label }), _jsx("strong", { children: percent ? pct(d.value) : format(d.value) }), percent && _jsx("span", { className: "k-proportion__abs", children: format(d.value) })] }, d.label))) })] }));
118
120
  }
119
121
  /**
120
122
  * نمودار دایره‌ای یا دونات تا پنج بخش، با فاصلهٔ کوچک بین بخش‌ها، راهنمای درصد و جدول هم‌ارز.
@@ -130,7 +132,8 @@ export function PieChart({ title, data, variant = "donut", format, totalLabel, s
130
132
  const parts = sorted.length > 5 ? [...sorted.slice(0, 4), { label: M.common.other, value: sorted.slice(4).reduce((n, d) => n + d.value, 0) }] : sorted;
131
133
  const total = parts.reduce((n, d) => n + d.value, 0) || 1;
132
134
  const pct = (v) => T.pct(v, total);
133
- const slot = (i) => (i < 4 ? `var(--k-chart-${i + 1})` : "var(--k-text-quaternary)");
135
+ // چهار برش رنگی، بقیه در «سایر» با رنگ خنثی جمع می‌شوند
136
+ const slot = (i) => (i < 4 ? chartColor(i) : "var(--k-text-quaternary)");
134
137
  const donut = variant === "donut";
135
138
  // دایره با stroke-dasharray: هر بخش یک کمان؛ برای pie، شعاع نصف و ضخامت برابر قطر
136
139
  const R = 50, r = donut ? 40 : 25, w = donut ? 16 : 50;
@@ -213,7 +216,7 @@ export function LineChart({ title, labels, series, format, area, height, classNa
213
216
  return Object.fromEntries(order.map((o) => [o.i, o.y]));
214
217
  })();
215
218
  const endX = (i) => x(i) + (size.rtl ? -8 : 8);
216
- const color = (i) => ({ "--_c": `var(--k-chart-${i + 1})` });
219
+ const color = (i) => ({ "--_c": chartColor(i) });
217
220
  const pick = (clientX) => {
218
221
  const r = plot.current.getBoundingClientRect();
219
222
  const px = clientX - r.left;
@@ -238,5 +241,5 @@ export function LineChart({ title, labels, series, format, area, height, classNa
238
241
  const step = Math.max(1, Math.ceil(labels.length / Math.max(2, Math.floor(innerW / 64))));
239
242
  if (loading || !labels?.length || !series?.length)
240
243
  return _jsx(ChartPlaceholder, { title: title, loading: loading, emptyMessage: emptyMessage, className: className });
241
- return (_jsxs("figure", { className: cx("k-chart", className), "aria-labelledby": `${id}-t`, style: { margin: 0, ...(height ? { "--k-chart-height": height } : {}) }, children: [_jsxs("figcaption", { className: "k-chart__head", children: [_jsx("p", { className: "k-chart__title", id: `${id}-t`, children: title }), shown.length > 1 && (_jsx("ul", { className: "k-chart__legend", "aria-hidden": "true", children: shown.map((s, i) => _jsxs("li", { style: color(i), children: [_jsx("span", { className: "k-chart__key" }), s.name] }, s.name)) }))] }), _jsxs("div", { ref: plot, className: "k-chart__plot", tabIndex: 0, role: "img", "aria-label": M.chart.keyboard(title), "aria-describedby": `${id}-live`, onPointerMove: (e) => pick(e.clientX), onPointerLeave: () => setActive(null), onKeyDown: onKey, onBlur: () => setActive(null), children: [_jsxs("svg", { className: "k-chart__svg", "aria-hidden": "true", direction: "ltr", children: [_jsx("g", { className: "k-chart__grid", children: ticks.map((t) => _jsx("line", { x1: pad.start - (size.rtl ? 0 : 0), x2: size.w - pad.end, y1: y(t), y2: y(t), transform: size.rtl ? `translate(${pad.end - pad.start} 0)` : undefined }, t)) }), ticks.map((t) => _jsx("text", { className: "k-chart__tick", x: tickX, y: y(t) + 4, textAnchor: anchor, children: T.compact(t) }, t)), labels.map((l, i) => (i % step === 0 || i === labels.length - 1) && _jsx("text", { className: "k-chart__tick", x: x(i), y: size.h - 6, textAnchor: "middle", children: l }, l)), _jsx("defs", { children: _jsxs("linearGradient", { id: `${id}-fade`, x1: "0", y1: "0", x2: "0", y2: "1", children: [_jsx("stop", { offset: "0", style: { stopColor: "var(--k-chart-1)", stopOpacity: 0.28 } }), _jsx("stop", { offset: "1", style: { stopColor: "var(--k-chart-1)", stopOpacity: 0 } })] }) }), (area ?? shown.length === 1) && shown.length === 1 && (_jsx("path", { className: "k-chart__area", fill: `url(#${id}-fade)`, d: `M${x(0)},${y(0)} ${shown[0].values.map((v, i) => `L${x(i)},${y(v)}`).join(" ")} L${x(labels.length - 1)},${y(0)} Z` })), active !== null && _jsx("line", { className: "k-chart__cross", x1: x(active), x2: x(active), y1: pad.top, y2: pad.top + innerH }), shown.map((s, si) => (_jsxs("g", { style: color(si), children: [_jsx("path", { className: "k-chart__line", pathLength: 1, d: s.values.map((v, i) => `${i ? "L" : "M"}${x(i)},${y(v)}`).join(" ") }), _jsx("circle", { className: "k-chart__dot", cx: x(s.values.length - 1), cy: y(s.values[s.values.length - 1]), r: 4 }), shown.length > 1 && _jsx("text", { className: "k-chart__end", x: endX(last), y: endY[si] + 4, textAnchor: size.rtl ? "end" : "start", children: s.name }), active !== null && _jsx("circle", { className: "k-chart__dot", cx: x(active), cy: y(s.values[active]), r: 4.5 })] }, s.name)))] }), active !== null && (_jsx(ChartTip, { x: x(active), y: Math.min(...shown.map((s) => y(s.values[active]))) - 6, width: size.w, title: labels[active], rows: shown.map((s, si) => ({ name: s.name, value: format(s.values[active]), color: `var(--k-chart-${si + 1})` })) }))] }), _jsx("span", { className: "k-sr-only", "aria-live": "polite", id: `${id}-live`, children: active !== null ? `${labels[active]}: ${shown.map((s) => `${s.name} ${format(s.values[active])}`).join(M.common.list)}` : "" }), _jsx(DataTable, { caption: title, labels: labels, series: shown, format: format })] }));
244
+ return (_jsxs("figure", { className: cx("k-chart", className), "aria-labelledby": `${id}-t`, style: { margin: 0, ...(height ? { "--k-chart-height": height } : {}) }, children: [_jsxs("figcaption", { className: "k-chart__head", children: [_jsx("p", { className: "k-chart__title", id: `${id}-t`, children: title }), shown.length > 1 && (_jsx("ul", { className: "k-chart__legend", "aria-hidden": "true", children: shown.map((s, i) => _jsxs("li", { style: color(i), children: [_jsx("span", { className: "k-chart__key" }), s.name] }, s.name)) }))] }), _jsxs("div", { ref: plot, className: "k-chart__plot", tabIndex: 0, role: "img", "aria-label": M.chart.keyboard(title), "aria-describedby": `${id}-live`, onPointerMove: (e) => pick(e.clientX), onPointerLeave: () => setActive(null), onKeyDown: onKey, onBlur: () => setActive(null), children: [_jsxs("svg", { className: "k-chart__svg", "aria-hidden": "true", direction: "ltr", children: [_jsx("g", { className: "k-chart__grid", children: ticks.map((t) => _jsx("line", { x1: pad.start - (size.rtl ? 0 : 0), x2: size.w - pad.end, y1: y(t), y2: y(t), transform: size.rtl ? `translate(${pad.end - pad.start} 0)` : undefined }, t)) }), ticks.map((t) => _jsx("text", { className: "k-chart__tick", x: tickX, y: y(t) + 4, textAnchor: anchor, children: T.compact(t) }, t)), labels.map((l, i) => (i % step === 0 || i === labels.length - 1) && _jsx("text", { className: "k-chart__tick", x: x(i), y: size.h - 6, textAnchor: "middle", children: l }, l)), _jsx("defs", { children: _jsxs("linearGradient", { id: `${id}-fade`, x1: "0", y1: "0", x2: "0", y2: "1", children: [_jsx("stop", { offset: "0", style: { stopColor: "var(--k-chart-1)", stopOpacity: 0.28 } }), _jsx("stop", { offset: "1", style: { stopColor: "var(--k-chart-1)", stopOpacity: 0 } })] }) }), (area ?? shown.length === 1) && shown.length === 1 && (_jsx("path", { className: "k-chart__area", fill: `url(#${id}-fade)`, d: `M${x(0)},${y(0)} ${shown[0].values.map((v, i) => `L${x(i)},${y(v)}`).join(" ")} L${x(labels.length - 1)},${y(0)} Z` })), active !== null && _jsx("line", { className: "k-chart__cross", x1: x(active), x2: x(active), y1: pad.top, y2: pad.top + innerH }), shown.map((s, si) => (_jsxs("g", { style: color(si), children: [_jsx("path", { className: "k-chart__line", pathLength: 1, d: s.values.map((v, i) => `${i ? "L" : "M"}${x(i)},${y(v)}`).join(" ") }), _jsx("circle", { className: "k-chart__dot", cx: x(s.values.length - 1), cy: y(s.values[s.values.length - 1]), r: 4 }), shown.length > 1 && _jsx("text", { className: "k-chart__end", x: endX(last), y: endY[si] + 4, textAnchor: size.rtl ? "end" : "start", children: s.name }), active !== null && _jsx("circle", { className: "k-chart__dot", cx: x(active), cy: y(s.values[active]), r: 4.5 })] }, s.name)))] }), active !== null && (_jsx(ChartTip, { x: x(active), y: Math.min(...shown.map((s) => y(s.values[active]))) - 6, width: size.w, title: labels[active], rows: shown.map((s, si) => ({ name: s.name, value: format(s.values[active]), color: chartColor(si) })) }))] }), _jsx("span", { className: "k-sr-only", "aria-live": "polite", id: `${id}-live`, children: active !== null ? `${labels[active]}: ${shown.map((s) => `${s.name} ${format(s.values[active])}`).join(M.common.list)}` : "" }), _jsx(DataTable, { caption: title, labels: labels, series: shown, format: format })] }));
242
245
  }
package/dist/index.d.ts CHANGED
@@ -128,7 +128,7 @@ export { MonthPicker } from "./MonthPicker.js";
128
128
  export type { JalaliMonth, MonthPickerProps } from "./MonthPicker.js";
129
129
  export { LandlineInput } from "./LandlineInput.js";
130
130
  export type { LandlineInputProps } from "./LandlineInput.js";
131
- export { BarChart, BarList, LineChart, PieChart, ProportionBar, Sparkline } from "./Chart.js";
131
+ export { BarChart, BarList, LineChart, PieChart, ProportionBar, Sparkline, chartColor } from "./Chart.js";
132
132
  export type { BarChartProps, BarListProps, LineChartProps, LineSeries, PieChartProps, ProportionBarProps, SparklineProps } from "./Chart.js";
133
133
  export { ActivityHeatmap } from "./ActivityHeatmap.js";
134
134
  export type { ActivityHeatmapProps } from "./ActivityHeatmap.js";
package/dist/index.js CHANGED
@@ -64,7 +64,7 @@ export { PasswordStrength, defaultPasswordRules } from "./PasswordStrength.js";
64
64
  export { Countdown } from "./Countdown.js";
65
65
  export { MonthPicker } from "./MonthPicker.js";
66
66
  export { LandlineInput } from "./LandlineInput.js";
67
- export { BarChart, BarList, LineChart, PieChart, ProportionBar, Sparkline } from "./Chart.js";
67
+ export { BarChart, BarList, LineChart, PieChart, ProportionBar, Sparkline, chartColor } from "./Chart.js";
68
68
  export { ActivityHeatmap } from "./ActivityHeatmap.js";
69
69
  export { ContextMenu } from "./ContextMenu.js";
70
70
  export { InlineEdit } from "./InlineEdit.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kashi-ui/react",
3
- "version": "2.11.0",
3
+ "version": "2.15.0",
4
4
  "description": "کامپوننت‌های React دیزاین‌سیستم کاشی",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "test": "node --test test/*.test.mjs"
23
23
  },
24
24
  "peerDependencies": {
25
- "@kashi-ui/css": "^2.11.0",
25
+ "@kashi-ui/css": "^2.15.0",
26
26
  "react": ">=18"
27
27
  },
28
28
  "devDependencies": {
@@ -59,7 +59,7 @@
59
59
  }
60
60
  },
61
61
  "dependencies": {
62
- "@kashi-ui/bank-logos": "^2.11.0",
63
- "@kashi-ui/persian": "^2.11.0"
62
+ "@kashi-ui/bank-logos": "^2.15.0",
63
+ "@kashi-ui/persian": "^2.15.0"
64
64
  }
65
65
  }