@kashi-ui/react 0.26.0 → 1.0.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.
Files changed (77) hide show
  1. package/dist/ActivityHeatmap.js +12 -8
  2. package/dist/AddressForm.js +8 -4
  3. package/dist/Alert.js +4 -1
  4. package/dist/AppointmentPicker.js +16 -11
  5. package/dist/Avatar.js +8 -11
  6. package/dist/Badge.js +3 -1
  7. package/dist/BankBadge.js +4 -1
  8. package/dist/BankCard.js +7 -4
  9. package/dist/Banner.js +5 -1
  10. package/dist/Breadcrumb.js +5 -1
  11. package/dist/Button.js +4 -1
  12. package/dist/Calendar.js +10 -6
  13. package/dist/CardNumberInput.js +5 -1
  14. package/dist/Carousel.js +5 -4
  15. package/dist/Chart.js +57 -30
  16. package/dist/CitySelect.js +7 -4
  17. package/dist/ColorPicker.d.ts +1 -1
  18. package/dist/ColorPicker.js +22 -17
  19. package/dist/Combobox.js +8 -4
  20. package/dist/CommandPalette.js +6 -3
  21. package/dist/ContextMenu.js +5 -2
  22. package/dist/CopyButton.js +3 -1
  23. package/dist/Countdown.js +6 -3
  24. package/dist/DataTable.js +4 -2
  25. package/dist/DatePicker.js +8 -2
  26. package/dist/DateRangePicker.d.ts +1 -1
  27. package/dist/DateRangePicker.js +16 -10
  28. package/dist/DateTile.js +7 -4
  29. package/dist/Dialog.js +4 -1
  30. package/dist/Field.js +3 -1
  31. package/dist/FileUpload.d.ts +3 -2
  32. package/dist/FileUpload.js +15 -11
  33. package/dist/IbanInput.js +4 -1
  34. package/dist/InlineEdit.js +5 -3
  35. package/dist/Input.js +3 -1
  36. package/dist/IranMap.js +5 -3
  37. package/dist/KashiProvider.d.ts +28 -0
  38. package/dist/KashiProvider.js +27 -0
  39. package/dist/KeyboardFixInput.js +3 -1
  40. package/dist/LandlineInput.js +5 -1
  41. package/dist/LegalIdInput.js +5 -1
  42. package/dist/Meter.js +7 -4
  43. package/dist/MobileInput.js +7 -3
  44. package/dist/Money.js +10 -6
  45. package/dist/MonthPicker.js +8 -4
  46. package/dist/MultiSelect.js +7 -5
  47. package/dist/NationalIdInput.js +5 -1
  48. package/dist/NumberInput.js +5 -2
  49. package/dist/OtpInput.js +4 -1
  50. package/dist/Pagination.js +6 -3
  51. package/dist/PasswordStrength.d.ts +1 -0
  52. package/dist/PasswordStrength.js +15 -9
  53. package/dist/PaymentReceipt.js +10 -8
  54. package/dist/PersianInput.js +3 -1
  55. package/dist/PersianTextarea.js +9 -7
  56. package/dist/PlateInput.js +6 -3
  57. package/dist/PostalCodeInput.js +5 -1
  58. package/dist/PriceInput.js +9 -3
  59. package/dist/Progress.js +6 -3
  60. package/dist/ProvinceSelect.js +5 -3
  61. package/dist/Rating.js +6 -3
  62. package/dist/RelativeTime.js +5 -2
  63. package/dist/SideNav.js +4 -1
  64. package/dist/Slider.js +5 -2
  65. package/dist/Splitter.js +5 -3
  66. package/dist/Stat.js +4 -3
  67. package/dist/Stepper.js +6 -4
  68. package/dist/TagInput.js +4 -2
  69. package/dist/TimeInput.js +6 -1
  70. package/dist/Timeline.js +1 -1
  71. package/dist/Toast.js +5 -1
  72. package/dist/Tour.js +3 -2
  73. package/dist/index.d.ts +4 -0
  74. package/dist/index.js +2 -0
  75. package/dist/utils.d.ts +5 -0
  76. package/dist/utils.js +11 -0
  77. package/package.json +4 -4
package/dist/Chart.js CHANGED
@@ -3,19 +3,29 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useId, useLayoutEffect, useRef, useState } from "react";
4
4
  import { formatNumber } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
- const fmtDefault = (n) => formatNumber(Math.round(n));
7
- /** عدد کوتاه برای محور: ۱٬۲۰۰٬۰۰۰ ← ۱٫۲ م */
8
- const compact = (n) => {
9
- const a = Math.abs(n);
10
- const fa = (x, u) => `${formatNumber(Math.round(x * 10) / 10).replace(".", "٫")}${u}`;
11
- if (a >= 1e9)
12
- return fa(n / 1e9, " میلیارد");
13
- if (a >= 1e6)
14
- return fa(n / 1e6, " م");
15
- if (a >= 1e3)
16
- return fa(n / 1e3, " هزار");
17
- return formatNumber(n);
18
- };
6
+ import { useKashi } from "./KashiProvider.js";
7
+ /** متن‌ها و قالب عددهای نمودار به زبان و ارقام KashiProvider */
8
+ function useChartText() {
9
+ const { messages: M, digits } = useKashi();
10
+ const num = (n) => formatNumber(n, { digits });
11
+ const dec = (x) => num(Math.round(x * 10) / 10).replace(".", M.common.decimal);
12
+ return {
13
+ M,
14
+ fmt: (n) => num(Math.round(n)),
15
+ pct: (v, total) => M.common.percent(dec((v / total) * 100)),
16
+ /** عدد کوتاه برای محور: ۱٬۲۰۰٬۰۰۰ ← ۱٫۲ م */
17
+ compact: (n) => {
18
+ const a = Math.abs(n);
19
+ if (a >= 1e9)
20
+ return dec(n / 1e9) + M.chart.billion;
21
+ if (a >= 1e6)
22
+ return dec(n / 1e6) + M.chart.million;
23
+ if (a >= 1e3)
24
+ return dec(n / 1e3) + M.chart.thousand;
25
+ return num(n);
26
+ },
27
+ };
28
+ }
19
29
  /** گام‌های گرد محور: ۰، ۲۵، ۵۰… */
20
30
  function niceTicks(max, count = 4) {
21
31
  if (max <= 0)
@@ -41,10 +51,14 @@ const tipAt = (el, box, i, anchor) => {
41
51
  };
42
52
  /** جدول هم‌ارز برای صفحه‌خوان و چاپ */
43
53
  function DataTable({ caption, labels, series, format }) {
44
- return (_jsxs("table", { className: "k-sr-only", children: [_jsx("caption", { children: caption }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "\u062F\u0648\u0631\u0647" }), 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)) })] }));
54
+ const { messages: M } = useKashi();
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)) })] }));
45
56
  }
46
57
  /** نمودار ستونی؛ تک‌سری یا انباشته تا چهار سری. با موس یا Tab روی هر ستون مقدار دقیق نمایش داده می‌شود */
47
- export function BarChart({ title, data, series, labels, format = fmtDefault, labelMax = true, height, className }) {
58
+ export function BarChart({ title, data, series, labels, format, labelMax = true, height, className }) {
59
+ const T = useChartText();
60
+ const M = T.M;
61
+ format ?? (format = T.fmt);
48
62
  const id = useId();
49
63
  const stacked = series?.slice(0, 4);
50
64
  const cats = stacked ? labels ?? [] : (data ?? []).map((d) => d.label);
@@ -54,45 +68,55 @@ export function BarChart({ title, data, series, labels, format = fmtDefault, lab
54
68
  const top = ticks[ticks.length - 1] || 1;
55
69
  const maxIndex = totals.indexOf(max);
56
70
  const color = (i) => ({ "--_c": `var(--k-chart-${i + 1})` });
57
- const describe = (i) => stacked ? `${cats[i]}: ${stacked.map((s) => `${s.name} ${format(s.values[i] ?? 0)}`).join("، ")}، جمع ${format(totals[i])}` : `${cats[i]}: ${format(totals[i])}`;
71
+ 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])}`;
58
72
  const box = useRef(null);
59
73
  const [tip, setTip] = useState(null);
60
74
  const show = (e, i) => setTip(tipAt(e.currentTarget, box.current, i, e.currentTarget.querySelector(".k-bars__bar, .k-bars__stack")));
61
- 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": 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
62
- ? [...stacked.map((s, si) => ({ name: s.name, value: format(s.values[tip.i] ?? 0), color: `var(--k-chart-${si + 1})` })), { name: "جمع", value: format(totals[tip.i]) }]
75
+ 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
+ ? [...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]) }]
63
77
  : [{ value: format(totals[tip.i]) }] }))] })] }));
64
78
  }
65
79
  /** میله‌های افقی برای رتبه‌بندی با نام‌های بلند، مثل پربازدیدترین صفحه‌ها */
66
- export function BarList({ title, data, format = fmtDefault, className }) {
80
+ export function BarList({ title, data, format, className }) {
81
+ const T = useChartText();
82
+ const M = T.M;
83
+ format ?? (format = T.fmt);
67
84
  const id = useId();
68
85
  const max = Math.max(1, ...data.map((d) => d.value));
69
86
  const total = data.reduce((n, d) => n + d.value, 0) || 1;
70
- const share = (v) => `${formatNumber(Math.round((v / total) * 1000) / 10).replace(".", "٫")}٪`;
87
+ const share = (v) => T.pct(v, total);
71
88
  const box = useRef(null);
72
89
  const [tip, setTip] = useState(null);
73
- 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: "مقدار", value: format(data[tip.i].value) }, { name: "سهم از کل", value: share(data[tip.i].value) }] })] })] }));
90
+ 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) }] })] })] }));
74
91
  }
75
92
  /** سهم هر بخش از کل در یک میلهٔ افقی، مثل منبع ورود کاربران؛ جایگزین خواناتر نمودار دایره‌ای */
76
- export function ProportionBar({ title, data, percent = true, format = fmtDefault, className }) {
93
+ export function ProportionBar({ title, data, percent = true, format, className }) {
94
+ const T = useChartText();
95
+ const M = T.M;
96
+ format ?? (format = T.fmt);
77
97
  const id = useId();
78
98
  const parts = data.slice(0, 4);
79
99
  const total = parts.reduce((n, d) => n + d.value, 0) || 1;
80
- const pct = (v) => `${formatNumber(Math.round((v / total) * 1000) / 10).replace(".", "٫")}٪`;
100
+ const pct = (v) => T.pct(v, total);
81
101
  const color = (i) => ({ "--_c": `var(--k-chart-${i + 1})` });
82
102
  const box = useRef(null);
83
103
  const [tip, setTip] = useState(null);
84
- 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: "تعداد", 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))) })] }));
104
+ 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))) })] }));
85
105
  }
86
106
  /**
87
107
  * نمودار دایره‌ای یا دونات تا پنج بخش، با فاصلهٔ کوچک بین بخش‌ها، راهنمای درصد و جدول هم‌ارز.
88
108
  * برای مقایسهٔ دقیق بخش‌ها ProportionBar خواناتر است.
89
109
  */
90
- export function PieChart({ title, data, variant = "donut", format = fmtDefault, totalLabel = "جمع", size = 176, className }) {
110
+ export function PieChart({ title, data, variant = "donut", format, totalLabel, size = 176, className }) {
111
+ const T = useChartText();
112
+ const M = T.M;
113
+ format ?? (format = T.fmt);
114
+ totalLabel ?? (totalLabel = M.common.total);
91
115
  const id = useId();
92
116
  const sorted = [...data].sort((a, b) => b.value - a.value);
93
- const parts = sorted.length > 5 ? [...sorted.slice(0, 4), { label: "سایر", value: sorted.slice(4).reduce((n, d) => n + d.value, 0) }] : sorted;
117
+ 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;
94
118
  const total = parts.reduce((n, d) => n + d.value, 0) || 1;
95
- const pct = (v) => `${formatNumber(Math.round((v / total) * 1000) / 10).replace(".", "٫")}٪`;
119
+ const pct = (v) => T.pct(v, total);
96
120
  const slot = (i) => (i < 4 ? `var(--k-chart-${i + 1})` : "var(--k-text-quaternary)");
97
121
  const donut = variant === "donut";
98
122
  // دایره با stroke-dasharray: هر بخش یک کمان؛ برای pie، شعاع نصف و ضخامت برابر قطر
@@ -113,7 +137,7 @@ export function PieChart({ title, data, variant = "donut", format = fmtDefault,
113
137
  const rr = donut ? r : r * 1.3;
114
138
  return { x: (R + rr * Math.cos(ang)) / (2 * R), y: (R + rr * Math.sin(ang)) / (2 * R) };
115
139
  };
116
- 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: "تعداد", 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))) })] })] }));
140
+ 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))) })] })] }));
117
141
  }
118
142
  /** خط روند کوچک برای کارت آمار و جدول؛ بدون محور، فقط شکل روند */
119
143
  export function Sparkline({ values, "aria-label": ariaLabel, tone = "brand", area = true, className }) {
@@ -130,7 +154,10 @@ export function Sparkline({ values, "aria-label": ariaLabel, tone = "brand", are
130
154
  * نمودار خطی تا چهار سری: خط ۲ پیکسلی، برچسب نام در انتهای هر خط،
131
155
  * راهنمای عمودی با موس و ←→ روی کیبورد، و جدول هم‌ارز برای صفحه‌خوان.
132
156
  */
133
- export function LineChart({ title, labels, series, format = fmtDefault, area, height, className }) {
157
+ export function LineChart({ title, labels, series, format, area, height, className }) {
158
+ const T = useChartText();
159
+ const M = T.M;
160
+ format ?? (format = T.fmt);
134
161
  const id = useId();
135
162
  const plot = useRef(null);
136
163
  const [size, setSize] = useState({ w: 600, h: 220, rtl: true });
@@ -194,5 +221,5 @@ export function LineChart({ title, labels, series, format = fmtDefault, area, he
194
221
  setActive(null);
195
222
  };
196
223
  const step = Math.max(1, Math.ceil(labels.length / Math.max(2, Math.floor(innerW / 64))));
197
- 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": `${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: 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("، ")}` : "" }), _jsx(DataTable, { caption: title, labels: labels, series: shown, format: format })] }));
224
+ 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 })] }));
198
225
  }
@@ -3,12 +3,15 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef, useMemo, useState } from "react";
4
4
  import { CITIES, getCities } from "@kashi-ui/persian";
5
5
  import { Combobox, searchText } from "./Combobox.js";
6
+ import { useKashi } from "./KashiProvider.js";
6
7
  const SEP = "|";
7
8
  // «علی آباد»، «علی‌آباد» و «علیآباد» یکی‌اند
8
9
  const loose = (s) => searchText(s).replace(/[\s‌]/g, "");
9
10
  const filter = (o, q) => o.value.startsWith(`custom${SEP}`) || [o.label, o.description ?? ""].some((t) => loose(t).includes(loose(q)));
10
11
  /** انتخاب شهر با جستجو؛ با استان فقط شهرهای همان استان، بدون آن همهٔ ۱۲۰۰+ شهر ایران با نام استان */
11
- export const CitySelect = forwardRef(function CitySelect({ province, value, defaultValue = null, onChange, allowCustom = true, label = "شهر", placeholder, onInputChange, ...rest }, ref) {
12
+ export const CitySelect = forwardRef(function CitySelect({ province, value, defaultValue = null, onChange, allowCustom = true, label, placeholder, onInputChange, ...rest }, ref) {
13
+ const { messages: M } = useKashi();
14
+ label ?? (label = M.city.label);
12
15
  const [query, setQuery] = useState("");
13
16
  const [inner, setInner] = useState(defaultValue);
14
17
  const city = value !== undefined ? value : inner;
@@ -20,13 +23,13 @@ export const CitySelect = forwardRef(function CitySelect({ province, value, defa
20
23
  const known = list.some((o) => o.label === city);
21
24
  // شهر انتخاب‌شده‌ای که در فهرست نیست هم باید در فیلد بماند
22
25
  if (city && !known)
23
- list.unshift({ value: `custom${SEP}${city}`, label: city, description: "خارج از فهرست" });
26
+ list.unshift({ value: `custom${SEP}${city}`, label: city, description: M.city.outside });
24
27
  if (allowCustom && q && q !== city && !list.some((o) => loose(o.label) === loose(q)))
25
- list.push({ value: `custom${SEP}${q}`, label: q, description: "شهر دیگر؛ همین نام ثبت شود" });
28
+ list.push({ value: `custom${SEP}${q}`, label: q, description: M.city.custom });
26
29
  return list;
27
30
  }, [province, query, city, allowCustom]);
28
31
  const selected = city ? options.find((o) => o.label === city && (!province || o.value.startsWith(`${province}${SEP}`) || o.value.startsWith(`custom${SEP}`)))?.value ?? null : null;
29
- return (_jsx(Combobox, { ref: ref, label: label, placeholder: placeholder ?? (province ? "جستجوی شهر" : "نام شهر، مثلاً کاشان"), options: options, filter: filter, value: selected, onInputChange: (q) => {
32
+ return (_jsx(Combobox, { ref: ref, label: label, placeholder: placeholder ?? (province ? M.city.search : M.city.hint), options: options, filter: filter, value: selected, onInputChange: (q) => {
30
33
  setQuery(q);
31
34
  onInputChange?.(q);
32
35
  }, onChange: (v) => {
@@ -20,4 +20,4 @@ export interface ColorPickerProps {
20
20
  /** نسبت کنتراست WCAG */
21
21
  export declare const contrastRatio: (a: string, b: string) => number;
22
22
  /** انتخاب رنگ برند یا برچسب: نمونه‌رنگ‌ها، پنل انتخاب دلخواه و کد hex، با کنتراست متن روی آن */
23
- export declare function ColorPicker({ label, hint, value, defaultValue, onChange, swatches, showContrast, name, id, className }: ColorPickerProps): import("react").JSX.Element;
23
+ export declare function ColorPicker({ label, hint, value, defaultValue, onChange, swatches: swatchesProp, showContrast, name, id, className }: ColorPickerProps): import("react").JSX.Element;
@@ -1,16 +1,17 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useRef, useState } from "react";
4
- import { toFaDigits } from "@kashi-ui/persian";
5
4
  import { Field } from "./Field.js";
5
+ import { useKashi } from "./KashiProvider.js";
6
+ // نام رنگ‌ها از فرهنگ متن‌ها می‌آید تا با زبان KashiProvider عوض شود
6
7
  const DEFAULT_SWATCHES = [
7
- { name: "فیروزه‌ای", value: "#0b8077" },
8
- { name: "لاجوردی", value: "#2740ed" },
9
- { name: "بنفش", value: "#7c3aed" },
10
- { name: "اناری", value: "#e51d2a" },
11
- { name: "زعفرانی", value: "#dd5e02" },
12
- { name: "پسته‌ای", value: "#518b25" },
13
- { name: "شب", value: "#2a2f3d" },
8
+ { key: "firoozeh", value: "#0b8077" },
9
+ { key: "lajvard", value: "#2740ed" },
10
+ { key: "violet", value: "#7c3aed" },
11
+ { key: "anar", value: "#e51d2a" },
12
+ { key: "zafaran", value: "#dd5e02" },
13
+ { key: "peste", value: "#518b25" },
14
+ { key: "shab", value: "#2a2f3d" },
14
15
  ];
15
16
  const HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
16
17
  const norm = (v) => {
@@ -51,6 +52,8 @@ function hsvToHex({ h, s, v }) {
51
52
  const Dropper = () => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m11 5 4 4M13.5 2.5a2.1 2.1 0 0 1 3 3L15 7 13 5ZM12 6l-7.5 7.5L3 17l3.5-1.5L14 8" }) });
52
53
  /** پنل انتخاب رنگ: سطح اشباع و روشنایی، نوار رنگ‌مایه، قطره‌چکان و کدها */
53
54
  function ColorPanel({ hex, onChange, onClose }) {
55
+ const { messages: M, n: N } = useKashi();
56
+ const C = M.colorPicker;
54
57
  const [hsv, setHsv] = useState(() => hexToHsv(hex));
55
58
  const area = useRef(null);
56
59
  const panel = useRef(null);
@@ -87,17 +90,17 @@ function ColorPanel({ hex, onChange, onClose }) {
87
90
  }
88
91
  };
89
92
  const [r, g, b] = hexToRgb(hex);
90
- const pct = (n) => `${toFaDigits(Math.round(n * 100))}٪`;
93
+ const pct = (x) => M.common.percent(N(Math.round(x * 100)));
91
94
  const eye = typeof window !== "undefined" && "EyeDropper" in window;
92
- return (_jsxs("div", { ref: panel, className: "k-color__panel", role: "dialog", "aria-label": "\u0627\u0646\u062A\u062E\u0627\u0628 \u0631\u0646\u06AF \u062F\u0644\u062E\u0648\u0627\u0647", onKeyDown: (e) => {
95
+ return (_jsxs("div", { ref: panel, className: "k-color__panel", role: "dialog", "aria-label": M.colorPicker.custom, onKeyDown: (e) => {
93
96
  if (e.key === "Escape") {
94
97
  e.stopPropagation();
95
98
  onClose();
96
99
  }
97
- }, children: [_jsx("div", { ref: area, className: "k-color__area", style: { "--_hue": `hsl(${hsv.h} 100% 50%)` }, role: "slider", tabIndex: 0, "aria-label": "\u0627\u0634\u0628\u0627\u0639 \u0648 \u0631\u0648\u0634\u0646\u0627\u06CC\u06CC", "aria-valuetext": `اشباع ${pct(hsv.s)}، روشنایی ${pct(hsv.v)}`, "aria-valuenow": Math.round(hsv.s * 100), onPointerDown: (e) => {
100
+ }, children: [_jsx("div", { ref: area, className: "k-color__area", style: { "--_hue": `hsl(${hsv.h} 100% 50%)` }, role: "slider", tabIndex: 0, "aria-label": C.area, "aria-valuetext": C.areaValue(pct(hsv.s), pct(hsv.v)), "aria-valuenow": Math.round(hsv.s * 100), onPointerDown: (e) => {
98
101
  e.currentTarget.setPointerCapture(e.pointerId);
99
102
  fromPointer(e);
100
- }, onPointerMove: (e) => e.buttons === 1 && fromPointer(e), onKeyDown: onAreaKey, children: _jsx("span", { className: "k-color__thumb", style: { left: `${hsv.s * 100}%`, top: `${(1 - hsv.v) * 100}%` } }) }), _jsxs("div", { className: "k-color__tools", children: [eye && (_jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": "\u0628\u0631\u062F\u0627\u0634\u062A\u0646 \u0631\u0646\u06AF \u0627\u0632 \u0635\u0641\u062D\u0647", onClick: async () => {
103
+ }, onPointerMove: (e) => e.buttons === 1 && fromPointer(e), onKeyDown: onAreaKey, children: _jsx("span", { className: "k-color__thumb", style: { left: `${hsv.s * 100}%`, top: `${(1 - hsv.v) * 100}%` } }) }), _jsxs("div", { className: "k-color__tools", children: [eye && (_jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": C.eyedropper, onClick: async () => {
101
104
  try {
102
105
  const res = await new window.EyeDropper().open();
103
106
  const h = norm(res.sRGBHex);
@@ -105,7 +108,7 @@ function ColorPanel({ hex, onChange, onClose }) {
105
108
  onChange(h);
106
109
  }
107
110
  catch { /* کاربر انصراف داد */ }
108
- }, children: _jsx(Dropper, {}) })), _jsx("span", { className: "k-color__current", "aria-hidden": "true" }), _jsx("input", { type: "range", className: "k-color__hue", min: 0, max: 359, value: Math.round(hsv.h), "aria-label": "\u0631\u0646\u06AF\u200C\u0645\u0627\u06CC\u0647", "aria-valuetext": `${toFaDigits(Math.round(hsv.h))} درجه`, onChange: (e) => apply({ ...hsv, h: Number(e.target.value) }) })] }), _jsx("div", { className: "k-color__codes", dir: "ltr", children: ["R", "G", "B"].map((ch, i) => (_jsxs("label", { className: "k-color__code", children: [_jsx("input", { className: "k-color__num", inputMode: "numeric", value: [r, g, b][i], "aria-label": { R: "قرمز", G: "سبز", B: "آبی" }[ch], onChange: (e) => {
111
+ }, children: _jsx(Dropper, {}) })), _jsx("span", { className: "k-color__current", "aria-hidden": "true" }), _jsx("input", { type: "range", className: "k-color__hue", min: 0, max: 359, value: Math.round(hsv.h), "aria-label": C.hue, "aria-valuetext": C.degrees(N(Math.round(hsv.h))), onChange: (e) => apply({ ...hsv, h: Number(e.target.value) }) })] }), _jsx("div", { className: "k-color__codes", dir: "ltr", children: ["R", "G", "B"].map((ch, i) => (_jsxs("label", { className: "k-color__code", children: [_jsx("input", { className: "k-color__num", inputMode: "numeric", value: [r, g, b][i], "aria-label": { R: C.red, G: C.green, B: C.blue }[ch], onChange: (e) => {
109
112
  const n = Math.min(255, Math.max(0, Number(e.target.value.replace(/\D/g, "")) || 0));
110
113
  const rgb = [r, g, b];
111
114
  rgb[i] = n;
@@ -114,7 +117,9 @@ function ColorPanel({ hex, onChange, onClose }) {
114
117
  }
115
118
  const Check = () => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2.2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m5 10.5 3.2 3L15 7" }) });
116
119
  /** انتخاب رنگ برند یا برچسب: نمونه‌رنگ‌ها، پنل انتخاب دلخواه و کد hex، با کنتراست متن روی آن */
117
- export function ColorPicker({ label, hint, value, defaultValue = "#0b8077", onChange, swatches = DEFAULT_SWATCHES, showContrast = true, name, id, className }) {
120
+ export function ColorPicker({ label, hint, value, defaultValue = "#0b8077", onChange, swatches: swatchesProp, showContrast = true, name, id, className }) {
121
+ const { messages: M, n: N } = useKashi();
122
+ const swatches = swatchesProp ?? DEFAULT_SWATCHES.map((s) => ({ name: M.colorPicker.names[s.key], value: s.value }));
118
123
  const autoId = useId();
119
124
  const fieldId = id ?? autoId;
120
125
  const [inner, setInner] = useState(norm(defaultValue) ?? "#000000");
@@ -130,9 +135,9 @@ export function ColorPicker({ label, hint, value, defaultValue = "#0b8077", onCh
130
135
  };
131
136
  const white = contrastRatio(current, "#ffffff"), black = contrastRatio(current, "#000000");
132
137
  const ink = white >= black ? "#ffffff" : "#000000";
133
- const fmt = (r) => toFaDigits((Math.round(r * 10) / 10).toFixed(1)).replace(".", "٫");
138
+ const fmt = (r) => N((Math.round(r * 10) / 10).toFixed(1)).replace(".", M.common.decimal);
134
139
  const invalid = text !== null && !norm(text);
135
- return (_jsx(Field, { id: `${fieldId}-hex`, label: label, hint: hint, error: invalid ? "کد رنگ معتبر نیست؛ مثل ‎#0fa89b‎ وارد کنید." : undefined, className: className, children: _jsxs("div", { className: "k-color", style: { "--_sw": current, "--_ink": ink }, children: [swatches.length > 0 && (_jsx("div", { className: "k-color__swatches", role: "radiogroup", "aria-label": "\u0631\u0646\u06AF\u200C\u0647\u0627\u06CC \u067E\u06CC\u0634\u0646\u0647\u0627\u062F\u06CC", children: swatches.map((s) => (_jsxs("label", { className: "k-color__swatch", style: { "--_sw": s.value, "--_ink": contrastRatio(s.value, "#ffffff") >= 3 ? "#fff" : "#000" }, title: s.name, children: [_jsx("input", { type: "radio", className: "k-sr-only", name: `${fieldId}-sw`, checked: norm(s.value) === current, "aria-label": s.name, onChange: () => set(norm(s.value)) }), _jsx(Check, {})] }, s.value))) })), _jsxs("div", { className: "k-color__row", children: [_jsxs("span", { className: "k-color__anchor", children: [_jsx("button", { ref: trigger, type: "button", className: "k-color__preview", "aria-label": "\u0627\u0646\u062A\u062E\u0627\u0628 \u0631\u0646\u06AF \u062F\u0644\u062E\u0648\u0627\u0647", "aria-haspopup": "dialog", "aria-expanded": open, onClick: () => setOpen((o) => !o) }), open && _jsx(ColorPanel, { hex: current, onChange: set, onClose: () => { setOpen(false); trigger.current?.focus(); } })] }), _jsx("div", { className: "k-input", "data-state": invalid ? "invalid" : undefined, children: _jsx("input", { id: `${fieldId}-hex`, className: "k-input__control", dir: "ltr", spellCheck: false, autoComplete: "off", value: text ?? current, "aria-invalid": invalid || undefined, onChange: (e) => {
140
+ return (_jsx(Field, { id: `${fieldId}-hex`, label: label, hint: hint, error: invalid ? M.colorPicker.invalid : undefined, className: className, children: _jsxs("div", { className: "k-color", style: { "--_sw": current, "--_ink": ink }, children: [swatches.length > 0 && (_jsx("div", { className: "k-color__swatches", role: "radiogroup", "aria-label": M.colorPicker.swatches, children: swatches.map((s) => (_jsxs("label", { className: "k-color__swatch", style: { "--_sw": s.value, "--_ink": contrastRatio(s.value, "#ffffff") >= 3 ? "#fff" : "#000" }, title: s.name, children: [_jsx("input", { type: "radio", className: "k-sr-only", name: `${fieldId}-sw`, checked: norm(s.value) === current, "aria-label": s.name, onChange: () => set(norm(s.value)) }), _jsx(Check, {})] }, s.value))) })), _jsxs("div", { className: "k-color__row", children: [_jsxs("span", { className: "k-color__anchor", children: [_jsx("button", { ref: trigger, type: "button", className: "k-color__preview", "aria-label": M.colorPicker.custom, "aria-haspopup": "dialog", "aria-expanded": open, onClick: () => setOpen((o) => !o) }), open && _jsx(ColorPanel, { hex: current, onChange: set, onClose: () => { setOpen(false); trigger.current?.focus(); } })] }), _jsx("div", { className: "k-input", "data-state": invalid ? "invalid" : undefined, children: _jsx("input", { id: `${fieldId}-hex`, className: "k-input__control", dir: "ltr", spellCheck: false, autoComplete: "off", value: text ?? current, "aria-invalid": invalid || undefined, onChange: (e) => {
136
141
  setText(e.target.value);
137
142
  const h = norm(e.target.value);
138
143
  if (h) {
@@ -140,5 +145,5 @@ export function ColorPicker({ label, hint, value, defaultValue = "#0b8077", onCh
140
145
  setInner(h);
141
146
  onChange?.(h);
142
147
  }
143
- }, onBlur: () => !invalid && setText(null) }) })] }), showContrast && (_jsxs("p", { className: "k-color__contrast", "aria-live": "polite", children: [_jsx("span", { className: "k-color__sample", children: "\u0645\u062A\u0646 \u0646\u0645\u0648\u0646\u0647" }), _jsxs("span", { children: ["\u06A9\u0646\u062A\u0631\u0627\u0633\u062A \u0628\u0627 \u0645\u062A\u0646 ", ink === "#ffffff" ? "سفید" : "مشکی", ": ", fmt(Math.max(white, black)), " \u0628\u0647 \u06F1 ", Math.max(white, black) >= 4.5 ? "(AA)" : "(کمتر از AA)"] })] })), name && _jsx("input", { type: "hidden", name: name, value: current })] }) }));
148
+ }, onBlur: () => !invalid && setText(null) }) })] }), showContrast && (_jsxs("p", { className: "k-color__contrast", "aria-live": "polite", children: [_jsx("span", { className: "k-color__sample", children: M.colorPicker.sample }), _jsx("span", { children: M.colorPicker.contrast(ink === "#ffffff" ? "white" : "black", fmt(Math.max(white, black)), Math.max(white, black) >= 4.5) })] })), name && _jsx("input", { type: "hidden", name: name, value: current })] }) }));
144
149
  }
package/dist/Combobox.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useId, useMemo, useRef, useState } from "react";
4
- import { normalizePersian, toFaDigits } from "@kashi-ui/persian";
4
+ import { normalizePersian } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
6
  import { Field, describedBy } from "./Field.js";
7
7
  import { mergeRefs } from "./utils.js";
8
+ import { useKashi } from "./KashiProvider.js";
8
9
  /** متن یکدست برای جستجو: ي/ی، ك/ک، ارقام، حروف کوچک */
9
10
  export const searchText = (s) => normalizePersian(s, { digits: "latin" }).toLowerCase();
10
11
  export function defaultFilter(option, query) {
@@ -29,7 +30,10 @@ const Check = () => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "
29
30
  * تایپ فهرست را فیلتر می‌کند، ↑↓ حرکت، Enter انتخاب، Esc بستن (و در حالت بسته، پاک کردن).
30
31
  * جستجو «علي» و «علی» را یکی می‌داند.
31
32
  */
32
- 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 = (n) => `${toFaDigits(n)} نتیجه`, }, ref) {
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) {
34
+ const { messages: M, n: N } = useKashi();
35
+ emptyMessage ?? (emptyMessage = M.common.noResults);
36
+ resultsLabel ?? (resultsLabel = (x) => M.common.results(N(x)));
33
37
  const autoId = useId();
34
38
  const inputId = id ?? autoId;
35
39
  const listId = `${inputId}-list`;
@@ -125,7 +129,7 @@ export const Combobox = forwardRef(function Combobox({ label, hint, error, optio
125
129
  setOpen(true);
126
130
  setActive(-1);
127
131
  onInputChange?.(e.target.value);
128
- }, onKeyDown: onKeyDown, onClick: () => !open && openList() }), loading && _jsx("span", { className: "k-input__addon", children: _jsx("span", { className: "k-spinner k-spinner--sm", "aria-hidden": "true" }) }), _jsx("button", { type: "button", tabIndex: -1, className: "k-input__action k-combobox__toggle", "aria-label": "\u0646\u0645\u0627\u06CC\u0634 \u06AF\u0632\u06CC\u0646\u0647\u200C\u0647\u0627", disabled: disabled, onClick: () => {
132
+ }, onKeyDown: onKeyDown, onClick: () => !open && openList() }), loading && _jsx("span", { className: "k-input__addon", children: _jsx("span", { className: "k-spinner k-spinner--sm", "aria-hidden": "true" }) }), _jsx("button", { type: "button", tabIndex: -1, className: "k-input__action k-combobox__toggle", "aria-label": M.combobox.toggle, disabled: disabled, onClick: () => {
129
133
  if (open)
130
134
  setOpen(false);
131
135
  else {
@@ -133,7 +137,7 @@ export const Combobox = forwardRef(function Combobox({ label, hint, error, optio
133
137
  openList();
134
138
  inputRef.current?.focus();
135
139
  }
136
- }, children: _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 8 4 4 4-4" }) }) })] }), _jsxs("ul", { id: listId, role: "listbox", "aria-labelledby": label ? undefined : inputId, "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: loading ? "در حال جستجو…" : emptyMessage }), filtered.map((o, i) => {
140
+ }, children: _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 8 4 4 4-4" }) }) })] }), _jsxs("ul", { id: listId, role: "listbox", "aria-labelledby": label ? undefined : inputId, "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: loading ? M.common.searching : emptyMessage }), filtered.map((o, i) => {
137
141
  const header = o.group && o.group !== lastGroup ? o.group : null;
138
142
  lastGroup = o.group;
139
143
  return [
@@ -1,14 +1,17 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useMemo, useRef, useState } from "react";
4
- import { toFaDigits } from "@kashi-ui/persian";
5
4
  import { defaultFilter, highlight } from "./Combobox.js";
6
5
  import { cx } from "./cx.js";
6
+ import { useKashi } from "./KashiProvider.js";
7
7
  /**
8
8
  * پالت فرمان: جستجوی سریع در عمل‌ها و صفحه‌ها با Ctrl+K.
9
9
  * پنجره روی <dialog> بومی است (تلهٔ فوکوس و Esc) و فهرست با الگوی combobox/listbox پیمایش می‌شود.
10
10
  */
11
- export function CommandPalette({ open, onOpenChange, items, shortcut = true, placeholder = "جستجوی دستور یا صفحه…", emptyMessage = "دستوری پیدا نشد.", labels = {}, className, }) {
11
+ export function CommandPalette({ open, onOpenChange, items, shortcut = true, placeholder, emptyMessage, labels = {}, className, }) {
12
+ const { messages: M, n: N } = useKashi();
13
+ placeholder ?? (placeholder = M.command.placeholder);
14
+ emptyMessage ?? (emptyMessage = M.command.empty);
12
15
  const id = useId();
13
16
  const listId = `${id}-list`;
14
17
  const ref = useRef(null);
@@ -16,7 +19,7 @@ export function CommandPalette({ open, onOpenChange, items, shortcut = true, pla
16
19
  const opener = useRef(null);
17
20
  const [query, setQuery] = useState("");
18
21
  const [active, setActive] = useState(0);
19
- const { title = "پالت فرمان", navigate = "حرکت", select = "انتخاب", close = "بستن", results = (n) => `${toFaDigits(n)} نتیجه` } = labels;
22
+ const { title = M.command.title, navigate = M.command.navigate, select = M.command.select, close = M.common.close, results = (x) => M.common.results(N(x)) } = labels;
20
23
  // میان‌بر سراسری
21
24
  useEffect(() => {
22
25
  if (!shortcut)
@@ -3,11 +3,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useRef, useState } from "react";
4
4
  import { MenuCtx, items, menuKeyDown } from "./DropdownMenu.js";
5
5
  import { cx } from "./cx.js";
6
+ import { useKashi } from "./KashiProvider.js";
6
7
  /**
7
8
  * منوی راست‌کلیک؛ با کیبورد هم: کلید ContextMenu یا Shift+F10 روی ناحیهٔ فوکوس‌شده.
8
9
  * همان گزینه‌ها و پیمایش منوی کشویی را دارد.
9
10
  */
10
- export function ContextMenu({ children, menu, label = "گزینه‌ها", className }) {
11
+ export function ContextMenu({ children, menu, label, className }) {
12
+ const { messages: M } = useKashi();
13
+ label ?? (label = M.contextMenu.label);
11
14
  const id = useId();
12
15
  const [pos, setPos] = useState(null);
13
16
  const area = useRef(null);
@@ -68,5 +71,5 @@ export function ContextMenu({ children, menu, label = "گزینه‌ها", class
68
71
  const r = document.activeElement.getBoundingClientRect();
69
72
  openAt(r.left + r.width / 2, r.top + r.height / 2);
70
73
  }
71
- }, children: [children, _jsx("span", { id: `${id}-hint`, className: "k-sr-only", children: "\u0628\u0631\u0627\u06CC \u06AF\u0632\u06CC\u0646\u0647\u200C\u0647\u0627 \u0631\u0627\u0633\u062A\u200C\u06A9\u0644\u06CC\u06A9 \u06A9\u0646\u06CC\u062F \u06CC\u0627 Shift+F10 \u0631\u0627 \u0628\u0632\u0646\u06CC\u062F." }), _jsx(MenuCtx.Provider, { value: { close }, children: _jsx("ul", { ref: list, ...{ popover: "manual" }, role: "menu", "aria-label": label, className: "k-menu k-menu--context", hidden: !pos, style: pos ? { "--_x": `${pos.x}px`, "--_y": `${pos.y}px` } : undefined, onKeyDown: (e) => menuKeyDown(e, list.current, () => close(), () => close(false)), children: menu }) })] }));
74
+ }, children: [children, _jsx("span", { id: `${id}-hint`, className: "k-sr-only", children: M.contextMenu.hint }), _jsx(MenuCtx.Provider, { value: { close }, children: _jsx("ul", { ref: list, ...{ popover: "manual" }, role: "menu", "aria-label": label, className: "k-menu k-menu--context", hidden: !pos, style: pos ? { "--_x": `${pos.x}px`, "--_y": `${pos.y}px` } : undefined, onKeyDown: (e) => menuKeyDown(e, list.current, () => close(), () => close(false)), children: menu }) })] }));
72
75
  }
@@ -2,11 +2,13 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import { Button } from "./Button.js";
5
+ import { useKashi } from "./KashiProvider.js";
5
6
  const CopyIcon = () => (_jsxs("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("rect", { x: "7", y: "7", width: "10", height: "10", rx: "2" }), _jsx("path", { d: "M13 7V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v6a2 2 0 0 0 2 2h2" })] }));
6
7
  const CheckIcon = () => (_jsx("svg", { 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
8
  /** دکمهٔ کپی در کلیپ‌بورد با بازخورد «کپی شد» برای چشم و صفحه‌خوان */
8
9
  export function CopyButton({ value, onCopy, iconOnly, timeout = 2000, labels = {}, variant = "secondary", size = "sm", ...rest }) {
9
- const { copy = "کپی", copied = "کپی شد", failed = "کپی نشد" } = labels;
10
+ const { messages: M } = useKashi();
11
+ const { copy = M.copy.copy, copied = M.copy.copied, failed = M.copy.failed } = labels;
10
12
  const [state, setState] = useState("idle");
11
13
  const timer = useRef(undefined);
12
14
  useEffect(() => () => clearTimeout(timer.current), []);
package/dist/Countdown.js CHANGED
@@ -3,10 +3,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import { toFaDigits } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
+ import { useKashi } from "./KashiProvider.js";
6
7
  const pad = (n) => String(n).padStart(2, "0");
7
8
  /** شمارش معکوس با ارقام فارسی؛ هر ثانیه به‌روز می‌شود و در پایان onComplete را صدا می‌زند */
8
- export function Countdown({ to, seconds, onComplete, variant = "clock", digits = "fa", "aria-label": ariaLabel, className, labels = {} }) {
9
- const { days = "روز", hours = "ساعت", minutes = "دقیقه", seconds: secLabel = "ثانیه" } = labels;
9
+ export function Countdown({ to, seconds, onComplete, variant = "clock", digits, "aria-label": ariaLabel, className, labels = {} }) {
10
+ const { messages: M, digits: D } = useKashi();
11
+ digits ?? (digits = D);
12
+ const { days = M.countdown.days, hours = M.countdown.hours, minutes = M.countdown.minutes, seconds: secLabel = M.countdown.seconds } = labels;
10
13
  const end = useRef(to?.getTime() ?? Date.now() + (seconds ?? 0) * 1000);
11
14
  const [left, setLeft] = useState(() => Math.max(0, Math.ceil((end.current - Date.now()) / 1000)));
12
15
  const done = useRef(false);
@@ -28,7 +31,7 @@ export function Countdown({ to, seconds, onComplete, variant = "clock", digits =
28
31
  const d = Math.floor(left / 86400), h = Math.floor((left % 86400) / 3600), m = Math.floor((left % 3600) / 60), s = left % 60;
29
32
  const f = (x) => (digits === "fa" ? toFaDigits(String(x)) : String(x));
30
33
  // متن کامل برای صفحه‌خوان؛ role="timer" به‌طور پیش‌فرض هر ثانیه خوانده نمی‌شود
31
- const spoken = [d && `${f(d)} ${days}`, h && `${f(h)} ${hours}`, m && `${f(m)} ${minutes}`, `${f(s)} ${secLabel}`].filter(Boolean).join(" و ");
34
+ const spoken = [d && `${f(d)} ${days}`, h && `${f(h)} ${hours}`, m && `${f(m)} ${minutes}`, `${f(s)} ${secLabel}`].filter(Boolean).join(M.common.and);
32
35
  if (variant === "blocks") {
33
36
  const units = [...(d ? [[d, days]] : []), [h, hours], [m, minutes], [s, secLabel]];
34
37
  return (_jsx("div", { role: "timer", "aria-label": ariaLabel ? `${ariaLabel}: ${spoken}` : spoken, className: cx("k-countdown k-countdown--blocks", className), "data-done": left === 0 ? "" : undefined, children: units.map(([v, name]) => (_jsxs("span", { className: "k-countdown__unit", "aria-hidden": "true", children: [_jsx("span", { className: "k-countdown__num", children: f(pad(v)) }), _jsx("span", { className: "k-countdown__name", children: name })] }, name))) }));
package/dist/DataTable.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useMemo, useRef, useState } from "react";
4
4
  import { cx } from "./cx.js";
5
+ import { useKashi } from "./KashiProvider.js";
5
6
  /** جدول داده با مرتب‌سازی (aria-sort)، انتخاب ردیف‌ها و حالت خالی */
6
7
  export function DataTable({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort = null, onSortChange, empty, compact, striped, stickyHeader, maxHeight, loading, onRowClick, footer, labels = {}, classNames = {}, className, }) {
7
8
  const id = useId();
@@ -40,14 +41,15 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
40
41
  if (allRef.current)
41
42
  allRef.current.indeterminate = some;
42
43
  }, [some]);
43
- const { selectAll = "انتخاب همهٔ ردیف‌ها", selectRow = () => "انتخاب ردیف", loading: loadingLabel = "در حال بارگذاری" } = labels;
44
+ const { messages: M } = useKashi();
45
+ const { selectAll = M.table.selectAll, selectRow = () => M.table.selectRow, loading: loadingLabel = M.common.loading } = labels;
44
46
  const loadingRows = loading === true ? 5 : typeof loading === "number" ? loading : 0;
45
47
  const cellCls = (c) => cx(c.numeric && "k-table__num", c.align && !c.numeric && `k-table__align-${c.align}`, c.hideBelow && `k-table__hide-${c.hideBelow}`, c.className, classNames.cell) || undefined;
46
48
  const colCount = columns.length + (selectable ? 1 : 0);
47
49
  return (_jsxs("div", { className: cx("k-table-wrap", stickyHeader && "k-table-wrap--sticky", className, classNames.root), role: "region", "aria-labelledby": `${id}-caption`, "aria-busy": loadingRows > 0 || undefined, tabIndex: 0, style: maxHeight ? { maxBlockSize: maxHeight } : undefined, children: [_jsxs("table", { className: cx("k-table", compact && "k-table--compact", striped && "k-table--striped", onRowClick && "k-table--clickable", classNames.table), children: [_jsxs("caption", { id: `${id}-caption`, className: hideCaption ? "k-sr-only" : undefined, children: [_jsx("span", { className: "k-table__caption-title", children: caption }), description && _jsx("span", { className: "k-table__caption-desc", children: description })] }), _jsx("thead", { children: _jsxs("tr", { children: [selectable && (_jsx("th", { scope: "col", className: "k-table__check", children: _jsx("input", { ref: allRef, type: "checkbox", className: "k-checkbox", "aria-label": selectAll, checked: all, onChange: () => setSel(all ? [] : ids) }) })), columns.map((c) => {
48
50
  const s = activeSort?.key === c.key ? activeSort.direction : undefined;
49
51
  return (_jsx("th", { scope: "col", "aria-sort": c.sortable ? (s ?? "none") : undefined, className: cx(cellCls(c), classNames.header) || undefined, style: c.width ? { inlineSize: c.width } : undefined, children: c.sortable ? _jsx("button", { type: "button", className: "k-table__sort", onClick: () => setSort(c.key), children: c.header }) : c.header }, c.key));
50
- })] }) }), _jsx("tbody", { children: loadingRows > 0 ? (Array.from({ length: loadingRows }, (_, i) => (_jsxs("tr", { "aria-hidden": "true", children: [selectable && _jsx("td", { className: "k-table__check", children: _jsx("span", { className: "k-skeleton", style: { inlineSize: "1.125rem", blockSize: "1.125rem" } }) }), columns.map((c) => (_jsx("td", { className: cellCls(c), children: _jsx("span", { className: "k-skeleton", style: { inlineSize: `${50 + ((i * 17 + c.key.length * 11) % 40)}%` } }) }, c.key)))] }, `sk-${i}`)))) : sorted.length === 0 ? (_jsx("tr", { className: "k-table__empty", children: _jsx("td", { colSpan: colCount, children: empty ?? _jsx("p", { style: { padding: "2rem", margin: 0, textAlign: "center" }, children: "\u062F\u0627\u062F\u0647\u200C\u0627\u06CC \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F." }) }) })) : (sorted.map((r) => {
52
+ })] }) }), _jsx("tbody", { children: loadingRows > 0 ? (Array.from({ length: loadingRows }, (_, i) => (_jsxs("tr", { "aria-hidden": "true", children: [selectable && _jsx("td", { className: "k-table__check", children: _jsx("span", { className: "k-skeleton", style: { inlineSize: "1.125rem", blockSize: "1.125rem" } }) }), columns.map((c) => (_jsx("td", { className: cellCls(c), children: _jsx("span", { className: "k-skeleton", style: { inlineSize: `${50 + ((i * 17 + c.key.length * 11) % 40)}%` } }) }, c.key)))] }, `sk-${i}`)))) : sorted.length === 0 ? (_jsx("tr", { className: "k-table__empty", children: _jsx("td", { colSpan: colCount, children: empty ?? _jsx("p", { style: { padding: "2rem", margin: 0, textAlign: "center" }, children: M.table.empty }) }) })) : (sorted.map((r) => {
51
53
  const rid = getRowId(r);
52
54
  const on = sel.includes(rid);
53
55
  return (_jsxs("tr", { "aria-selected": selectable ? on : undefined, className: classNames.row, onClick: onRowClick ? (e) => {
@@ -5,11 +5,17 @@ import { formatJalali, parseJalali, toISODate } from "@kashi-ui/persian";
5
5
  import { Calendar, sameDay } from "./Calendar.js";
6
6
  import { Input } from "./Input.js";
7
7
  import { mergeRefs, useIsomorphicLayoutEffect } from "./utils.js";
8
+ import { useKashi } from "./KashiProvider.js";
8
9
  /**
9
10
  * انتخاب تاریخ شمسی: تایپ مستقیم (۱۴۰۳/۰۵/۱۲) یا انتخاب از تقویم.
10
11
  * با name، مقدار میلادی به شکل YYYY-MM-DD در فرم ارسال می‌شود.
11
12
  */
12
- export const DatePicker = forwardRef(function DatePicker({ value, defaultValue = null, onChange, min, max, isDateDisabled, holidays, digits = "fa", yearRange, invalidMessage = "این تاریخ معتبر نیست؛ آن را به شکل ۱۴۰۳/۰۵/۱۲ وارد کنید.", openLabel = "انتخاب تاریخ از تقویم", todayLabel = "امروز", calendarLabels, error, name, onBlur, placeholder, ...rest }, ref) {
13
+ export const DatePicker = forwardRef(function DatePicker({ value, defaultValue = null, onChange, min, max, isDateDisabled, holidays, digits, yearRange, invalidMessage, openLabel, todayLabel, calendarLabels, error, name, onBlur, placeholder, ...rest }, ref) {
14
+ const { messages: M, digits: D, locale } = useKashi();
15
+ digits ?? (digits = D);
16
+ invalidMessage ?? (invalidMessage = M.datePicker.invalid);
17
+ openLabel ?? (openLabel = M.datePicker.open);
18
+ todayLabel ?? (todayLabel = M.common.today);
13
19
  const id = useId();
14
20
  const popoverId = `${id}-calendar`;
15
21
  const [inner, setInner] = useState(defaultValue);
@@ -70,7 +76,7 @@ export const DatePicker = forwardRef(function DatePicker({ value, defaultValue =
70
76
  setInvalid(true);
71
77
  }
72
78
  onBlur?.(e);
73
- }, error: error ?? (invalid ? invalidMessage : undefined), addonEnd: _jsx("button", { ref: button, type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm k-datepicker__toggle", "aria-label": selected ? `${openLabel}، ${formatJalali(selected, { style: "full", digits })}` : openLabel, "aria-haspopup": "dialog", "aria-expanded": open, "aria-controls": open ? popoverId : undefined, onClick: () => setOpen((o) => !o), children: _jsxs("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("rect", { x: "3", y: "4.5", width: "14", height: "12.5", rx: "2" }), _jsx("path", { d: "M3 8.5h14M7 3v3M13 3v3" })] }) }), ...rest }), name && _jsx("input", { type: "hidden", name: name, value: selected ? toISODate(selected) : "" }), open && (_jsx("div", { id: popoverId, className: "k-datepicker__popover", role: "dialog", "aria-label": openLabel, style: { insetBlockStart: top }, onKeyDown: (e) => {
79
+ }, error: error ?? (invalid ? invalidMessage : undefined), addonEnd: _jsx("button", { ref: button, type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm k-datepicker__toggle", "aria-label": selected ? `${openLabel}${M.common.list}${formatJalali(selected, { style: "full", digits, locale })}` : openLabel, "aria-haspopup": "dialog", "aria-expanded": open, "aria-controls": open ? popoverId : undefined, onClick: () => setOpen((o) => !o), children: _jsxs("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("rect", { x: "3", y: "4.5", width: "14", height: "12.5", rx: "2" }), _jsx("path", { d: "M3 8.5h14M7 3v3M13 3v3" })] }) }), ...rest }), name && _jsx("input", { type: "hidden", name: name, value: selected ? toISODate(selected) : "" }), open && (_jsx("div", { id: popoverId, className: "k-datepicker__popover", role: "dialog", "aria-label": openLabel, style: { insetBlockStart: top }, onKeyDown: (e) => {
74
80
  if (e.key === "Escape") {
75
81
  e.stopPropagation();
76
82
  close();
@@ -12,7 +12,7 @@ export interface DateRangePreset {
12
12
  end: Date;
13
13
  };
14
14
  }
15
- /** میان‌برهای پیش‌فرض با ماه‌های شمسی */
15
+ /** میان‌برهای پیش‌فرض به فارسی؛ بدون presets، کامپوننت همین‌ها را به زبان KashiProvider نشان می‌دهد */
16
16
  export declare const defaultRangePresets: DateRangePreset[];
17
17
  export interface DateRangePickerProps {
18
18
  label?: ReactNode;