@kashi-ui/react 0.26.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ActivityHeatmap.js +12 -8
- package/dist/AddressForm.js +8 -4
- package/dist/Alert.js +4 -1
- package/dist/AppointmentPicker.js +16 -11
- package/dist/Avatar.js +8 -11
- package/dist/Badge.js +3 -1
- package/dist/BankBadge.js +4 -1
- package/dist/BankCard.js +7 -4
- package/dist/Banner.js +5 -1
- package/dist/Breadcrumb.js +5 -1
- package/dist/Button.js +4 -1
- package/dist/Calendar.js +10 -6
- package/dist/CardNumberInput.js +5 -1
- package/dist/Carousel.js +5 -4
- package/dist/Chart.js +57 -30
- package/dist/CitySelect.js +7 -4
- package/dist/ColorPicker.d.ts +1 -1
- package/dist/ColorPicker.js +22 -17
- package/dist/Combobox.js +8 -4
- package/dist/CommandPalette.js +6 -3
- package/dist/ContextMenu.js +5 -2
- package/dist/CopyButton.js +3 -1
- package/dist/Countdown.js +6 -3
- package/dist/DataTable.js +4 -2
- package/dist/DatePicker.js +8 -2
- package/dist/DateRangePicker.d.ts +1 -1
- package/dist/DateRangePicker.js +16 -10
- package/dist/DateTile.js +7 -4
- package/dist/Dialog.js +4 -1
- package/dist/Field.js +3 -1
- package/dist/FileUpload.d.ts +3 -2
- package/dist/FileUpload.js +15 -11
- package/dist/IbanInput.js +4 -1
- package/dist/InlineEdit.js +5 -3
- package/dist/Input.js +3 -1
- package/dist/IranMap.js +5 -3
- package/dist/KashiProvider.d.ts +28 -0
- package/dist/KashiProvider.js +27 -0
- package/dist/KeyboardFixInput.js +3 -1
- package/dist/LandlineInput.js +5 -1
- package/dist/LegalIdInput.js +5 -1
- package/dist/Meter.js +7 -4
- package/dist/MobileInput.js +7 -3
- package/dist/Money.js +10 -6
- package/dist/MonthPicker.js +8 -4
- package/dist/MultiSelect.js +7 -5
- package/dist/NationalIdInput.js +5 -1
- package/dist/NumberInput.js +5 -2
- package/dist/OtpInput.js +4 -1
- package/dist/Pagination.js +6 -3
- package/dist/PasswordStrength.d.ts +1 -0
- package/dist/PasswordStrength.js +15 -9
- package/dist/PaymentReceipt.js +10 -8
- package/dist/PersianInput.js +3 -1
- package/dist/PersianTextarea.js +9 -7
- package/dist/PlateInput.js +6 -3
- package/dist/PostalCodeInput.js +5 -1
- package/dist/PriceInput.js +9 -3
- package/dist/Progress.js +6 -3
- package/dist/ProvinceSelect.js +5 -3
- package/dist/Rating.js +6 -3
- package/dist/RelativeTime.js +5 -2
- package/dist/SideNav.js +4 -1
- package/dist/Slider.js +5 -2
- package/dist/Splitter.js +5 -3
- package/dist/Stat.js +4 -3
- package/dist/Stepper.js +6 -4
- package/dist/TagInput.js +4 -2
- package/dist/TimeInput.js +6 -1
- package/dist/Timeline.js +1 -1
- package/dist/Toast.js +5 -1
- package/dist/Tour.js +3 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +11 -0
- package/package.json +4 -4
package/dist/MultiSelect.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useId, useMemo, useRef, useState } from "react";
|
|
4
|
-
import { toFaDigits } from "@kashi-ui/persian";
|
|
5
4
|
import { Badge } from "./Badge.js";
|
|
6
5
|
import { defaultFilter, highlight } from "./Combobox.js";
|
|
7
6
|
import { Field, describedBy } from "./Field.js";
|
|
7
|
+
import { useKashi } from "./KashiProvider.js";
|
|
8
8
|
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" }) });
|
|
9
9
|
/**
|
|
10
10
|
* انتخاب چند گزینه با جستجو؛ انتخابها بهشکل برچسب داخل فیلد.
|
|
11
11
|
* ↑↓ حرکت، Enter انتخاب یا لغو انتخاب، Backspace در فیلد خالی آخرین برچسب را حذف میکند، Esc بستن.
|
|
12
12
|
*/
|
|
13
|
-
export function MultiSelect({ label, hint, error, options, value, defaultValue = [], onChange, placeholder, max, filter = defaultFilter, emptyMessage
|
|
14
|
-
const {
|
|
13
|
+
export function MultiSelect({ label, hint, error, options, value, defaultValue = [], onChange, placeholder, max, filter = defaultFilter, emptyMessage, disabled, name, id, className, labels = {}, }) {
|
|
14
|
+
const { messages: M, n: N } = useKashi();
|
|
15
|
+
emptyMessage ?? (emptyMessage = M.common.noResults);
|
|
16
|
+
const { remove = M.common.remove, selected: selectedLabel = (x) => M.multiSelect.selected(N(x)), max: maxLabel = (x) => M.common.max(N(x)), clear = M.common.clearAll, } = labels;
|
|
15
17
|
const autoId = useId();
|
|
16
18
|
const inputId = id ?? autoId;
|
|
17
19
|
const listId = `${inputId}-list`;
|
|
@@ -37,7 +39,7 @@ export function MultiSelect({ label, hint, error, options, value, defaultValue =
|
|
|
37
39
|
if (!on && full)
|
|
38
40
|
return setAnnounce(maxLabel(max));
|
|
39
41
|
set(on ? chosen.filter((v) => v !== o.value) : [...chosen, o.value]);
|
|
40
|
-
setAnnounce(
|
|
42
|
+
setAnnounce(on ? M.common.removed(o.label) : M.common.selected(o.label));
|
|
41
43
|
setQuery("");
|
|
42
44
|
};
|
|
43
45
|
const move = (d) => {
|
|
@@ -68,7 +70,7 @@ export function MultiSelect({ label, hint, error, options, value, defaultValue =
|
|
|
68
70
|
const last = options.find((o) => o.value === chosen[chosen.length - 1]);
|
|
69
71
|
set(chosen.slice(0, -1));
|
|
70
72
|
if (last)
|
|
71
|
-
setAnnounce(
|
|
73
|
+
setAnnounce(M.common.removed(last.label));
|
|
72
74
|
}
|
|
73
75
|
};
|
|
74
76
|
const labelOf = (v) => options.find((o) => o.value === v)?.label ?? v;
|
package/dist/NationalIdInput.js
CHANGED
|
@@ -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 { isValidNationalId, onlyDigits, toFaDigits } from "@kashi-ui/persian";
|
|
5
5
|
import { Input } from "./Input.js";
|
|
6
|
+
import { useKashi } from "./KashiProvider.js";
|
|
6
7
|
/** فیلد کد ملی: ارقام فارسی و لاتین را میپذیرد، ۱۰ رقم را محدود و رقم کنترل را بررسی میکند. */
|
|
7
|
-
export const NationalIdInput = forwardRef(function NationalIdInput({ value, defaultValue = "", onValueChange, digits
|
|
8
|
+
export const NationalIdInput = forwardRef(function NationalIdInput({ 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.nationalId);
|
|
8
12
|
const [inner, setInner] = useState(() => onlyDigits(defaultValue).slice(0, 10));
|
|
9
13
|
const [touched, setTouched] = useState(false);
|
|
10
14
|
const raw = value !== undefined ? onlyDigits(value).slice(0, 10) : inner;
|
package/dist/NumberInput.js
CHANGED
|
@@ -4,16 +4,19 @@ import { forwardRef, useId, useState } from "react";
|
|
|
4
4
|
import { formatNumber, onlyDigits, toFaDigits } from "@kashi-ui/persian";
|
|
5
5
|
import { cx } from "./cx.js";
|
|
6
6
|
import { Field, describedBy } from "./Field.js";
|
|
7
|
+
import { useKashi } from "./KashiProvider.js";
|
|
7
8
|
const Minus = () => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M5 10h10" }) });
|
|
8
9
|
const Plus = () => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "M10 5v10M5 10h10" }) });
|
|
9
10
|
/** ورودی عدد با دکمههای + و −؛ ↑↓ یک گام، PageUp/PageDown ده گام، Home/End کمینه و بیشینه */
|
|
10
|
-
export const NumberInput = forwardRef(function NumberInput({ label, hint, error, value, defaultValue = null, onChange, min, max, step = 1, thousands, digits
|
|
11
|
+
export const NumberInput = forwardRef(function NumberInput({ label, hint, error, value, defaultValue = null, onChange, min, max, step = 1, thousands, digits, unit, disabled, name, id, className, labels = {} }, ref) {
|
|
12
|
+
const { messages: M, digits: D } = useKashi();
|
|
13
|
+
digits ?? (digits = D);
|
|
11
14
|
const autoId = useId();
|
|
12
15
|
const inputId = id ?? autoId;
|
|
13
16
|
const [inner, setInner] = useState(defaultValue);
|
|
14
17
|
const current = value !== undefined ? value : inner;
|
|
15
18
|
const [draft, setDraft] = useState(null);
|
|
16
|
-
const { increment =
|
|
19
|
+
const { increment = M.numberInput.increment, decrement = M.numberInput.decrement } = labels;
|
|
17
20
|
const clamp = (n) => Math.min(max ?? Infinity, Math.max(min ?? -Infinity, n));
|
|
18
21
|
const show = (n) => {
|
|
19
22
|
if (n === null)
|
package/dist/OtpInput.js
CHANGED
|
@@ -5,11 +5,14 @@ import { onlyDigits, toFaDigits } from "@kashi-ui/persian";
|
|
|
5
5
|
import { cx } from "./cx.js";
|
|
6
6
|
import { Field, describedBy } from "./Field.js";
|
|
7
7
|
import { mergeRefs } from "./utils.js";
|
|
8
|
+
import { useKashi } from "./KashiProvider.js";
|
|
8
9
|
/**
|
|
9
10
|
* کد تأیید یکبارمصرف: یک input واقعی (نه شش input جدا)، پس چسباندن، پاک کردن،
|
|
10
11
|
* صفحهخوان و پر شدن خودکار کد پیامکی (autocomplete="one-time-code") بینقص کار میکنند.
|
|
11
12
|
*/
|
|
12
|
-
export const OtpInput = forwardRef(function OtpInput({ label, hint, error, length = 6, value, defaultValue = "", onChange, onComplete, digits
|
|
13
|
+
export const OtpInput = forwardRef(function OtpInput({ label, hint, error, length = 6, value, defaultValue = "", onChange, onComplete, digits, groupAfter, size = "md", disabled, autoFocus, name, id, className }, ref) {
|
|
14
|
+
const { digits: D } = useKashi();
|
|
15
|
+
digits ?? (digits = D);
|
|
13
16
|
const autoId = useId();
|
|
14
17
|
const inputId = id ?? autoId;
|
|
15
18
|
const [inner, setInner] = useState(() => onlyDigits(defaultValue).slice(0, length));
|
package/dist/Pagination.js
CHANGED
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { toFaDigits } from "@kashi-ui/persian";
|
|
5
5
|
import { cx } from "./cx.js";
|
|
6
|
+
import { useKashi } from "./KashiProvider.js";
|
|
6
7
|
/** صفحههایی که نمایش داده میشوند؛ null یعنی «…» */
|
|
7
8
|
export function pageRange(page, total, siblings = 1) {
|
|
8
9
|
const out = [];
|
|
@@ -21,9 +22,11 @@ export function pageRange(page, total, siblings = 1) {
|
|
|
21
22
|
}
|
|
22
23
|
const Chevron = ({ dir }) => (_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: dir === "prev" ? "m12 5-5 5 5 5" : "m8 5 5 5-5 5" }) }));
|
|
23
24
|
/** صفحهبندی با ارقام فارسی؛ صفحهٔ فعلی با aria-current="page" */
|
|
24
|
-
export function Pagination({ page, total, onChange, getHref, siblings = 1, summary, digits
|
|
25
|
+
export function Pagination({ page, total, onChange, getHref, siblings = 1, summary, digits, pageSize, pageSizes = [10, 20, 50, 100], onPageSizeChange, jumper, labels = {}, className, }) {
|
|
26
|
+
const { messages: M, digits: D } = useKashi();
|
|
27
|
+
digits ?? (digits = D);
|
|
25
28
|
const n = (v) => (digits === "fa" ? toFaDigits(v) : String(v));
|
|
26
|
-
const { nav =
|
|
29
|
+
const { nav = M.pagination.nav, prev = M.common.prev, next = M.common.next, page: pageLabel = (x) => M.pagination.page(x), perPage = M.pagination.perPage, jump = M.pagination.jump } = labels;
|
|
27
30
|
const [jumpText, setJumpText] = useState("");
|
|
28
31
|
// تابع معمولی، نه کامپوننت: تا دکمهها با هر رندر دوباره ساخته نشوند و فوکوس کیبورد حفظ شود
|
|
29
32
|
const item = ({ to, children, current, disabled, aria, className: c }) => getHref && !disabled ? (_jsx("a", { className: c, href: getHref(to), "aria-current": current ? "page" : undefined, "aria-label": aria, children: children })) : (_jsx("button", { type: "button", className: c, disabled: disabled, "aria-current": current ? "page" : undefined, "aria-label": aria, onClick: () => onChange?.(to), children: children }));
|
|
@@ -33,5 +36,5 @@ export function Pagination({ page, total, onChange, getHref, siblings = 1, summa
|
|
|
33
36
|
if (to >= 1 && to <= total)
|
|
34
37
|
onChange(to);
|
|
35
38
|
setJumpText("");
|
|
36
|
-
}, children: _jsxs("label", { className: "k-pagination__tool", children: [_jsx("span", { children: jump }), _jsx("span", { className: "k-input k-input--sm k-pagination__jump", children: _jsx("input", { className: "k-input__control", inputMode: "numeric", dir: "ltr", value: jumpText, placeholder: n(page), "aria-label":
|
|
39
|
+
}, children: _jsxs("label", { className: "k-pagination__tool", children: [_jsx("span", { children: jump }), _jsx("span", { className: "k-input k-input--sm k-pagination__jump", children: _jsx("input", { className: "k-input__control", inputMode: "numeric", dir: "ltr", value: jumpText, placeholder: n(page), "aria-label": M.pagination.jumpRange(jump, n(1), n(total)), onChange: (e) => setJumpText(e.target.value) }) })] }) }))] }))] }));
|
|
37
40
|
}
|
|
@@ -2,6 +2,7 @@ export interface PasswordRule {
|
|
|
2
2
|
label: string;
|
|
3
3
|
test: (password: string) => boolean;
|
|
4
4
|
}
|
|
5
|
+
/** شرطهای پیشفرض به فارسی؛ بدون rules، کامپوننت همینها را به زبان KashiProvider نشان میدهد */
|
|
5
6
|
export declare const defaultPasswordRules: PasswordRule[];
|
|
6
7
|
export interface PasswordStrengthProps {
|
|
7
8
|
password: string;
|
package/dist/PasswordStrength.js
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { toFaDigits } from "@kashi-ui/persian";
|
|
3
|
+
import { faMessages, toFaDigits } from "@kashi-ui/persian";
|
|
4
4
|
import { cx } from "./cx.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
{ label:
|
|
9
|
-
{ label:
|
|
5
|
+
import { useKashi } from "./KashiProvider.js";
|
|
6
|
+
/** شرطهای پیشفرض با متنهای زبان فعلی */
|
|
7
|
+
const rulesFor = (m, n) => [
|
|
8
|
+
{ label: m.length(n(8)), test: (p) => p.length >= 8 },
|
|
9
|
+
{ label: m.cases, test: (p) => /[a-z]/.test(p) && /[A-Z]/.test(p) },
|
|
10
|
+
{ label: m.digit, test: (p) => /\d/.test(p) },
|
|
11
|
+
{ label: m.symbol, test: (p) => /[^A-Za-z0-9\s-ۿ]/.test(p) },
|
|
10
12
|
];
|
|
13
|
+
/** شرطهای پیشفرض به فارسی؛ بدون rules، کامپوننت همینها را به زبان KashiProvider نشان میدهد */
|
|
14
|
+
export const defaultPasswordRules = rulesFor(faMessages.password, (v) => toFaDigits(v));
|
|
11
15
|
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" }) });
|
|
12
16
|
const Dot = () => _jsx("svg", { viewBox: "0 0 20 20", "aria-hidden": "true", children: _jsx("circle", { cx: "10", cy: "10", r: "2.5", fill: "currentColor" }) });
|
|
13
17
|
/** قدرت رمز عبور با نوار چهارقسمتی و فهرست شرطها؛ زیر فیلد رمز بگذارید و با id به آن وصل کنید */
|
|
14
|
-
export function PasswordStrength({ password, rules
|
|
15
|
-
const {
|
|
18
|
+
export function PasswordStrength({ password, rules, showRules = true, warnPersian = true, id, className, labels = {} }) {
|
|
19
|
+
const { messages: M, n: N } = useKashi();
|
|
20
|
+
rules ?? (rules = rulesFor(M.password, N));
|
|
21
|
+
const { title = M.password.title, levels = M.password.levels, persian = M.password.persian } = labels;
|
|
16
22
|
const met = rules.map((r) => r.test(password));
|
|
17
23
|
const n = met.filter(Boolean).length;
|
|
18
24
|
// امتیاز ۰ تا ۴ به نسبت شرطهای برآوردهشده
|
|
19
25
|
const score = password ? Math.max(1, Math.round((n / rules.length) * 4)) : 0;
|
|
20
26
|
const persianTyped = warnPersian && /[-ۿ]/.test(password);
|
|
21
|
-
return (_jsxs("div", { id: id, className: cx("k-strength", className), "data-score": score, children: [_jsx("div", { className: "k-strength__bars", "aria-hidden": "true", children: [0, 1, 2, 3].map((i) => _jsx("span", { className: "k-strength__bar" }, i)) }), _jsx("p", { className: "k-strength__label", "aria-live": "polite", style: { margin: 0 }, children: score > 0 && _jsxs(_Fragment, { children: [title, ": ", _jsx("strong", { children: levels[score - 1] })] }) }), persianTyped && _jsx("p", { className: "k-hint k-hint--error", role: "alert", children: persian }), showRules && (_jsx("ul", { className: "k-strength__rules", children: rules.map((r, i) => (_jsxs("li", { className: "k-strength__rule", "data-met": met[i] ? "" : undefined, children: [met[i] ? _jsx(Check, {}) : _jsx(Dot, {}), _jsxs("span", { children: [r.label, _jsx("span", { className: "k-sr-only", children: met[i] ?
|
|
27
|
+
return (_jsxs("div", { id: id, className: cx("k-strength", className), "data-score": score, children: [_jsx("div", { className: "k-strength__bars", "aria-hidden": "true", children: [0, 1, 2, 3].map((i) => _jsx("span", { className: "k-strength__bar" }, i)) }), _jsx("p", { className: "k-strength__label", "aria-live": "polite", style: { margin: 0 }, children: score > 0 && _jsxs(_Fragment, { children: [title, ": ", _jsx("strong", { children: levels[score - 1] })] }) }), persianTyped && _jsx("p", { className: "k-hint k-hint--error", role: "alert", children: persian }), showRules && (_jsx("ul", { className: "k-strength__rules", children: rules.map((r, i) => (_jsxs("li", { className: "k-strength__rule", "data-met": met[i] ? "" : undefined, children: [met[i] ? _jsx(Check, {}) : _jsx(Dot, {}), _jsxs("span", { children: [r.label, _jsx("span", { className: "k-sr-only", children: met[i] ? M.password.met : M.password.unmet })] })] }, r.label))) }))] }));
|
|
22
28
|
}
|
package/dist/PaymentReceipt.js
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef, useId } from "react";
|
|
4
|
-
import { formatJalali, formatTime, getBankByCard, numberToWords, onlyDigits,
|
|
4
|
+
import { formatJalali, formatTime, getBankByCard, numberToWords, onlyDigits, bankName } from "@kashi-ui/persian";
|
|
5
5
|
import { useBankLogo } from "./BankBadge.js";
|
|
6
6
|
import { CopyButton } from "./CopyButton.js";
|
|
7
7
|
import { cx } from "./cx.js";
|
|
8
8
|
import { ErrorIcon, SuccessIcon, WarningIcon } from "./icons.js";
|
|
9
9
|
import { Money } from "./Money.js";
|
|
10
|
-
|
|
10
|
+
import { useKashi } from "./KashiProvider.js";
|
|
11
11
|
const ICONS = { success: SuccessIcon, failed: ErrorIcon, pending: WarningIcon };
|
|
12
12
|
/** رسید پرداخت: وضعیت، مبلغ به عدد و حروف، کد پیگیری با دکمهٔ کپی، کارت پوشانده با لوگوی بانک و تاریخ شمسی */
|
|
13
13
|
export const PaymentReceipt = forwardRef(function PaymentReceipt({ status, amount, unit = "toman", title, description, merchant, trackingCode, referenceId, cardNumber, date, rows = [], children, className, ...rest }, ref) {
|
|
14
|
+
const { messages: M, digits: D, locale, n } = useKashi();
|
|
15
|
+
const R = M.receipt;
|
|
14
16
|
const id = useId();
|
|
15
17
|
const card = cardNumber ? onlyDigits(cardNumber) : "";
|
|
16
18
|
const bank = card ? getBankByCard(card) : null;
|
|
17
19
|
const logo = useBankLogo(bank?.slug, Boolean(bank));
|
|
18
20
|
const Icon = ICONS[status];
|
|
19
21
|
const all = [
|
|
20
|
-
...(merchant ? [[
|
|
21
|
-
...(trackingCode ? [[
|
|
22
|
-
...(referenceId ? [[
|
|
23
|
-
...(card ? [[
|
|
24
|
-
...(date ? [[
|
|
22
|
+
...(merchant ? [[R.merchant, merchant]] : []),
|
|
23
|
+
...(trackingCode ? [[R.tracking, _jsxs("span", { className: "k-receipt__code", children: [_jsx("span", { dir: "ltr", children: n(trackingCode) }), _jsx(CopyButton, { value: trackingCode, iconOnly: true, size: "xs", variant: "tertiary", labels: { copy: R.copyTracking } })] })]] : []),
|
|
24
|
+
...(referenceId ? [[R.reference, _jsx("span", { dir: "ltr", children: n(referenceId) })]] : []),
|
|
25
|
+
...(card ? [[R.card, _jsxs("span", { className: "k-receipt__card", children: [logo && _jsx("img", { src: logo, alt: "", width: 20, height: 20 }), _jsx("span", { dir: "ltr", "aria-label": `${bank ? bankName(bank, locale) : R.card} ${M.bankCard.endingIn(n(card.slice(-4)))}`, children: n(`${card.slice(0, 4)}-${card.slice(4, 6)}**-****-${card.slice(-4)}`) })] })]] : []),
|
|
26
|
+
...(date ? [[R.date, `${formatJalali(date, { style: "long", digits: D, locale })}${M.common.list}${R.at(n(formatTime({ hours: date.getHours(), minutes: date.getMinutes() })))}`]] : []),
|
|
25
27
|
...rows,
|
|
26
28
|
];
|
|
27
|
-
return (_jsxs("section", { ref: ref, className: cx("k-receipt", className), "data-status": status, "aria-labelledby": `${id}-t`, ...rest, children: [_jsxs("div", { className: "k-receipt__head", children: [_jsx("span", { className: "k-receipt__icon", children: _jsx(Icon, {}) }), _jsx("h2", { className: "k-receipt__title", id: `${id}-t`, children: title ??
|
|
29
|
+
return (_jsxs("section", { ref: ref, className: cx("k-receipt", className), "data-status": status, "aria-labelledby": `${id}-t`, ...rest, children: [_jsxs("div", { className: "k-receipt__head", children: [_jsx("span", { className: "k-receipt__icon", children: _jsx(Icon, {}) }), _jsx("h2", { className: "k-receipt__title", id: `${id}-t`, children: title ?? R[status] }), description && _jsx("p", { className: "k-receipt__desc", children: description }), _jsx(Money, { className: "k-receipt__amount", value: amount, unit: unit, from: unit, size: "xl", words: false }), _jsxs("p", { className: "k-receipt__words", children: [numberToWords(Math.round(amount), { locale }), " ", unit === "toman" ? M.money.toman : M.money.rial] })] }), all.length > 0 && (_jsx("dl", { className: "k-receipt__rows", children: all.map(([k, v], i) => _jsxs("div", { className: "k-receipt__row", children: [_jsx("dt", { children: k }), _jsx("dd", { children: v })] }, i)) })), children && _jsx("div", { className: "k-receipt__actions", children: children })] }));
|
|
28
30
|
});
|
package/dist/PersianInput.js
CHANGED
|
@@ -12,6 +12,7 @@ import { PostalCodeInput } from "./PostalCodeInput.js";
|
|
|
12
12
|
import { PlateInput } from "./PlateInput.js";
|
|
13
13
|
import { PriceInput } from "./PriceInput.js";
|
|
14
14
|
import { TimeInput } from "./TimeInput.js";
|
|
15
|
+
import { useKashi } from "./KashiProvider.js";
|
|
15
16
|
/** برچسب پیشفرض هر نوع، اگر label یا aria-label داده نشود */
|
|
16
17
|
export const PERSIAN_INPUT_LABELS = {
|
|
17
18
|
text: "متن",
|
|
@@ -46,7 +47,8 @@ const COMPONENTS = {
|
|
|
46
47
|
export const PersianInput = forwardRef(function PersianInput({ kind, ...rest }, ref) {
|
|
47
48
|
const Component = COMPONENTS[kind];
|
|
48
49
|
const props = rest;
|
|
49
|
-
const
|
|
50
|
+
const { messages: M } = useKashi();
|
|
51
|
+
const label = props.label ?? (props["aria-label"] ? undefined : M.persianInput[kind]);
|
|
50
52
|
// PlateInput چند فیلد دارد و ref نمیگیرد
|
|
51
53
|
return _jsx(Component, { ref: kind === "plate" ? undefined : ref, ...props, label: label, "data-kind": kind });
|
|
52
54
|
});
|
package/dist/PersianTextarea.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef, useMemo, useState } from "react";
|
|
4
|
-
import { fixPersianText
|
|
4
|
+
import { fixPersianText } from "@kashi-ui/persian";
|
|
5
5
|
import { Button } from "./Button.js";
|
|
6
6
|
import { Textarea } from "./Input.js";
|
|
7
|
-
|
|
7
|
+
import { useKashi } from "./KashiProvider.js";
|
|
8
|
+
const KINDS = ["arabic", "zwnj", "punctuation", "digits", "spacing"];
|
|
8
9
|
/** ناحیهٔ متن با ویرایش نگارشی فارسی: «ي/ك» عربی، نیمفاصله، ویرگول و علامت سؤال فارسی و ارقام */
|
|
9
10
|
export const PersianTextarea = forwardRef(function PersianTextarea({ value, defaultValue = "", onValueChange, fixDigits = true, fixOnBlur = false, labels = {}, hint, onBlur, ...rest }, ref) {
|
|
10
|
-
const {
|
|
11
|
+
const { messages: M, n } = useKashi();
|
|
12
|
+
const { fix = M.textFix.fix, clean = M.textFix.clean } = labels;
|
|
11
13
|
const [inner, setInner] = useState(defaultValue);
|
|
12
14
|
const current = value ?? inner;
|
|
13
15
|
const result = useMemo(() => fixPersianText(current, { digits: fixDigits }), [current, fixDigits]);
|
|
@@ -16,13 +18,13 @@ export const PersianTextarea = forwardRef(function PersianTextarea({ value, defa
|
|
|
16
18
|
setInner(next);
|
|
17
19
|
onValueChange?.(next);
|
|
18
20
|
};
|
|
19
|
-
const summary =
|
|
21
|
+
const summary = KINDS
|
|
20
22
|
.filter((k) => result.fixes[k])
|
|
21
|
-
.map((k) => `${
|
|
22
|
-
.join(
|
|
23
|
+
.map((k) => `${n(result.fixes[k])} ${M.textFix[k]}`)
|
|
24
|
+
.join(M.common.list);
|
|
23
25
|
return (_jsx(Textarea, { ref: ref, value: current, onChange: (e) => update(e.target.value), onBlur: (e) => {
|
|
24
26
|
if (fixOnBlur && result.count)
|
|
25
27
|
update(result.text);
|
|
26
28
|
onBlur?.(e);
|
|
27
|
-
}, hint: current.trim() ? (_jsxs("span", { className: "k-textfix", "data-state": result.count ? "fix" : "clean", children: [_jsx("span", { className: "k-textfix__text", children: result.count ?
|
|
29
|
+
}, hint: current.trim() ? (_jsxs("span", { className: "k-textfix", "data-state": result.count ? "fix" : "clean", children: [_jsx("span", { className: "k-textfix__text", children: result.count ? M.textFix.count(n(result.count), summary) : clean }), result.count > 0 && _jsx(Button, { size: "xs", variant: "tertiary", onClick: () => update(result.text), children: fix })] })) : hint, ...rest }));
|
|
28
30
|
});
|
package/dist/PlateInput.js
CHANGED
|
@@ -3,17 +3,20 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useId, useRef, useState } from "react";
|
|
4
4
|
import { PLATE_LETTERS, formatPlate, isValidPlate, onlyDigits, plateType, toFaDigits } from "@kashi-ui/persian";
|
|
5
5
|
import { Field, describedBy } from "./Field.js";
|
|
6
|
+
import { useKashi } from "./KashiProvider.js";
|
|
6
7
|
const EMPTY = { first: "", letter: "", middle: "", region: "" };
|
|
7
8
|
/**
|
|
8
9
|
* پلاک خودروی ایران با ظاهر واقعی: دو رقم، حرف، سه رقم و کد استان.
|
|
9
10
|
* با پر شدن هر بخش فوکوس خودکار به بخش بعد میرود و Backspace در بخش خالی به قبلی برمیگردد.
|
|
10
11
|
*/
|
|
11
|
-
export function PlateInput({ label, hint, error, value, defaultValue, onChange, name, disabled, id, className, invalidMessage
|
|
12
|
+
export function PlateInput({ label, hint, error, value, defaultValue, onChange, name, disabled, id, className, invalidMessage, labels = {}, }) {
|
|
13
|
+
const { messages: M } = useKashi();
|
|
14
|
+
invalidMessage ?? (invalidMessage = M.invalid.plate);
|
|
12
15
|
const autoId = useId();
|
|
13
16
|
const groupId = id ?? autoId;
|
|
14
17
|
// برچسب به اولین بخش وصل است تا کلیک روی آن فوکوس بدهد
|
|
15
18
|
const firstId = `${groupId}-first`;
|
|
16
|
-
const { first =
|
|
19
|
+
const { first = M.plate.first, letter = M.plate.letter, middle = M.plate.middle, region = M.plate.region } = labels;
|
|
17
20
|
const [inner, setInner] = useState({ ...EMPTY, ...defaultValue });
|
|
18
21
|
const plate = value ?? inner;
|
|
19
22
|
const [touched, setTouched] = useState(false);
|
|
@@ -41,7 +44,7 @@ export function PlateInput({ label, hint, error, value, defaultValue, onChange,
|
|
|
41
44
|
if (e.key === "Backspace" && !plate[key])
|
|
42
45
|
refs[idx - 1]?.current?.focus();
|
|
43
46
|
} }));
|
|
44
|
-
return (_jsxs(Field, { id: firstId, label: label, hint: hint, error: error ?? (showInvalid ? invalidMessage : undefined), className: className, children: [_jsxs("div", { className: "k-plate", role: "group", id: groupId, "aria-describedby": describedBy(firstId, hint, error ?? (showInvalid ? invalidMessage : undefined)), "aria-label": typeof label === "string" ? label :
|
|
47
|
+
return (_jsxs(Field, { id: firstId, label: label, hint: hint, error: error ?? (showInvalid ? invalidMessage : undefined), className: className, children: [_jsxs("div", { className: "k-plate", role: "group", id: groupId, "aria-describedby": describedBy(firstId, hint, error ?? (showInvalid ? invalidMessage : undefined)), "aria-label": typeof label === "string" ? label : M.plate.label, "data-invalid": showInvalid || error ? "" : undefined, "data-type": plateType(plate.letter), onBlur: (e) => {
|
|
45
48
|
if (!e.currentTarget.contains(e.relatedTarget))
|
|
46
49
|
setTouched(true);
|
|
47
50
|
}, children: [_jsxs("span", { className: "k-plate__flag", "aria-hidden": "true", children: [_jsx("span", { className: "k-plate__flag-colors" }), "I.R.", _jsx("br", {}), "IRAN"] }), seg("first", 2, 0, first), _jsxs("select", { ref: refs[1], className: "k-plate__letter", "aria-label": letter, disabled: disabled, value: plate.letter, onChange: (e) => {
|
package/dist/PostalCodeInput.js
CHANGED
|
@@ -5,8 +5,12 @@ import { formatPostalCode, isValidPostalCode } 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
|
/** کد پستی ۱۰ رقمی با قالب ۱۲۳۴۵-۶۷۸۹۰ و بررسی قواعد کد پستی ایران */
|
|
9
|
-
export const PostalCodeInput = forwardRef(function PostalCodeInput({ value, defaultValue, onValueChange, digits
|
|
10
|
+
export const PostalCodeInput = forwardRef(function PostalCodeInput({ value, defaultValue, onValueChange, digits, invalidMessage, error, name, onBlur, placeholder, ...rest }, ref) {
|
|
11
|
+
const { messages: M, digits: D, locale } = useKashi();
|
|
12
|
+
digits ?? (digits = D);
|
|
13
|
+
invalidMessage ?? (invalidMessage = M.invalid.postal);
|
|
10
14
|
const { raw, shown, inputRef, handleChange } = useDigitsInput({ value, defaultValue, maxDigits: 10, format: formatPostalCode, digits });
|
|
11
15
|
const [touched, setTouched] = useState(false);
|
|
12
16
|
const showInvalid = raw.length > 0 && (touched || raw.length === 10) && !isValidPostalCode(raw);
|
package/dist/PriceInput.js
CHANGED
|
@@ -5,21 +5,27 @@ import { formatNumber, numberToWords, toFaDigits } 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
|
const toRaw = (n) => (n === null || n === undefined ? undefined : String(Math.trunc(Math.abs(n))));
|
|
9
10
|
/** فیلد مبلغ: جداکنندهٔ هزارگان، واحد پول و نمایش مبلغ به حروف برای اطمینان کاربر */
|
|
10
|
-
export const PriceInput = forwardRef(function PriceInput({ value, defaultValue, onValueChange, unit
|
|
11
|
+
export const PriceInput = forwardRef(function PriceInput({ value, defaultValue, onValueChange, unit, showWords = true, digits, min, max, rangeMessage, error, hint, name, onBlur, placeholder, ...rest }, ref) {
|
|
12
|
+
const { messages: M, digits: D, locale } = useKashi();
|
|
13
|
+
digits ?? (digits = D);
|
|
14
|
+
unit ?? (unit = M.money.toman);
|
|
15
|
+
const money = (v) => (digits === "fa" ? toFaDigits(formatNumber(v)) : formatNumber(v, { digits: "latin" }));
|
|
16
|
+
rangeMessage ?? (rangeMessage = (lo, hi) => (lo !== undefined && hi !== undefined ? M.invalid.priceRange(money(lo), money(hi)) : lo !== undefined ? M.invalid.priceMin(money(lo)) : M.invalid.priceMax(money(hi))));
|
|
11
17
|
const [touched, setTouched] = useState(false);
|
|
12
18
|
const { raw, shown, inputRef, handleChange } = useDigitsInput({
|
|
13
19
|
value: value === undefined ? undefined : (toRaw(value) ?? ""),
|
|
14
20
|
defaultValue: toRaw(defaultValue),
|
|
15
21
|
maxDigits: 15,
|
|
16
22
|
normalize: (d) => d.replace(/^0+(?=\d)/, ""),
|
|
17
|
-
format: (d) => (d ? formatNumber(d, { digits: "latin" }).replace(/,/g, "٬") : ""),
|
|
23
|
+
format: (d) => (d ? formatNumber(d, { digits: "latin" }).replace(/,/g, digits === "fa" ? "٬" : ",") : ""),
|
|
18
24
|
digits,
|
|
19
25
|
});
|
|
20
26
|
const n = raw ? Number(raw) : null;
|
|
21
27
|
const outOfRange = n !== null && ((min !== undefined && n < min) || (max !== undefined && n > max));
|
|
22
|
-
const words = showWords && n !== null ? `${numberToWords(n)}${typeof unit === "string" ? ` ${unit}` : ""}` : null;
|
|
28
|
+
const words = showWords && n !== null ? `${numberToWords(n, { locale })}${typeof unit === "string" ? ` ${unit}` : ""}` : null;
|
|
23
29
|
return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: mergeRefs(ref, inputRef), type: "text", inputMode: "numeric", autoComplete: "off", dir: "ltr", placeholder: placeholder ?? (digits === "fa" ? "۰" : "0"), value: shown, onChange: (e) => {
|
|
24
30
|
const next = handleChange(e);
|
|
25
31
|
onValueChange?.(next ? Number(next) : null);
|
package/dist/Progress.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { toFaDigits } from "@kashi-ui/persian";
|
|
4
3
|
import { cx } from "./cx.js";
|
|
4
|
+
import { useKashi } from "./KashiProvider.js";
|
|
5
5
|
export function Progress({ value, max = 100, label, showValue, size = "md", tone = "brand", variant = "linear", className, "aria-label": ariaLabel, ...rest }) {
|
|
6
|
+
const { messages: M, n } = useKashi();
|
|
6
7
|
const pct = value === undefined ? undefined : Math.max(0, Math.min(100, (value / max) * 100));
|
|
7
|
-
const text = pct === undefined ? undefined :
|
|
8
|
+
const text = pct === undefined ? undefined : M.common.percent(n(Math.round(pct)));
|
|
8
9
|
if (variant === "circular") {
|
|
9
10
|
const r = 16;
|
|
10
11
|
const c = 2 * Math.PI * r;
|
|
@@ -16,6 +17,8 @@ export function Progress({ value, max = 100, label, showValue, size = "md", tone
|
|
|
16
17
|
return (_jsxs("div", { className: cx("k-progress-field", className), children: [_jsxs("div", { className: "k-progress-field__head", "aria-hidden": "true", children: [_jsx("span", { className: "k-progress-field__label", children: label }), showValue && text && _jsx("span", { className: "k-progress-field__value", children: text })] }), bar] }));
|
|
17
18
|
}
|
|
18
19
|
/** اسپینر با متن صفحهخوان */
|
|
19
|
-
export function Spinner({ label
|
|
20
|
+
export function Spinner({ label, size = "md", className, ...rest }) {
|
|
21
|
+
const { messages: M } = useKashi();
|
|
22
|
+
label ?? (label = M.common.loading);
|
|
20
23
|
return (_jsxs("span", { role: "status", className: className, ...rest, children: [_jsx("span", { className: cx("k-spinner", size !== "md" && `k-spinner--${size}`), "aria-hidden": "true" }), _jsx("span", { className: "k-sr-only", children: label })] }));
|
|
21
24
|
}
|
package/dist/ProvinceSelect.js
CHANGED
|
@@ -3,8 +3,10 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
4
|
import { PROVINCES } from "@kashi-ui/persian";
|
|
5
5
|
import { Combobox } from "./Combobox.js";
|
|
6
|
-
|
|
6
|
+
import { useKashi } from "./KashiProvider.js";
|
|
7
|
+
const options = (capital, label) => PROVINCES.map((p) => ({ value: p.name, label: p.name, description: capital ? label(p.capital) : undefined, keywords: [p.capital] }));
|
|
7
8
|
/** انتخاب یکی از ۳۱ استان با جستجو؛ با نام مرکز استان هم پیدا میشود (مثلاً «مشهد») */
|
|
8
|
-
export const ProvinceSelect = forwardRef(function ProvinceSelect({ showCapital = true, label
|
|
9
|
-
|
|
9
|
+
export const ProvinceSelect = forwardRef(function ProvinceSelect({ showCapital = true, label, placeholder, ...rest }, ref) {
|
|
10
|
+
const { messages: M } = useKashi();
|
|
11
|
+
return _jsx(Combobox, { ref: ref, label: label ?? M.province.label, placeholder: placeholder ?? M.province.search, options: options(showCapital, M.province.capital), ...rest });
|
|
10
12
|
});
|
package/dist/Rating.js
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useId, useState } from "react";
|
|
4
|
-
import { toFaDigits } from "@kashi-ui/persian";
|
|
5
4
|
import { cx } from "./cx.js";
|
|
5
|
+
import { useKashi } from "./KashiProvider.js";
|
|
6
6
|
const Star = () => (_jsxs("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", children: [_jsx("path", { fill: "currentColor", d: "M12 2.8l2.8 5.9 6.4.8-4.7 4.4 1.2 6.3L12 17.1l-5.7 3.1 1.2-6.3L2.8 9.5l6.4-.8z" }), _jsx("path", { className: "k-rating__half", fill: "none", d: "M12 2.8v14.3l-5.7 3.1 1.2-6.3L2.8 9.5l6.4-.8z" })] }));
|
|
7
|
-
const fa = (n) => toFaDigits(String(n)).replace(".", "٫");
|
|
8
7
|
/** امتیاز ستارهای؛ قابلانتخاب با رادیوهای بومی (←→) یا فقطخواندنی */
|
|
9
|
-
export function Rating({ value, defaultValue = 0, onChange, max = 5, readOnly, showValue, size = "md", label
|
|
8
|
+
export function Rating({ value, defaultValue = 0, onChange, max = 5, readOnly, showValue, size = "md", label, name, disabled, className, starLabel, }) {
|
|
9
|
+
const { messages: M, n: N } = useKashi();
|
|
10
|
+
const fa = (x) => N(x).replace(".", M.common.decimal);
|
|
11
|
+
label ?? (label = M.rating.label);
|
|
12
|
+
starLabel ?? (starLabel = (a, b) => M.common.of(fa(a), fa(b)));
|
|
10
13
|
const id = useId();
|
|
11
14
|
const [inner, setInner] = useState(defaultValue);
|
|
12
15
|
const [hover, setHover] = useState(null);
|
package/dist/RelativeTime.js
CHANGED
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import { formatJalali, formatRelative } from "@kashi-ui/persian";
|
|
5
|
+
import { useKashi } from "./KashiProvider.js";
|
|
5
6
|
/** «۵ دقیقه پیش» در یک <time> معنایی؛ تاریخ کامل شمسی در title و برای صفحهخوان در دسترس است */
|
|
6
|
-
export function RelativeTime({ date, digits
|
|
7
|
+
export function RelativeTime({ date, digits, refresh = 60000, ...rest }) {
|
|
8
|
+
const { digits: D, locale } = useKashi();
|
|
9
|
+
digits ?? (digits = D);
|
|
7
10
|
const [now, setNow] = useState(() => new Date());
|
|
8
11
|
useEffect(() => {
|
|
9
12
|
const t = setInterval(() => setNow(new Date()), refresh);
|
|
10
13
|
return () => clearInterval(t);
|
|
11
14
|
}, [refresh]);
|
|
12
|
-
return (_jsx("time", { dateTime: date.toISOString(), title: formatJalali(date, { style: "full", digits }), ...rest, children: formatRelative(date, { now, digits }) }));
|
|
15
|
+
return (_jsx("time", { dateTime: date.toISOString(), title: formatJalali(date, { style: "full", digits, locale }), ...rest, children: formatRelative(date, { now, digits, locale }) }));
|
|
13
16
|
}
|
package/dist/SideNav.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useId, useState } from "react";
|
|
4
4
|
import { cx } from "./cx.js";
|
|
5
|
+
import { useKashi } from "./KashiProvider.js";
|
|
5
6
|
const Chevron = () => (_jsx("svg", { className: "k-sidenav__chevron", 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" }) }));
|
|
6
7
|
const hasCurrent = (it) => Boolean(it.current || it.items?.some(hasCurrent));
|
|
7
8
|
function Item({ item, collapsed }) {
|
|
@@ -17,7 +18,9 @@ function Item({ item, collapsed }) {
|
|
|
17
18
|
return _jsx("li", { children: item.href ? _jsx("a", { href: item.href, ...props, children: inner }) : _jsx("button", { type: "button", ...props, children: inner }) });
|
|
18
19
|
}
|
|
19
20
|
/** ناوبری کناری پنل مدیریت با گروه، زیرمنو، نشان و حالت جمعشده */
|
|
20
|
-
export function SideNav({ sections, header, footer, collapsed, "aria-label": ariaLabel
|
|
21
|
+
export function SideNav({ sections, header, footer, collapsed, "aria-label": ariaLabel, className }) {
|
|
22
|
+
const { messages: M } = useKashi();
|
|
23
|
+
ariaLabel ?? (ariaLabel = M.sideNav.label);
|
|
21
24
|
const id = useId();
|
|
22
25
|
return (_jsxs("nav", { className: cx("k-sidenav", collapsed && "k-sidenav--collapsed", className), "aria-label": ariaLabel, children: [header && _jsx("div", { className: "k-sidenav__header", children: header }), sections.map((sec, i) => (_jsxs("div", { children: [sec.label && _jsx("p", { className: "k-sidenav__label", id: `${id}-s${i}`, children: sec.label }), _jsx("ul", { className: "k-sidenav__group", role: "list", "aria-labelledby": sec.label ? `${id}-s${i}` : undefined, children: sec.items.map((it) => _jsx(Item, { item: it, collapsed: collapsed }, it.label)) })] }, sec.label ?? i))), footer && _jsx("div", { className: "k-sidenav__footer", children: footer })] }));
|
|
23
26
|
}
|
package/dist/Slider.js
CHANGED
|
@@ -3,15 +3,18 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { useId, useState } from "react";
|
|
4
4
|
import { formatNumber } from "@kashi-ui/persian";
|
|
5
5
|
import { cx } from "./cx.js";
|
|
6
|
+
import { useKashi } from "./KashiProvider.js";
|
|
6
7
|
/** اسلایدر روی <input type="range"> بومی؛ با آرایهٔ دوتایی، بازه با دو دستگیره */
|
|
7
|
-
export function Slider({ label, value, defaultValue, onChange, min = 0, max = 100, step = 1, showValue = true, format
|
|
8
|
+
export function Slider({ label, value, defaultValue, onChange, min = 0, max = 100, step = 1, showValue = true, format, marks, disabled, name, className, labels = {}, }) {
|
|
8
9
|
const id = useId();
|
|
9
10
|
const isRange = Array.isArray(value ?? defaultValue);
|
|
10
11
|
const [inner, setInner] = useState(defaultValue ?? (isRange ? [min, max] : min));
|
|
11
12
|
const current = (value ?? inner);
|
|
12
13
|
const [lo, hi] = Array.isArray(current) ? current : [min, current];
|
|
13
14
|
const pct = (n) => `${((n - min) / (max - min)) * 100}%`;
|
|
14
|
-
const {
|
|
15
|
+
const { messages: M, digits: D } = useKashi();
|
|
16
|
+
format ?? (format = (x) => formatNumber(x, { digits: D }));
|
|
17
|
+
const { from = M.slider.from, to = M.slider.to, separator = M.common.range } = labels;
|
|
15
18
|
const set = (next) => {
|
|
16
19
|
if (value === undefined)
|
|
17
20
|
setInner(next);
|
package/dist/Splitter.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useRef, useState } from "react";
|
|
4
|
-
import { toFaDigits } from "@kashi-ui/persian";
|
|
5
4
|
import { cx } from "./cx.js";
|
|
5
|
+
import { useKashi } from "./KashiProvider.js";
|
|
6
6
|
/** دو پنل با مرز قابلکشیدن؛ با کیبورد: ←→ (یا ↑↓) پنج درصد، Home/End کمینه و بیشینه */
|
|
7
|
-
export function Splitter({ children, orientation = "horizontal", size, defaultSize = 40, onSizeChange, min = 15, max = 85, label
|
|
7
|
+
export function Splitter({ children, orientation = "horizontal", size, defaultSize = 40, onSizeChange, min = 15, max = 85, label, height, className }) {
|
|
8
|
+
const { messages: M, n } = useKashi();
|
|
9
|
+
label ?? (label = M.splitter.label);
|
|
8
10
|
const [inner, setInner] = useState(defaultSize);
|
|
9
11
|
const current = size ?? inner;
|
|
10
12
|
const [dragging, setDragging] = useState(false);
|
|
@@ -39,7 +41,7 @@ export function Splitter({ children, orientation = "horizontal", size, defaultSi
|
|
|
39
41
|
return;
|
|
40
42
|
e.preventDefault();
|
|
41
43
|
};
|
|
42
|
-
return (_jsxs("div", { ref: box, className: cx("k-splitter", vertical && "k-splitter--vertical", className), "data-dragging": dragging ? "" : undefined, style: { blockSize: height }, children: [_jsx("div", { className: "k-splitter__pane", style: vertical ? { blockSize: `${current}%` } : { inlineSize: `${current}%` }, children: children[0] }), _jsx("div", { className: "k-splitter__handle", role: "separator", tabIndex: 0, "aria-orientation": vertical ? "horizontal" : "vertical", "aria-valuenow": current, "aria-valuemin": min, "aria-valuemax": max, "aria-valuetext":
|
|
44
|
+
return (_jsxs("div", { ref: box, className: cx("k-splitter", vertical && "k-splitter--vertical", className), "data-dragging": dragging ? "" : undefined, style: { blockSize: height }, children: [_jsx("div", { className: "k-splitter__pane", style: vertical ? { blockSize: `${current}%` } : { inlineSize: `${current}%` }, children: children[0] }), _jsx("div", { className: "k-splitter__handle", role: "separator", tabIndex: 0, "aria-orientation": vertical ? "horizontal" : "vertical", "aria-valuenow": current, "aria-valuemin": min, "aria-valuemax": max, "aria-valuetext": M.common.percent(n(Math.round(current))), "aria-label": label, "data-dragging": dragging ? "" : undefined, onKeyDown: onKey, onPointerDown: (e) => {
|
|
43
45
|
e.currentTarget.setPointerCapture(e.pointerId);
|
|
44
46
|
setDragging(true);
|
|
45
47
|
}, onPointerMove: (e) => dragging && fromPointer(e), onPointerUp: () => setDragging(false), onPointerCancel: () => setDragging(false), onDoubleClick: () => set(defaultSize) }), _jsx("div", { className: "k-splitter__pane", children: children[1] })] }));
|
package/dist/Stat.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
|
-
import { toFaDigits } from "@kashi-ui/persian";
|
|
5
4
|
import { cx } from "./cx.js";
|
|
5
|
+
import { useKashi } from "./KashiProvider.js";
|
|
6
6
|
const Arrow = ({ dir }) => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: dir === "up" ? _jsx("path", { d: "M10 15V5m0 0-4 4m4-4 4 4" }) : _jsx("path", { d: "M10 5v10m0 0-4-4m4 4 4-4" }) }));
|
|
7
7
|
/** کارت شاخص کلیدی (KPI) با روند؛ صفحهخوان روند را به شکل «۱۲٪ افزایش» میخواند */
|
|
8
8
|
export const StatCard = forwardRef(function StatCard({ label, value, unit, icon, change, invertTrend, caption, children, labels = {}, className, ...rest }, ref) {
|
|
9
|
-
const {
|
|
9
|
+
const { messages: M, n } = useKashi();
|
|
10
|
+
const { up = M.stat.up, down = M.stat.down, flat = M.stat.flat } = labels;
|
|
10
11
|
const dir = change === undefined ? null : change > 0 ? "up" : change < 0 ? "down" : "flat";
|
|
11
12
|
// رنگ بر اساس خوب یا بد بودن، نه جهت
|
|
12
13
|
const good = dir === "flat" ? "flat" : (dir === "up") !== Boolean(invertTrend) ? "up" : "down";
|
|
13
|
-
const pct = change === undefined ? "" :
|
|
14
|
+
const pct = change === undefined ? "" : M.common.percent(n(Math.abs(Math.round(change * 10) / 10)).replace(".", M.common.decimal));
|
|
14
15
|
return (_jsxs("div", { ref: ref, className: cx("k-stat", className), ...rest, children: [_jsxs("div", { className: "k-stat__head", children: [icon && _jsx("span", { className: "k-stat__icon", "aria-hidden": "true", children: icon }), _jsx("p", { className: "k-stat__label", children: label })] }), _jsxs("p", { className: "k-stat__value", children: [_jsx("span", { children: value }), unit && _jsx("span", { className: "k-stat__unit", children: unit })] }), (dir || caption) && (_jsxs("div", { className: "k-stat__foot", children: [dir && (_jsxs("span", { className: `k-trend k-trend--${good}`, children: [dir !== "flat" && _jsx(Arrow, { dir: dir }), _jsx("span", { "aria-hidden": "true", children: dir === "flat" ? flat : pct }), _jsx("span", { className: "k-sr-only", children: dir === "flat" ? flat : `${pct} ${dir === "up" ? up : down}` })] })), caption && _jsx("span", { children: caption })] })), children && _jsx("div", { className: "k-stat__chart", children: children })] }));
|
|
15
16
|
});
|
|
16
17
|
export function StatGrid({ className, ...rest }) {
|
package/dist/Stepper.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { toFaDigits } from "@kashi-ui/persian";
|
|
4
3
|
import { cx } from "./cx.js";
|
|
4
|
+
import { useKashi } from "./KashiProvider.js";
|
|
5
5
|
const Check = () => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2.2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m5 10.5 3.2 3L15 7" }) }));
|
|
6
6
|
/** مراحل یک فرایند؛ مرحلهٔ فعلی با aria-current="step" و وضعیت هر مرحله برای صفحهخوان */
|
|
7
|
-
export function Stepper({ steps, current, orientation = "horizontal", label
|
|
8
|
-
const {
|
|
7
|
+
export function Stepper({ steps, current, orientation = "horizontal", label, labels = {}, className }) {
|
|
8
|
+
const { messages: M, n } = useKashi();
|
|
9
|
+
label ?? (label = M.stepper.label);
|
|
10
|
+
const { complete = M.stepper.complete, current: currentLabel = M.stepper.current } = labels;
|
|
9
11
|
return (_jsx("ol", { className: cx("k-steps", orientation === "vertical" && "k-steps--vertical", className), "aria-label": label, children: steps.map((s, i) => {
|
|
10
12
|
const status = i < current ? "complete" : i === current ? "current" : "upcoming";
|
|
11
|
-
return (_jsxs("li", { className: "k-steps__step", "data-status": status, "aria-current": status === "current" ? "step" : undefined, children: [_jsx("span", { className: "k-steps__marker", "aria-hidden": "true", children: status === "complete" ? _jsx(Check, {}) :
|
|
13
|
+
return (_jsxs("li", { className: "k-steps__step", "data-status": status, "aria-current": status === "current" ? "step" : undefined, children: [_jsx("span", { className: "k-steps__marker", "aria-hidden": "true", children: status === "complete" ? _jsx(Check, {}) : n(i + 1) }), _jsxs("span", { className: "k-steps__title", children: [s.title, status !== "upcoming" && _jsx("span", { className: "k-sr-only", children: `${M.common.list}${status === "complete" ? complete : currentLabel}` })] }), s.description && _jsx("span", { className: "k-steps__description", children: s.description })] }, i));
|
|
12
14
|
}) }));
|
|
13
15
|
}
|