@kashi-ui/react 0.8.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.
- package/README.md +2 -2
- package/dist/Calendar.d.ts +6 -1
- package/dist/Calendar.js +12 -5
- package/dist/Combobox.d.ts +48 -0
- package/dist/Combobox.js +143 -0
- package/dist/CommandPalette.d.ts +37 -0
- package/dist/CommandPalette.js +95 -0
- package/dist/DateRangePicker.d.ts +50 -0
- package/dist/DateRangePicker.js +94 -0
- package/dist/FileUpload.d.ts +39 -0
- package/dist/FileUpload.js +90 -0
- package/dist/NumberInput.d.ts +29 -0
- package/dist/NumberInput.js +56 -0
- package/dist/Popover.d.ts +19 -0
- package/dist/Popover.js +58 -0
- package/dist/SideNav.d.ts +28 -0
- package/dist/SideNav.js +22 -0
- package/dist/Slider.d.ts +32 -0
- package/dist/Slider.js +33 -0
- package/dist/Stat.d.ts +24 -0
- package/dist/Stat.js +17 -0
- package/dist/TagInput.d.ts +33 -0
- package/dist/TagInput.js +88 -0
- package/dist/Timeline.d.ts +19 -0
- package/dist/Timeline.js +8 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +11 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -20,8 +20,8 @@ export function SignUp() {
|
|
|
20
20
|
}
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
کامپوننتها: Button · Input · Textarea · Select · Checkbox · RadioGroup · Switch · Badge · Card · Alert · Avatar · AvatarGroup · Tabs · Dialog · Toast · Tooltip · DropdownMenu · DataTable · Pagination · Breadcrumb · Accordion · Stepper · Progress · Spinner · Skeleton · EmptyState · Divider · Kbd · RelativeTime
|
|
23
|
+
کامپوننتها: Button · Input · Textarea · Select · Checkbox · RadioGroup · Switch · Badge · Card · Alert · Avatar · AvatarGroup · Tabs · Dialog · Toast · Tooltip · DropdownMenu · DataTable · Pagination · Breadcrumb · Accordion · Stepper · Progress · Spinner · Skeleton · EmptyState · Divider · Kbd · RelativeTime · Combobox · CommandPalette · TagInput · FileUpload · Slider · NumberInput · Popover · StatCard · Timeline · SideNav
|
|
24
24
|
|
|
25
|
-
فارسی: DatePicker و Calendar شمسی · NationalIdInput · CardNumberInput · IbanInput · MobileInput · PriceInput · OtpInput
|
|
25
|
+
فارسی: DatePicker و Calendar شمسی · DateRangePicker · NationalIdInput · CardNumberInput · IbanInput · MobileInput · PriceInput · OtpInput
|
|
26
26
|
|
|
27
27
|
نیازمند React ۱۸ یا بالاتر. مستندات کامل: [kashi.sepantapouya.com](https://kashi.sepantapouya.com) · کد: [GitHub](https://github.com/Sepantapouya/Kashi) · لایسنس MIT
|
package/dist/Calendar.d.ts
CHANGED
|
@@ -30,8 +30,13 @@ export interface CalendarProps {
|
|
|
30
30
|
labels?: CalendarLabels;
|
|
31
31
|
/** محتوای پایین تقویم، مثل دکمهٔ «امروز» */
|
|
32
32
|
footer?: ReactNode;
|
|
33
|
+
/** حالت بازه: روزهای بین start و end برجسته میشوند؛ با start بدون end، hover پیشنمایش میدهد */
|
|
34
|
+
range?: {
|
|
35
|
+
start: Date | null;
|
|
36
|
+
end: Date | null;
|
|
37
|
+
};
|
|
33
38
|
className?: string;
|
|
34
39
|
"aria-label"?: string;
|
|
35
40
|
}
|
|
36
41
|
/** تقویم شمسی با الگوی grid استاندارد WAI-ARIA و پیمایش کامل با کیبورد */
|
|
37
|
-
export declare function Calendar({ value, defaultValue, onChange, min, max, isDateDisabled, digits, autoFocus, yearRange, labels, footer, className, "aria-label": ariaLabel, }: CalendarProps): import("react").JSX.Element;
|
|
42
|
+
export declare function Calendar({ value, defaultValue, onChange, min, max, isDateDisabled, digits, autoFocus, yearRange, labels, footer, range, className, "aria-label": ariaLabel, }: CalendarProps): import("react").JSX.Element;
|
package/dist/Calendar.js
CHANGED
|
@@ -22,12 +22,13 @@ function clamp(d, min, max) {
|
|
|
22
22
|
return d;
|
|
23
23
|
}
|
|
24
24
|
/** تقویم شمسی با الگوی grid استاندارد WAI-ARIA و پیمایش کامل با کیبورد */
|
|
25
|
-
export function Calendar({ value, defaultValue = null, onChange, min, max, isDateDisabled, digits = "fa", autoFocus = false, yearRange, labels = {}, footer, className, "aria-label": ariaLabel = "تقویم", }) {
|
|
25
|
+
export function Calendar({ value, defaultValue = null, onChange, min, max, isDateDisabled, digits = "fa", autoFocus = false, yearRange, labels = {}, footer, range, className, "aria-label": ariaLabel = "تقویم", }) {
|
|
26
26
|
const id = useId();
|
|
27
27
|
const [inner, setInner] = useState(defaultValue);
|
|
28
28
|
const selected = value !== undefined ? value : inner;
|
|
29
29
|
const [today] = useState(() => startOfDay(new Date()));
|
|
30
|
-
const [focused, setFocused] = useState(() => clamp(startOfDay(selected ?? today), min, max));
|
|
30
|
+
const [focused, setFocused] = useState(() => clamp(startOfDay(range?.start ?? selected ?? today), min, max));
|
|
31
|
+
const [hover, setHover] = useState(null);
|
|
31
32
|
const moveFocus = useRef(autoFocus);
|
|
32
33
|
const grid = useRef(null);
|
|
33
34
|
const n = (v) => (digits === "fa" ? toFaDigits(v) : String(v));
|
|
@@ -97,11 +98,17 @@ export function Calendar({ value, defaultValue = null, onChange, min, max, isDat
|
|
|
97
98
|
return (_jsxs("div", { className: cx("k-calendar", className), role: "group", "aria-label": ariaLabel, children: [_jsxs("div", { className: "k-calendar__header", children: [_jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": prevMonth, disabled: prevDisabled, onClick: () => go(addJalaliMonths(focused, -1), false), children: _jsx("svg", { "data-k-mirror": "", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m12 5-5 5 5 5" }) }) }), _jsxs("div", { className: "k-calendar__selects", children: [_jsx("select", { className: "k-calendar__select", "aria-label": monthLabel, value: jm, onChange: (e) => go(toGregorian(jy, Number(e.target.value), Math.min(toJalali(focused).jd, jalaliMonthLength(jy, Number(e.target.value)))), false), children: JALALI_MONTHS.map((name, i) => _jsx("option", { value: i + 1, children: name }, name)) }), _jsx("select", { className: "k-calendar__select", "aria-label": yearLabel, value: jy, onChange: (e) => go(toGregorian(Number(e.target.value), jm, Math.min(toJalali(focused).jd, jalaliMonthLength(Number(e.target.value), jm))), false), children: years.sort((a, b) => a - b).map((y) => _jsx("option", { value: y, children: n(y) }, y)) })] }), _jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": nextMonth, disabled: nextDisabled, onClick: () => go(addJalaliMonths(focused, 1), false), children: _jsx("svg", { "data-k-mirror": "", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m8 5 5 5-5 5" }) }) })] }), _jsx("h2", { className: "k-sr-only", id: `${id}-title`, "aria-live": "polite", children: `${JALALI_MONTHS[jm - 1]} ${n(jy)}` }), _jsxs("table", { className: "k-calendar__grid", role: "grid", "aria-labelledby": `${id}-title`, ref: grid, children: [_jsx("thead", { children: _jsx("tr", { children: WEEKDAYS_SHORT.map((s, i) => (_jsx("th", { scope: "col", abbr: WEEKDAYS[i], children: s }, s))) }) }), _jsx("tbody", { children: weeks.map((week, wi) => (_jsx("tr", { children: week.map((d, di) => {
|
|
98
99
|
if (!d)
|
|
99
100
|
return _jsx("td", { role: "gridcell" }, di);
|
|
100
|
-
const isSelected = sameDay(d, selected);
|
|
101
101
|
const isDisabled = disabled(d);
|
|
102
|
-
|
|
102
|
+
// حالت بازه
|
|
103
|
+
const rs = range?.start ? startOfDay(range.start) : null;
|
|
104
|
+
const re = range?.end ? startOfDay(range.end) : null;
|
|
105
|
+
const previewEnd = rs && !re && hover ? hover : null;
|
|
106
|
+
const [lo, hi] = rs && (re || previewEnd) ? [rs, (re ?? previewEnd)].sort((a, b) => +a - +b) : [null, null];
|
|
107
|
+
const inRange = !!lo && !!hi && d >= lo && d <= hi;
|
|
108
|
+
const isSelected = range ? inRange || sameDay(d, rs) : sameDay(d, selected);
|
|
109
|
+
return (_jsx("td", { role: "gridcell", "aria-selected": isSelected, "data-in-range": range && inRange && re ? "" : undefined, "data-preview": range && inRange && !re ? "" : undefined, "data-range-start": range && (lo ? sameDay(d, lo) : sameDay(d, rs)) ? "" : undefined, "data-range-end": range && (hi ? sameDay(d, hi) : sameDay(d, rs)) ? "" : undefined, children: _jsx("button", { type: "button", className: "k-calendar__day", "data-day": dayKey(d), tabIndex: sameDay(d, focused) ? 0 : -1, "aria-label": formatJalali(d, { style: "full", digits }), "aria-current": sameDay(d, today) ? "date" : undefined, "aria-disabled": isDisabled || undefined, onClick: () => {
|
|
103
110
|
setFocused(d);
|
|
104
111
|
select(d);
|
|
105
|
-
}, onKeyDown: onKeyDown, children: n(toJalali(d).jd) }) }, di));
|
|
112
|
+
}, onKeyDown: onKeyDown, onPointerEnter: range ? () => setHover(d) : undefined, onFocus: range ? () => setHover(d) : undefined, children: n(toJalali(d).jd) }) }, di));
|
|
106
113
|
}) }, wi))) })] }), footer && _jsx("div", { className: "k-calendar__footer", children: footer })] }));
|
|
107
114
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface ComboboxOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** نام گروه برای دستهبندی گزینهها */
|
|
9
|
+
group?: string;
|
|
10
|
+
/** کلمههای اضافه برای جستجو، مثل نام انگلیسی */
|
|
11
|
+
keywords?: string[];
|
|
12
|
+
}
|
|
13
|
+
/** متن یکدست برای جستجو: ي/ی، ك/ک، ارقام، حروف کوچک */
|
|
14
|
+
export declare const searchText: (s: string) => string;
|
|
15
|
+
export declare function defaultFilter(option: ComboboxOption, query: string): boolean;
|
|
16
|
+
/** بخش منطبق با جستجو را با <mark> برجسته میکند */
|
|
17
|
+
export declare function highlight(text: string, query: string): ReactNode;
|
|
18
|
+
export interface ComboboxProps {
|
|
19
|
+
label?: ReactNode;
|
|
20
|
+
hint?: ReactNode;
|
|
21
|
+
error?: ReactNode;
|
|
22
|
+
options: ComboboxOption[];
|
|
23
|
+
value?: string | null;
|
|
24
|
+
defaultValue?: string | null;
|
|
25
|
+
onChange?: (value: string | null) => void;
|
|
26
|
+
/** وقتی متن جستجو عوض میشود؛ برای جستجوی سمت سرور */
|
|
27
|
+
onInputChange?: (query: string) => void;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
/** جستجوی سفارشی؛ پیشفرض با یکدستسازی فارسی */
|
|
30
|
+
filter?: (option: ComboboxOption, query: string) => boolean;
|
|
31
|
+
/** @default "نتیجهای پیدا نشد." */
|
|
32
|
+
emptyMessage?: ReactNode;
|
|
33
|
+
/** نمایش اسپینر، مثلاً هنگام جستجوی سمت سرور */
|
|
34
|
+
loading?: boolean;
|
|
35
|
+
required?: boolean;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
name?: string;
|
|
38
|
+
id?: string;
|
|
39
|
+
className?: string;
|
|
40
|
+
/** @default (n) => «n نتیجه» */
|
|
41
|
+
resultsLabel?: (count: number) => string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* جستجو و انتخاب با الگوی Combobox در WAI-ARIA:
|
|
45
|
+
* تایپ فهرست را فیلتر میکند، ↑↓ حرکت، Enter انتخاب، Esc بستن (و در حالت بسته، پاک کردن).
|
|
46
|
+
* جستجو «علي» و «علی» را یکی میداند.
|
|
47
|
+
*/
|
|
48
|
+
export declare const Combobox: import("react").ForwardRefExoticComponent<ComboboxProps & import("react").RefAttributes<HTMLInputElement>>;
|
package/dist/Combobox.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { normalizePersian, toFaDigits } from "@kashi-ui/persian";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
import { Field, describedBy } from "./Field.js";
|
|
6
|
+
import { mergeRefs } from "./utils.js";
|
|
7
|
+
/** متن یکدست برای جستجو: ي/ی، ك/ک، ارقام، حروف کوچک */
|
|
8
|
+
export const searchText = (s) => normalizePersian(s, { digits: "latin" }).toLowerCase();
|
|
9
|
+
export function defaultFilter(option, query) {
|
|
10
|
+
const q = searchText(query.trim());
|
|
11
|
+
if (!q)
|
|
12
|
+
return true;
|
|
13
|
+
return [option.label, option.description ?? "", ...(option.keywords ?? [])].some((t) => searchText(t).includes(q));
|
|
14
|
+
}
|
|
15
|
+
/** بخش منطبق با جستجو را با <mark> برجسته میکند */
|
|
16
|
+
export function highlight(text, query) {
|
|
17
|
+
const q = searchText(query.trim());
|
|
18
|
+
if (!q)
|
|
19
|
+
return text;
|
|
20
|
+
const i = searchText(text).indexOf(q);
|
|
21
|
+
if (i < 0)
|
|
22
|
+
return text;
|
|
23
|
+
return (_jsxs(_Fragment, { children: [text.slice(0, i), _jsx("mark", { children: text.slice(i, i + q.length) }), text.slice(i + q.length)] }));
|
|
24
|
+
}
|
|
25
|
+
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" }) }));
|
|
26
|
+
/**
|
|
27
|
+
* جستجو و انتخاب با الگوی Combobox در WAI-ARIA:
|
|
28
|
+
* تایپ فهرست را فیلتر میکند، ↑↓ حرکت، Enter انتخاب، Esc بستن (و در حالت بسته، پاک کردن).
|
|
29
|
+
* جستجو «علي» و «علی» را یکی میداند.
|
|
30
|
+
*/
|
|
31
|
+
export const Combobox = forwardRef(function Combobox({ label, hint, error, options, value, defaultValue = null, onChange, onInputChange, placeholder, filter = defaultFilter, emptyMessage = "نتیجهای پیدا نشد.", loading, required, disabled, name, id, className, resultsLabel = (n) => `${toFaDigits(n)} نتیجه`, }, ref) {
|
|
32
|
+
const autoId = useId();
|
|
33
|
+
const inputId = id ?? autoId;
|
|
34
|
+
const listId = `${inputId}-list`;
|
|
35
|
+
const [inner, setInner] = useState(defaultValue);
|
|
36
|
+
const selected = value !== undefined ? value : inner;
|
|
37
|
+
const selectedOption = options.find((o) => o.value === selected) ?? null;
|
|
38
|
+
const [query, setQuery] = useState(selectedOption?.label ?? "");
|
|
39
|
+
const [open, setOpen] = useState(false);
|
|
40
|
+
const [typing, setTyping] = useState(false);
|
|
41
|
+
const [active, setActive] = useState(-1);
|
|
42
|
+
const inputRef = useRef(null);
|
|
43
|
+
const wrapRef = useRef(null);
|
|
44
|
+
// وقتی مقدار از بیرون عوض شد، متن فیلد هم هماهنگ شود
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!typing)
|
|
47
|
+
setQuery(selectedOption?.label ?? "");
|
|
48
|
+
}, [selectedOption?.label]);
|
|
49
|
+
const filtered = useMemo(() => (typing ? options.filter((o) => filter(o, query)) : options), [options, query, typing, filter]);
|
|
50
|
+
const enabled = filtered.map((o, i) => (o.disabled ? -1 : i)).filter((i) => i >= 0);
|
|
51
|
+
const commit = (o) => {
|
|
52
|
+
if (value === undefined)
|
|
53
|
+
setInner(o?.value ?? null);
|
|
54
|
+
onChange?.(o?.value ?? null);
|
|
55
|
+
setQuery(o?.label ?? "");
|
|
56
|
+
setTyping(false);
|
|
57
|
+
setOpen(false);
|
|
58
|
+
setActive(-1);
|
|
59
|
+
};
|
|
60
|
+
const openList = (at = "selected") => {
|
|
61
|
+
if (disabled)
|
|
62
|
+
return;
|
|
63
|
+
setOpen(true);
|
|
64
|
+
const sel = filtered.findIndex((o) => o.value === selected);
|
|
65
|
+
setActive(at === "last" ? enabled[enabled.length - 1] ?? -1 : at === "first" || sel < 0 ? enabled[0] ?? -1 : sel);
|
|
66
|
+
};
|
|
67
|
+
const move = (delta) => {
|
|
68
|
+
if (!enabled.length)
|
|
69
|
+
return;
|
|
70
|
+
const pos = enabled.indexOf(active);
|
|
71
|
+
setActive(enabled[(pos + delta + enabled.length) % enabled.length]);
|
|
72
|
+
};
|
|
73
|
+
// گزینهٔ فعال همیشه دیده شود
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (active < 0)
|
|
76
|
+
return;
|
|
77
|
+
document.getElementById(`${listId}-${active}`)?.scrollIntoView({ block: "nearest" });
|
|
78
|
+
}, [active, listId]);
|
|
79
|
+
const onKeyDown = (e) => {
|
|
80
|
+
if (e.key === "ArrowDown") {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
open ? move(1) : openList(e.altKey ? "selected" : "first");
|
|
83
|
+
}
|
|
84
|
+
else if (e.key === "ArrowUp") {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
open ? move(-1) : openList("last");
|
|
87
|
+
}
|
|
88
|
+
else if (e.key === "Enter" && open && active >= 0) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
commit(filtered[active]);
|
|
91
|
+
}
|
|
92
|
+
else if (e.key === "Escape") {
|
|
93
|
+
if (open) {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
setOpen(false);
|
|
96
|
+
setTyping(false);
|
|
97
|
+
setQuery(selectedOption?.label ?? "");
|
|
98
|
+
}
|
|
99
|
+
else if (query) {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
commit(null);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (e.key === "Home" || e.key === "End") {
|
|
105
|
+
if (!open)
|
|
106
|
+
return;
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
setActive(e.key === "Home" ? enabled[0] : enabled[enabled.length - 1]);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
let lastGroup;
|
|
112
|
+
return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, required: required, className: className, children: _jsxs("div", { ref: wrapRef, className: "k-combobox", "data-open": open ? "" : undefined, onBlur: (e) => {
|
|
113
|
+
if (wrapRef.current?.contains(e.relatedTarget))
|
|
114
|
+
return;
|
|
115
|
+
setOpen(false);
|
|
116
|
+
// متن نیمهکاره به گزینهٔ انتخابشده برمیگردد
|
|
117
|
+
if (typing) {
|
|
118
|
+
setTyping(false);
|
|
119
|
+
setQuery(selectedOption?.label ?? "");
|
|
120
|
+
}
|
|
121
|
+
}, children: [_jsxs("div", { className: cx("k-input"), "data-state": error ? "invalid" : undefined, children: [_jsx("input", { ref: mergeRefs(ref, inputRef), id: inputId, className: "k-input__control", type: "text", role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? `${listId}-${active}` : undefined, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error), autoComplete: "off", placeholder: placeholder, value: query, required: required, disabled: disabled, onChange: (e) => {
|
|
122
|
+
setQuery(e.target.value);
|
|
123
|
+
setTyping(true);
|
|
124
|
+
setOpen(true);
|
|
125
|
+
setActive(-1);
|
|
126
|
+
onInputChange?.(e.target.value);
|
|
127
|
+
}, onKeyDown: onKeyDown, onClick: () => !open && openList() }), loading && _jsx("span", { className: "k-input__addon", children: _jsx("span", { className: "k-spinner k-spinner--sm", "aria-hidden": "true" }) }), _jsx("button", { type: "button", tabIndex: -1, className: "k-input__action k-combobox__toggle", "aria-label": "\u0646\u0645\u0627\u06CC\u0634 \u06AF\u0632\u06CC\u0646\u0647\u200C\u0647\u0627", disabled: disabled, onClick: () => {
|
|
128
|
+
if (open)
|
|
129
|
+
setOpen(false);
|
|
130
|
+
else {
|
|
131
|
+
setTyping(false);
|
|
132
|
+
openList();
|
|
133
|
+
inputRef.current?.focus();
|
|
134
|
+
}
|
|
135
|
+
}, children: _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 8 4 4 4-4" }) }) })] }), _jsxs("ul", { id: listId, role: "listbox", "aria-labelledby": label ? undefined : inputId, "aria-label": typeof label === "string" ? label : undefined, className: "k-listbox", hidden: !open, style: { insetBlockStart: "calc(100% + 6px)" }, children: [filtered.length === 0 && _jsx("li", { className: "k-listbox__empty", role: "presentation", children: loading ? "در حال جستجو…" : emptyMessage }), filtered.map((o, i) => {
|
|
136
|
+
const header = o.group && o.group !== lastGroup ? o.group : null;
|
|
137
|
+
lastGroup = o.group;
|
|
138
|
+
return [
|
|
139
|
+
header && _jsx("li", { role: "presentation", className: "k-listbox__group", children: header }, `g-${header}`),
|
|
140
|
+
_jsxs("li", { id: `${listId}-${i}`, role: "option", "aria-selected": o.value === selected, "aria-disabled": o.disabled || undefined, "data-active": i === active ? "" : undefined, className: "k-option", onPointerDown: (e) => e.preventDefault() /* فوکوس در فیلد بماند */, onClick: () => !o.disabled && commit(o), onPointerMove: () => !o.disabled && active !== i && setActive(i), children: [o.icon, _jsxs("span", { className: "k-option__body", children: [_jsx("span", { children: highlight(o.label, typing ? query : "") }), o.description && _jsx("span", { className: "k-option__desc", children: o.description })] }), o.value === selected && _jsx("span", { className: "k-option__check", children: _jsx(Check, {}) })] }, o.value),
|
|
141
|
+
];
|
|
142
|
+
})] }), _jsx("span", { className: "k-sr-only", "aria-live": "polite", children: open && typing ? resultsLabel(filtered.length) : "" }), name && _jsx("input", { type: "hidden", name: name, value: selected ?? "" })] }) }));
|
|
143
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface CommandItem {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
group?: string;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
/** میانبر نمایشی، مثل "Ctrl+N" */
|
|
8
|
+
shortcut?: string;
|
|
9
|
+
/** کلمههای اضافه برای جستجو */
|
|
10
|
+
keywords?: string[];
|
|
11
|
+
description?: string;
|
|
12
|
+
onSelect?: () => void;
|
|
13
|
+
/** بهجای onSelect، رفتن به یک آدرس */
|
|
14
|
+
href?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface CommandPaletteProps {
|
|
17
|
+
open: boolean;
|
|
18
|
+
onOpenChange: (open: boolean) => void;
|
|
19
|
+
items: CommandItem[];
|
|
20
|
+
/** باز کردن با Ctrl+K یا ⌘K @default true */
|
|
21
|
+
shortcut?: boolean;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
emptyMessage?: ReactNode;
|
|
24
|
+
labels?: {
|
|
25
|
+
title?: string;
|
|
26
|
+
navigate?: string;
|
|
27
|
+
select?: string;
|
|
28
|
+
close?: string;
|
|
29
|
+
results?: (n: number) => string;
|
|
30
|
+
};
|
|
31
|
+
className?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* پالت فرمان: جستجوی سریع در عملها و صفحهها با Ctrl+K.
|
|
35
|
+
* پنجره روی <dialog> بومی است (تلهٔ فوکوس و Esc) و فهرست با الگوی combobox/listbox پیمایش میشود.
|
|
36
|
+
*/
|
|
37
|
+
export declare function CommandPalette({ open, onOpenChange, items, shortcut, placeholder, emptyMessage, labels, className, }: CommandPaletteProps): import("react").JSX.Element;
|
|
@@ -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
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -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;
|