@kashi-ui/react 2.1.0 → 2.3.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/Chart.d.ts CHANGED
@@ -13,6 +13,10 @@ export declare function ChartTip({ x, y, title, rows, width }: {
13
13
  width?: number;
14
14
  }): import("react").JSX.Element;
15
15
  export interface BarChartProps {
16
+ /** داده در راه است؛ اسکلت جای نمودار */
17
+ loading?: boolean;
18
+ /** پیام نمودار بی‌داده @default «داده‌ای برای نمایش نیست.» */
19
+ emptyMessage?: ReactNode;
16
20
  /** عنوان نمودار؛ نام دسترس‌پذیر هم هست */
17
21
  title: string;
18
22
  /** یک سری */
@@ -31,8 +35,12 @@ export interface BarChartProps {
31
35
  className?: string;
32
36
  }
33
37
  /** نمودار ستونی؛ تک‌سری یا انباشته تا چهار سری. با موس یا Tab روی هر ستون مقدار دقیق نمایش داده می‌شود */
34
- export declare function BarChart({ title, data, series, labels, format, labelMax, height, className }: BarChartProps): import("react").JSX.Element;
38
+ export declare function BarChart({ title, data, series, labels, format, labelMax, height, className, loading, emptyMessage }: BarChartProps): import("react").JSX.Element;
35
39
  export interface BarListProps {
40
+ /** داده در راه است؛ اسکلت جای نمودار */
41
+ loading?: boolean;
42
+ /** پیام نمودار بی‌داده @default «داده‌ای برای نمایش نیست.» */
43
+ emptyMessage?: ReactNode;
36
44
  title: string;
37
45
  /** به ترتیب داده‌شده؛ معمولاً از بیشترین به کمترین */
38
46
  data: {
@@ -44,8 +52,12 @@ export interface BarListProps {
44
52
  className?: string;
45
53
  }
46
54
  /** میله‌های افقی برای رتبه‌بندی با نام‌های بلند، مثل پربازدیدترین صفحه‌ها */
47
- export declare function BarList({ title, data, format, className }: BarListProps): import("react").JSX.Element;
55
+ export declare function BarList({ title, data, format, className, loading, emptyMessage }: BarListProps): import("react").JSX.Element;
48
56
  export interface ProportionBarProps {
57
+ /** داده در راه است؛ اسکلت جای نمودار */
58
+ loading?: boolean;
59
+ /** پیام نمودار بی‌داده @default «داده‌ای برای نمایش نیست.» */
60
+ emptyMessage?: ReactNode;
49
61
  title: string;
50
62
  /** حداکثر چهار بخش؛ بیشتر را در «سایر» جمع کنید */
51
63
  data: {
@@ -58,8 +70,12 @@ export interface ProportionBarProps {
58
70
  className?: string;
59
71
  }
60
72
  /** سهم هر بخش از کل در یک میلهٔ افقی، مثل منبع ورود کاربران؛ جایگزین خواناتر نمودار دایره‌ای */
61
- export declare function ProportionBar({ title, data, percent, format, className }: ProportionBarProps): import("react").JSX.Element;
73
+ export declare function ProportionBar({ title, data, percent, format, className, loading, emptyMessage }: ProportionBarProps): import("react").JSX.Element;
62
74
  export interface PieChartProps {
75
+ /** داده در راه است؛ اسکلت جای نمودار */
76
+ loading?: boolean;
77
+ /** پیام نمودار بی‌داده @default «داده‌ای برای نمایش نیست.» */
78
+ emptyMessage?: ReactNode;
63
79
  title: string;
64
80
  /** بیش از پنج بخش در «سایر» جمع می‌شود */
65
81
  data: {
@@ -79,7 +95,7 @@ export interface PieChartProps {
79
95
  * نمودار دایره‌ای یا دونات تا پنج بخش، با فاصلهٔ کوچک بین بخش‌ها، راهنمای درصد و جدول هم‌ارز.
80
96
  * برای مقایسهٔ دقیق بخش‌ها ProportionBar خواناتر است.
81
97
  */
82
- export declare function PieChart({ title, data, variant, format, totalLabel, size, className }: PieChartProps): import("react").JSX.Element;
98
+ export declare function PieChart({ title, data, variant, format, totalLabel, size, className, loading, emptyMessage }: PieChartProps): import("react").JSX.Element;
83
99
  export interface SparklineProps {
84
100
  values: number[];
85
101
  /** نام دسترس‌پذیر، مثل «روند فروش هفت روز اخیر: افزایشی» */
@@ -97,6 +113,10 @@ export interface LineSeries {
97
113
  values: number[];
98
114
  }
99
115
  export interface LineChartProps {
116
+ /** داده در راه است؛ اسکلت جای نمودار */
117
+ loading?: boolean;
118
+ /** پیام نمودار بی‌داده @default «داده‌ای برای نمایش نیست.» */
119
+ emptyMessage?: ReactNode;
100
120
  title: string;
101
121
  /** برچسب محور افقی، مثل ماه‌ها */
102
122
  labels: string[];
@@ -112,4 +132,4 @@ export interface LineChartProps {
112
132
  * نمودار خطی تا چهار سری: خط ۲ پیکسلی، برچسب نام در انتهای هر خط،
113
133
  * راهنمای عمودی با موس و ←→ روی کیبورد، و جدول هم‌ارز برای صفحه‌خوان.
114
134
  */
115
- export declare function LineChart({ title, labels, series, format, area, height, className }: LineChartProps): import("react").JSX.Element;
135
+ export declare function LineChart({ title, labels, series, format, area, height, className, loading, emptyMessage }: LineChartProps): import("react").JSX.Element;
package/dist/Chart.js CHANGED
@@ -54,8 +54,15 @@ function DataTable({ caption, labels, series, format }) {
54
54
  const { messages: M } = useKashi();
55
55
  return (_jsxs("table", { className: "k-sr-only", children: [_jsx("caption", { children: caption }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: M.chart.period }), series.map((s) => _jsx("th", { scope: "col", children: s.name }, s.name))] }) }), _jsx("tbody", { children: labels.map((l, i) => _jsxs("tr", { children: [_jsx("th", { scope: "row", children: l }), series.map((s) => _jsx("td", { children: format(s.values[i]) }, s.name))] }, l)) })] }));
56
56
  }
57
+ /** قاب نمودار در حالت بارگذاری یا بی‌داده: عنوان می‌ماند، جای نمودار اسکلت یا پیام */
58
+ function ChartPlaceholder({ title, loading, emptyMessage, className }) {
59
+ const { messages: M } = useKashi();
60
+ return (_jsxs("figure", { className: cx("k-chart", className), style: { margin: 0 }, "aria-busy": loading || undefined, children: [title && _jsx("figcaption", { className: "k-chart__head", children: _jsx("p", { className: "k-chart__title", children: title }) }), loading
61
+ ? _jsx("div", { className: "k-chart__skeleton", role: "status", children: _jsx("span", { className: "k-sr-only", children: M.common.loading }) })
62
+ : _jsx("div", { className: "k-chart__empty", role: "status", children: emptyMessage ?? M.common.noData })] }));
63
+ }
57
64
  /** نمودار ستونی؛ تک‌سری یا انباشته تا چهار سری. با موس یا Tab روی هر ستون مقدار دقیق نمایش داده می‌شود */
58
- export function BarChart({ title, data, series, labels, format, labelMax = true, height, className }) {
65
+ export function BarChart({ title, data, series, labels, format, labelMax = true, height, className, loading, emptyMessage }) {
59
66
  const T = useChartText();
60
67
  const M = T.M;
61
68
  format ?? (format = T.fmt);
@@ -72,12 +79,14 @@ export function BarChart({ title, data, series, labels, format, labelMax = true,
72
79
  const box = useRef(null);
73
80
  const [tip, setTip] = useState(null);
74
81
  const show = (e, i) => setTip(tipAt(e.currentTarget, box.current, i, e.currentTarget.querySelector(".k-bars__bar, .k-bars__stack")));
82
+ if (loading || cats.length === 0)
83
+ return _jsx(ChartPlaceholder, { title: title, loading: loading, emptyMessage: emptyMessage, className: className });
75
84
  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
76
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]) }]
77
86
  : [{ value: format(totals[tip.i]) }] }))] })] }));
78
87
  }
79
88
  /** میله‌های افقی برای رتبه‌بندی با نام‌های بلند، مثل پربازدیدترین صفحه‌ها */
80
- export function BarList({ title, data, format, className }) {
89
+ export function BarList({ title, data, format, className, loading, emptyMessage }) {
81
90
  const T = useChartText();
82
91
  const M = T.M;
83
92
  format ?? (format = T.fmt);
@@ -87,10 +96,12 @@ export function BarList({ title, data, format, className }) {
87
96
  const share = (v) => T.pct(v, total);
88
97
  const box = useRef(null);
89
98
  const [tip, setTip] = useState(null);
99
+ if (loading || !data?.length)
100
+ return _jsx(ChartPlaceholder, { title: title, loading: loading, emptyMessage: emptyMessage, className: className });
90
101
  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("ol", { className: "k-barlist", ref: box, style: { position: "relative" }, children: [data.map((d, i) => (_jsxs("li", { className: "k-barlist__row", "data-active": tip?.i === i ? "" : undefined, style: { "--_d": `${i * 60}ms` }, onPointerEnter: (e) => setTip(tipAt(e.currentTarget, box.current, i, e.currentTarget.querySelector(".k-barlist__fill"))), onPointerLeave: () => setTip(null), children: [_jsxs("span", { className: "k-barlist__track", children: [_jsx("span", { className: "k-barlist__fill", style: { inlineSize: `${(d.value / max) * 100}%` }, "aria-hidden": "true" }), d.href ? _jsx("a", { className: "k-barlist__label", href: d.href, children: d.label }) : _jsx("span", { className: "k-barlist__label", children: d.label })] }), _jsxs("span", { className: "k-barlist__value", children: [format(d.value), " ", _jsx("span", { className: "k-barlist__share", children: share(d.value) })] })] }, d.label))), tip && _jsx(ChartTip, { x: tip.x, y: tip.y, width: box.current?.clientWidth, title: data[tip.i].label, rows: [{ name: M.chart.value, value: format(data[tip.i].value) }, { name: M.chart.share, value: share(data[tip.i].value) }] })] })] }));
91
102
  }
92
103
  /** سهم هر بخش از کل در یک میلهٔ افقی، مثل منبع ورود کاربران؛ جایگزین خواناتر نمودار دایره‌ای */
93
- export function ProportionBar({ title, data, percent = true, format, className }) {
104
+ export function ProportionBar({ title, data, percent = true, format, className, loading, emptyMessage }) {
94
105
  const T = useChartText();
95
106
  const M = T.M;
96
107
  format ?? (format = T.fmt);
@@ -101,13 +112,15 @@ export function ProportionBar({ title, data, percent = true, format, className }
101
112
  const color = (i) => ({ "--_c": `var(--k-chart-${i + 1})` });
102
113
  const box = useRef(null);
103
114
  const [tip, setTip] = useState(null);
115
+ if (loading || !data?.length)
116
+ return _jsx(ChartPlaceholder, { title: title, loading: loading, emptyMessage: emptyMessage, className: className });
104
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))) })] }));
105
118
  }
106
119
  /**
107
120
  * نمودار دایره‌ای یا دونات تا پنج بخش، با فاصلهٔ کوچک بین بخش‌ها، راهنمای درصد و جدول هم‌ارز.
108
121
  * برای مقایسهٔ دقیق بخش‌ها ProportionBar خواناتر است.
109
122
  */
110
- export function PieChart({ title, data, variant = "donut", format, totalLabel, size = 176, className }) {
123
+ export function PieChart({ title, data, variant = "donut", format, totalLabel, size = 176, className, loading, emptyMessage }) {
111
124
  const T = useChartText();
112
125
  const M = T.M;
113
126
  format ?? (format = T.fmt);
@@ -137,6 +150,8 @@ export function PieChart({ title, data, variant = "donut", format, totalLabel, s
137
150
  const rr = donut ? r : r * 1.3;
138
151
  return { x: (R + rr * Math.cos(ang)) / (2 * R), y: (R + rr * Math.sin(ang)) / (2 * R) };
139
152
  };
153
+ if (loading || !data?.length)
154
+ return _jsx(ChartPlaceholder, { title: title, loading: loading, emptyMessage: emptyMessage, className: className });
140
155
  return (_jsxs("figure", { className: cx("k-chart k-pie", 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-pie__body", children: [_jsxs("div", { className: "k-pie__plot", ref: box, style: { inlineSize: size, blockSize: size }, onPointerLeave: () => setActive(null), children: [_jsxs("svg", { viewBox: "0 0 100 100", className: "k-pie__svg", "aria-hidden": "true", children: [donut && _jsx("circle", { cx: R, cy: R, r: r, fill: "none", stroke: "var(--k-bg-tertiary)", strokeWidth: w }), parts.map((d, i) => (_jsx("circle", { className: "k-pie__slice", "data-active": active === i ? "" : undefined, cx: R, cy: R, r: r, fill: "none", stroke: slot(i), strokeWidth: w, strokeDasharray: `${Math.max(0, arcs[i].len - gap)} ${C}`, strokeDashoffset: -arcs[i].start, transform: `rotate(-90 ${R} ${R})`, style: { "--_d": `${i * 80}ms` }, onPointerEnter: () => setActive(i) }, d.label)))] }), donut && (_jsxs("div", { className: "k-pie__center", "aria-hidden": "true", children: [_jsx("strong", { children: active === null ? format(total) : pct(parts[active].value) }), _jsx("span", { children: active === null ? totalLabel : parts[active].label })] })), active !== null && !donut && (_jsx(ChartTip, { x: mid(active).x * size, y: mid(active).y * size - 8, rows: [{ name: parts[active].label, value: pct(parts[active].value), color: slot(active) }, { name: M.chart.count, value: format(parts[active].value) }] }))] }), _jsx("ul", { className: "k-pie__legend", children: parts.map((d, i) => (_jsxs("li", { style: { "--_c": slot(i) }, "data-active": active === i ? "" : undefined, onPointerEnter: () => setActive(i), onPointerLeave: () => setActive(null), children: [_jsx("span", { className: "k-chart__key k-chart__key--box", "aria-hidden": "true" }), _jsx("span", { className: "k-pie__name", children: d.label }), _jsx("strong", { children: pct(d.value) }), _jsx("span", { className: "k-pie__abs", children: format(d.value) })] }, d.label))) })] })] }));
141
156
  }
142
157
  /** خط روند کوچک برای کارت آمار و جدول؛ بدون محور، فقط شکل روند */
@@ -154,7 +169,7 @@ export function Sparkline({ values, "aria-label": ariaLabel, tone = "brand", are
154
169
  * نمودار خطی تا چهار سری: خط ۲ پیکسلی، برچسب نام در انتهای هر خط،
155
170
  * راهنمای عمودی با موس و ←→ روی کیبورد، و جدول هم‌ارز برای صفحه‌خوان.
156
171
  */
157
- export function LineChart({ title, labels, series, format, area, height, className }) {
172
+ export function LineChart({ title, labels, series, format, area, height, className, loading, emptyMessage }) {
158
173
  const T = useChartText();
159
174
  const M = T.M;
160
175
  format ?? (format = T.fmt);
@@ -221,5 +236,7 @@ export function LineChart({ title, labels, series, format, area, height, classNa
221
236
  setActive(null);
222
237
  };
223
238
  const step = Math.max(1, Math.ceil(labels.length / Math.max(2, Math.floor(innerW / 64))));
239
+ if (loading || !labels?.length || !series?.length)
240
+ return _jsx(ChartPlaceholder, { title: title, loading: loading, emptyMessage: emptyMessage, className: className });
224
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 })] }));
225
242
  }
@@ -15,6 +15,8 @@ interface CheckOwnProps {
15
15
  description?: ReactNode;
16
16
  /** حالت خطا */
17
17
  invalid?: boolean;
18
+ /** فقط‌خواندنی: وضعیت دیده و با فرم ارسال می‌شود ولی با کلیک یا صفحه‌کلید عوض نمی‌شود (برخلاف disabled، کم‌رنگ نمی‌شود) */
19
+ readOnly?: boolean;
18
20
  }
19
21
  export interface CheckboxProps extends CheckOwnProps, Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "size"> {
20
22
  /** حالت نیمه‌انتخاب (مثلاً برای «انتخاب همه») */
package/dist/Checkbox.js CHANGED
@@ -3,13 +3,15 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
3
3
  import { forwardRef, useEffect, useId, useRef } from "react";
4
4
  import { cx } from "./cx.js";
5
5
  import { mergeRefs } from "./utils.js";
6
+ /** فقط‌خواندنی: کلیک و فاصله تیک را عوض نمی‌کنند؛ checkbox بومی readonly را نادیده می‌گیرد */
7
+ const readOnlyProps = (readOnly, onClick) => readOnly ? { "aria-readonly": true, onClick: (e) => { e.preventDefault(); onClick?.(e); } } : { onClick };
6
8
  /** برچسب و توضیح مشترک بین Checkbox و Switch */
7
- function CheckLabel({ id, label, description, className, classNames = {}, labelPosition = "end", children }) {
9
+ function CheckLabel({ id, label, description, className, classNames = {}, labelPosition = "end", readOnly, children }) {
8
10
  if (!label && !description)
9
11
  return _jsx(_Fragment, { children: children });
10
- return (_jsxs("label", { className: cx("k-check", labelPosition === "start" && "k-check--start", className, classNames.root), htmlFor: id, children: [children, _jsxs("span", { className: "k-check__text", children: [label && _jsx("span", { className: cx("k-check__label", classNames.label), children: label }), description && _jsx("span", { className: cx("k-check__description", classNames.description), id: `${id}-desc`, children: description })] })] }));
12
+ return (_jsxs("label", { className: cx("k-check", labelPosition === "start" && "k-check--start", className, classNames.root), htmlFor: id, "data-readonly": readOnly || undefined, children: [children, _jsxs("span", { className: "k-check__text", children: [label && _jsx("span", { className: cx("k-check__label", classNames.label), children: label }), description && _jsx("span", { className: cx("k-check__description", classNames.description), id: `${id}-desc`, children: description })] })] }));
11
13
  }
12
- export const Checkbox = forwardRef(function Checkbox({ label, description, invalid, indeterminate = false, size = "md", id, className, classNames, labelPosition, ...rest }, ref) {
14
+ export const Checkbox = forwardRef(function Checkbox({ label, description, invalid, indeterminate = false, size = "md", id, className, classNames, labelPosition, readOnly, onClick, ...rest }, ref) {
13
15
  const autoId = useId();
14
16
  const inputId = id ?? autoId;
15
17
  const inner = useRef(null);
@@ -18,10 +20,10 @@ export const Checkbox = forwardRef(function Checkbox({ label, description, inval
18
20
  if (inner.current)
19
21
  inner.current.indeterminate = indeterminate;
20
22
  }, [indeterminate]);
21
- return (_jsx(CheckLabel, { id: inputId, label: label, description: description, className: className, classNames: classNames, labelPosition: labelPosition, children: _jsx("input", { ref: mergeRefs(ref, inner), type: "checkbox", id: inputId, className: cx("k-checkbox", size === "lg" && "k-checkbox--lg", !label && !description && className, classNames?.control), "aria-invalid": invalid || undefined, "aria-describedby": description ? `${inputId}-desc` : undefined, "data-indeterminate": indeterminate || undefined, ...rest }) }));
23
+ return (_jsx(CheckLabel, { id: inputId, label: label, description: description, className: className, classNames: classNames, labelPosition: labelPosition, readOnly: readOnly, children: _jsx("input", { ref: mergeRefs(ref, inner), type: "checkbox", id: inputId, className: cx("k-checkbox", size === "lg" && "k-checkbox--lg", !label && !description && className, classNames?.control), "aria-invalid": invalid || undefined, "aria-describedby": description ? `${inputId}-desc` : undefined, "data-indeterminate": indeterminate || undefined, ...readOnlyProps(readOnly, onClick), ...rest }) }));
22
24
  });
23
- export const Switch = forwardRef(function Switch({ label, description, invalid, size = "md", id, className, classNames, labelPosition, ...rest }, ref) {
25
+ export const Switch = forwardRef(function Switch({ label, description, invalid, size = "md", id, className, classNames, labelPosition, readOnly, onClick, ...rest }, ref) {
24
26
  const autoId = useId();
25
27
  const inputId = id ?? autoId;
26
- return (_jsx(CheckLabel, { id: inputId, label: label, description: description, className: className, classNames: classNames, labelPosition: labelPosition, children: _jsx("input", { ref: ref, type: "checkbox", role: "switch", id: inputId, className: cx("k-switch", size !== "md" && `k-switch--${size}`, !label && !description && className, classNames?.control), "aria-invalid": invalid || undefined, "aria-describedby": description ? `${inputId}-desc` : undefined, ...rest }) }));
28
+ return (_jsx(CheckLabel, { id: inputId, label: label, description: description, className: className, classNames: classNames, labelPosition: labelPosition, readOnly: readOnly, children: _jsx("input", { ref: ref, type: "checkbox", role: "switch", id: inputId, className: cx("k-switch", size !== "md" && `k-switch--${size}`, !label && !description && className, classNames?.control), "aria-invalid": invalid || undefined, "aria-describedby": description ? `${inputId}-desc` : undefined, ...readOnlyProps(readOnly, onClick), ...rest }) }));
27
29
  });
@@ -15,8 +15,10 @@ export interface ChipGroupProps {
15
15
  onChange?: (value: string[]) => void;
16
16
  /** فقط یک انتخاب؛ کلیک دوباره انتخاب را برمی‌دارد */
17
17
  single?: boolean;
18
+ /** فقط‌خواندنی: انتخاب‌ها دیده می‌شوند ولی عوض نمی‌شوند */
19
+ readOnly?: boolean;
18
20
  "aria-label"?: string;
19
21
  className?: string;
20
22
  }
21
23
  /** چیپ‌های فیلتر روشن و خاموش‌شونده، مثل دسته‌بندی‌ها یا وضعیت سفارش */
22
- export declare function ChipGroup({ options, value, defaultValue, onChange, single, "aria-label": ariaLabel, className }: ChipGroupProps): import("react").JSX.Element;
24
+ export declare function ChipGroup({ options, value, defaultValue, onChange, single, readOnly, "aria-label": ariaLabel, className }: ChipGroupProps): import("react").JSX.Element;
package/dist/ChipGroup.js CHANGED
@@ -5,15 +5,17 @@ import { toFaDigits } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
6
  const Check = () => (_jsx("svg", { className: "k-chip__check", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m5 10.5 3.2 3L15 7" }) }));
7
7
  /** چیپ‌های فیلتر روشن و خاموش‌شونده، مثل دسته‌بندی‌ها یا وضعیت سفارش */
8
- export function ChipGroup({ options, value, defaultValue = [], onChange, single, "aria-label": ariaLabel, className }) {
8
+ export function ChipGroup({ options, value, defaultValue = [], onChange, single, readOnly, "aria-label": ariaLabel, className }) {
9
9
  const [inner, setInner] = useState(defaultValue);
10
10
  const current = value ?? inner;
11
11
  const toggle = (v) => {
12
+ if (readOnly)
13
+ return;
12
14
  const on = current.includes(v);
13
15
  const next = single ? (on ? [] : [v]) : on ? current.filter((x) => x !== v) : [...current, v];
14
16
  if (value === undefined)
15
17
  setInner(next);
16
18
  onChange?.(next);
17
19
  };
18
- return (_jsx("div", { role: "group", "aria-label": ariaLabel, className: cx("k-chips", className), children: options.map((o) => (_jsxs("button", { type: "button", className: "k-chip", "aria-pressed": current.includes(o.value), disabled: o.disabled, onClick: () => toggle(o.value), children: [_jsx(Check, {}), o.icon, o.label, o.count !== undefined && _jsx("span", { className: "k-chip__count", children: toFaDigits(o.count) })] }, o.value))) }));
20
+ return (_jsx("div", { role: "group", "aria-label": ariaLabel, "aria-readonly": readOnly || undefined, "data-readonly": readOnly || undefined, className: cx("k-chips", className), children: options.map((o) => (_jsxs("button", { type: "button", className: "k-chip", "aria-pressed": current.includes(o.value), disabled: o.disabled, onClick: () => toggle(o.value), children: [_jsx(Check, {}), o.icon, o.label, o.count !== undefined && _jsx("span", { className: "k-chip__count", children: toFaDigits(o.count) })] }, o.value))) }));
19
21
  }
@@ -30,6 +30,8 @@ export interface ComboboxProps {
30
30
  filter?: (option: ComboboxOption, query: string) => boolean;
31
31
  /** @default "نتیجه‌ای پیدا نشد." */
32
32
  emptyMessage?: ReactNode;
33
+ /** فقط‌خواندنی: مقدار دیده و ارسال می‌شود ولی فهرست باز و متن عوض نمی‌شود */
34
+ readOnly?: boolean;
33
35
  /** نمایش اسپینر، مثلاً هنگام جستجوی سمت سرور */
34
36
  loading?: boolean;
35
37
  required?: boolean;
package/dist/Combobox.js CHANGED
@@ -30,7 +30,7 @@ const Check = () => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "
30
30
  * تایپ فهرست را فیلتر می‌کند، ↑↓ حرکت، Enter انتخاب، Esc بستن (و در حالت بسته، پاک کردن).
31
31
  * جستجو «علي» و «علی» را یکی می‌داند.
32
32
  */
33
- export const Combobox = forwardRef(function Combobox({ label, hint, error, options, value, defaultValue = null, onChange, onInputChange, placeholder, filter = defaultFilter, emptyMessage, loading, required, disabled, name, id, className, resultsLabel, }, ref) {
33
+ export const Combobox = forwardRef(function Combobox({ label, hint, error, options, value, defaultValue = null, onChange, onInputChange, placeholder, filter = defaultFilter, emptyMessage, loading, required, disabled, readOnly, name, id, className, resultsLabel, }, ref) {
34
34
  const { messages: M, n: N } = useKashi();
35
35
  emptyMessage ?? (emptyMessage = M.common.noResults);
36
36
  resultsLabel ?? (resultsLabel = (x) => M.common.results(N(x)));
@@ -63,6 +63,8 @@ export const Combobox = forwardRef(function Combobox({ label, hint, error, optio
63
63
  setActive(-1);
64
64
  };
65
65
  const openList = (at = "selected") => {
66
+ if (readOnly)
67
+ return;
66
68
  if (disabled)
67
69
  return;
68
70
  setOpen(true);
@@ -114,7 +116,7 @@ export const Combobox = forwardRef(function Combobox({ label, hint, error, optio
114
116
  }
115
117
  };
116
118
  let lastGroup;
117
- return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, required: required, className: className, children: _jsxs("div", { ref: wrapRef, className: "k-combobox", "data-open": open ? "" : undefined, onBlur: (e) => {
119
+ return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, required: required, className: className, children: _jsxs("div", { ref: wrapRef, className: "k-combobox", "data-open": open ? "" : undefined, "data-readonly": readOnly || undefined, onBlur: (e) => {
118
120
  if (wrapRef.current?.contains(e.relatedTarget))
119
121
  return;
120
122
  setOpen(false);
@@ -123,7 +125,9 @@ export const Combobox = forwardRef(function Combobox({ label, hint, error, optio
123
125
  setTyping(false);
124
126
  setQuery(selectedOption?.label ?? "");
125
127
  }
126
- }, children: [_jsxs("div", { className: cx("k-input"), "data-state": error ? "invalid" : undefined, children: [_jsx("input", { ref: mergeRefs(ref, inputRef), id: inputId, className: "k-input__control", type: "text", role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? `${listId}-${active}` : undefined, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error), autoComplete: "off", placeholder: placeholder, value: query, required: required, disabled: disabled, onChange: (e) => {
128
+ }, children: [_jsxs("div", { className: cx("k-input"), "data-state": error ? "invalid" : undefined, children: [_jsx("input", { ref: mergeRefs(ref, inputRef), id: inputId, className: "k-input__control", type: "text", role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? `${listId}-${active}` : undefined, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error), autoComplete: "off", placeholder: placeholder, value: query, required: required, disabled: disabled, readOnly: readOnly, onChange: (e) => {
129
+ if (readOnly)
130
+ return;
127
131
  setQuery(e.target.value);
128
132
  setTyping(true);
129
133
  setOpen(true);
@@ -14,6 +14,10 @@ export interface MultiSelectProps {
14
14
  filter?: (option: ComboboxOption, query: string) => boolean;
15
15
  /** @default "نتیجه‌ای پیدا نشد." */
16
16
  emptyMessage?: ReactNode;
17
+ /** فقط‌خواندنی: انتخاب‌ها دیده و ارسال می‌شوند ولی فهرست باز و چیزی حذف نمی‌شود */
18
+ readOnly?: boolean;
19
+ /** گزینه‌ها در حال بارگذاری‌اند؛ ردیف‌های اسکلتی در فهرست */
20
+ loading?: boolean;
17
21
  disabled?: boolean;
18
22
  /** با name، یک فیلد پنهان برای هر مقدار */
19
23
  name?: string;
@@ -30,4 +34,4 @@ export interface MultiSelectProps {
30
34
  * انتخاب چند گزینه با جستجو؛ انتخاب‌ها به‌شکل برچسب داخل فیلد.
31
35
  * ↑↓ حرکت، Enter انتخاب یا لغو انتخاب، Backspace در فیلد خالی آخرین برچسب را حذف می‌کند، Esc بستن.
32
36
  */
33
- export declare function MultiSelect({ label, hint, error, options, value, defaultValue, onChange, placeholder, max, filter, emptyMessage, disabled, name, id, className, labels, }: MultiSelectProps): import("react").JSX.Element;
37
+ export declare function MultiSelect({ label, hint, error, options, value, defaultValue, onChange, placeholder, max, filter, emptyMessage, disabled, readOnly, loading, name, id, className, labels, }: MultiSelectProps): import("react").JSX.Element;
@@ -10,7 +10,7 @@ const Check = () => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "c
10
10
  * انتخاب چند گزینه با جستجو؛ انتخاب‌ها به‌شکل برچسب داخل فیلد.
11
11
  * ↑↓ حرکت، Enter انتخاب یا لغو انتخاب، Backspace در فیلد خالی آخرین برچسب را حذف می‌کند، Esc بستن.
12
12
  */
13
- export function MultiSelect({ label, hint, error, options, value, defaultValue = [], onChange, placeholder, max, filter = defaultFilter, emptyMessage, disabled, name, id, className, labels = {}, }) {
13
+ export function MultiSelect({ label, hint, error, options, value, defaultValue = [], onChange, placeholder, max, filter = defaultFilter, emptyMessage, disabled, readOnly, loading, name, id, className, labels = {}, }) {
14
14
  const { messages: M, n: N } = useKashi();
15
15
  emptyMessage ?? (emptyMessage = M.common.noResults);
16
16
  const { remove = M.common.remove, selected: selectedLabel = (x) => M.multiSelect.selected(N(x)), max: maxLabel = (x) => M.common.max(N(x)), clear = M.common.clearAll, } = labels;
@@ -74,11 +74,13 @@ export function MultiSelect({ label, hint, error, options, value, defaultValue =
74
74
  }
75
75
  };
76
76
  const labelOf = (v) => options.find((o) => o.value === v)?.label ?? v;
77
- return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, className: className, children: _jsxs("div", { ref: wrap, className: "k-combobox k-multiselect", "data-open": open ? "" : undefined, onBlur: (e) => !wrap.current?.contains(e.relatedTarget) && setOpen(false), children: [_jsxs("div", { className: "k-tag-input", "data-invalid": error ? "" : undefined, onClick: () => input.current?.focus(), children: [chosen.map((v) => (_jsx(Badge, { tone: "brand", onRemove: disabled ? undefined : () => set(chosen.filter((x) => x !== v)), removeLabel: remove(labelOf(v)), children: labelOf(v) }, v))), _jsx("input", { ref: input, id: inputId, className: "k-tag-input__control", role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? `${listId}-${active}` : undefined, "aria-describedby": describedBy(inputId, hint, error, `${inputId}-count`), "aria-invalid": error ? true : undefined, autoComplete: "off", placeholder: chosen.length ? undefined : placeholder, disabled: disabled, value: query, onChange: (e) => {
77
+ return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, className: className, children: _jsxs("div", { ref: wrap, className: "k-combobox k-multiselect", "data-open": open ? "" : undefined, onBlur: (e) => !wrap.current?.contains(e.relatedTarget) && setOpen(false), children: [_jsxs("div", { className: "k-tag-input", "data-invalid": error ? "" : undefined, "data-readonly": readOnly || undefined, "aria-busy": loading || undefined, onClick: () => input.current?.focus(), children: [chosen.map((v) => (_jsx(Badge, { tone: "brand", onRemove: disabled || readOnly ? undefined : () => set(chosen.filter((x) => x !== v)), removeLabel: remove(labelOf(v)), children: labelOf(v) }, v))), _jsx("input", { ref: input, id: inputId, className: "k-tag-input__control", role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? `${listId}-${active}` : undefined, "aria-describedby": describedBy(inputId, hint, error, `${inputId}-count`), "aria-invalid": error ? true : undefined, autoComplete: "off", placeholder: chosen.length || readOnly ? undefined : placeholder, disabled: disabled, readOnly: readOnly, value: query, onChange: (e) => {
78
+ if (readOnly)
79
+ return;
78
80
  setQuery(e.target.value);
79
81
  setOpen(true);
80
82
  setActive(0);
81
- }, onFocus: () => setOpen(true), onKeyDown: onKey }), chosen.length > 1 && !disabled && (_jsx("button", { type: "button", className: "k-input__action", "aria-label": clear, onClick: () => { set([]); input.current?.focus(); }, children: _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 6 8 8M14 6l-8 8" }) }) }))] }), _jsxs("ul", { id: listId, role: "listbox", "aria-multiselectable": "true", "aria-label": typeof label === "string" ? label : undefined, className: "k-listbox", hidden: !open, style: { insetBlockStart: "calc(100% + 6px)" }, children: [filtered.length === 0 && _jsx("li", { className: "k-listbox__empty", role: "presentation", children: emptyMessage }), filtered.map((o, i) => {
83
+ }, onFocus: () => !readOnly && setOpen(true), onKeyDown: readOnly ? undefined : onKey }), chosen.length > 1 && !disabled && !readOnly && (_jsx("button", { type: "button", className: "k-input__action", "aria-label": clear, onClick: () => { set([]); input.current?.focus(); }, children: _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 6 8 8M14 6l-8 8" }) }) }))] }), _jsxs("ul", { id: listId, role: "listbox", "aria-multiselectable": "true", "aria-label": typeof label === "string" ? label : undefined, className: "k-listbox", hidden: !open, style: { insetBlockStart: "calc(100% + 6px)" }, children: [loading && filtered.length === 0 && [0, 1, 2].map((k) => _jsx("li", { className: "k-listbox__loading", role: "presentation" }, `l${k}`)), !loading && filtered.length === 0 && _jsx("li", { className: "k-listbox__empty", role: "presentation", children: emptyMessage }), filtered.map((o, i) => {
82
84
  const on = chosen.includes(o.value);
83
85
  return (_jsxs("li", { id: `${listId}-${i}`, role: "option", "aria-selected": on, "aria-disabled": o.disabled || (!on && full) || undefined, "data-active": i === active ? "" : undefined, className: "k-option k-option--check", onPointerDown: (e) => e.preventDefault(), onClick: () => toggle(o), onPointerMove: () => active !== i && setActive(i), children: [_jsx("span", { className: "k-multiselect__box", "aria-hidden": "true", children: on && _jsx(Check, {}) }), o.icon, _jsxs("span", { className: "k-option__body", children: [_jsx("span", { children: highlight(o.label, query) }), o.description && _jsx("span", { className: "k-option__desc", children: o.description })] })] }, o.value));
84
86
  })] }), _jsx("span", { id: `${inputId}-count`, className: "k-sr-only", children: selectedLabel(chosen.length) }), _jsx("span", { className: "k-sr-only", "aria-live": "polite", children: announce }), name && chosen.map((v) => _jsx("input", { type: "hidden", name: name, value: v }, v))] }) }));
package/dist/Radio.d.ts CHANGED
@@ -13,11 +13,13 @@ export interface RadioGroupProps {
13
13
  error?: ReactNode;
14
14
  required?: boolean;
15
15
  disabled?: boolean;
16
+ /** فقط‌خواندنی: گزینهٔ انتخاب‌شده دیده و با فرم ارسال می‌شود ولی عوض نمی‌شود */
17
+ readOnly?: boolean;
16
18
  className?: string;
17
19
  children: ReactNode;
18
20
  }
19
21
  /** گروه رادیو با fieldset و legend؛ پیمایش با کلیدهای جهت‌دار را مرورگر انجام می‌دهد */
20
- export declare function RadioGroup({ label, name, value, defaultValue, onChange, variant, hint, error, required, disabled, className, children, }: RadioGroupProps): import("react").JSX.Element;
22
+ export declare function RadioGroup({ label, name, value, defaultValue, onChange, variant, hint, error, required, disabled, readOnly, className, children, }: RadioGroupProps): import("react").JSX.Element;
21
23
  export interface RadioProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "value"> {
22
24
  value: string;
23
25
  label: ReactNode;
package/dist/Radio.js CHANGED
@@ -5,17 +5,20 @@ import { cx } from "./cx.js";
5
5
  import { isDev } from "./utils.js";
6
6
  const RadioCtx = createContext(null);
7
7
  /** گروه رادیو با fieldset و legend؛ پیمایش با کلیدهای جهت‌دار را مرورگر انجام می‌دهد */
8
- export function RadioGroup({ label, name, value, defaultValue, onChange, variant = "list", hint, error, required, disabled, className, children, }) {
8
+ export function RadioGroup({ label, name, value, defaultValue, onChange, variant = "list", hint, error, required, disabled, readOnly, className, children, }) {
9
9
  const id = useId();
10
10
  const [inner, setInner] = useState(defaultValue);
11
11
  const current = value !== undefined ? value : inner;
12
12
  const describedBy = [error && `${id}-error`, hint && `${id}-hint`].filter(Boolean).join(" ") || undefined;
13
- return (_jsxs("fieldset", { className: cx("k-radio-group", variant !== "list" && `k-radio-group--${variant}`, className), "aria-describedby": describedBy, "aria-required": required || undefined, "aria-invalid": error ? true : undefined, disabled: disabled, children: [_jsxs("legend", { className: "k-label", children: [label, required && _jsx("span", { className: "k-label__required", "aria-hidden": "true", children: "*" })] }), _jsx(RadioCtx.Provider, { value: {
13
+ return (_jsxs("fieldset", { className: cx("k-radio-group", variant !== "list" && `k-radio-group--${variant}`, className), "aria-describedby": describedBy, "aria-required": required || undefined, "aria-invalid": error ? true : undefined, "aria-readonly": readOnly || undefined, "data-readonly": readOnly || undefined, disabled: disabled, children: [_jsxs("legend", { className: "k-label", children: [label, required && _jsx("span", { className: "k-label__required", "aria-hidden": "true", children: "*" })] }), _jsx(RadioCtx.Provider, { value: {
14
14
  name: name ?? id,
15
15
  value: current,
16
16
  invalid: !!error,
17
17
  disabled,
18
+ readOnly,
18
19
  setValue: (v) => {
20
+ if (readOnly)
21
+ return;
19
22
  if (value === undefined)
20
23
  setInner(v);
21
24
  onChange?.(v);
@@ -30,5 +33,5 @@ export const Radio = forwardRef(function Radio({ value, label, description, badg
30
33
  }
31
34
  const autoId = useId();
32
35
  const inputId = id ?? autoId;
33
- return (_jsxs("label", { className: cx("k-check", className), htmlFor: inputId, children: [_jsx("input", { ref: ref, type: "radio", className: "k-radio", id: inputId, name: ctx?.name ?? name, value: value, checked: ctx ? ctx.value === value : undefined, onChange: () => ctx?.setValue(value), disabled: disabled, "aria-describedby": description ? `${inputId}-desc` : undefined, ...rest }), _jsxs("span", { className: "k-check__text", children: [badge != null && badge !== false ? (_jsxs("span", { className: "k-check__head", children: [_jsx("span", { className: "k-check__label", children: label }), typeof badge === "string" ? _jsx("span", { className: "k-badge k-badge--brand k-badge--sm", children: badge }) : badge] })) : (_jsx("span", { className: "k-check__label", children: label })), description && _jsx("span", { className: "k-check__description", id: `${inputId}-desc`, children: description })] }), meta != null && meta !== false && _jsx("span", { className: "k-check__meta", children: meta })] }));
36
+ return (_jsxs("label", { className: cx("k-check", className), htmlFor: inputId, "data-readonly": ctx?.readOnly || undefined, children: [_jsx("input", { ref: ref, type: "radio", className: "k-radio", id: inputId, name: ctx?.name ?? name, value: value, checked: ctx ? ctx.value === value : undefined, onChange: () => ctx?.setValue(value), disabled: disabled, "aria-readonly": ctx?.readOnly || undefined, "aria-describedby": description ? `${inputId}-desc` : undefined, ...rest }), _jsxs("span", { className: "k-check__text", children: [badge != null && badge !== false ? (_jsxs("span", { className: "k-check__head", children: [_jsx("span", { className: "k-check__label", children: label }), typeof badge === "string" ? _jsx("span", { className: "k-badge k-badge--brand k-badge--sm", children: badge }) : badge] })) : (_jsx("span", { className: "k-check__label", children: label })), description && _jsx("span", { className: "k-check__description", id: `${inputId}-desc`, children: description })] }), meta != null && meta !== false && _jsx("span", { className: "k-check__meta", children: meta })] }));
34
37
  });
@@ -24,6 +24,10 @@ export interface SearchSuggestProps {
24
24
  popular?: ReactNode;
25
25
  clear?: ReactNode;
26
26
  };
27
+ /** پیشنهادها در راه‌اند (مثلاً از سرور)؛ ردیف‌های اسکلتی زیر جعبه */
28
+ loading?: boolean;
29
+ /** پیام وقتی برای عبارت تایپ‌شده پیشنهادی نیست؛ بدون آن، پنل بسته می‌ماند */
30
+ emptyMessage?: ReactNode;
27
31
  }
28
32
  /** جعبهٔ جستجو با جستجوهای اخیر و پرطرفدار و پیشنهاد هنگام تایپ (الگوی فروشگاه‌های اینترنتی) */
29
- export declare function SearchSuggest({ value, defaultValue, onChange, onSearch, recent, onClearRecent, storageKey, popular, suggestions, placeholder, label, name, className, labels, }: SearchSuggestProps): import("react").JSX.Element;
33
+ export declare function SearchSuggest({ value, defaultValue, onChange, onSearch, recent, onClearRecent, storageKey, popular, suggestions, placeholder, label, name, className, labels, loading, emptyMessage, }: SearchSuggestProps): import("react").JSX.Element;
@@ -9,7 +9,7 @@ const SearchIcon = () => _jsxs("svg", { viewBox: "0 0 20 20", width: "20", heigh
9
9
  const TrendIcon = () => _jsx("svg", { viewBox: "0 0 20 20", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m2.75 13.5 4.6-4.6 3.2 3.2 6.2-6.2M12.75 5.9h4v4" }) });
10
10
  const HistoryIcon = () => _jsx("svg", { viewBox: "0 0 20 20", width: "16", height: "16", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "M3.3 10a6.7 6.7 0 1 0 1.9-4.7M3.2 2.9v2.6h2.6M10 6.6V10l2.3 1.5" }) });
11
11
  /** جعبهٔ جستجو با جستجوهای اخیر و پرطرفدار و پیشنهاد هنگام تایپ (الگوی فروشگاه‌های اینترنتی) */
12
- export function SearchSuggest({ value, defaultValue, onChange, onSearch, recent, onClearRecent, storageKey, popular = [], suggestions, placeholder, label, name, className, labels = {}, }) {
12
+ export function SearchSuggest({ value, defaultValue, onChange, onSearch, recent, onClearRecent, storageKey, popular = [], suggestions, placeholder, label, name, className, labels = {}, loading, emptyMessage, }) {
13
13
  const { messages: M } = useKashi();
14
14
  const id = useId();
15
15
  const listId = `${id}-panel`;
@@ -63,7 +63,9 @@ export function SearchSuggest({ value, defaultValue, onChange, onSearch, recent,
63
63
  const boxRef = useRef(null);
64
64
  const showList = list.length > 0;
65
65
  const showIdle = !q.trim() && (history.length > 0 || popular.length > 0);
66
- const visible = open && (showList || showIdle);
66
+ const showLoading = !!loading && !!q.trim() && !showList;
67
+ const showEmpty = !loading && !!q.trim() && !showList && emptyMessage !== undefined;
68
+ const visible = open && (showList || showIdle || showLoading || showEmpty);
67
69
  const submit = (s) => {
68
70
  const t = s.trim();
69
71
  if (!t)
@@ -137,8 +139,8 @@ export function SearchSuggest({ value, defaultValue, onChange, onSearch, recent,
137
139
  return s;
138
140
  return _jsxs(_Fragment, { children: [s.slice(0, i), _jsx("mark", { children: s.slice(i, i + q.trim().length) }), s.slice(i + q.trim().length)] });
139
141
  };
140
- return (_jsxs("form", { role: "search", className: cx("k-search-suggest", className), onSubmit: onSubmit, "data-open": visible || undefined, children: [_jsxs("div", { className: "k-search-suggest__box", ref: boxRef, children: [_jsx(SearchIcon, {}), _jsx("input", { ref: inputRef, type: "search", name: name, className: "k-search-suggest__input", value: q, placeholder: placeholder, "aria-label": label ?? M.searchSuggest.label, role: "combobox", "aria-autocomplete": "list", "aria-expanded": visible, "aria-controls": listId, "aria-activedescendant": visible && showList && active >= 0 ? `${listId}-${active}` : undefined, autoComplete: "off", enterKeyHint: "search", onFocus: () => setOpen(true), onChange: (e) => { setQ(e.target.value); setOpen(true); }, onKeyDown: onKeyDown })] }), _jsx("div", { id: listId, ref: panelRef, className: "k-search-suggest__panel", hidden: !visible, ...{ popover: "manual" }, style: pos ? { position: "fixed", inset: "auto", margin: 0, top: pos.top, left: pos.left, width: pos.width } : undefined, onKeyDown: (e) => { if (e.key === "Escape") {
142
+ return (_jsxs("form", { role: "search", className: cx("k-search-suggest", className), onSubmit: onSubmit, "data-open": visible || undefined, children: [_jsxs("div", { className: "k-search-suggest__box", ref: boxRef, "aria-busy": loading || undefined, children: [_jsx(SearchIcon, {}), _jsx("input", { ref: inputRef, type: "search", name: name, className: "k-search-suggest__input", value: q, placeholder: placeholder, "aria-label": label ?? M.searchSuggest.label, role: "combobox", "aria-autocomplete": "list", "aria-expanded": visible, "aria-controls": listId, "aria-activedescendant": visible && showList && active >= 0 ? `${listId}-${active}` : undefined, autoComplete: "off", enterKeyHint: "search", onFocus: () => setOpen(true), onChange: (e) => { setQ(e.target.value); setOpen(true); }, onKeyDown: onKeyDown })] }), _jsx("div", { id: listId, ref: panelRef, className: "k-search-suggest__panel", hidden: !visible, ...{ popover: "manual" }, style: pos ? { position: "fixed", inset: "auto", margin: 0, top: pos.top, left: pos.left, width: pos.width } : undefined, onKeyDown: (e) => { if (e.key === "Escape") {
141
143
  setOpen(false);
142
144
  inputRef.current?.focus();
143
- } }, children: showList ? (_jsx("ul", { role: "listbox", "aria-label": M.searchSuggest.suggestions, className: "k-search-suggest__list", children: list.map((s, i) => (_jsxs("li", { id: `${listId}-${i}`, role: "option", "aria-selected": i === active, className: "k-option", "data-active": i === active || undefined, onMouseDown: (e) => e.preventDefault(), onPointerMove: () => setActive(i), onClick: () => submit(s), children: [_jsx(SearchIcon, {}), _jsx("span", { className: "k-option__label", children: highlight(s) })] }, s))) })) : (_jsxs(_Fragment, { children: [history.length > 0 && (_jsxs("section", { className: "k-search-suggest__section", children: [_jsxs("div", { className: "k-search-suggest__head", children: [_jsx("b", { children: labels.recent ?? M.searchSuggest.recent }), _jsx("button", { type: "button", className: "k-btn k-btn--link k-btn--sm", onMouseDown: (e) => e.preventDefault(), onClick: clearHistory, children: labels.clear ?? M.searchSuggest.clear })] }), _jsx("ul", { className: "k-search-suggest__chips", children: history.map((s) => chip(s, "recent")) })] })), popular.length > 0 && (_jsxs("section", { className: "k-search-suggest__section", children: [_jsx("div", { className: "k-search-suggest__head", children: _jsx("b", { children: labels.popular ?? M.searchSuggest.popular }) }), _jsx("ul", { className: "k-search-suggest__chips", children: popular.map((s) => chip(s, "popular")) })] }))] })) })] }));
145
+ } }, children: showLoading ? (_jsx("ul", { className: "k-search-suggest__list", role: "presentation", children: [0, 1, 2].map((k) => _jsx("li", { className: "k-listbox__loading" }, k)) })) : showEmpty ? (_jsx("ul", { className: "k-search-suggest__list", role: "presentation", children: _jsx("li", { className: "k-listbox__empty", children: emptyMessage }) })) : showList ? (_jsx("ul", { role: "listbox", "aria-label": M.searchSuggest.suggestions, className: "k-search-suggest__list", children: list.map((s, i) => (_jsxs("li", { id: `${listId}-${i}`, role: "option", "aria-selected": i === active, className: "k-option", "data-active": i === active || undefined, onMouseDown: (e) => e.preventDefault(), onPointerMove: () => setActive(i), onClick: () => submit(s), children: [_jsx(SearchIcon, {}), _jsx("span", { className: "k-option__label", children: highlight(s) })] }, s))) })) : (_jsxs(_Fragment, { children: [history.length > 0 && (_jsxs("section", { className: "k-search-suggest__section", children: [_jsxs("div", { className: "k-search-suggest__head", children: [_jsx("b", { children: labels.recent ?? M.searchSuggest.recent }), _jsx("button", { type: "button", className: "k-btn k-btn--link k-btn--sm", onMouseDown: (e) => e.preventDefault(), onClick: clearHistory, children: labels.clear ?? M.searchSuggest.clear })] }), _jsx("ul", { className: "k-search-suggest__chips", children: history.map((s) => chip(s, "recent")) })] })), popular.length > 0 && (_jsxs("section", { className: "k-search-suggest__section", children: [_jsx("div", { className: "k-search-suggest__head", children: _jsx("b", { children: labels.popular ?? M.searchSuggest.popular }) }), _jsx("ul", { className: "k-search-suggest__chips", children: popular.map((s) => chip(s, "popular")) })] }))] })) })] }));
144
146
  }
@@ -21,7 +21,9 @@ export interface SegmentedControlProps {
21
21
  /** تمام‌عرض با بخش‌های هم‌اندازه */
22
22
  block?: boolean;
23
23
  disabled?: boolean;
24
+ /** فقط‌خواندنی: انتخاب‌ها دیده می‌شوند ولی عوض نمی‌شوند */
25
+ readOnly?: boolean;
24
26
  className?: string;
25
27
  }
26
28
  /** انتخاب یکی از چند گزینهٔ کوتاه، مثل «فهرست / جدول / کارت»؛ روی رادیوی بومی با پیمایش ↑↓←→ */
27
- export declare function SegmentedControl({ options, value, defaultValue, onChange, name, size, block, disabled, className, "aria-label": ariaLabel, "aria-labelledby": labelledBy, }: SegmentedControlProps): import("react").JSX.Element;
29
+ export declare function SegmentedControl({ options, value, defaultValue, onChange, name, size, block, disabled, readOnly, className, "aria-label": ariaLabel, "aria-labelledby": labelledBy, }: SegmentedControlProps): import("react").JSX.Element;
@@ -4,7 +4,7 @@ import { useId, useRef, useState } from "react";
4
4
  import { cx } from "./cx.js";
5
5
  import { useIsomorphicLayoutEffect } from "./utils.js";
6
6
  /** انتخاب یکی از چند گزینهٔ کوتاه، مثل «فهرست / جدول / کارت»؛ روی رادیوی بومی با پیمایش ↑↓←→ */
7
- export function SegmentedControl({ options, value, defaultValue, onChange, name, size = "md", block, disabled, className, "aria-label": ariaLabel, "aria-labelledby": labelledBy, }) {
7
+ export function SegmentedControl({ options, value, defaultValue, onChange, name, size = "md", block, disabled, readOnly, className, "aria-label": ariaLabel, "aria-labelledby": labelledBy, }) {
8
8
  const autoName = useId();
9
9
  const [inner, setInner] = useState(defaultValue ?? options.find((o) => !o.disabled)?.value);
10
10
  const current = value ?? inner;
@@ -24,7 +24,9 @@ export function SegmentedControl({ options, value, defaultValue, onChange, name,
24
24
  ro.observe(el);
25
25
  return () => ro.disconnect();
26
26
  }, [current]);
27
- return (_jsxs("div", { ref: ref, role: "radiogroup", "aria-label": ariaLabel, "aria-labelledby": labelledBy, className: cx("k-segmented", size === "sm" && "k-segmented--sm", block && "k-segmented--block", className), "data-indicator": box ? "" : undefined, style: box ? { "--_ix": `${box.x}px`, "--_iw": `${box.w}px` } : undefined, children: [box && _jsx("span", { className: "k-segmented__indicator", "aria-hidden": "true" }), options.map((o) => (_jsxs("label", { className: "k-segmented__item", children: [_jsx("input", { type: "radio", className: "k-sr-only", name: name ?? autoName, value: o.value, checked: current === o.value, disabled: disabled || o.disabled, "aria-label": o["aria-label"], onChange: () => {
27
+ return (_jsxs("div", { ref: ref, role: "radiogroup", "aria-label": ariaLabel, "aria-labelledby": labelledBy, "aria-readonly": readOnly || undefined, "data-readonly": readOnly || undefined, className: cx("k-segmented", size === "sm" && "k-segmented--sm", block && "k-segmented--block", className), "data-indicator": box ? "" : undefined, style: box ? { "--_ix": `${box.x}px`, "--_iw": `${box.w}px` } : undefined, children: [box && _jsx("span", { className: "k-segmented__indicator", "aria-hidden": "true" }), options.map((o) => (_jsxs("label", { className: "k-segmented__item", children: [_jsx("input", { type: "radio", className: "k-sr-only", name: name ?? autoName, value: o.value, checked: current === o.value, disabled: disabled || o.disabled, "aria-label": o["aria-label"], onChange: () => {
28
+ if (readOnly)
29
+ return;
28
30
  if (value === undefined)
29
31
  setInner(o.value);
30
32
  onChange?.(o.value);
package/dist/Select.d.ts CHANGED
@@ -17,6 +17,12 @@ export interface SelectProps extends Omit<SelectHTMLAttributes<HTMLSelectElement
17
17
  fieldClassName?: string;
18
18
  /** فهرست بومی مرورگر به‌جای فهرست کاشی؛ برای فهرست‌های خیلی بلند یا وقتی انتخاب‌گر سیستم گوشی را می‌خواهید @default false */
19
19
  native?: boolean;
20
+ /** فقط‌خواندنی: مقدار دیده و با فرم ارسال می‌شود ولی فهرست باز نمی‌شود (برخلاف disabled، کم‌رنگ نمی‌شود) */
21
+ readOnly?: boolean;
22
+ /** گزینه‌ها در حال بارگذاری‌اند؛ اسپینر جای شورون و ردیف‌های اسکلتی در فهرست */
23
+ loading?: boolean;
24
+ /** پیام فهرست خالی @default «گزینه‌ای برای انتخاب نیست.» */
25
+ emptyMessage?: ReactNode;
20
26
  }
21
27
  /**
22
28
  * انتخاب از فهرست. نسخهٔ ۲: فهرست با ظاهر کاشی، صفحه‌کلید کامل (فلش‌ها، Home/End، Enter، Escape و تایپ حرف اول)
package/dist/Select.js CHANGED
@@ -4,6 +4,7 @@ import { Children, forwardRef, isValidElement, useCallback, useEffect, useId, us
4
4
  import { cx } from "./cx.js";
5
5
  import { Field, describedBy } from "./Field.js";
6
6
  import { useIsomorphicLayoutEffect } from "./utils.js";
7
+ import { useKashi } from "./KashiProvider.js";
7
8
  const textOf = (node) => typeof node === "string" || typeof node === "number" ? String(node)
8
9
  : Array.isArray(node) ? node.map(textOf).join("")
9
10
  : isValidElement(node) ? textOf(node.props.children) : "";
@@ -34,17 +35,18 @@ const Check = () => (_jsx("svg", { className: "k-option__check", viewBox: "0 0 2
34
35
  * و یک <select> بومیِ پنهان زیرش، تا فرم، name، required، onChange و ref مثل قبل کار کنند.
35
36
  * برای انتخاب‌گر سیستم، native بدهید.
36
37
  */
37
- export const Select = forwardRef(function Select({ label, hint, error, placeholder, options, size = "md", id, required, className, fieldClassName, children, native = false, "aria-describedby": extra, ...rest }, ref) {
38
+ export const Select = forwardRef(function Select({ label, hint, error, placeholder, options, size = "md", id, required, className, fieldClassName, children, native = false, readOnly, loading, emptyMessage, "aria-describedby": extra, ...rest }, ref) {
38
39
  const autoId = useId();
39
40
  const selectId = id ?? autoId;
40
41
  const placeholderSelected = placeholder !== undefined && rest.value === undefined && rest.defaultValue === undefined;
41
42
  if (native) {
42
43
  return (_jsx(Field, { id: selectId, label: label, hint: hint, error: error, required: required, className: fieldClassName, children: _jsx("div", { className: cx("k-select", size !== "md" && `k-select--${size}`, className), children: _jsxs("select", { ref: ref, id: selectId, className: "k-select__control", required: required, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(selectId, hint, error, extra), defaultValue: placeholderSelected ? "" : undefined, ...rest, children: [placeholder !== undefined && _jsx("option", { value: "", disabled: true, children: placeholder }), options?.map((o) => _jsx("option", { value: o.value, disabled: o.disabled, children: o.label }, o.value)), children] }) }) }));
43
44
  }
44
- return _jsx(CustomSelect, { selectId, label, hint, error, placeholder, options, size, required, className, fieldClassName, children, extra, placeholderSelected, rest, forwardedRef: ref });
45
+ return _jsx(CustomSelect, { selectId, label, hint, error, placeholder, options, size, required, className, fieldClassName, children, extra, placeholderSelected, rest, readOnly, loading, emptyMessage, forwardedRef: ref });
45
46
  });
46
- function CustomSelect({ selectId, label, hint, error, placeholder, options, size, required, className, fieldClassName, children, extra, placeholderSelected, rest, forwardedRef, }) {
47
+ function CustomSelect({ selectId, label, hint, error, placeholder, options, size, required, className, fieldClassName, children, extra, placeholderSelected, rest, forwardedRef, readOnly, loading, emptyMessage, }) {
47
48
  const { value, defaultValue, onChange, disabled, name, form, autoComplete, onBlur, onFocus, ...other } = rest;
49
+ const { messages: M } = useKashi();
48
50
  const items = useMemo(() => collect(options, children), [options, children]);
49
51
  const opts = items.filter((i) => i.kind === "option");
50
52
  const nativeRef = useRef(null);
@@ -71,7 +73,7 @@ function CustomSelect({ selectId, label, hint, error, placeholder, options, size
71
73
  }
72
74
  }, [controlled]);
73
75
  const openList = (to) => {
74
- if (disabled)
76
+ if (disabled || readOnly)
75
77
  return;
76
78
  const idx = to ?? Math.max(0, opts.findIndex((o) => o.value === current));
77
79
  setActive(idx);
@@ -147,7 +149,7 @@ function CustomSelect({ selectId, label, hint, error, placeholder, options, size
147
149
  choose(opts[hit].value);
148
150
  };
149
151
  const onKeyDown = (e) => {
150
- if (disabled)
152
+ if (disabled || readOnly)
151
153
  return;
152
154
  const k = e.key;
153
155
  if (!open) {
@@ -202,15 +204,15 @@ function CustomSelect({ selectId, label, hint, error, placeholder, options, size
202
204
  typeahead(k);
203
205
  };
204
206
  let index = -1;
205
- return (_jsx(Field, { id: selectId, label: label, hint: hint, error: error, required: required, className: fieldClassName, children: _jsxs("div", { className: cx("k-select", "k-select--custom", size !== "md" && `k-select--${size}`, className), "data-open": open || undefined, children: [_jsxs("button", { ref: triggerRef, id: selectId, type: "button", role: "combobox", className: "k-select__control", "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? `${listId}-${active}` : undefined, "aria-invalid": error ? true : undefined, "aria-required": required || undefined, "aria-describedby": describedBy(selectId, hint, error, extra), disabled: disabled, onClick: () => (open ? close(false) : openList()), onKeyDown: onKeyDown, onBlur: (e) => { if (!listRef.current?.contains(e.relatedTarget))
206
- setOpen(false); }, ...other, children: [_jsx("span", { className: cx("k-select__value", !selected && "k-select__value--placeholder"), children: selected ? selected.label : placeholder ?? " " }), _jsx(Chevron, {})] }), _jsx("ul", { id: listId, ref: listRef, role: "listbox", "aria-labelledby": selectId, className: cx("k-listbox", "k-select__list", up && "k-select__list--up"), hidden: !open, tabIndex: -1, ...{ popover: "manual" }, style: pos ? { position: "fixed", insetBlock: "auto", top: pos.top, bottom: pos.bottom, left: pos.left, width: pos.width, right: "auto" } : undefined, children: items.map((it, i) => {
207
- if (it.kind === "group")
208
- return _jsx("li", { role: "presentation", className: "k-listbox__group", children: it.label }, `g${i}`);
209
- index += 1;
210
- const n = index;
211
- const isSel = it.value === current;
212
- return (_jsxs("li", { id: `${listId}-${n}`, "data-index": n, role: "option", className: "k-option", "aria-selected": isSel, "aria-disabled": it.disabled || undefined, "data-active": n === active || undefined, onPointerMove: () => !it.disabled && setActive(n), onMouseDown: (e) => e.preventDefault(), onClick: () => { if (it.disabled)
213
- return; choose(it.value); close(); }, children: [_jsx("span", { className: "k-option__label", children: it.label }), isSel && _jsx(Check, {})] }, it.value));
214
- }) }), _jsxs("select", { ref: nativeRef, className: "k-select__native", tabIndex: -1, "aria-hidden": "true", name: name, form: form, autoComplete: autoComplete, required: required, disabled: disabled, value: current, onChange: (e) => { if (!controlled)
207
+ return (_jsx(Field, { id: selectId, label: label, hint: hint, error: error, required: required, className: fieldClassName, children: _jsxs("div", { className: cx("k-select", "k-select--custom", size !== "md" && `k-select--${size}`, className), "data-open": open || undefined, "data-readonly": readOnly || undefined, "aria-busy": loading || undefined, children: [_jsxs("button", { ref: triggerRef, id: selectId, type: "button", role: "combobox", className: "k-select__control", "aria-haspopup": "listbox", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? `${listId}-${active}` : undefined, "aria-invalid": error ? true : undefined, "aria-required": required || undefined, "aria-readonly": readOnly || undefined, "aria-describedby": describedBy(selectId, hint, error, extra), disabled: disabled, onClick: () => (open ? close(false) : openList()), onKeyDown: onKeyDown, onBlur: (e) => { if (!listRef.current?.contains(e.relatedTarget))
208
+ setOpen(false); }, ...other, children: [_jsx("span", { className: cx("k-select__value", !selected && "k-select__value--placeholder"), children: selected ? selected.label : placeholder ?? " " }), _jsx(Chevron, {})] }), _jsxs("ul", { id: listId, ref: listRef, role: "listbox", "aria-labelledby": selectId, className: cx("k-listbox", "k-select__list", up && "k-select__list--up"), hidden: !open, tabIndex: -1, ...{ popover: "manual" }, style: pos ? { position: "fixed", insetBlock: "auto", top: pos.top, bottom: pos.bottom, left: pos.left, width: pos.width, right: "auto" } : undefined, children: [loading && opts.length === 0 && [0, 1, 2].map((k) => _jsx("li", { className: "k-listbox__loading", role: "presentation" }, `l${k}`)), !loading && opts.length === 0 && _jsx("li", { className: "k-listbox__empty", role: "presentation", children: emptyMessage ?? M.common.noOptions }), items.map((it, i) => {
209
+ if (it.kind === "group")
210
+ return _jsx("li", { role: "presentation", className: "k-listbox__group", children: it.label }, `g${i}`);
211
+ index += 1;
212
+ const n = index;
213
+ const isSel = it.value === current;
214
+ return (_jsxs("li", { id: `${listId}-${n}`, "data-index": n, role: "option", className: "k-option", "aria-selected": isSel, "aria-disabled": it.disabled || undefined, "data-active": n === active || undefined, onPointerMove: () => !it.disabled && setActive(n), onMouseDown: (e) => e.preventDefault(), onClick: () => { if (it.disabled)
215
+ return; choose(it.value); close(); }, children: [_jsx("span", { className: "k-option__label", children: it.label }), isSel && _jsx(Check, {})] }, it.value));
216
+ })] }), _jsxs("select", { ref: nativeRef, className: "k-select__native", tabIndex: -1, "aria-hidden": "true", name: name, form: form, autoComplete: autoComplete, required: required, disabled: disabled, value: current, onChange: (e) => { if (!controlled)
215
217
  setInner(e.target.value); onChange?.(e); }, onFocus: (e) => { triggerRef.current?.focus(); onFocus?.(e); }, onBlur: onBlur, onInvalid: () => triggerRef.current?.focus(), children: [_jsx("option", { value: "" }), opts.map((o) => _jsx("option", { value: o.value, disabled: o.disabled, children: o.text }, o.value))] })] }) }));
216
218
  }
package/dist/Stat.d.ts CHANGED
@@ -18,6 +18,8 @@ export interface StatCardProps extends Omit<HTMLAttributes<HTMLDivElement>, "tit
18
18
  down?: string;
19
19
  flat?: string;
20
20
  };
21
+ /** عدد در راه است؛ اسکلت جای محتوا */
22
+ loading?: boolean;
21
23
  }
22
24
  /** کارت شاخص کلیدی (KPI) با روند؛ صفحه‌خوان روند را به شکل «۱۲٪ افزایش» می‌خواند */
23
25
  export declare const StatCard: import("react").ForwardRefExoticComponent<StatCardProps & import("react").RefAttributes<HTMLDivElement>>;
package/dist/Stat.js CHANGED
@@ -5,14 +5,14 @@ import { cx } from "./cx.js";
5
5
  import { useKashi } from "./KashiProvider.js";
6
6
  const Arrow = ({ dir }) => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: dir === "up" ? _jsx("path", { d: "M10 15V5m0 0-4 4m4-4 4 4" }) : _jsx("path", { d: "M10 5v10m0 0-4-4m4 4 4-4" }) }));
7
7
  /** کارت شاخص کلیدی (KPI) با روند؛ صفحه‌خوان روند را به شکل «۱۲٪ افزایش» می‌خواند */
8
- export const StatCard = forwardRef(function StatCard({ label, value, unit, icon, change, invertTrend, caption, children, labels = {}, className, ...rest }, ref) {
8
+ export const StatCard = forwardRef(function StatCard({ label, value, unit, icon, change, invertTrend, caption, children, labels = {}, loading, className, ...rest }, ref) {
9
9
  const { messages: M, n } = useKashi();
10
10
  const { up = M.stat.up, down = M.stat.down, flat = M.stat.flat } = labels;
11
11
  const dir = change === undefined ? null : change > 0 ? "up" : change < 0 ? "down" : "flat";
12
12
  // رنگ بر اساس خوب یا بد بودن، نه جهت
13
13
  const good = dir === "flat" ? "flat" : (dir === "up") !== Boolean(invertTrend) ? "up" : "down";
14
14
  const pct = change === undefined ? "" : M.common.percent(n(Math.abs(Math.round(change * 10) / 10)).replace(".", M.common.decimal));
15
- return (_jsxs("div", { ref: ref, className: cx("k-stat", className), ...rest, children: [_jsxs("div", { className: "k-stat__head", children: [icon && _jsx("span", { className: "k-stat__icon", "aria-hidden": "true", children: icon }), _jsx("p", { className: "k-stat__label", children: label })] }), _jsxs("p", { className: "k-stat__value", children: [_jsx("span", { children: value }), unit && _jsx("span", { className: "k-stat__unit", children: unit })] }), (dir || caption) && (_jsxs("div", { className: "k-stat__foot", children: [dir && (_jsxs("span", { className: `k-trend k-trend--${good}`, children: [dir !== "flat" && _jsx(Arrow, { dir: dir }), _jsx("span", { "aria-hidden": "true", children: dir === "flat" ? flat : pct }), _jsx("span", { className: "k-sr-only", children: dir === "flat" ? flat : `${pct} ${dir === "up" ? up : down}` })] })), caption && _jsx("span", { children: caption })] })), children && _jsx("div", { className: "k-stat__chart", children: children })] }));
15
+ return (_jsxs("div", { ref: ref, className: cx("k-stat", className), "aria-busy": loading || undefined, ...rest, children: [_jsxs("div", { className: "k-stat__head", children: [icon && _jsx("span", { className: "k-stat__icon", "aria-hidden": "true", children: icon }), _jsx("p", { className: "k-stat__label", children: label })] }), _jsxs("p", { className: "k-stat__value", children: [_jsx("span", { children: value }), unit && _jsx("span", { className: "k-stat__unit", children: unit })] }), (dir || caption) && (_jsxs("div", { className: "k-stat__foot", children: [dir && (_jsxs("span", { className: `k-trend k-trend--${good}`, children: [dir !== "flat" && _jsx(Arrow, { dir: dir }), _jsx("span", { "aria-hidden": "true", children: dir === "flat" ? flat : pct }), _jsx("span", { className: "k-sr-only", children: dir === "flat" ? flat : `${pct} ${dir === "up" ? up : down}` })] })), caption && _jsx("span", { children: caption })] })), children && _jsx("div", { className: "k-stat__chart", children: children })] }));
16
16
  });
17
17
  export function StatGrid({ className, ...rest }) {
18
18
  return _jsx("div", { className: cx("k-stat-grid", className), ...rest });
@@ -20,7 +20,9 @@ export interface SwatchGroupProps {
20
20
  size?: "sm" | "md" | "lg";
21
21
  /** با name، مقدارهای انتخاب‌شده در فرم ارسال می‌شوند */
22
22
  name?: string;
23
+ /** فقط‌خواندنی: انتخاب‌ها دیده می‌شوند ولی عوض نمی‌شوند */
24
+ readOnly?: boolean;
23
25
  className?: string;
24
26
  }
25
27
  /** انتخاب رنگ از میان نمونه‌ها (فیلتر رنگ کالا)؛ روی چک‌باکس یا رادیوی بومی، پس صفحه‌کلید و فرم خودکار کار می‌کنند */
26
- export declare function SwatchGroup({ options, value, defaultValue, onChange, single, label, size, name, className }: SwatchGroupProps): import("react").JSX.Element;
28
+ export declare function SwatchGroup({ options, value, defaultValue, onChange, single, label, size, name, readOnly, className }: SwatchGroupProps): import("react").JSX.Element;
@@ -4,20 +4,25 @@ import { useId, useState } from "react";
4
4
  import { cx } from "./cx.js";
5
5
  import { useKashi } from "./KashiProvider.js";
6
6
  /** انتخاب رنگ از میان نمونه‌ها (فیلتر رنگ کالا)؛ روی چک‌باکس یا رادیوی بومی، پس صفحه‌کلید و فرم خودکار کار می‌کنند */
7
- export function SwatchGroup({ options, value, defaultValue, onChange, single = false, label, size = "md", name, className }) {
7
+ export function SwatchGroup({ options, value, defaultValue, onChange, single = false, label, size = "md", name, readOnly, className }) {
8
8
  const { messages: M } = useKashi();
9
9
  const id = useId();
10
10
  const [inner, setInner] = useState(defaultValue ?? []);
11
11
  const selected = value ?? inner;
12
12
  const toggle = (v) => {
13
+ if (readOnly)
14
+ return;
13
15
  const next = single ? (selected[0] === v ? [] : [v]) : selected.includes(v) ? selected.filter((x) => x !== v) : [...selected, v];
14
16
  if (value === undefined)
15
17
  setInner(next);
16
18
  onChange?.(next);
17
19
  };
18
- return (_jsxs("fieldset", { className: cx("k-swatches", size !== "md" && `k-swatches--${size}`, className), children: [label && _jsx("legend", { className: "k-label k-swatches__legend", children: label }), _jsx("div", { className: "k-swatches__grid", role: single ? "radiogroup" : undefined, children: options.map((o) => {
20
+ return (_jsxs("fieldset", { className: cx("k-swatches", size !== "md" && `k-swatches--${size}`, className), "aria-readonly": readOnly || undefined, "data-readonly": readOnly || undefined, children: [label && _jsx("legend", { className: "k-label k-swatches__legend", children: label }), _jsx("div", { className: "k-swatches__grid", role: single ? "radiogroup" : undefined, children: options.map((o) => {
19
21
  const on = selected.includes(o.value);
20
- return (_jsxs("label", { className: "k-swatch", "data-disabled": o.disabled || undefined, children: [_jsx("input", { type: single ? "radio" : "checkbox", className: "k-sr-only", name: name ?? (single ? id : undefined), value: o.value, checked: on, disabled: o.disabled, onChange: () => toggle(o.value), onClick: (e) => { if (single && on) {
22
+ return (_jsxs("label", { className: "k-swatch", "data-disabled": o.disabled || undefined, children: [_jsx("input", { type: single ? "radio" : "checkbox", className: "k-sr-only", name: name ?? (single ? id : undefined), value: o.value, checked: on, disabled: o.disabled, onChange: () => toggle(o.value), onClick: (e) => { if (readOnly) {
23
+ e.preventDefault();
24
+ return;
25
+ } if (single && on) {
21
26
  e.preventDefault();
22
27
  toggle(o.value);
23
28
  } } }), _jsx("span", { className: "k-swatch__color", style: { "--_c": o.color }, "aria-hidden": "true", children: _jsx("svg", { className: "k-swatch__check", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: "2.2", strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "m5 10.5 3.2 3L15 7" }) }) }), _jsxs("span", { className: "k-swatch__label", children: [o.label, on && _jsxs("span", { className: "k-sr-only", children: ["\u060C ", M.swatch.selected] })] })] }, o.value));
@@ -18,6 +18,8 @@ export interface TagInputProps {
18
18
  allowDuplicates?: boolean;
19
19
  tone?: BadgeTone;
20
20
  disabled?: boolean;
21
+ /** فقط‌خواندنی: برچسب‌ها دیده و ارسال می‌شوند ولی اضافه یا حذف نمی‌شوند */
22
+ readOnly?: boolean;
21
23
  name?: string;
22
24
  id?: string;
23
25
  className?: string;
package/dist/TagInput.js CHANGED
@@ -7,7 +7,7 @@ import { Field, describedBy } from "./Field.js";
7
7
  import { mergeRefs } from "./utils.js";
8
8
  import { useKashi } from "./KashiProvider.js";
9
9
  /** ورود چند مقدار، مثل مهارت‌ها یا ایمیل‌ها؛ Enter یا ویرگول (, یا ،) ثبت می‌کند و Backspace آخری را حذف می‌کند */
10
- export const TagInput = forwardRef(function TagInput({ label, hint, error, value, defaultValue = [], onChange, placeholder, separators = ["Enter", ",", "،"], validate, max, allowDuplicates = false, tone = "brand", disabled, name, id, className, labels = {}, }, ref) {
10
+ export const TagInput = forwardRef(function TagInput({ label, hint, error, value, defaultValue = [], onChange, placeholder, separators = ["Enter", ",", "،"], validate, max, allowDuplicates = false, tone = "brand", disabled, readOnly, name, id, className, labels = {}, }, ref) {
11
11
  const autoId = useId();
12
12
  const inputId = id ?? autoId;
13
13
  const [inner, setInner] = useState(defaultValue);
@@ -74,7 +74,7 @@ export const TagInput = forwardRef(function TagInput({ label, hint, error, value
74
74
  }
75
75
  };
76
76
  const shownError = error ?? localError;
77
- return (_jsxs(Field, { id: inputId, label: label, hint: hint, error: shownError, className: className, children: [_jsxs("div", { className: "k-tag-input", "data-invalid": shownError ? "" : undefined, onClick: () => inputRef.current?.focus(), children: [tags.map((t, i) => (_jsx(Badge, { tone: tone, onRemove: disabled ? undefined : () => removeAt(i), removeLabel: remove(t), children: t }, `${t}-${i}`))), _jsx("input", { ref: mergeRefs(ref, inputRef), id: inputId, className: "k-tag-input__control", value: text, placeholder: tags.length ? undefined : placeholder, disabled: disabled, "aria-invalid": shownError ? true : undefined, "aria-describedby": describedBy(inputId, hint, shownError), onChange: (e) => {
77
+ return (_jsxs(Field, { id: inputId, label: label, hint: hint, error: shownError, className: className, children: [_jsxs("div", { className: "k-tag-input", "data-invalid": shownError ? "" : undefined, "data-readonly": readOnly || undefined, onClick: () => inputRef.current?.focus(), children: [tags.map((t, i) => (_jsx(Badge, { tone: tone, onRemove: disabled || readOnly ? undefined : () => removeAt(i), removeLabel: remove(t), children: t }, `${t}-${i}`))), _jsx("input", { ref: mergeRefs(ref, inputRef), id: inputId, className: "k-tag-input__control", value: text, placeholder: tags.length || readOnly ? undefined : placeholder, disabled: disabled, readOnly: readOnly, "aria-invalid": shownError ? true : undefined, "aria-describedby": describedBy(inputId, hint, shownError), onChange: (e) => {
78
78
  const v = e.target.value;
79
79
  setLocalError(undefined);
80
80
  // صفحه‌کلید موبایل و IME رویداد کلید نمی‌فرستند؛ جداکننده را در متن هم پیدا کن
@@ -87,5 +87,5 @@ export const TagInput = forwardRef(function TagInput({ label, hint, error, value
87
87
  }
88
88
  else
89
89
  setText(v);
90
- }, onKeyDown: onKeyDown, onPaste: onPaste, onBlur: () => text.trim() && addMany([text]) })] }), _jsx("span", { className: "k-sr-only", "aria-live": "polite", children: announce }), name && tags.map((t, i) => _jsx("input", { type: "hidden", name: name, value: t }, i))] }));
90
+ }, onKeyDown: readOnly ? undefined : onKeyDown, onPaste: readOnly ? undefined : onPaste, onBlur: () => !readOnly && text.trim() && addMany([text]) })] }), _jsx("span", { className: "k-sr-only", "aria-live": "polite", children: announce }), name && tags.map((t, i) => _jsx("input", { type: "hidden", name: name, value: t }, i))] }));
91
91
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kashi-ui/react",
3
- "version": "2.1.0",
3
+ "version": "2.3.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.1.0",
25
+ "@kashi-ui/css": "^2.3.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.1.0",
63
- "@kashi-ui/persian": "^2.1.0"
62
+ "@kashi-ui/bank-logos": "^2.3.0",
63
+ "@kashi-ui/persian": "^2.3.0"
64
64
  }
65
65
  }