@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
@@ -1,24 +1,25 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useRef, useState } from "react";
4
- import { formatJalali, toGregorian, toISODate, toJalali } from "@kashi-ui/persian";
4
+ import { faMessages, formatJalali, toFaDigits, toGregorian, toISODate, toJalali } from "@kashi-ui/persian";
5
5
  import { Calendar } from "./Calendar.js";
6
6
  import { Field } from "./Field.js";
7
7
  import { cx } from "./cx.js";
8
+ import { useKashi } from "./KashiProvider.js";
8
9
  const day = (d, add = 0) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + add);
9
- /** میان‌برهای پیش‌فرض با ماه‌های شمسی */
10
- export const defaultRangePresets = [
11
- { label: "۷ روز اخیر", range: (t) => ({ start: day(t, -6), end: t }) },
12
- { label: "۳۰ روز اخیر", range: (t) => ({ start: day(t, -29), end: t }) },
10
+ /** میان‌برهای پیش‌فرض با ماه‌های شمسی، با متن‌های یک زبان */
11
+ const presetsFor = (m, n) => [
12
+ { label: m.last7(n(7)), range: (t) => ({ start: day(t, -6), end: t }) },
13
+ { label: m.last30(n(30)), range: (t) => ({ start: day(t, -29), end: t }) },
13
14
  {
14
- label: "این ماه",
15
+ label: m.thisMonth,
15
16
  range: (t) => {
16
17
  const { jy, jm } = toJalali(t);
17
18
  return { start: toGregorian(jy, jm, 1), end: t };
18
19
  },
19
20
  },
20
21
  {
21
- label: "ماه قبل",
22
+ label: m.lastMonth,
22
23
  range: (t) => {
23
24
  const { jy, jm } = toJalali(t);
24
25
  const [py, pm] = jm === 1 ? [jy - 1, 12] : [jy, jm - 1];
@@ -26,15 +27,20 @@ export const defaultRangePresets = [
26
27
  },
27
28
  },
28
29
  ];
30
+ /** میان‌برهای پیش‌فرض به فارسی؛ بدون presets، کامپوننت همین‌ها را به زبان KashiProvider نشان می‌دهد */
31
+ export const defaultRangePresets = presetsFor(faMessages.dateRange, (v) => toFaDigits(v));
29
32
  /**
30
33
  * انتخاب بازهٔ تاریخ شمسی: کلیک اول شروع، کلیک دوم پایان؛ پیش از تأیید، بازه با حرکت موس پیش‌نمایش می‌شود.
31
34
  * تغییرها فقط با «تأیید» ثبت می‌شوند.
32
35
  */
33
- export function DateRangePicker({ label, hint, error, value, defaultValue = { start: null, end: null }, onChange, min, max, isDateDisabled, holidays, presets = defaultRangePresets, digits = "fa", name, disabled, id, className, calendarLabels, labels = {}, }) {
36
+ export function DateRangePicker({ label, hint, error, value, defaultValue = { start: null, end: null }, onChange, min, max, isDateDisabled, holidays, presets, digits, name, disabled, id, className, calendarLabels, labels = {}, }) {
37
+ const { messages: M, digits: D, locale, n: N } = useKashi();
38
+ digits ?? (digits = D);
39
+ presets ?? (presets = presetsFor(M.dateRange, N));
34
40
  const autoId = useId();
35
41
  const triggerId = id ?? autoId;
36
42
  const popoverId = `${triggerId}-popover`;
37
- const { placeholder = "انتخاب بازهٔ تاریخ", separator = " تا ", apply = "تأیید", cancel = "انصراف", presets: presetsLabel = "میان‌برها", pickEnd = "حالا تاریخ پایان را انتخاب کنید.", } = labels;
43
+ const { placeholder = M.dateRange.placeholder, separator = M.common.range, apply = M.common.confirm, cancel = M.common.cancel, presets: presetsLabel = M.dateRange.presets, pickEnd = M.dateRange.pickEnd, } = labels;
38
44
  const [inner, setInner] = useState(defaultValue);
39
45
  const current = value ?? inner;
40
46
  const [draft, setDraft] = useState(current);
@@ -43,7 +49,7 @@ export function DateRangePicker({ label, hint, error, value, defaultValue = { st
43
49
  const [nav, setNav] = useState(0);
44
50
  const wrap = useRef(null);
45
51
  const trigger = useRef(null);
46
- const fmt = (d) => formatJalali(d, { digits });
52
+ const fmt = (d) => formatJalali(d, { digits, locale });
47
53
  const text = current.start && current.end ? `${fmt(current.start)}${separator}${fmt(current.end)}` : null;
48
54
  const close = (focus = true) => {
49
55
  setOpen(false);
package/dist/DateTile.js CHANGED
@@ -1,13 +1,16 @@
1
1
  "use client";
2
2
  import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef } from "react";
4
- import { getIranHoliday, JALALI_MONTHS, jalaliWeekday, toFaDigits, toISODate, toJalali, WEEKDAYS } from "@kashi-ui/persian";
4
+ import { getIranHoliday, jalaliWeekday, toISODate, toJalali } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
+ import { useKashi } from "./KashiProvider.js";
6
7
  const gregFmt = new Intl.DateTimeFormat("fa-IR-u-ca-gregory-nu-arabext", { day: "numeric", month: "long", year: "numeric" });
8
+ const gregFmtEn = new Intl.DateTimeFormat("en-US", { day: "numeric", month: "long", year: "numeric" });
7
9
  /** کاشی تاریخ شمسی به شکل برگ تقویم: روز، ماه، روز هفته، مناسبت تعطیل و معادل میلادی */
8
10
  export const DateTile = forwardRef(function DateTile({ date, holidays = true, gregorian = true, size = "md", className, ...rest }, ref) {
9
11
  const { jy, jm, jd } = toJalali(date);
10
- const holiday = holidays ? getIranHoliday(date, holidays === true ? {} : holidays) : null;
11
- const occasion = holiday && holiday !== "جمعه" ? holiday : null;
12
- return (_jsxs("time", { ref: ref, dateTime: toISODate(date), className: cx("k-datetile", `k-datetile--${size}`, className), "data-holiday": holiday ? "" : undefined, ...rest, children: [_jsxs("span", { className: "k-datetile__head", children: [JALALI_MONTHS[jm - 1], " ", toFaDigits(jy)] }), _jsx("span", { className: "k-datetile__day", children: toFaDigits(jd) }), _jsx("span", { className: "k-datetile__weekday", children: WEEKDAYS[jalaliWeekday(date)] }), occasion && _jsx("span", { className: "k-datetile__occasion", children: occasion }), gregorian && _jsx("span", { className: "k-datetile__greg", children: gregFmt.format(date) })] }));
12
+ const { n, locale, months: MONTHS, weekdays: WD, friday: FRI } = useKashi();
13
+ const holiday = holidays ? getIranHoliday(date, holidays === true ? { locale } : { locale, ...holidays }) : null;
14
+ const occasion = holiday && holiday !== FRI ? holiday : null;
15
+ return (_jsxs("time", { ref: ref, dateTime: toISODate(date), className: cx("k-datetile", `k-datetile--${size}`, className), "data-holiday": holiday ? "" : undefined, ...rest, children: [_jsxs("span", { className: "k-datetile__head", children: [MONTHS[jm - 1], " ", n(jy)] }), _jsx("span", { className: "k-datetile__day", children: n(jd) }), _jsx("span", { className: "k-datetile__weekday", children: WD[jalaliWeekday(date)] }), occasion && _jsx("span", { className: "k-datetile__occasion", children: occasion }), gregorian && _jsx("span", { className: "k-datetile__greg", children: (locale === "en" ? gregFmtEn : gregFmt).format(date) })] }));
13
16
  });
package/dist/Dialog.js CHANGED
@@ -3,12 +3,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useId, useRef } from "react";
4
4
  import { cx } from "./cx.js";
5
5
  import { CloseIcon } from "./icons.js";
6
+ import { useKashi } from "./KashiProvider.js";
6
7
  /**
7
8
  * پنجرهٔ گفتگو روی <dialog> بومی با showModal:
8
9
  * فوکوس داخل پنجره می‌ماند، Esc می‌بندد، بقیهٔ صفحه از دسترس صفحه‌خوان خارج می‌شود
9
10
  * و پس از بستن، فوکوس به عنصری که پنجره را باز کرده برمی‌گردد.
10
11
  */
11
- export function Dialog({ open, onOpenChange, title, description, icon, tone = "default", size = "md", footer, dismissible = true, closeLabel = "بستن", placement = "center", className, children, }) {
12
+ export function Dialog({ open, onOpenChange, title, description, icon, tone = "default", size = "md", footer, dismissible = true, closeLabel, placement = "center", className, children, }) {
13
+ const { messages: M } = useKashi();
14
+ closeLabel ?? (closeLabel = M.common.close);
12
15
  const ref = useRef(null);
13
16
  const opener = useRef(null);
14
17
  const id = useId();
package/dist/Field.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { cx } from "./cx.js";
4
+ import { useKashi } from "./KashiProvider.js";
4
5
  /** شناسهٔ متن‌های راهنما و خطا برای aria-describedby */
5
6
  export const hintId = (id) => `${id}-hint`;
6
7
  export const errorId = (id) => `${id}-error`;
@@ -9,6 +10,7 @@ export function describedBy(id, hint, error, extra) {
9
10
  }
10
11
  /** قالب مشترک برچسب + کنترل + راهنما/خطا */
11
12
  export function Field({ id, label, hint, error, required, optional, labelEnd, hintEnd, className, classNames = {}, children }) {
12
- const optionalText = optional === true ? "اختیاری" : optional;
13
+ const { messages: M } = useKashi();
14
+ const optionalText = optional === true ? M.common.optional : optional;
13
15
  return (_jsxs("div", { className: cx("k-field", className, classNames.root), "data-invalid": error ? "" : undefined, children: [(label || labelEnd) && (_jsxs("div", { className: "k-field__label-row", children: [label && (_jsxs("label", { className: cx("k-label", classNames.label), htmlFor: id, children: [label, required && _jsx("span", { className: "k-label__required", "aria-hidden": "true", children: "*" }), optionalText && _jsx("span", { className: "k-label__optional", children: optionalText })] })), labelEnd && _jsx("span", { className: "k-field__label-end", children: labelEnd })] })), children, (error || hint || hintEnd) && (_jsxs("div", { className: "k-field__hint-row", children: [_jsxs("div", { className: "k-field__hints", children: [error && _jsx("p", { className: cx("k-hint k-hint--error", classNames.error), id: errorId(id), children: error }), hint && _jsx("p", { className: cx("k-hint", classNames.hint), id: hintId(id), children: hint })] }), hintEnd] }))] }));
14
16
  }
@@ -1,4 +1,5 @@
1
1
  import { type ReactNode } from "react";
2
+ import { type KashiLocale } from "@kashi-ui/persian";
2
3
  export type FileStatus = "uploading" | "done" | "error";
3
4
  export interface FileItem {
4
5
  id: string;
@@ -7,8 +8,8 @@ export interface FileItem {
7
8
  progress: number;
8
9
  error?: string;
9
10
  }
10
- /** حجم فایل به فارسی: ۱٫۲ مگابایت */
11
- export declare function formatBytes(bytes: number): string;
11
+ /** حجم فایل: ۱٫۲ مگابایت؛ با locale="en" ← «1.2 MB» */
12
+ export declare function formatBytes(bytes: number, locale?: KashiLocale): string;
12
13
  export interface FileUploadProps {
13
14
  /** مثل "image/*,.pdf" */
14
15
  accept?: string;
@@ -1,12 +1,14 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useId, useRef, useState } from "react";
4
- import { toFaDigits } from "@kashi-ui/persian";
4
+ import { getMessages, toFaDigits } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
6
  import { Progress } from "./Progress.js";
7
- /** حجم فایل به فارسی: ۱٫۲ مگابایت */
8
- export function formatBytes(bytes) {
9
- const units = ["بایت", "کیلوبایت", "مگابایت", "گیگابایت"];
7
+ import { useKashi } from "./KashiProvider.js";
8
+ /** حجم فایل: ۱٫۲ مگابایت؛ با locale="en" ← «1.2 MB» */
9
+ export function formatBytes(bytes, locale = "fa") {
10
+ const en = locale === "en";
11
+ const units = getMessages(locale).fileUpload.units;
10
12
  let v = bytes;
11
13
  let i = 0;
12
14
  while (v >= 1024 && i < units.length - 1) {
@@ -14,7 +16,7 @@ export function formatBytes(bytes) {
14
16
  i++;
15
17
  }
16
18
  const n = i === 0 ? String(v) : v.toFixed(v < 10 ? 1 : 0).replace(/\.0$/, "");
17
- return `${toFaDigits(n).replace(".", "٫")} ${units[i]}`;
19
+ return `${en ? n : toFaDigits(n).replace(".", "٫")} ${units[i]}`;
18
20
  }
19
21
  const ext = (name) => (name.split(".").pop() ?? "").slice(0, 4).toUpperCase();
20
22
  function accepts(file, accept) {
@@ -31,7 +33,9 @@ export function FileUpload({ accept, multiple = true, maxSize, maxFiles, uploade
31
33
  const [items, setItems] = useState([]);
32
34
  const [dragging, setDragging] = useState(false);
33
35
  const [announce, setAnnounce] = useState("");
34
- const { browse = "انتخاب فایل", drop = "یا فایل را اینجا رها کنید", remove = (n) => `حذف ${n}`, tooBig = (m) => `حجم فایل بیشتر از ${m} است.`, wrongType = "این نوع فایل پذیرفته نیست.", tooMany = (n) => `حداکثر ${toFaDigits(n)} فایل.`, done = "بارگذاری شد", uploading = "در حال بارگذاری", } = labels;
36
+ const { messages: M, n: N, locale } = useKashi();
37
+ const bytes = (b) => formatBytes(b, locale);
38
+ const { browse = M.fileUpload.browse, drop = M.fileUpload.drop, remove = M.common.remove, tooBig = M.fileUpload.tooBig, wrongType = M.fileUpload.wrongType, tooMany = (x) => M.fileUpload.tooMany(N(x)), done = M.fileUpload.done, uploading = M.fileUpload.uploading, } = labels;
35
39
  const update = (fn) => setItems((prev) => {
36
40
  const next = fn(prev);
37
41
  onFilesChange?.(next);
@@ -45,13 +49,13 @@ export function FileUpload({ accept, multiple = true, maxSize, maxFiles, uploade
45
49
  if (!accepts(file, accept))
46
50
  err = wrongType;
47
51
  else if (maxSize && file.size > maxSize)
48
- err = tooBig(formatBytes(maxSize));
52
+ err = tooBig(bytes(maxSize));
49
53
  else if (maxFiles && items.length + i >= maxFiles)
50
54
  err = tooMany(maxFiles);
51
55
  return { id: fid, file, status: err ? "error" : uploader ? "uploading" : "done", progress: err ? 0 : uploader ? 0 : 100, error: err };
52
56
  });
53
57
  update((prev) => (multiple ? [...prev, ...added] : added));
54
- setAnnounce(added.map((a) => `${a.file.name}: ${a.error ?? (uploader ? uploading : done)}`).join("، "));
58
+ setAnnounce(added.map((a) => `${a.file.name}: ${a.error ?? (uploader ? uploading : done)}`).join(M.common.list));
55
59
  for (const it of added) {
56
60
  if (it.status !== "uploading" || !uploader)
57
61
  continue;
@@ -61,7 +65,7 @@ export function FileUpload({ accept, multiple = true, maxSize, maxFiles, uploade
61
65
  setAnnounce(`${it.file.name}: ${done}`);
62
66
  })
63
67
  .catch((e) => {
64
- const msg = e instanceof Error ? e.message : "خطا در بارگذاری";
68
+ const msg = e instanceof Error ? e.message : M.fileUpload.error;
65
69
  update((l) => l.map((x) => (x.id === it.id ? { ...x, status: "error", error: msg } : x)));
66
70
  setAnnounce(`${it.file.name}: ${msg}`);
67
71
  });
@@ -86,6 +90,6 @@ export function FileUpload({ accept, multiple = true, maxSize, maxFiles, uploade
86
90
  e.target.value = "";
87
91
  } })] }), items.length > 0 && (_jsx("ul", { className: "k-file-list", role: "list", children: items.map((it) => (_jsxs("li", { className: "k-file", "data-status": it.status, children: [_jsx("span", { className: "k-file__icon", "aria-hidden": "true", children: ext(it.file.name) }), _jsx("span", { className: "k-file__name", title: it.file.name, children: it.file.name }), _jsx("button", { type: "button", className: cx("k-btn k-btn--tertiary k-btn--icon k-btn--sm k-file__remove"), "aria-label": remove(it.file.name), onClick: () => {
88
92
  update((l) => l.filter((x) => x.id !== it.id));
89
- setAnnounce(`${it.file.name} حذف شد`);
90
- }, children: _jsx(TrashIcon, {}) }), _jsx("span", { className: "k-file__meta", children: it.error ?? `${formatBytes(it.file.size)}${it.status === "uploading" ? ` · ${toFaDigits(Math.round(it.progress))}٪` : it.status === "done" ? ` · ${done}` : ""}` }), it.status === "uploading" && _jsx(Progress, { value: it.progress, size: "sm", "aria-label": `${uploading} ${it.file.name}` })] }, it.id))) })), _jsx("span", { className: "k-sr-only", "aria-live": "polite", children: announce })] }));
93
+ setAnnounce(M.common.removed(it.file.name));
94
+ }, children: _jsx(TrashIcon, {}) }), _jsx("span", { className: "k-file__meta", children: it.error ?? `${bytes(it.file.size)}${it.status === "uploading" ? ` · ${M.common.percent(N(Math.round(it.progress)))}` : it.status === "done" ? ` · ${done}` : ""}` }), it.status === "uploading" && _jsx(Progress, { value: it.progress, size: "sm", "aria-label": `${uploading} ${it.file.name}` })] }, it.id))) })), _jsx("span", { className: "k-sr-only", "aria-live": "polite", children: announce })] }));
91
95
  }
package/dist/IbanInput.js CHANGED
@@ -6,9 +6,12 @@ import { BankBadge } from "./BankBadge.js";
6
6
  import { Input } from "./Input.js";
7
7
  import { useDigitsInput } from "./useDigitsInput.js";
8
8
  import { mergeRefs } from "./utils.js";
9
+ import { useKashi } from "./KashiProvider.js";
9
10
  const ibanOf = (d) => (d ? `IR${d}` : "");
10
11
  /** فیلد شماره شبا: IR خودکار، گروه‌بندی، تشخیص بانک با لوگو و بررسی رقم‌های کنترل */
11
- export const IbanInput = forwardRef(function IbanInput({ value, defaultValue, onValueChange, digits = "latin", showBank = true, showBankLogo = true, invalidMessage = "شماره شبا معتبر نیست.", error, name, id, onBlur, placeholder, ...rest }, ref) {
12
+ export const IbanInput = forwardRef(function IbanInput({ value, defaultValue, onValueChange, digits = "latin", showBank = true, showBankLogo = true, invalidMessage, error, name, id, onBlur, placeholder, ...rest }, ref) {
13
+ const { messages: M } = useKashi();
14
+ invalidMessage ?? (invalidMessage = M.invalid.iban);
12
15
  const autoId = useId();
13
16
  const inputId = id ?? autoId;
14
17
  const [touched, setTouched] = useState(false);
@@ -2,12 +2,14 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import { cx } from "./cx.js";
5
+ import { useKashi } from "./KashiProvider.js";
5
6
  const Pencil = () => _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: "m13.5 3.5 3 3L7 16H4v-3Z" }) });
6
7
  const Check = () => _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
  const X = () => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 6 8 8M14 6l-8 8" }) });
8
9
  /** ویرایش درجا: کلیک یا Enter برای ویرایش، Enter ثبت، Esc انصراف */
9
10
  export function InlineEdit({ value, defaultValue = "", onSave, label, placeholder, validate, renderView, className, labels = {} }) {
10
- const { edit = "ویرایش", save = "ثبت", cancel = "انصراف", empty = "خالی" } = labels;
11
+ const { messages: M } = useKashi();
12
+ const { edit = M.common.edit, save = M.common.save, cancel = M.common.cancel, empty = M.inlineEdit.empty } = labels;
11
13
  const [inner, setInner] = useState(defaultValue);
12
14
  const current = value ?? inner;
13
15
  const [editing, setEditing] = useState(false);
@@ -52,14 +54,14 @@ export function InlineEdit({ value, defaultValue = "", onSave, label, placeholde
52
54
  catch {
53
55
  if (value === undefined)
54
56
  setInner(prev);
55
- setError("ذخیره نشد؛ دوباره امتحان کنید.");
57
+ setError(M.inlineEdit.failed);
56
58
  }
57
59
  finally {
58
60
  setBusy(false);
59
61
  }
60
62
  };
61
63
  if (!editing) {
62
- return (_jsx("span", { className: cx("k-inline-edit", className), children: _jsxs("button", { ref: view, type: "button", className: "k-inline-edit__view", onClick: start, "aria-label": `${label}: ${current || empty}، ${edit}`, children: [current ? (renderView ? renderView(current) : current) : _jsx("span", { className: "k-inline-edit__placeholder", children: placeholder ?? empty }), _jsx(Pencil, {})] }) }));
64
+ return (_jsx("span", { className: cx("k-inline-edit", className), children: _jsxs("button", { ref: view, type: "button", className: "k-inline-edit__view", onClick: start, "aria-label": `${label}: ${current || empty}${M.common.list}${edit}`, children: [current ? (renderView ? renderView(current) : current) : _jsx("span", { className: "k-inline-edit__placeholder", children: placeholder ?? empty }), _jsx(Pencil, {})] }) }));
63
65
  }
64
66
  const errId = `${label}-err`.replace(/\s/g, "-");
65
67
  return (_jsxs("span", { className: cx("k-inline-edit", className), children: [_jsxs("span", { className: "k-field", style: { gap: 4 }, children: [_jsx("span", { className: "k-input", "data-state": error ? "invalid" : undefined, children: _jsx("input", { ref: input, className: "k-input__control", "aria-label": label, value: draft, placeholder: placeholder, "aria-invalid": error ? true : undefined, "aria-describedby": error ? errId : undefined, disabled: busy, onChange: (e) => {
package/dist/Input.js CHANGED
@@ -5,6 +5,7 @@ import { toFaDigits } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
6
  import { Field, describedBy } from "./Field.js";
7
7
  import { mergeRefs, useIsomorphicLayoutEffect } from "./utils.js";
8
+ import { useKashi } from "./KashiProvider.js";
8
9
  const Eye = ({ off }) => (_jsxs("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M1.8 10S4.8 4.5 10 4.5 18.2 10 18.2 10 15.2 15.5 10 15.5 1.8 10 1.8 10Z" }), _jsx("circle", { cx: "10", cy: "10", r: "2.5" }), off && _jsx("path", { d: "m3 3 14 14" })] }));
9
10
  const X = () => (_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" }) }));
10
11
  /** طول متن فعلی، برای کنترل‌شده و کنترل‌نشده */
@@ -29,7 +30,8 @@ export const Input = forwardRef(function Input({ label, hint, error, optional, l
29
30
  const [revealed, setRevealed] = useState(false);
30
31
  const [length, trackLength] = useLength(value, defaultValue);
31
32
  const isPassword = type === "password";
32
- const { clear = "پاک کردن", show = "نمایش رمز", hide = "پنهان کردن رمز", loading: loadingLabel = "در حال بررسی" } = labels;
33
+ const { messages: M } = useKashi();
34
+ const { clear = M.input.clear, show = M.input.show, hide = M.input.hide, loading: loadingLabel = M.input.checking } = labels;
33
35
  const counterId = `${inputId}-count`;
34
36
  const canClear = clearable && length > 0 && !disabled && !readOnly;
35
37
  const end = (_jsxs(_Fragment, { children: [loading && _jsx("span", { className: "k-input__addon", children: _jsx("span", { className: "k-spinner k-spinner--sm", role: "status", "aria-label": loadingLabel }) }), canClear && (_jsx("button", { type: "button", className: "k-input__action", "aria-label": clear, onClick: () => {
package/dist/IranMap.js CHANGED
@@ -5,12 +5,14 @@ import { PROVINCES, formatNumber } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
6
  import { ChartTip } from "./Chart.js";
7
7
  import { IRAN_PROVINCES, IRAN_VIEWBOX } from "./iranMapData.js";
8
+ import { useKashi } from "./KashiProvider.js";
8
9
  const NAMES = PROVINCES.map((p) => p.name);
9
10
  const CAPITAL = Object.fromEntries(PROVINCES.map((p) => [p.name, p.capital]));
10
11
  const [, , VW, VH] = IRAN_VIEWBOX.split(" ").map(Number);
11
12
  /** نقشهٔ ۳۱ استان ایران؛ نقشهٔ رنگی برای داده و/یا انتخاب یک یا چند استان، با صفحه‌کلید و جدول هم‌ارز */
12
13
  export function IranMap(props) {
13
- const { data, value, defaultValue, multiple = false, label = "نقشهٔ استان‌های ایران", unit, format = (n) => formatNumber(n), steps = 5, scale = "quantile", legend, tooltip, className, } = props;
14
+ const { messages: M, digits: D } = useKashi();
15
+ const { data, value, defaultValue, multiple = false, label = M.iranMap.label, unit, format = (n) => formatNumber(n, { digits: D }), steps = 5, scale = "quantile", legend, tooltip, className, } = props;
14
16
  const onChange = props.onChange;
15
17
  const selectable = value !== undefined || defaultValue !== undefined || onChange !== undefined;
16
18
  const [inner, setInner] = useState(defaultValue ?? (multiple ? [] : null));
@@ -85,7 +87,7 @@ export function IranMap(props) {
85
87
  const showLegend = legend ?? Boolean(data);
86
88
  const ratio = (VH / VW) * 100;
87
89
  return (_jsxs("figure", { ref: box, className: cx("k-iran-map", selectable && "k-iran-map--selectable", className), onPointerLeave: () => setTip(null), children: [_jsxs("div", { className: "k-iran-map__canvas", style: { paddingBlockEnd: `${ratio}%` }, children: [_jsx("svg", { viewBox: IRAN_VIEWBOX, className: "k-iran-map__svg", role: selectable ? (multiple ? "group" : "radiogroup") : "img", onFocus: () => setInside(true), onBlur: (e) => { if (!e.currentTarget.contains(e.relatedTarget))
88
- setInside(false); }, "aria-label": selectable ? label : `${label}${data ? `؛ جدول داده در ادامه` : ""}`, children: NAMES.map((n, i) => {
90
+ setInside(false); }, "aria-label": selectable ? label : `${label}${data ? M.iranMap.tableNote : ""}`, children: NAMES.map((n, i) => {
89
91
  const p = IRAN_PROVINCES[n];
90
92
  const on = isSelected(n);
91
93
  return (_jsx("path", { ref: (el) => { refs.current[i] = el; }, d: p.d, className: "k-iran-map__province", "data-l": level(n), style: level(n) ? { "--_p": shade(level(n)) } : undefined, "data-selected": on ? "" : undefined, "data-active": tip === n ? "" : undefined, role: selectable ? (multiple ? "checkbox" : "radio") : undefined, "aria-checked": selectable ? on : undefined, "aria-label": selectable ? describe(n) : undefined, tabIndex: selectable ? (i === tabStop ? 0 : -1) : undefined, onPointerEnter: () => setTip(n), onFocus: () => { setActive(i); setTip(n); }, onBlur: () => setTip(null), onClick: selectable ? () => { setActive(i); toggle(n); } : undefined, onKeyDown: selectable ? (e) => onKey(e, i) : undefined }, n));
@@ -94,6 +96,6 @@ export function IranMap(props) {
94
96
  y: Math.max(64, (tipProvince.y / VH) * ((box.current?.clientWidth ?? VW) * (VH / VW)) - 6), width: box.current?.clientWidth, title: tip, rows: [
95
97
  ...(typeof tipValue === "number" ? [{ value: `${format(tipValue)}${unit ? ` ${unit}` : ""}` }] : []),
96
98
  ...(tooltip ? [{ value: tooltip(tip, tipValue) }] : []),
97
- ...(typeof tipValue !== "number" && !tooltip ? [{ value: `مرکز: ${CAPITAL[tip]}` }] : []),
99
+ ...(typeof tipValue !== "number" && !tooltip ? [{ value: M.province.capital(CAPITAL[tip]) }] : []),
98
100
  ] }))] }), showLegend && values.length > 0 && (_jsxs("figcaption", { className: "k-iran-map__legend", children: [_jsx("span", { children: format(min) }), _jsx("span", { className: "k-iran-map__scale", "aria-hidden": "true", children: Array.from({ length: steps }, (_, i) => _jsx("i", { style: { "--_p": shade(i + 1) } }, i)) }), _jsxs("span", { children: [format(max), unit ? ` ${unit}` : ""] })] })), data && (_jsxs("table", { className: "k-sr-only", children: [_jsx("caption", { children: label }), _jsx("tbody", { children: NAMES.filter((n) => typeof data[n] === "number").sort((a, b) => data[b] - data[a]).map((n) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: n }), _jsxs("td", { children: [format(data[n]), unit ? ` ${unit}` : ""] })] }, n))) })] }))] }));
99
101
  }
@@ -0,0 +1,28 @@
1
+ import { type ReactNode } from "react";
2
+ import { type KashiLocale, type KashiMessages, type KashiMessagesInput } from "@kashi-ui/persian";
3
+ export interface KashiProviderProps {
4
+ /** زبان متن‌های داخلی کامپوننت‌ها، نام ماه‌ها و روزها @default "fa" */
5
+ locale?: KashiLocale;
6
+ /** عوض کردن هر متن دلخواه: { common: { close: "Dismiss" } } */
7
+ messages?: KashiMessagesInput;
8
+ /** ارقام پیش‌فرض کامپوننت‌ها؛ prop ‏digits هر کامپوننت بر این مقدم است @default "fa" برای فارسی، "latin" برای انگلیسی */
9
+ digits?: "fa" | "latin";
10
+ children: ReactNode;
11
+ }
12
+ /**
13
+ * زبان کامپوننت‌های کاشی: بدون آن همه‌چیز فارسی است. با locale="en" برچسب دکمه‌ها، متن صفحه‌خوان،
14
+ * پیام‌های خطا، نام ماه‌ها و ارقام انگلیسی می‌شوند. جهت صفحه (dir) را خودتان روی html بگذارید.
15
+ */
16
+ export declare function KashiProvider({ locale, messages, digits, children }: KashiProviderProps): import("react").JSX.Element;
17
+ /** زبان، فرهنگ متن‌ها و ارقام فعلی؛ n() عدد را با ارقام همان زبان می‌نویسد و months/weekdays نام‌های تقویم شمسی‌اند */
18
+ export declare function useKashi(): {
19
+ n: (v: number | string, digits?: "fa" | "latin") => string;
20
+ months: readonly ["Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand"] | readonly ["فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن", "اسفند"];
21
+ weekdays: readonly ["Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] | readonly ["شنبه", "یکشنبه", "دوشنبه", "سه‌شنبه", "چهارشنبه", "پنجشنبه", "جمعه"];
22
+ weekdaysShort: readonly ["Sa", "Su", "Mo", "Tu", "We", "Th", "Fr"] | readonly ["ش", "ی", "د", "س", "چ", "پ", "ج"];
23
+ /** نامی که getIranHoliday برای جمعه برمی‌گرداند */
24
+ friday: string;
25
+ locale: KashiLocale;
26
+ messages: KashiMessages;
27
+ digits: "fa" | "latin";
28
+ };
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { createContext, useContext, useMemo } from "react";
4
+ import { JALALI_MONTHS, JALALI_MONTHS_EN, WEEKDAYS, WEEKDAYS_EN, WEEKDAYS_SHORT, WEEKDAYS_SHORT_EN, faMessages, getMessages, toFaDigits, } from "@kashi-ui/persian";
5
+ const KashiContext = createContext({ locale: "fa", messages: faMessages, digits: "fa" });
6
+ /**
7
+ * زبان کامپوننت‌های کاشی: بدون آن همه‌چیز فارسی است. با locale="en" برچسب دکمه‌ها، متن صفحه‌خوان،
8
+ * پیام‌های خطا، نام ماه‌ها و ارقام انگلیسی می‌شوند. جهت صفحه (dir) را خودتان روی html بگذارید.
9
+ */
10
+ export function KashiProvider({ locale = "fa", messages, digits, children }) {
11
+ const value = useMemo(() => ({ locale, messages: getMessages(locale, messages), digits: digits ?? (locale === "en" ? "latin" : "fa") }), [locale, messages, digits]);
12
+ return _jsx(KashiContext.Provider, { value: value, children: children });
13
+ }
14
+ /** زبان، فرهنگ متن‌ها و ارقام فعلی؛ n() عدد را با ارقام همان زبان می‌نویسد و months/weekdays نام‌های تقویم شمسی‌اند */
15
+ export function useKashi() {
16
+ const ctx = useContext(KashiContext);
17
+ const en = ctx.locale === "en";
18
+ return {
19
+ ...ctx,
20
+ n: (v, digits = ctx.digits) => (digits === "fa" ? toFaDigits(String(v)) : String(v)),
21
+ months: en ? JALALI_MONTHS_EN : JALALI_MONTHS,
22
+ weekdays: en ? WEEKDAYS_EN : WEEKDAYS,
23
+ weekdaysShort: en ? WEEKDAYS_SHORT_EN : WEEKDAYS_SHORT,
24
+ /** نامی که getIranHoliday برای جمعه برمی‌گرداند */
25
+ friday: en ? "Friday" : "جمعه",
26
+ };
27
+ }
@@ -4,11 +4,13 @@ import { forwardRef, useRef, useState } from "react";
4
4
  import { fixKeyboardLayout, looksLikeWrongLayout } from "@kashi-ui/persian";
5
5
  import { Input } from "./Input.js";
6
6
  import { mergeRefs } from "./utils.js";
7
+ import { useKashi } from "./KashiProvider.js";
7
8
  /**
8
9
  * فیلدی که اگر کاربر فارسی را با صفحه‌کلید انگلیسی تایپ کرده باشد («sghl»)، شکل درست («سلام») را پیشنهاد می‌دهد.
9
10
  * مناسب جستجو و فرم‌هایی که کاربر زبان صفحه‌کلید را عوض نکرده است.
10
11
  */
11
12
  export const KeyboardFixInput = forwardRef(function KeyboardFixInput({ value, defaultValue = "", onValueChange, suggest = "auto", renderSuggestion, hint, ...rest }, ref) {
13
+ const { messages: M, locale } = useKashi();
12
14
  const [inner, setInner] = useState(defaultValue);
13
15
  const current = value ?? inner;
14
16
  const el = useRef(null);
@@ -24,5 +26,5 @@ export const KeyboardFixInput = forwardRef(function KeyboardFixInput({ value, de
24
26
  update(fixed);
25
27
  el.current?.focus();
26
28
  };
27
- return (_jsx(Input, { ref: mergeRefs(ref, el), dir: "auto", value: current, onChange: (e) => update(e.target.value), hint: show ? (_jsx("span", { className: "k-kbfix", role: "status", children: renderSuggestion ? renderSuggestion(fixed, apply) : _jsxs(_Fragment, { children: ["\u0645\u0646\u0638\u0648\u0631\u062A\u0627\u0646 ", _jsxs("button", { type: "button", className: "k-kbfix__btn", onClick: apply, children: ["\u00AB", fixed, "\u00BB"] }), " \u0628\u0648\u062F\u061F"] }) })) : hint, ...rest }));
29
+ return (_jsx(Input, { ref: mergeRefs(ref, el), dir: "auto", value: current, onChange: (e) => update(e.target.value), hint: show ? (_jsx("span", { className: "k-kbfix", role: "status", children: renderSuggestion ? renderSuggestion(fixed, apply) : _jsxs(_Fragment, { children: [M.keyboardFix.before, " ", _jsxs("button", { type: "button", className: "k-kbfix__btn", onClick: apply, children: ["\u00AB", fixed, "\u00BB"] }), locale === "en" ? "" : " ", M.keyboardFix.after] }) })) : hint, ...rest }));
28
30
  });
@@ -5,8 +5,12 @@ import { formatLandline, getLandlineProvince, isValidLandline, normalizeLandline
5
5
  import { Input } from "./Input.js";
6
6
  import { useDigitsInput } from "./useDigitsInput.js";
7
7
  import { mergeRefs } from "./utils.js";
8
+ import { useKashi } from "./KashiProvider.js";
8
9
  /** تلفن ثابت با پیش‌شماره: +98 را به ۰ تبدیل می‌کند، گروه‌بندی و نام استان را نشان می‌دهد */
9
- export const LandlineInput = forwardRef(function LandlineInput({ value, defaultValue, onValueChange, digits = "fa", showProvince = true, invalidMessage = "شمارهٔ تلفن ثابت معتبر نیست.", error, name, id, onBlur, placeholder, ...rest }, ref) {
10
+ export const LandlineInput = forwardRef(function LandlineInput({ value, defaultValue, onValueChange, digits, showProvince = true, invalidMessage, error, name, id, onBlur, placeholder, ...rest }, ref) {
11
+ const { messages: M, digits: D, locale } = useKashi();
12
+ digits ?? (digits = D);
13
+ invalidMessage ?? (invalidMessage = M.invalid.landline);
10
14
  const autoId = useId();
11
15
  const inputId = id ?? autoId;
12
16
  const [touched, setTouched] = useState(false);
@@ -3,8 +3,12 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  import { forwardRef, useState } from "react";
4
4
  import { isValidLegalId, onlyDigits, toFaDigits } from "@kashi-ui/persian";
5
5
  import { Input } from "./Input.js";
6
+ import { useKashi } from "./KashiProvider.js";
6
7
  /** شناسهٔ ملی اشخاص حقوقی (شرکت‌ها): ۱۱ رقم با بررسی رقم کنترل */
7
- export const LegalIdInput = forwardRef(function LegalIdInput({ value, defaultValue = "", onValueChange, digits = "fa", invalidMessage = "شناسهٔ ملی معتبر نیست.", error, name, onBlur, placeholder, ...rest }, ref) {
8
+ export const LegalIdInput = forwardRef(function LegalIdInput({ value, defaultValue = "", onValueChange, digits, invalidMessage, error, name, onBlur, placeholder, ...rest }, ref) {
9
+ const { messages: M, digits: D, locale } = useKashi();
10
+ digits ?? (digits = D);
11
+ invalidMessage ?? (invalidMessage = M.invalid.legalId);
8
12
  const [inner, setInner] = useState(() => onlyDigits(defaultValue).slice(0, 11));
9
13
  const [touched, setTouched] = useState(false);
10
14
  const raw = value !== undefined ? onlyDigits(value).slice(0, 11) : inner;
package/dist/Meter.js CHANGED
@@ -1,14 +1,17 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { formatNumber, toFaDigits } from "@kashi-ui/persian";
3
+ import { formatNumber } from "@kashi-ui/persian";
4
4
  import { cx } from "./cx.js";
5
+ import { useKashi } from "./KashiProvider.js";
5
6
  const Icon = ({ d }) => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: d }) });
6
7
  /** سنجهٔ یک مقدار در برابر سقف، مثل فضای ذخیره یا سهمیهٔ پیامک؛ وضعیت با متن و آیکون، نه فقط رنگ */
7
- export function Meter({ label, value, max = 100, warning = max * 0.8, critical = max * 0.95, format = (n) => formatNumber(n), className, labels = {} }) {
8
- const { ok = "در محدودهٔ مجاز", warning: warnText = "نزدیک به سقف", critical: critText = "سقف تقریباً پر شده", of = "از" } = labels;
8
+ export function Meter({ label, value, max = 100, warning = max * 0.8, critical = max * 0.95, format, className, labels = {} }) {
9
+ const { messages: M, n, digits: D } = useKashi();
10
+ format ?? (format = (x) => formatNumber(x, { digits: D }));
11
+ const { ok = M.meter.ok, warning: warnText = M.meter.warning, critical: critText = M.meter.critical, of } = labels;
9
12
  const v = Math.min(max, Math.max(0, value));
10
13
  const status = v >= critical ? "critical" : v >= warning ? "warning" : "ok";
11
14
  const pct = Math.round((v / max) * 100);
12
15
  const text = { ok, warning: warnText, critical: critText }[status];
13
- return (_jsxs("div", { className: cx("k-meter", className), "data-status": status, children: [_jsxs("div", { className: "k-meter__head", children: [_jsx("span", { className: "k-meter__label", children: label }), _jsxs("span", { className: "k-meter__value", children: [format(v), " ", _jsxs("span", { children: [of, " ", format(max)] })] })] }), _jsxs("div", { className: "k-meter__track", role: "meter", "aria-valuenow": v, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuetext": `${format(v)} ${of} ${format(max)}، ${toFaDigits(pct)}٪، ${text}`, "aria-label": typeof label === "string" ? label : undefined, children: [_jsx("span", { className: "k-meter__fill", style: { inlineSize: `${pct}%` } }), _jsx("span", { className: "k-meter__mark", style: { insetInlineStart: `${(warning / max) * 100}%` }, "aria-hidden": "true" })] }), _jsxs("p", { className: "k-meter__status", "aria-hidden": "true", children: [_jsx(Icon, { d: status === "ok" ? "m5 10.5 3.2 3L15 7" : "M10 3 2.5 16.5h15ZM10 8v4M10 14.5h.01" }), text, " \u00B7 ", toFaDigits(pct), "\u066A"] })] }));
16
+ return (_jsxs("div", { className: cx("k-meter", className), "data-status": status, children: [_jsxs("div", { className: "k-meter__head", children: [_jsx("span", { className: "k-meter__label", children: label }), _jsxs("span", { className: "k-meter__value", children: [format(v), " ", _jsxs("span", { children: [of, " ", format(max)] })] })] }), _jsxs("div", { className: "k-meter__track", role: "meter", "aria-valuenow": v, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuetext": `${of ? `${format(v)} ${of} ${format(max)}` : M.common.of(format(v), format(max))}${M.common.list}${M.common.percent(n(pct))}${M.common.list}${text}`, "aria-label": typeof label === "string" ? label : undefined, children: [_jsx("span", { className: "k-meter__fill", style: { inlineSize: `${pct}%` } }), _jsx("span", { className: "k-meter__mark", style: { insetInlineStart: `${(warning / max) * 100}%` }, "aria-hidden": "true" })] }), _jsxs("p", { className: "k-meter__status", "aria-hidden": "true", children: [_jsx(Icon, { d: status === "ok" ? "m5 10.5 3.2 3L15 7" : "M10 3 2.5 16.5h15ZM10 8v4M10 14.5h.01" }), text, " \u00B7 ", M.common.percent(n(pct))] })] }));
14
17
  }
@@ -1,12 +1,16 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useId, useState } from "react";
4
- import { formatMobile, getMobileOperator, isValidMobile, normalizeMobile } from "@kashi-ui/persian";
4
+ import { formatMobile, getMobileOperator, isValidMobile, normalizeMobile, operatorName } from "@kashi-ui/persian";
5
5
  import { Input } from "./Input.js";
6
6
  import { useDigitsInput } from "./useDigitsInput.js";
7
7
  import { mergeRefs } from "./utils.js";
8
+ import { useKashi } from "./KashiProvider.js";
8
9
  /** فیلد شماره موبایل: +98 و 0098 را به 09 تبدیل می‌کند، گروه‌بندی و تشخیص اپراتور */
9
- export const MobileInput = forwardRef(function MobileInput({ value, defaultValue, onValueChange, digits = "fa", showOperator = true, invalidMessage = "شماره موبایل معتبر نیست.", error, name, id, onBlur, placeholder, ...rest }, ref) {
10
+ export const MobileInput = forwardRef(function MobileInput({ value, defaultValue, onValueChange, digits, showOperator = true, invalidMessage, error, name, id, onBlur, placeholder, ...rest }, ref) {
11
+ const { messages: M, digits: D, locale } = useKashi();
12
+ digits ?? (digits = D);
13
+ invalidMessage ?? (invalidMessage = M.invalid.mobile);
10
14
  const autoId = useId();
11
15
  const inputId = id ?? autoId;
12
16
  const [touched, setTouched] = useState(false);
@@ -27,5 +31,5 @@ export const MobileInput = forwardRef(function MobileInput({ value, defaultValue
27
31
  }, onBlur: (e) => {
28
32
  setTouched(true);
29
33
  onBlur?.(e);
30
- }, addonEnd: operator ? _jsx("span", { className: "k-input__meta", id: opId, children: operator.name }) : undefined, "aria-describedby": operator ? opId : undefined, error: error ?? (showInvalid ? invalidMessage : undefined), ...rest }), name && _jsx("input", { type: "hidden", name: name, value: raw })] }));
34
+ }, addonEnd: operator ? _jsx("span", { className: "k-input__meta", id: opId, children: operatorName(operator, locale) }) : undefined, "aria-describedby": operator ? opId : undefined, error: error ?? (showInvalid ? invalidMessage : undefined), ...rest }), name && _jsx("input", { type: "hidden", name: name, value: raw })] }));
31
35
  });
package/dist/Money.js CHANGED
@@ -3,13 +3,17 @@ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef } from "react";
4
4
  import { formatMoney, numberToWords, rialToToman, tomanToRial } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
+ import { useKashi } from "./KashiProvider.js";
6
7
  /** نمایش مبلغ با تومان یا ریال، حالت خلاصه (۱٫۲ میلیون) و مبلغ به حروف برای صفحه‌خوان */
7
- export const Money = forwardRef(function Money({ value, unit = "toman", from = "toman", compact, digits = "fa", signed, words = true, size = "md", className, ...rest }, ref) {
8
+ export const Money = forwardRef(function Money({ value, unit = "toman", from = "toman", compact, digits, signed, words = true, size = "md", className, ...rest }, ref) {
9
+ const { messages: M, digits: D, locale } = useKashi();
10
+ digits ?? (digits = D);
8
11
  const n = from === unit ? value : from === "rial" ? rialToToman(value) : tomanToRial(value);
9
- const amount = formatMoney(n, { unit, compact, digits, showUnit: false });
10
- const full = formatMoney(n, { unit, compact });
11
- const unitText = full.endsWith("همت") ? null : unit === "toman" ? "تومان" : "ریال";
12
- const spoken = words && Number.isSafeInteger(Math.round(n)) ? `${numberToWords(Math.round(n))} ${unit === "toman" ? "تومان" : "ریال"}` : undefined;
12
+ const amount = formatMoney(n, { unit, compact, digits, locale, showUnit: false });
13
+ const full = formatMoney(n, { unit, compact, locale });
14
+ const unitName = unit === "toman" ? M.money.toman : M.money.rial;
15
+ const unitText = full.endsWith("همت") ? null : unitName;
16
+ const spoken = words && Number.isSafeInteger(Math.round(n)) ? `${numberToWords(Math.round(n), { locale })} ${unitName}` : undefined;
13
17
  const tone = signed ? (n > 0 ? "positive" : n < 0 ? "negative" : undefined) : undefined;
14
- return (_jsxs("data", { ref: ref, value: String(n), className: cx("k-money", `k-money--${size}`, className), "data-tone": tone, title: spoken, ...rest, children: [_jsxs("span", { className: "k-money__amount", "aria-hidden": spoken ? true : undefined, children: [signed && n > 0 ? "+" : "", amount] }), unitText && _jsx("span", { className: "k-money__unit", "aria-hidden": spoken ? true : undefined, children: unitText }), spoken && _jsxs("span", { className: "k-sr-only", children: [n < 0 ? "" : signed && n > 0 ? "مثبت " : "", spoken] })] }));
18
+ return (_jsxs("data", { ref: ref, value: String(n), className: cx("k-money", `k-money--${size}`, className), "data-tone": tone, title: spoken, ...rest, children: [_jsxs("span", { className: "k-money__amount", "aria-hidden": spoken ? true : undefined, children: [signed && n > 0 ? "+" : "", amount] }), unitText && _jsx("span", { className: "k-money__unit", "aria-hidden": spoken ? true : undefined, children: unitText }), spoken && _jsxs("span", { className: "k-sr-only", children: [n < 0 ? "" : signed && n > 0 ? M.money.positive : "", spoken] })] }));
15
19
  });
@@ -1,13 +1,17 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useEffect, useRef, useState } from "react";
4
- import { JALALI_MONTHS, toFaDigits, toJalali } from "@kashi-ui/persian";
4
+ import { toFaDigits, toJalali } from "@kashi-ui/persian";
5
5
  import { cx } from "./cx.js";
6
+ import { useKashi } from "./KashiProvider.js";
6
7
  const key = (m) => m.year * 12 + m.month;
7
8
  const Arrow = ({ next }) => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", "data-k-mirror": "", children: _jsx("path", { d: next ? "m8 5 5 5-5 5" : "m12 5-5 5 5 5" }) }));
8
9
  /** انتخاب ماه و سال شمسی، برای گزارش ماهانه یا تاریخ انقضای کارت؛ ↑↓←→ بین ماه‌ها و PageUp/PageDown بین سال‌ها */
9
- export function MonthPicker({ value, defaultValue = null, onChange, min, max, digits = "fa", "aria-label": ariaLabel = "انتخاب ماه", className, labels = {} }) {
10
- const { prevYear = "سال قبل", nextYear = "سال بعد" } = labels;
10
+ export function MonthPicker({ value, defaultValue = null, onChange, min, max, digits, "aria-label": ariaLabel, className, labels = {} }) {
11
+ const { messages: M, digits: D, months: MONTHS } = useKashi();
12
+ digits ?? (digits = D);
13
+ ariaLabel ?? (ariaLabel = M.monthPicker.label);
14
+ const { prevYear = M.monthPicker.prevYear, nextYear = M.monthPicker.nextYear } = labels;
11
15
  const today = toJalali(new Date());
12
16
  const [inner, setInner] = useState(defaultValue);
13
17
  const selected = value !== undefined ? value : inner;
@@ -55,7 +59,7 @@ export function MonthPicker({ value, defaultValue = null, onChange, min, max, di
55
59
  e.preventDefault();
56
60
  moveTo(Math.floor(idx / 12), (idx % 12) + 1);
57
61
  };
58
- return (_jsxs("div", { className: cx("k-monthpicker", className), role: "group", "aria-label": ariaLabel, children: [_jsxs("div", { className: "k-monthpicker__header", children: [_jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": prevYear, onClick: () => setYear(year - 1), disabled: !!min && year <= min.year, children: _jsx(Arrow, {}) }), _jsx("span", { className: "k-monthpicker__year", "aria-live": "polite", children: f(year) }), _jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": nextYear, onClick: () => setYear(year + 1), disabled: !!max && year >= max.year, children: _jsx(Arrow, { next: true }) })] }), _jsx("div", { className: "k-monthpicker__grid", ref: grid, onKeyDown: onKeyDown, children: JALALI_MONTHS.map((name, i) => {
62
+ return (_jsxs("div", { className: cx("k-monthpicker", className), role: "group", "aria-label": ariaLabel, children: [_jsxs("div", { className: "k-monthpicker__header", children: [_jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": prevYear, onClick: () => setYear(year - 1), disabled: !!min && year <= min.year, children: _jsx(Arrow, {}) }), _jsx("span", { className: "k-monthpicker__year", "aria-live": "polite", children: f(year) }), _jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": nextYear, onClick: () => setYear(year + 1), disabled: !!max && year >= max.year, children: _jsx(Arrow, { next: true }) })] }), _jsx("div", { className: "k-monthpicker__grid", ref: grid, onKeyDown: onKeyDown, children: MONTHS.map((name, i) => {
59
63
  const m = { year, month: i + 1 };
60
64
  const isSel = selected?.year === year && selected.month === i + 1;
61
65
  return (_jsx("button", { type: "button", "data-month": i + 1, className: "k-monthpicker__month", tabIndex: focus === i + 1 ? 0 : -1, "aria-pressed": isSel, "aria-label": `${name} ${f(year)}`, "aria-current": today.jy === year && today.jm === i + 1 ? "date" : undefined, disabled: !!out(m), onFocus: () => setFocus(i + 1), onClick: () => pick(m), children: name }, name));