@kashi-ui/react 0.7.0 → 0.9.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 (58) hide show
  1. package/README.md +2 -2
  2. package/dist/Alert.d.ts +11 -0
  3. package/dist/Alert.js +2 -2
  4. package/dist/Avatar.d.ts +6 -0
  5. package/dist/Avatar.js +11 -2
  6. package/dist/Badge.d.ts +9 -1
  7. package/dist/Badge.js +3 -2
  8. package/dist/Button.d.ts +15 -4
  9. package/dist/Button.js +12 -2
  10. package/dist/Calendar.d.ts +6 -1
  11. package/dist/Calendar.js +12 -5
  12. package/dist/Card.d.ts +17 -3
  13. package/dist/Card.js +13 -4
  14. package/dist/Checkbox.d.ts +9 -0
  15. package/dist/Checkbox.js +6 -6
  16. package/dist/Combobox.d.ts +48 -0
  17. package/dist/Combobox.js +143 -0
  18. package/dist/CommandPalette.d.ts +37 -0
  19. package/dist/CommandPalette.js +95 -0
  20. package/dist/DataTable.d.ts +28 -1
  21. package/dist/DataTable.js +17 -10
  22. package/dist/DateRangePicker.d.ts +50 -0
  23. package/dist/DateRangePicker.js +94 -0
  24. package/dist/Dialog.d.ts +4 -2
  25. package/dist/Dialog.js +2 -2
  26. package/dist/DropdownMenu.d.ts +3 -1
  27. package/dist/DropdownMenu.js +7 -5
  28. package/dist/Field.d.ts +15 -1
  29. package/dist/Field.js +4 -2
  30. package/dist/FileUpload.d.ts +39 -0
  31. package/dist/FileUpload.js +90 -0
  32. package/dist/Input.d.ts +34 -0
  33. package/dist/Input.js +57 -6
  34. package/dist/NumberInput.d.ts +29 -0
  35. package/dist/NumberInput.js +56 -0
  36. package/dist/Popover.d.ts +19 -0
  37. package/dist/Popover.js +58 -0
  38. package/dist/Progress.d.ts +3 -1
  39. package/dist/Progress.js +6 -1
  40. package/dist/SideNav.d.ts +28 -0
  41. package/dist/SideNav.js +22 -0
  42. package/dist/Slider.d.ts +32 -0
  43. package/dist/Slider.js +33 -0
  44. package/dist/Stat.d.ts +24 -0
  45. package/dist/Stat.js +17 -0
  46. package/dist/Tabs.d.ts +5 -1
  47. package/dist/Tabs.js +8 -9
  48. package/dist/TagInput.d.ts +33 -0
  49. package/dist/TagInput.js +88 -0
  50. package/dist/Timeline.d.ts +19 -0
  51. package/dist/Timeline.js +8 -0
  52. package/dist/Toast.d.ts +22 -8
  53. package/dist/Toast.js +55 -12
  54. package/dist/Tooltip.d.ts +2 -2
  55. package/dist/Tooltip.js +1 -1
  56. package/dist/index.d.ts +28 -6
  57. package/dist/index.js +13 -2
  58. package/package.json +4 -4
@@ -0,0 +1,95 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useMemo, useRef, useState } from "react";
3
+ import { toFaDigits } from "@kashi-ui/persian";
4
+ import { defaultFilter, highlight } from "./Combobox.js";
5
+ import { cx } from "./cx.js";
6
+ /**
7
+ * پالت فرمان: جستجوی سریع در عمل‌ها و صفحه‌ها با Ctrl+K.
8
+ * پنجره روی <dialog> بومی است (تلهٔ فوکوس و Esc) و فهرست با الگوی combobox/listbox پیمایش می‌شود.
9
+ */
10
+ export function CommandPalette({ open, onOpenChange, items, shortcut = true, placeholder = "جستجوی دستور یا صفحه…", emptyMessage = "دستوری پیدا نشد.", labels = {}, className, }) {
11
+ const id = useId();
12
+ const listId = `${id}-list`;
13
+ const ref = useRef(null);
14
+ const inputRef = useRef(null);
15
+ const opener = useRef(null);
16
+ const [query, setQuery] = useState("");
17
+ const [active, setActive] = useState(0);
18
+ const { title = "پالت فرمان", navigate = "حرکت", select = "انتخاب", close = "بستن", results = (n) => `${toFaDigits(n)} نتیجه` } = labels;
19
+ // میان‌بر سراسری
20
+ useEffect(() => {
21
+ if (!shortcut)
22
+ return;
23
+ const onKey = (e) => {
24
+ if ((e.ctrlKey || e.metaKey) && (e.key === "k" || e.key === "K" || e.code === "KeyK")) {
25
+ e.preventDefault();
26
+ onOpenChange(!open);
27
+ }
28
+ };
29
+ document.addEventListener("keydown", onKey);
30
+ return () => document.removeEventListener("keydown", onKey);
31
+ }, [shortcut, open, onOpenChange]);
32
+ useEffect(() => {
33
+ const d = ref.current;
34
+ if (!d)
35
+ return;
36
+ if (open && !d.open) {
37
+ opener.current = document.activeElement;
38
+ setQuery("");
39
+ setActive(0);
40
+ d.showModal();
41
+ inputRef.current?.focus();
42
+ }
43
+ else if (!open && d.open)
44
+ d.close();
45
+ }, [open]);
46
+ const filtered = useMemo(() => items.filter((it) => defaultFilter({ value: it.id, label: it.label, description: it.description, keywords: it.keywords }, query)), [items, query]);
47
+ useEffect(() => {
48
+ document.getElementById(`${listId}-${active}`)?.scrollIntoView({ block: "nearest" });
49
+ }, [active, listId]);
50
+ const run = (it) => {
51
+ if (!it)
52
+ return;
53
+ onOpenChange(false);
54
+ if (it.href)
55
+ window.location.href = it.href;
56
+ else
57
+ it.onSelect?.();
58
+ };
59
+ const onKeyDown = (e) => {
60
+ const n = filtered.length;
61
+ if (!n)
62
+ return;
63
+ if (e.key === "ArrowDown")
64
+ setActive((a) => (a + 1) % n);
65
+ else if (e.key === "ArrowUp")
66
+ setActive((a) => (a - 1 + n) % n);
67
+ else if (e.key === "Home")
68
+ setActive(0);
69
+ else if (e.key === "End")
70
+ setActive(n - 1);
71
+ else if (e.key === "Enter")
72
+ run(filtered[active]);
73
+ else
74
+ return;
75
+ e.preventDefault();
76
+ };
77
+ let lastGroup;
78
+ return (_jsxs("dialog", { ref: ref, className: cx("k-dialog", "k-command", className), "aria-label": title, onClose: () => {
79
+ onOpenChange(false);
80
+ opener.current?.focus?.();
81
+ }, onCancel: (e) => {
82
+ e.preventDefault();
83
+ onOpenChange(false);
84
+ }, onClick: (e) => e.target === ref.current && onOpenChange(false), children: [_jsxs("div", { className: "k-input", children: [_jsx("span", { className: "k-input__addon", children: _jsxs("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "9", cy: "9", r: "5.5" }), _jsx("path", { d: "m13.5 13.5 3 3" })] }) }), _jsx("input", { ref: inputRef, className: "k-input__control", type: "text", role: "combobox", "aria-expanded": "true", "aria-controls": listId, "aria-autocomplete": "list", "aria-activedescendant": filtered.length ? `${listId}-${active}` : undefined, "aria-label": title, placeholder: placeholder, autoComplete: "off", value: query, onChange: (e) => {
85
+ setQuery(e.target.value);
86
+ setActive(0);
87
+ }, onKeyDown: onKeyDown })] }), _jsxs("ul", { id: listId, role: "listbox", "aria-label": title, className: "k-listbox k-listbox--inline k-command__list", children: [filtered.length === 0 && _jsx("li", { role: "presentation", className: "k-listbox__empty", children: emptyMessage }), filtered.map((it, i) => {
88
+ const header = it.group && it.group !== lastGroup ? it.group : null;
89
+ lastGroup = it.group;
90
+ return [
91
+ header && _jsx("li", { role: "presentation", className: "k-listbox__group", children: header }, `g-${header}`),
92
+ _jsxs("li", { id: `${listId}-${i}`, role: "option", "aria-selected": i === active, "data-active": i === active ? "" : undefined, className: "k-option", onPointerDown: (e) => e.preventDefault(), onPointerMove: () => active !== i && setActive(i), onClick: () => run(it), children: [it.icon, _jsxs("span", { className: "k-option__body", children: [_jsx("span", { children: highlight(it.label, query) }), it.description && _jsx("span", { className: "k-option__desc", children: it.description })] }), it.shortcut && _jsx("span", { className: "k-menu__shortcut", "aria-hidden": "true", children: it.shortcut })] }, it.id),
93
+ ];
94
+ })] }), _jsxs("div", { className: "k-command__footer", "aria-hidden": "true", children: [_jsxs("span", { children: [_jsx("kbd", { className: "k-kbd", children: "\u2191" }), _jsx("kbd", { className: "k-kbd", children: "\u2193" }), navigate] }), _jsxs("span", { children: [_jsx("kbd", { className: "k-kbd", children: "Enter" }), select] }), _jsxs("span", { children: [_jsx("kbd", { className: "k-kbd", children: "Esc" }), close] })] }), _jsx("span", { className: "k-sr-only", "aria-live": "polite", children: query ? results(filtered.length) : "" })] }));
95
+ }
@@ -9,7 +9,13 @@ export interface Column<T> {
9
9
  sortable?: boolean;
10
10
  /** عدد و مبلغ: چپ‌چین در RTL با ارقام هم‌عرض */
11
11
  numeric?: boolean;
12
+ /** چینش خانه‌ها؛ numeric خودکار «end» است */
13
+ align?: "start" | "center" | "end";
12
14
  width?: string;
15
+ /** پنهان کردن ستون در صفحه‌های باریک */
16
+ hideBelow?: "sm" | "md";
17
+ /** کلاس خانه‌های این ستون */
18
+ className?: string;
13
19
  }
14
20
  export type SortState = {
15
21
  key: string;
@@ -33,11 +39,32 @@ export interface DataTableProps<T> {
33
39
  /** وقتی ردیفی نیست */
34
40
  empty?: ReactNode;
35
41
  compact?: boolean;
42
+ /** ردیف‌های راه‌راه */
43
+ striped?: boolean;
44
+ /** سرستون هنگام اسکرول ثابت بماند؛ با maxHeight */
45
+ stickyHeader?: boolean;
46
+ /** بیشترین ارتفاع جدول (مثل "24rem")؛ بیشتر از آن اسکرول می‌خورد */
47
+ maxHeight?: string;
48
+ /** نمایش ردیف‌های اسکلت به‌جای داده */
49
+ loading?: boolean | number;
50
+ /** کلیک روی ردیف؛ برای ناوبری بهتر است در یک خانه لینک واقعی هم بگذارید */
51
+ onRowClick?: (row: T) => void;
52
+ /** محتوای پایین جدول، مثل صفحه‌بندی */
53
+ footer?: ReactNode;
36
54
  labels?: {
37
55
  selectAll?: string;
38
56
  selectRow?: (row: T) => string;
57
+ loading?: string;
58
+ };
59
+ classNames?: {
60
+ root?: string;
61
+ table?: string;
62
+ row?: string;
63
+ cell?: string;
64
+ header?: string;
65
+ footer?: string;
39
66
  };
40
67
  className?: string;
41
68
  }
42
69
  /** جدول داده با مرتب‌سازی (aria-sort)، انتخاب ردیف‌ها و حالت خالی */
43
- export declare function DataTable<T extends Record<string, unknown>>({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort, onSortChange, empty, compact, labels, className, }: DataTableProps<T>): import("react").JSX.Element;
70
+ export declare function DataTable<T extends Record<string, unknown>>({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort, onSortChange, empty, compact, striped, stickyHeader, maxHeight, loading, onRowClick, footer, labels, classNames, className, }: DataTableProps<T>): import("react").JSX.Element;
package/dist/DataTable.js CHANGED
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useMemo, useRef, useState } from "react";
3
3
  import { cx } from "./cx.js";
4
4
  /** جدول داده با مرتب‌سازی (aria-sort)، انتخاب ردیف‌ها و حالت خالی */
5
- export function DataTable({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort = null, onSortChange, empty, compact, labels = {}, className, }) {
5
+ 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, }) {
6
6
  const id = useId();
7
7
  const [innerSort, setInnerSort] = useState(defaultSort);
8
8
  const [innerSel, setInnerSel] = useState([]);
@@ -39,14 +39,21 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
39
39
  if (allRef.current)
40
40
  allRef.current.indeterminate = some;
41
41
  }, [some]);
42
- const { selectAll = "انتخاب همهٔ ردیف‌ها", selectRow = () => "انتخاب ردیف" } = labels;
42
+ const { selectAll = "انتخاب همهٔ ردیف‌ها", selectRow = () => "انتخاب ردیف", loading: loadingLabel = "در حال بارگذاری" } = labels;
43
+ const loadingRows = loading === true ? 5 : typeof loading === "number" ? loading : 0;
44
+ 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;
43
45
  const colCount = columns.length + (selectable ? 1 : 0);
44
- return (_jsx("div", { className: cx("k-table-wrap", className), role: "region", "aria-labelledby": `${id}-caption`, tabIndex: 0, children: _jsxs("table", { className: cx("k-table", compact && "k-table--compact"), 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) => {
45
- const s = activeSort?.key === c.key ? activeSort.direction : undefined;
46
- return (_jsx("th", { scope: "col", "aria-sort": c.sortable ? (s ?? "none") : undefined, className: c.numeric ? "k-table__num" : 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));
47
- })] }) }), _jsx("tbody", { children: 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) => {
48
- const rid = getRowId(r);
49
- const on = sel.includes(rid);
50
- return (_jsxs("tr", { "aria-selected": selectable ? on : undefined, children: [selectable && (_jsx("td", { className: "k-table__check", children: _jsx("input", { type: "checkbox", className: "k-checkbox", "aria-label": selectRow(r), checked: on, onChange: () => setSel(on ? sel.filter((x) => x !== rid) : [...sel, rid]) }) })), columns.map((c) => (_jsx("td", { className: c.numeric ? "k-table__num" : undefined, children: c.render ? c.render(r) : r[c.key] }, c.key)))] }, rid));
51
- })) })] }) }));
46
+ 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) => {
47
+ const s = activeSort?.key === c.key ? activeSort.direction : undefined;
48
+ 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));
49
+ })] }) }), _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) => {
50
+ const rid = getRowId(r);
51
+ const on = sel.includes(rid);
52
+ return (_jsxs("tr", { "aria-selected": selectable ? on : undefined, className: classNames.row, onClick: onRowClick ? (e) => {
53
+ // کلیک روی چک‌باکس، دکمه یا لینک داخل ردیف را ردیف نگیرد
54
+ if (e.target.closest("a, button, input, label, select, textarea"))
55
+ return;
56
+ onRowClick(r);
57
+ } : undefined, children: [selectable && (_jsx("td", { className: "k-table__check", children: _jsx("input", { type: "checkbox", className: "k-checkbox", "aria-label": selectRow(r), checked: on, onChange: () => setSel(on ? sel.filter((x) => x !== rid) : [...sel, rid]) }) })), columns.map((c) => (_jsx("td", { className: cellCls(c), children: c.render ? c.render(r) : r[c.key] }, c.key)))] }, rid));
58
+ })) })] }), loadingRows > 0 && _jsx("span", { className: "k-sr-only", role: "status", children: loadingLabel }), footer && _jsx("div", { className: cx("k-table__footer", classNames.footer), children: footer })] }));
52
59
  }
@@ -0,0 +1,50 @@
1
+ import { type ReactNode } from "react";
2
+ import { type CalendarLabels } from "./Calendar.js";
3
+ export interface DateRange {
4
+ start: Date | null;
5
+ end: Date | null;
6
+ }
7
+ export interface DateRangePreset {
8
+ label: string;
9
+ /** بازه را بر اساس امروز می‌سازد */
10
+ range: (today: Date) => {
11
+ start: Date;
12
+ end: Date;
13
+ };
14
+ }
15
+ /** میان‌برهای پیش‌فرض با ماه‌های شمسی */
16
+ export declare const defaultRangePresets: DateRangePreset[];
17
+ export interface DateRangePickerProps {
18
+ label?: ReactNode;
19
+ hint?: ReactNode;
20
+ error?: ReactNode;
21
+ value?: DateRange;
22
+ defaultValue?: DateRange;
23
+ onChange?: (range: DateRange) => void;
24
+ min?: Date;
25
+ max?: Date;
26
+ isDateDisabled?: (date: Date) => boolean;
27
+ /** میان‌برهای کنار تقویم؛ [] برای حذف */
28
+ presets?: DateRangePreset[];
29
+ /** @default "fa" */
30
+ digits?: "fa" | "latin";
31
+ /** با name، دو فیلد پنهان name_start و name_end به شکل YYYY-MM-DD ساخته می‌شود */
32
+ name?: string;
33
+ disabled?: boolean;
34
+ id?: string;
35
+ className?: string;
36
+ calendarLabels?: CalendarLabels;
37
+ labels?: {
38
+ placeholder?: string;
39
+ separator?: string;
40
+ apply?: string;
41
+ cancel?: string;
42
+ presets?: string;
43
+ pickEnd?: string;
44
+ };
45
+ }
46
+ /**
47
+ * انتخاب بازهٔ تاریخ شمسی: کلیک اول شروع، کلیک دوم پایان؛ پیش از تأیید، بازه با حرکت موس پیش‌نمایش می‌شود.
48
+ * تغییرها فقط با «تأیید» ثبت می‌شوند.
49
+ */
50
+ export declare function DateRangePicker({ label, hint, error, value, defaultValue, onChange, min, max, isDateDisabled, presets, digits, name, disabled, id, className, calendarLabels, labels, }: DateRangePickerProps): import("react").JSX.Element;
@@ -0,0 +1,94 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef, useState } from "react";
3
+ import { formatJalali, toGregorian, toISODate, toJalali } from "@kashi-ui/persian";
4
+ import { Calendar } from "./Calendar.js";
5
+ import { Field } from "./Field.js";
6
+ import { cx } from "./cx.js";
7
+ const day = (d, add = 0) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + add);
8
+ /** میان‌برهای پیش‌فرض با ماه‌های شمسی */
9
+ export const defaultRangePresets = [
10
+ { label: "۷ روز اخیر", range: (t) => ({ start: day(t, -6), end: t }) },
11
+ { label: "۳۰ روز اخیر", range: (t) => ({ start: day(t, -29), end: t }) },
12
+ {
13
+ label: "این ماه",
14
+ range: (t) => {
15
+ const { jy, jm } = toJalali(t);
16
+ return { start: toGregorian(jy, jm, 1), end: t };
17
+ },
18
+ },
19
+ {
20
+ label: "ماه قبل",
21
+ range: (t) => {
22
+ const { jy, jm } = toJalali(t);
23
+ const [py, pm] = jm === 1 ? [jy - 1, 12] : [jy, jm - 1];
24
+ return { start: toGregorian(py, pm, 1), end: day(toGregorian(jy, jm, 1), -1) };
25
+ },
26
+ },
27
+ ];
28
+ /**
29
+ * انتخاب بازهٔ تاریخ شمسی: کلیک اول شروع، کلیک دوم پایان؛ پیش از تأیید، بازه با حرکت موس پیش‌نمایش می‌شود.
30
+ * تغییرها فقط با «تأیید» ثبت می‌شوند.
31
+ */
32
+ export function DateRangePicker({ label, hint, error, value, defaultValue = { start: null, end: null }, onChange, min, max, isDateDisabled, presets = defaultRangePresets, digits = "fa", name, disabled, id, className, calendarLabels, labels = {}, }) {
33
+ const autoId = useId();
34
+ const triggerId = id ?? autoId;
35
+ const popoverId = `${triggerId}-popover`;
36
+ const { placeholder = "انتخاب بازهٔ تاریخ", separator = " تا ", apply = "تأیید", cancel = "انصراف", presets: presetsLabel = "میان‌برها", pickEnd = "حالا تاریخ پایان را انتخاب کنید.", } = labels;
37
+ const [inner, setInner] = useState(defaultValue);
38
+ const current = value ?? inner;
39
+ const [draft, setDraft] = useState(current);
40
+ const [open, setOpen] = useState(false);
41
+ // با انتخاب میان‌بر، تقویم دوباره ساخته می‌شود تا به ماه آن بازه برود
42
+ const [nav, setNav] = useState(0);
43
+ const wrap = useRef(null);
44
+ const trigger = useRef(null);
45
+ const fmt = (d) => formatJalali(d, { digits });
46
+ const text = current.start && current.end ? `${fmt(current.start)}${separator}${fmt(current.end)}` : null;
47
+ const close = (focus = true) => {
48
+ setOpen(false);
49
+ if (focus)
50
+ trigger.current?.focus();
51
+ };
52
+ useEffect(() => {
53
+ if (!open)
54
+ return;
55
+ setDraft(current);
56
+ const onDown = (e) => {
57
+ if (!wrap.current?.contains(e.target))
58
+ setOpen(false);
59
+ };
60
+ document.addEventListener("pointerdown", onDown);
61
+ return () => document.removeEventListener("pointerdown", onDown);
62
+ }, [open]);
63
+ const pick = (d) => {
64
+ // کلیک اول یا کلیک پس از بازهٔ کامل: شروع تازه؛ کلیک دوم پایان (اگر قبل از شروع بود، جابه‌جا می‌شوند)
65
+ if (!draft.start || draft.end)
66
+ setDraft({ start: d, end: null });
67
+ else
68
+ setDraft(d < draft.start ? { start: d, end: draft.start } : { start: draft.start, end: d });
69
+ };
70
+ const commit = (r) => {
71
+ if (value === undefined)
72
+ setInner(r);
73
+ onChange?.(r);
74
+ close();
75
+ };
76
+ const today = day(new Date());
77
+ const activePreset = presets.findIndex((p) => {
78
+ const r = p.range(today);
79
+ return draft.start?.getTime() === r.start.getTime() && draft.end?.getTime() === r.end.getTime();
80
+ });
81
+ return (_jsx(Field, { id: triggerId, label: label, hint: hint, error: error, className: className, children: _jsxs("div", { className: "k-datepicker k-daterange", ref: wrap, children: [_jsx("div", { className: "k-select", children: _jsxs("button", { ref: trigger, id: triggerId, type: "button", className: "k-select__control k-daterange__trigger", "aria-haspopup": "dialog", "aria-expanded": open, "aria-controls": open ? popoverId : undefined, "aria-invalid": error ? true : undefined, disabled: disabled, "data-placeholder": text ? 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" })] }), _jsx("span", { children: text ?? placeholder })] }) }), name && (_jsxs(_Fragment, { children: [_jsx("input", { type: "hidden", name: `${name}_start`, value: current.start ? toISODate(current.start) : "" }), _jsx("input", { type: "hidden", name: `${name}_end`, value: current.end ? toISODate(current.end) : "" })] })), open && (_jsxs("div", { id: popoverId, role: "dialog", "aria-label": typeof label === "string" ? label : placeholder, className: "k-datepicker__popover k-daterange__popover", onKeyDown: (e) => {
82
+ if (e.key === "Escape") {
83
+ e.stopPropagation();
84
+ close();
85
+ }
86
+ }, onBlur: (e) => {
87
+ const next = e.relatedTarget;
88
+ if (next && !wrap.current?.contains(next))
89
+ setOpen(false);
90
+ }, children: [presets.length > 0 && (_jsx("ul", { className: "k-daterange__presets", role: "list", "aria-label": presetsLabel, children: presets.map((p, i) => (_jsx("li", { children: _jsx("button", { type: "button", className: "k-daterange__preset", "aria-pressed": i === activePreset, onClick: () => {
91
+ setDraft(p.range(today));
92
+ setNav((n) => n + 1);
93
+ }, children: p.label }) }, p.label))) })), _jsxs("div", { className: "k-daterange__main", children: [_jsx(Calendar, { range: draft, value: draft.end ?? draft.start, onChange: pick, min: min, max: max, isDateDisabled: isDateDisabled, digits: digits, labels: calendarLabels, autoFocus: true }, nav), _jsxs("div", { className: "k-daterange__footer", children: [_jsx("span", { className: "k-daterange__summary", "aria-live": "polite", children: draft.start && draft.end ? `${fmt(draft.start)}${separator}${fmt(draft.end)}` : draft.start ? pickEnd : "" }), _jsx("button", { type: "button", className: "k-btn k-btn--secondary k-btn--sm", onClick: () => close(), children: cancel }), _jsx("button", { type: "button", className: cx("k-btn k-btn--primary k-btn--sm"), disabled: !draft.start || !draft.end, onClick: () => commit(draft), children: apply })] })] })] }))] }) }));
94
+ }
package/dist/Dialog.d.ts CHANGED
@@ -9,7 +9,9 @@ export interface DialogProps {
9
9
  /** «danger» برای تأیید عملیات مخرب */
10
10
  tone?: "default" | "danger";
11
11
  /** @default "md" */
12
- size?: "sm" | "md" | "lg";
12
+ size?: "sm" | "md" | "lg" | "full";
13
+ /** «center» پنجرهٔ وسط، «start»/«end» کشوی کناری، «bottom» برگهٔ پایین (مناسب گوشی) @default "center" */
14
+ placement?: "center" | "start" | "end" | "bottom";
13
15
  /** دکمه‌های پایین پنجره */
14
16
  footer?: ReactNode;
15
17
  /** بستن با کلیک روی پس‌زمینه @default true */
@@ -24,4 +26,4 @@ export interface DialogProps {
24
26
  * فوکوس داخل پنجره می‌ماند، Esc می‌بندد، بقیهٔ صفحه از دسترس صفحه‌خوان خارج می‌شود
25
27
  * و پس از بستن، فوکوس به عنصری که پنجره را باز کرده برمی‌گردد.
26
28
  */
27
- export declare function Dialog({ open, onOpenChange, title, description, icon, tone, size, footer, dismissible, closeLabel, className, children, }: DialogProps): import("react").JSX.Element;
29
+ export declare function Dialog({ open, onOpenChange, title, description, icon, tone, size, footer, dismissible, closeLabel, placement, className, children, }: DialogProps): import("react").JSX.Element;
package/dist/Dialog.js CHANGED
@@ -7,7 +7,7 @@ import { CloseIcon } from "./icons.js";
7
7
  * فوکوس داخل پنجره می‌ماند، Esc می‌بندد، بقیهٔ صفحه از دسترس صفحه‌خوان خارج می‌شود
8
8
  * و پس از بستن، فوکوس به عنصری که پنجره را باز کرده برمی‌گردد.
9
9
  */
10
- export function Dialog({ open, onOpenChange, title, description, icon, tone = "default", size = "md", footer, dismissible = true, closeLabel = "بستن", className, children, }) {
10
+ export function Dialog({ open, onOpenChange, title, description, icon, tone = "default", size = "md", footer, dismissible = true, closeLabel = "بستن", placement = "center", className, children, }) {
11
11
  const ref = useRef(null);
12
12
  const opener = useRef(null);
13
13
  const id = useId();
@@ -23,7 +23,7 @@ export function Dialog({ open, onOpenChange, title, description, icon, tone = "d
23
23
  d.close();
24
24
  }
25
25
  }, [open]);
26
- return (_jsxs("dialog", { ref: ref, className: cx("k-dialog", size !== "md" && `k-dialog--${size}`, tone === "danger" && "k-dialog--danger", className), "aria-labelledby": `${id}-title`, "aria-describedby": description ? `${id}-desc` : undefined, onClose: () => {
26
+ return (_jsxs("dialog", { ref: ref, "data-placement": placement, className: cx("k-dialog", size !== "md" && `k-dialog--${size}`, placement !== "center" && `k-dialog--${placement}`, tone === "danger" && "k-dialog--danger", className), "aria-labelledby": `${id}-title`, "aria-describedby": description ? `${id}-desc` : undefined, onClose: () => {
27
27
  onOpenChange(false);
28
28
  opener.current?.focus?.();
29
29
  }, onCancel: (e) => {
@@ -24,9 +24,11 @@ export interface MenuItemProps {
24
24
  disabled?: boolean;
25
25
  /** لینک به‌جای عمل */
26
26
  href?: string;
27
+ /** گزینهٔ تیک‌دار (menuitemcheckbox)، مثل «نمایش ستون تاریخ»؛ منو پس از انتخاب باز می‌ماند */
28
+ checked?: boolean;
27
29
  children: ReactNode;
28
30
  }
29
- export declare function MenuItem({ onSelect, icon, shortcut, tone, disabled, href, children }: MenuItemProps): import("react").JSX.Element;
31
+ export declare function MenuItem({ onSelect, icon, shortcut, tone, disabled, href, checked, children }: MenuItemProps): import("react").JSX.Element;
30
32
  export declare const MenuSeparator: () => import("react").JSX.Element;
31
33
  export declare const MenuLabel: ({ children }: {
32
34
  children: ReactNode;
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { Children, cloneElement, createContext, isValidElement, useContext, useEffect, useId, useRef, useState, } from "react";
3
3
  import { cx } from "./cx.js";
4
4
  const MenuCtx = createContext(null);
5
- const items = (menu) => [...(menu?.querySelectorAll('[role="menuitem"]:not([aria-disabled="true"])') ?? [])];
5
+ const items = (menu) => [...(menu?.querySelectorAll('[role^="menuitem"]:not([aria-disabled="true"])') ?? [])];
6
6
  /**
7
7
  * منوی کشویی با الگوی Menu Button در WAI-ARIA:
8
8
  * Enter، Space یا ↓ باز می‌کند و اولین گزینه را فوکوس می‌کند، ↑ آخرین را؛
@@ -81,17 +81,19 @@ export function DropdownMenu({ trigger, label, align = "start", children }) {
81
81
  : trigger;
82
82
  return (_jsxs("span", { className: "k-menu-anchor", ref: anchorRef, children: [t, _jsx(MenuCtx.Provider, { value: { close }, children: _jsx("ul", { ref: menuRef, id: `${id}-menu`, role: "menu", "aria-label": label, "aria-labelledby": label ? undefined : `${id}-trigger`, className: cx("k-menu", align === "end" && "k-menu--end"), hidden: !open, onKeyDown: onMenuKey, children: Children.map(children, (c) => c) }) })] }));
83
83
  }
84
- export function MenuItem({ onSelect, icon, shortcut, tone = "default", disabled, href, children }) {
84
+ export function MenuItem({ onSelect, icon, shortcut, tone = "default", disabled, href, checked, children }) {
85
+ const checkable = checked !== undefined;
85
86
  const ctx = useContext(MenuCtx);
86
87
  const cls = cx("k-menu__item", tone === "danger" && "k-menu__item--danger");
87
- const content = (_jsxs(_Fragment, { children: [icon, _jsx("span", { children: children }), shortcut && _jsx("span", { className: "k-menu__shortcut", "aria-hidden": "true", children: shortcut })] }));
88
+ const content = (_jsxs(_Fragment, { children: [checkable && (_jsx("span", { className: "k-menu__check", "aria-hidden": "true", children: checked && _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "m5 10.5 3.2 3L15 7" }) }) })), icon, _jsx("span", { children: children }), shortcut && _jsx("span", { className: "k-menu__shortcut", "aria-hidden": "true", children: shortcut })] }));
88
89
  const select = () => {
89
90
  if (disabled)
90
91
  return;
91
92
  onSelect?.();
92
- ctx?.close();
93
+ if (!checkable)
94
+ ctx?.close();
93
95
  };
94
- return (_jsx("li", { role: "none", children: href && !disabled ? (_jsx("a", { role: "menuitem", tabIndex: -1, className: cls, href: href, onClick: () => ctx?.close(false), children: content })) : (_jsx("button", { type: "button", role: "menuitem", tabIndex: -1, className: cls, "aria-disabled": disabled || undefined, onClick: select, children: content })) }));
96
+ return (_jsx("li", { role: "none", children: href && !disabled ? (_jsx("a", { role: "menuitem", tabIndex: -1, className: cls, href: href, onClick: () => ctx?.close(false), children: content })) : (_jsx("button", { type: "button", role: checkable ? "menuitemcheckbox" : "menuitem", "aria-checked": checkable ? checked : undefined, tabIndex: -1, className: cls, "aria-disabled": disabled || undefined, onClick: select, children: content })) }));
95
97
  }
96
98
  export const MenuSeparator = () => _jsx("li", { role: "separator", className: "k-menu__separator" });
97
99
  export const MenuLabel = ({ children }) => _jsx("li", { role: "presentation", className: "k-menu__label", children: children });
package/dist/Field.d.ts CHANGED
@@ -1,11 +1,25 @@
1
1
  import { type ReactNode } from "react";
2
+ /** کلاس دلخواه برای هر بخش داخلی فیلد */
3
+ export interface FieldClassNames {
4
+ root?: string;
5
+ label?: string;
6
+ hint?: string;
7
+ error?: string;
8
+ }
2
9
  export interface FieldProps {
3
10
  id: string;
4
11
  label?: ReactNode;
5
12
  hint?: ReactNode;
6
13
  error?: ReactNode;
7
14
  required?: boolean;
15
+ /** نشان «اختیاری» کنار برچسب */
16
+ optional?: boolean | string;
17
+ /** محتوای انتهای ردیف برچسب، مثل شمارندهٔ نویسه یا لینک «فراموشی رمز» */
18
+ labelEnd?: ReactNode;
19
+ /** محتوای انتهای ردیف راهنما، مثل شمارنده */
20
+ hintEnd?: ReactNode;
8
21
  className?: string;
22
+ classNames?: FieldClassNames;
9
23
  children: ReactNode;
10
24
  }
11
25
  /** شناسهٔ متن‌های راهنما و خطا برای aria-describedby */
@@ -13,4 +27,4 @@ export declare const hintId: (id: string) => string;
13
27
  export declare const errorId: (id: string) => string;
14
28
  export declare function describedBy(id: string, hint: unknown, error: unknown, extra?: string): string | undefined;
15
29
  /** قالب مشترک برچسب + کنترل + راهنما/خطا */
16
- export declare function Field({ id, label, hint, error, required, className, children }: FieldProps): import("react").JSX.Element;
30
+ export declare function Field({ id, label, hint, error, required, optional, labelEnd, hintEnd, className, classNames, children }: FieldProps): import("react").JSX.Element;
package/dist/Field.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
2
3
  /** شناسهٔ متن‌های راهنما و خطا برای aria-describedby */
3
4
  export const hintId = (id) => `${id}-hint`;
4
5
  export const errorId = (id) => `${id}-error`;
@@ -6,6 +7,7 @@ export function describedBy(id, hint, error, extra) {
6
7
  return [extra, error ? errorId(id) : null, hint ? hintId(id) : null].filter(Boolean).join(" ") || undefined;
7
8
  }
8
9
  /** قالب مشترک برچسب + کنترل + راهنما/خطا */
9
- export function Field({ id, label, hint, error, required, className, children }) {
10
- return (_jsxs("div", { className: className ? `k-field ${className}` : "k-field", children: [label && (_jsxs("label", { className: "k-label", htmlFor: id, children: [label, required && _jsx("span", { className: "k-label__required", "aria-hidden": "true", children: "*" })] })), children, error && _jsx("p", { className: "k-hint k-hint--error", id: errorId(id), children: error }), hint && _jsx("p", { className: "k-hint", id: hintId(id), children: hint })] }));
10
+ export function Field({ id, label, hint, error, required, optional, labelEnd, hintEnd, className, classNames = {}, children }) {
11
+ const optionalText = optional === true ? "اختیاری" : optional;
12
+ 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] }))] }));
11
13
  }
@@ -0,0 +1,39 @@
1
+ import { type ReactNode } from "react";
2
+ export type FileStatus = "uploading" | "done" | "error";
3
+ export interface FileItem {
4
+ id: string;
5
+ file: File;
6
+ status: FileStatus;
7
+ progress: number;
8
+ error?: string;
9
+ }
10
+ /** حجم فایل به فارسی: ۱٫۲ مگابایت */
11
+ export declare function formatBytes(bytes: number): string;
12
+ export interface FileUploadProps {
13
+ /** مثل "image/*,.pdf" */
14
+ accept?: string;
15
+ multiple?: boolean;
16
+ /** بیشترین حجم هر فایل (بایت) */
17
+ maxSize?: number;
18
+ maxFiles?: number;
19
+ /** آپلود هر فایل؛ onProgress با عدد ۰ تا ۱۰۰. بدون آن فایل‌ها فقط انتخاب می‌شوند */
20
+ uploader?: (file: File, onProgress: (percent: number) => void) => Promise<void>;
21
+ onFilesChange?: (files: FileItem[]) => void;
22
+ /** متن راهنما، مثل «PNG یا PDF، حداکثر ۵ مگابایت» */
23
+ hint?: ReactNode;
24
+ disabled?: boolean;
25
+ name?: string;
26
+ className?: string;
27
+ labels?: {
28
+ browse?: string;
29
+ drop?: string;
30
+ remove?: (n: string) => string;
31
+ tooBig?: (max: string) => string;
32
+ wrongType?: string;
33
+ tooMany?: (n: number) => string;
34
+ done?: string;
35
+ uploading?: string;
36
+ };
37
+ }
38
+ /** بارگذاری فایل با کشیدن و رها کردن یا دکمهٔ انتخاب؛ هر فایل وضعیت و پیشرفت خودش را دارد */
39
+ export declare function FileUpload({ accept, multiple, maxSize, maxFiles, uploader, onFilesChange, hint, disabled, name, className, labels }: FileUploadProps): import("react").JSX.Element;
@@ -0,0 +1,90 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useRef, useState } from "react";
3
+ import { toFaDigits } from "@kashi-ui/persian";
4
+ import { cx } from "./cx.js";
5
+ import { Progress } from "./Progress.js";
6
+ /** حجم فایل به فارسی: ۱٫۲ مگابایت */
7
+ export function formatBytes(bytes) {
8
+ const units = ["بایت", "کیلوبایت", "مگابایت", "گیگابایت"];
9
+ let v = bytes;
10
+ let i = 0;
11
+ while (v >= 1024 && i < units.length - 1) {
12
+ v /= 1024;
13
+ i++;
14
+ }
15
+ const n = i === 0 ? String(v) : v.toFixed(v < 10 ? 1 : 0).replace(/\.0$/, "");
16
+ return `${toFaDigits(n).replace(".", "٫")} ${units[i]}`;
17
+ }
18
+ const ext = (name) => (name.split(".").pop() ?? "").slice(0, 4).toUpperCase();
19
+ function accepts(file, accept) {
20
+ if (!accept)
21
+ return true;
22
+ return accept.split(",").map((a) => a.trim().toLowerCase()).some((a) => a.startsWith(".") ? file.name.toLowerCase().endsWith(a) : a.endsWith("/*") ? file.type.startsWith(a.slice(0, -1)) : file.type === a);
23
+ }
24
+ const UploadIcon = () => (_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: "M10 13V3.5m-4 4 4-4 4 4M4 13v2.5A1.5 1.5 0 0 0 5.5 17h9a1.5 1.5 0 0 0 1.5-1.5V13" }) }));
25
+ const TrashIcon = () => (_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: "M3.5 5.5h13M8 5.5V4h4v1.5M5 5.5l.8 10.2a1.5 1.5 0 0 0 1.5 1.3h5.4a1.5 1.5 0 0 0 1.5-1.3L15 5.5" }) }));
26
+ /** بارگذاری فایل با کشیدن و رها کردن یا دکمهٔ انتخاب؛ هر فایل وضعیت و پیشرفت خودش را دارد */
27
+ export function FileUpload({ accept, multiple = true, maxSize, maxFiles, uploader, onFilesChange, hint, disabled, name, className, labels = {} }) {
28
+ const id = useId();
29
+ const inputRef = useRef(null);
30
+ const [items, setItems] = useState([]);
31
+ const [dragging, setDragging] = useState(false);
32
+ const [announce, setAnnounce] = useState("");
33
+ const { browse = "انتخاب فایل", drop = "یا فایل را اینجا رها کنید", remove = (n) => `حذف ${n}`, tooBig = (m) => `حجم فایل بیشتر از ${m} است.`, wrongType = "این نوع فایل پذیرفته نیست.", tooMany = (n) => `حداکثر ${toFaDigits(n)} فایل.`, done = "بارگذاری شد", uploading = "در حال بارگذاری", } = labels;
34
+ const update = (fn) => setItems((prev) => {
35
+ const next = fn(prev);
36
+ onFilesChange?.(next);
37
+ return next;
38
+ });
39
+ const add = (files) => {
40
+ const list = Array.from(files).slice(0, multiple ? undefined : 1);
41
+ const added = list.map((file, i) => {
42
+ const fid = `${Date.now()}-${i}-${file.name}`;
43
+ let err;
44
+ if (!accepts(file, accept))
45
+ err = wrongType;
46
+ else if (maxSize && file.size > maxSize)
47
+ err = tooBig(formatBytes(maxSize));
48
+ else if (maxFiles && items.length + i >= maxFiles)
49
+ err = tooMany(maxFiles);
50
+ return { id: fid, file, status: err ? "error" : uploader ? "uploading" : "done", progress: err ? 0 : uploader ? 0 : 100, error: err };
51
+ });
52
+ update((prev) => (multiple ? [...prev, ...added] : added));
53
+ setAnnounce(added.map((a) => `${a.file.name}: ${a.error ?? (uploader ? uploading : done)}`).join("، "));
54
+ for (const it of added) {
55
+ if (it.status !== "uploading" || !uploader)
56
+ continue;
57
+ uploader(it.file, (p) => update((l) => l.map((x) => (x.id === it.id ? { ...x, progress: p } : x))))
58
+ .then(() => {
59
+ update((l) => l.map((x) => (x.id === it.id ? { ...x, status: "done", progress: 100 } : x)));
60
+ setAnnounce(`${it.file.name}: ${done}`);
61
+ })
62
+ .catch((e) => {
63
+ const msg = e instanceof Error ? e.message : "خطا در بارگذاری";
64
+ update((l) => l.map((x) => (x.id === it.id ? { ...x, status: "error", error: msg } : x)));
65
+ setAnnounce(`${it.file.name}: ${msg}`);
66
+ });
67
+ }
68
+ };
69
+ const onDrop = (e) => {
70
+ e.preventDefault();
71
+ setDragging(false);
72
+ if (!disabled && e.dataTransfer.files.length)
73
+ add(e.dataTransfer.files);
74
+ };
75
+ return (_jsxs("div", { className: className, children: [_jsxs("div", { className: "k-dropzone", "data-dragging": dragging ? "" : undefined, "data-disabled": disabled ? "" : undefined, onDragOver: (e) => {
76
+ e.preventDefault();
77
+ if (!disabled)
78
+ setDragging(true);
79
+ }, onDragLeave: (e) => {
80
+ if (!e.currentTarget.contains(e.relatedTarget))
81
+ setDragging(false);
82
+ }, onDrop: onDrop, children: [_jsx("span", { className: "k-dropzone__icon", "aria-hidden": "true", children: _jsx(UploadIcon, {}) }), _jsxs("p", { className: "k-dropzone__title", style: { margin: 0 }, children: [_jsx("button", { type: "button", className: "k-dropzone__browse", disabled: disabled, "aria-describedby": hint ? `${id}-hint` : undefined, onClick: () => inputRef.current?.click(), children: browse }), " ", _jsx("span", { children: drop })] }), hint && _jsx("p", { className: "k-dropzone__hint", id: `${id}-hint`, style: { margin: 0 }, children: hint }), _jsx("input", { ref: inputRef, type: "file", accept: accept, multiple: multiple, name: name, tabIndex: -1, "aria-hidden": "true", onChange: (e) => {
83
+ if (e.target.files?.length)
84
+ add(e.target.files);
85
+ e.target.value = "";
86
+ } })] }), 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: () => {
87
+ update((l) => l.filter((x) => x.id !== it.id));
88
+ setAnnounce(`${it.file.name} حذف شد`);
89
+ }, 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 })] }));
90
+ }