@kashi-ui/react 0.10.0 → 0.11.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/ButtonGroup.d.ts +7 -0
- package/dist/ButtonGroup.js +6 -0
- package/dist/ChipGroup.d.ts +22 -0
- package/dist/ChipGroup.js +18 -0
- package/dist/Countdown.d.ts +22 -0
- package/dist/Countdown.js +37 -0
- package/dist/LandlineInput.d.ts +19 -0
- package/dist/LandlineInput.js +23 -0
- package/dist/MonthPicker.d.ts +23 -0
- package/dist/MonthPicker.js +62 -0
- package/dist/PasswordStrength.d.ts +23 -0
- package/dist/PasswordStrength.js +21 -0
- package/dist/TreeView.d.ts +26 -0
- package/dist/TreeView.js +96 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +7 -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 · Combobox · CommandPalette · TagInput · FileUpload · Slider · NumberInput · Popover · StatCard · Timeline · SideNav · SegmentedControl · CopyButton · Banner · Rating
|
|
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 · SegmentedControl · CopyButton · Banner · Rating · TreeView · ButtonGroup · ChipGroup · PasswordStrength
|
|
24
24
|
|
|
25
|
-
فارسی: DatePicker و Calendar شمسی · DateRangePicker · TimeInput · PostalCodeInput · PlateInput · NationalIdInput · CardNumberInput · IbanInput · MobileInput · PriceInput · OtpInput
|
|
25
|
+
فارسی: DatePicker و Calendar شمسی · DateRangePicker · TimeInput · PostalCodeInput · PlateInput · LandlineInput · MonthPicker · Countdown · 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
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "react";
|
|
2
|
+
export interface ButtonGroupProps extends HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
/** نام گروه برای صفحهخوان */
|
|
4
|
+
"aria-label"?: string;
|
|
5
|
+
}
|
|
6
|
+
/** دکمههای چسبیده به هم، مثل «قبلی / امروز / بعدی» یا ابزار قالببندی */
|
|
7
|
+
export declare function ButtonGroup({ className, ...rest }: ButtonGroupProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from "./cx.js";
|
|
3
|
+
/** دکمههای چسبیده به هم، مثل «قبلی / امروز / بعدی» یا ابزار قالببندی */
|
|
4
|
+
export function ButtonGroup({ className, ...rest }) {
|
|
5
|
+
return _jsx("div", { role: "group", className: cx("k-btn-group", className), ...rest });
|
|
6
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface ChipOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: ReactNode;
|
|
5
|
+
icon?: ReactNode;
|
|
6
|
+
/** تعداد نتیجهها کنار برچسب */
|
|
7
|
+
count?: number;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ChipGroupProps {
|
|
11
|
+
options: ChipOption[];
|
|
12
|
+
/** مقدارهای انتخابشده */
|
|
13
|
+
value?: string[];
|
|
14
|
+
defaultValue?: string[];
|
|
15
|
+
onChange?: (value: string[]) => void;
|
|
16
|
+
/** فقط یک انتخاب؛ کلیک دوباره انتخاب را برمیدارد */
|
|
17
|
+
single?: boolean;
|
|
18
|
+
"aria-label"?: string;
|
|
19
|
+
className?: string;
|
|
20
|
+
}
|
|
21
|
+
/** تراشههای فیلتر روشن و خاموششونده، مثل دستهبندیها یا وضعیت سفارش */
|
|
22
|
+
export declare function ChipGroup({ options, value, defaultValue, onChange, single, "aria-label": ariaLabel, className }: ChipGroupProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { toFaDigits } from "@kashi-ui/persian";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
const Check = () => (_jsx("svg", { className: "k-chip__check", 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" }) }));
|
|
6
|
+
/** تراشههای فیلتر روشن و خاموششونده، مثل دستهبندیها یا وضعیت سفارش */
|
|
7
|
+
export function ChipGroup({ options, value, defaultValue = [], onChange, single, "aria-label": ariaLabel, className }) {
|
|
8
|
+
const [inner, setInner] = useState(defaultValue);
|
|
9
|
+
const current = value ?? inner;
|
|
10
|
+
const toggle = (v) => {
|
|
11
|
+
const on = current.includes(v);
|
|
12
|
+
const next = single ? (on ? [] : [v]) : on ? current.filter((x) => x !== v) : [...current, v];
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
setInner(next);
|
|
15
|
+
onChange?.(next);
|
|
16
|
+
};
|
|
17
|
+
return (_jsx("div", { role: "group", "aria-label": ariaLabel, className: cx("k-chips", className), children: options.map((o) => (_jsxs("button", { type: "button", className: "k-chip", "aria-pressed": current.includes(o.value), disabled: o.disabled, onClick: () => toggle(o.value), children: [_jsx(Check, {}), o.icon, o.label, o.count !== undefined && _jsx("span", { className: "k-chip__count", children: toFaDigits(o.count) })] }, o.value))) }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface CountdownProps {
|
|
2
|
+
/** زمان پایان */
|
|
3
|
+
to?: Date;
|
|
4
|
+
/** یا مدت به ثانیه از لحظهٔ نمایش (مثلاً ۱۲۰ برای ارسال دوبارهٔ کد) */
|
|
5
|
+
seconds?: number;
|
|
6
|
+
onComplete?: () => void;
|
|
7
|
+
/** «clock» مثل ۰۲:۳۴، «blocks» کادرهای روز/ساعت/دقیقه/ثانیه @default "clock" */
|
|
8
|
+
variant?: "clock" | "blocks";
|
|
9
|
+
/** @default "fa" */
|
|
10
|
+
digits?: "fa" | "latin";
|
|
11
|
+
/** نام برای صفحهخوان، مثل «زمان باقیمانده تا ارسال دوباره» */
|
|
12
|
+
"aria-label"?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
labels?: {
|
|
15
|
+
days?: string;
|
|
16
|
+
hours?: string;
|
|
17
|
+
minutes?: string;
|
|
18
|
+
seconds?: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** شمارش معکوس با ارقام فارسی؛ هر ثانیه بهروز میشود و در پایان onComplete را صدا میزند */
|
|
22
|
+
export declare function Countdown({ to, seconds, onComplete, variant, digits, "aria-label": ariaLabel, className, labels }: CountdownProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { toFaDigits } from "@kashi-ui/persian";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
6
|
+
/** شمارش معکوس با ارقام فارسی؛ هر ثانیه بهروز میشود و در پایان onComplete را صدا میزند */
|
|
7
|
+
export function Countdown({ to, seconds, onComplete, variant = "clock", digits = "fa", "aria-label": ariaLabel, className, labels = {} }) {
|
|
8
|
+
const { days = "روز", hours = "ساعت", minutes = "دقیقه", seconds: secLabel = "ثانیه" } = labels;
|
|
9
|
+
const end = useRef(to?.getTime() ?? Date.now() + (seconds ?? 0) * 1000);
|
|
10
|
+
const [left, setLeft] = useState(() => Math.max(0, Math.ceil((end.current - Date.now()) / 1000)));
|
|
11
|
+
const done = useRef(false);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
end.current = to?.getTime() ?? Date.now() + (seconds ?? 0) * 1000;
|
|
14
|
+
done.current = false;
|
|
15
|
+
const tick = () => {
|
|
16
|
+
const s = Math.max(0, Math.ceil((end.current - Date.now()) / 1000));
|
|
17
|
+
setLeft(s);
|
|
18
|
+
if (s === 0 && !done.current) {
|
|
19
|
+
done.current = true;
|
|
20
|
+
onComplete?.();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
tick();
|
|
24
|
+
const t = setInterval(tick, 1000);
|
|
25
|
+
return () => clearInterval(t);
|
|
26
|
+
}, [to?.getTime(), seconds]);
|
|
27
|
+
const d = Math.floor(left / 86400), h = Math.floor((left % 86400) / 3600), m = Math.floor((left % 3600) / 60), s = left % 60;
|
|
28
|
+
const f = (x) => (digits === "fa" ? toFaDigits(String(x)) : String(x));
|
|
29
|
+
// متن کامل برای صفحهخوان؛ role="timer" بهطور پیشفرض هر ثانیه خوانده نمیشود
|
|
30
|
+
const spoken = [d && `${f(d)} ${days}`, h && `${f(h)} ${hours}`, m && `${f(m)} ${minutes}`, `${f(s)} ${secLabel}`].filter(Boolean).join(" و ");
|
|
31
|
+
if (variant === "blocks") {
|
|
32
|
+
const units = [...(d ? [[d, days]] : []), [h, hours], [m, minutes], [s, secLabel]];
|
|
33
|
+
return (_jsx("div", { role: "timer", "aria-label": ariaLabel ? `${ariaLabel}: ${spoken}` : spoken, className: cx("k-countdown k-countdown--blocks", className), "data-done": left === 0 ? "" : undefined, children: units.map(([v, name]) => (_jsxs("span", { className: "k-countdown__unit", "aria-hidden": "true", children: [_jsx("span", { className: "k-countdown__num", children: f(pad(v)) }), _jsx("span", { className: "k-countdown__name", children: name })] }, name))) }));
|
|
34
|
+
}
|
|
35
|
+
const clock = (d ? `${d}:` : "") + (h || d ? `${pad(h)}:` : "") + `${pad(m)}:${pad(s)}`;
|
|
36
|
+
return (_jsx("span", { role: "timer", "aria-label": ariaLabel ? `${ariaLabel}: ${spoken}` : spoken, className: cx("k-countdown", className), "data-done": left === 0 ? "" : undefined, dir: "ltr", children: _jsx("span", { "aria-hidden": "true", children: f(clock) }) }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type InputProps } from "./Input.js";
|
|
3
|
+
type Base = Omit<InputProps, "value" | "defaultValue" | "onChange" | "type" | "inputMode" | "addonEnd">;
|
|
4
|
+
export interface LandlineInputProps extends Base {
|
|
5
|
+
/** مثل "02188776655" یا "+982188776655" */
|
|
6
|
+
value?: string;
|
|
7
|
+
defaultValue?: string;
|
|
8
|
+
/** شماره به شکل ۰۲۱xxxxxxxx، معتبر بودن و نام استان */
|
|
9
|
+
onValueChange?: (value: string, valid: boolean, province: string | null) => void;
|
|
10
|
+
/** @default "fa" */
|
|
11
|
+
digits?: "fa" | "latin";
|
|
12
|
+
/** نمایش نام استان از روی پیششماره @default true */
|
|
13
|
+
showProvince?: boolean;
|
|
14
|
+
/** @default "شمارهٔ تلفن ثابت معتبر نیست." */
|
|
15
|
+
invalidMessage?: ReactNode;
|
|
16
|
+
}
|
|
17
|
+
/** تلفن ثابت با پیششماره: +98 را به ۰ تبدیل میکند، گروهبندی و نام استان را نشان میدهد */
|
|
18
|
+
export declare const LandlineInput: import("react").ForwardRefExoticComponent<LandlineInputProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useId, useState } from "react";
|
|
3
|
+
import { formatLandline, getLandlineProvince, isValidLandline, normalizeLandline } from "@kashi-ui/persian";
|
|
4
|
+
import { Input } from "./Input.js";
|
|
5
|
+
import { useDigitsInput } from "./useDigitsInput.js";
|
|
6
|
+
import { mergeRefs } from "./utils.js";
|
|
7
|
+
/** تلفن ثابت با پیششماره: +98 را به ۰ تبدیل میکند، گروهبندی و نام استان را نشان میدهد */
|
|
8
|
+
export const LandlineInput = forwardRef(function LandlineInput({ value, defaultValue, onValueChange, digits = "fa", showProvince = true, invalidMessage = "شمارهٔ تلفن ثابت معتبر نیست.", error, name, id, onBlur, placeholder, ...rest }, ref) {
|
|
9
|
+
const autoId = useId();
|
|
10
|
+
const inputId = id ?? autoId;
|
|
11
|
+
const [touched, setTouched] = useState(false);
|
|
12
|
+
const { raw, shown, inputRef, handleChange } = useDigitsInput({ value, defaultValue, maxDigits: 11, normalize: normalizeLandline, format: formatLandline, digits });
|
|
13
|
+
const province = showProvince ? getLandlineProvince(raw) : null;
|
|
14
|
+
const showInvalid = raw.length > 0 && (touched || raw.length === 11) && !isValidLandline(raw);
|
|
15
|
+
const provId = `${inputId}-province`;
|
|
16
|
+
return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: mergeRefs(ref, inputRef), id: inputId, type: "tel", inputMode: "tel", autoComplete: "tel-national", dir: "ltr", placeholder: placeholder ?? (digits === "fa" ? "۰۲۱ ۸۸۷۷ ۶۶۵۵" : "021 8877 6655"), value: shown, onChange: (e) => {
|
|
17
|
+
const next = handleChange(e);
|
|
18
|
+
onValueChange?.(next, isValidLandline(next), getLandlineProvince(next));
|
|
19
|
+
}, onBlur: (e) => {
|
|
20
|
+
setTouched(true);
|
|
21
|
+
onBlur?.(e);
|
|
22
|
+
}, addonEnd: province ? _jsx("span", { className: "k-input__meta", id: provId, children: province }) : undefined, "aria-describedby": province ? provId : undefined, error: error ?? (showInvalid ? invalidMessage : undefined), ...rest }), name && _jsx("input", { type: "hidden", name: name, value: raw })] }));
|
|
23
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface JalaliMonth {
|
|
2
|
+
year: number;
|
|
3
|
+
/** ۱ تا ۱۲ */
|
|
4
|
+
month: number;
|
|
5
|
+
}
|
|
6
|
+
export interface MonthPickerProps {
|
|
7
|
+
value?: JalaliMonth | null;
|
|
8
|
+
defaultValue?: JalaliMonth | null;
|
|
9
|
+
onChange?: (value: JalaliMonth) => void;
|
|
10
|
+
min?: JalaliMonth;
|
|
11
|
+
max?: JalaliMonth;
|
|
12
|
+
/** @default "fa" */
|
|
13
|
+
digits?: "fa" | "latin";
|
|
14
|
+
/** @default "انتخاب ماه" */
|
|
15
|
+
"aria-label"?: string;
|
|
16
|
+
className?: string;
|
|
17
|
+
labels?: {
|
|
18
|
+
prevYear?: string;
|
|
19
|
+
nextYear?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** انتخاب ماه و سال شمسی، برای گزارش ماهانه یا تاریخ انقضای کارت؛ ↑↓←→ بین ماهها و PageUp/PageDown بین سالها */
|
|
23
|
+
export declare function MonthPicker({ value, defaultValue, onChange, min, max, digits, "aria-label": ariaLabel, className, labels }: MonthPickerProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { JALALI_MONTHS, toFaDigits, toJalali } from "@kashi-ui/persian";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
const key = (m) => m.year * 12 + m.month;
|
|
6
|
+
const Arrow = ({ next }) => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", "data-k-mirror": "", children: _jsx("path", { d: next ? "m8 5 5 5-5 5" : "m12 5-5 5 5 5" }) }));
|
|
7
|
+
/** انتخاب ماه و سال شمسی، برای گزارش ماهانه یا تاریخ انقضای کارت؛ ↑↓←→ بین ماهها و PageUp/PageDown بین سالها */
|
|
8
|
+
export function MonthPicker({ value, defaultValue = null, onChange, min, max, digits = "fa", "aria-label": ariaLabel = "انتخاب ماه", className, labels = {} }) {
|
|
9
|
+
const { prevYear = "سال قبل", nextYear = "سال بعد" } = labels;
|
|
10
|
+
const today = toJalali(new Date());
|
|
11
|
+
const [inner, setInner] = useState(defaultValue);
|
|
12
|
+
const selected = value !== undefined ? value : inner;
|
|
13
|
+
const [year, setYear] = useState(selected?.year ?? today.jy);
|
|
14
|
+
const [focus, setFocus] = useState(selected?.year === year ? selected.month : today.jy === year ? today.jm : 1);
|
|
15
|
+
const grid = useRef(null);
|
|
16
|
+
// پس از رندر سال یا ماه تازه، فوکوس به همان ماه برود (با کیبورد)
|
|
17
|
+
const pendingFocus = useRef(false);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!pendingFocus.current)
|
|
20
|
+
return;
|
|
21
|
+
pendingFocus.current = false;
|
|
22
|
+
grid.current?.querySelector(`[data-month="${focus}"]`)?.focus();
|
|
23
|
+
}, [year, focus]);
|
|
24
|
+
const f = (n) => (digits === "fa" ? toFaDigits(String(n)) : String(n));
|
|
25
|
+
const out = (m) => (min && key(m) < key(min)) || (max && key(m) > key(max));
|
|
26
|
+
const pick = (m) => {
|
|
27
|
+
if (out(m))
|
|
28
|
+
return;
|
|
29
|
+
if (value === undefined)
|
|
30
|
+
setInner(m);
|
|
31
|
+
onChange?.(m);
|
|
32
|
+
};
|
|
33
|
+
const moveTo = (y, m) => {
|
|
34
|
+
pendingFocus.current = true;
|
|
35
|
+
setYear(y);
|
|
36
|
+
setFocus(m);
|
|
37
|
+
};
|
|
38
|
+
const onKeyDown = (e) => {
|
|
39
|
+
const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
|
|
40
|
+
const delta = { ArrowRight: rtl ? -1 : 1, ArrowLeft: rtl ? 1 : -1, ArrowDown: 3, ArrowUp: -3 };
|
|
41
|
+
let idx = year * 12 + focus - 1;
|
|
42
|
+
if (e.key in delta)
|
|
43
|
+
idx += delta[e.key];
|
|
44
|
+
else if (e.key === "PageUp")
|
|
45
|
+
idx -= 12;
|
|
46
|
+
else if (e.key === "PageDown")
|
|
47
|
+
idx += 12;
|
|
48
|
+
else if (e.key === "Home")
|
|
49
|
+
idx = year * 12;
|
|
50
|
+
else if (e.key === "End")
|
|
51
|
+
idx = year * 12 + 11;
|
|
52
|
+
else
|
|
53
|
+
return;
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
moveTo(Math.floor(idx / 12), (idx % 12) + 1);
|
|
56
|
+
};
|
|
57
|
+
return (_jsxs("div", { className: cx("k-monthpicker", className), role: "group", "aria-label": ariaLabel, children: [_jsxs("div", { className: "k-monthpicker__header", children: [_jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": prevYear, onClick: () => setYear(year - 1), disabled: !!min && year <= min.year, children: _jsx(Arrow, {}) }), _jsx("span", { className: "k-monthpicker__year", "aria-live": "polite", children: f(year) }), _jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": nextYear, onClick: () => setYear(year + 1), disabled: !!max && year >= max.year, children: _jsx(Arrow, { next: true }) })] }), _jsx("div", { className: "k-monthpicker__grid", ref: grid, onKeyDown: onKeyDown, children: JALALI_MONTHS.map((name, i) => {
|
|
58
|
+
const m = { year, month: i + 1 };
|
|
59
|
+
const isSel = selected?.year === year && selected.month === i + 1;
|
|
60
|
+
return (_jsx("button", { type: "button", "data-month": i + 1, className: "k-monthpicker__month", tabIndex: focus === i + 1 ? 0 : -1, "aria-pressed": isSel, "aria-label": `${name} ${f(year)}`, "aria-current": today.jy === year && today.jm === i + 1 ? "date" : undefined, disabled: !!out(m), onFocus: () => setFocus(i + 1), onClick: () => pick(m), children: name }, name));
|
|
61
|
+
}) })] }));
|
|
62
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface PasswordRule {
|
|
2
|
+
label: string;
|
|
3
|
+
test: (password: string) => boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare const defaultPasswordRules: PasswordRule[];
|
|
6
|
+
export interface PasswordStrengthProps {
|
|
7
|
+
password: string;
|
|
8
|
+
rules?: PasswordRule[];
|
|
9
|
+
/** نمایش فهرست شرطها @default true */
|
|
10
|
+
showRules?: boolean;
|
|
11
|
+
/** هشدار وقتی رمز حروف فارسی دارد (صفحهکلید فارسی مانده) @default true */
|
|
12
|
+
warnPersian?: boolean;
|
|
13
|
+
/** شناسهٔ این بخش، برای aria-describedby فیلد رمز */
|
|
14
|
+
id?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
labels?: {
|
|
17
|
+
title?: string;
|
|
18
|
+
levels?: [string, string, string, string];
|
|
19
|
+
persian?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** قدرت رمز عبور با نوار چهارقسمتی و فهرست شرطها؛ زیر فیلد رمز بگذارید و با id به آن وصل کنید */
|
|
23
|
+
export declare function PasswordStrength({ password, rules, showRules, warnPersian, id, className, labels }: PasswordStrengthProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { toFaDigits } from "@kashi-ui/persian";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
export const defaultPasswordRules = [
|
|
5
|
+
{ label: `حداقل ${toFaDigits(8)} نویسه`, test: (p) => p.length >= 8 },
|
|
6
|
+
{ label: "حروف بزرگ و کوچک انگلیسی", test: (p) => /[a-z]/.test(p) && /[A-Z]/.test(p) },
|
|
7
|
+
{ label: "دستکم یک عدد", test: (p) => /\d/.test(p) },
|
|
8
|
+
{ label: "دستکم یک نماد، مثل ! یا @", test: (p) => /[^A-Za-z0-9\s-ۿ]/.test(p) },
|
|
9
|
+
];
|
|
10
|
+
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" }) });
|
|
11
|
+
const Dot = () => _jsx("svg", { viewBox: "0 0 20 20", "aria-hidden": "true", children: _jsx("circle", { cx: "10", cy: "10", r: "2.5", fill: "currentColor" }) });
|
|
12
|
+
/** قدرت رمز عبور با نوار چهارقسمتی و فهرست شرطها؛ زیر فیلد رمز بگذارید و با id به آن وصل کنید */
|
|
13
|
+
export function PasswordStrength({ password, rules = defaultPasswordRules, showRules = true, warnPersian = true, id, className, labels = {} }) {
|
|
14
|
+
const { title = "قدرت رمز", levels = ["ضعیف", "متوسط", "خوب", "قوی"], persian = "رمز حروف فارسی دارد؛ شاید صفحهکلید روی فارسی مانده است." } = labels;
|
|
15
|
+
const met = rules.map((r) => r.test(password));
|
|
16
|
+
const n = met.filter(Boolean).length;
|
|
17
|
+
// امتیاز ۰ تا ۴ به نسبت شرطهای برآوردهشده
|
|
18
|
+
const score = password ? Math.max(1, Math.round((n / rules.length) * 4)) : 0;
|
|
19
|
+
const persianTyped = warnPersian && /[-ۿ]/.test(password);
|
|
20
|
+
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] ? "، رعایت شده" : "، رعایت نشده" })] })] }, r.label))) }))] }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface TreeNode {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
icon?: ReactNode;
|
|
6
|
+
/** متن کوچک انتهای ردیف، مثل تعداد یا حجم */
|
|
7
|
+
meta?: ReactNode;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
children?: TreeNode[];
|
|
10
|
+
}
|
|
11
|
+
export interface TreeViewProps {
|
|
12
|
+
items: TreeNode[];
|
|
13
|
+
selected?: string | null;
|
|
14
|
+
defaultSelected?: string | null;
|
|
15
|
+
onSelect?: (id: string, node: TreeNode) => void;
|
|
16
|
+
expanded?: string[];
|
|
17
|
+
defaultExpanded?: string[];
|
|
18
|
+
onExpandedChange?: (ids: string[]) => void;
|
|
19
|
+
"aria-label"?: string;
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* درخت پوشهها یا دستهبندیها با الگوی Tree در WAI-ARIA:
|
|
24
|
+
* ↑↓ حرکت، → و ← (در RTL برعکس) باز و بسته کردن، Home/End، Enter یا Space انتخاب.
|
|
25
|
+
*/
|
|
26
|
+
export declare function TreeView({ items, selected, defaultSelected, onSelect, expanded, defaultExpanded, onExpandedChange, "aria-label": ariaLabel, className }: TreeViewProps): import("react").JSX.Element;
|
package/dist/TreeView.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
const Chevron = () => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m8 5 5 5-5 5" }) });
|
|
5
|
+
/**
|
|
6
|
+
* درخت پوشهها یا دستهبندیها با الگوی Tree در WAI-ARIA:
|
|
7
|
+
* ↑↓ حرکت، → و ← (در RTL برعکس) باز و بسته کردن، Home/End، Enter یا Space انتخاب.
|
|
8
|
+
*/
|
|
9
|
+
export function TreeView({ items, selected, defaultSelected = null, onSelect, expanded, defaultExpanded = [], onExpandedChange, "aria-label": ariaLabel, className }) {
|
|
10
|
+
const [innerSel, setInnerSel] = useState(defaultSelected);
|
|
11
|
+
const [innerExp, setInnerExp] = useState(defaultExpanded);
|
|
12
|
+
const sel = selected !== undefined ? selected : innerSel;
|
|
13
|
+
const exp = expanded ?? innerExp;
|
|
14
|
+
const [focusId, setFocusId] = useState(null);
|
|
15
|
+
const root = useRef(null);
|
|
16
|
+
// ردیفهای قابلمشاهده به ترتیب، برای پیمایش با کیبورد
|
|
17
|
+
const visible = [];
|
|
18
|
+
const walk = (nodes, level, parent) => {
|
|
19
|
+
for (const n of nodes) {
|
|
20
|
+
visible.push({ node: n, level, parent });
|
|
21
|
+
if (n.children?.length && exp.includes(n.id))
|
|
22
|
+
walk(n.children, level + 1, n.id);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
walk(items, 1, null);
|
|
26
|
+
const current = focusId && visible.some((v) => v.node.id === focusId) ? focusId : sel && visible.some((v) => v.node.id === sel) ? sel : visible[0]?.node.id;
|
|
27
|
+
const setExp = (ids) => {
|
|
28
|
+
if (expanded === undefined)
|
|
29
|
+
setInnerExp(ids);
|
|
30
|
+
onExpandedChange?.(ids);
|
|
31
|
+
};
|
|
32
|
+
const toggle = (id, open = !exp.includes(id)) => setExp(open ? [...new Set([...exp, id])] : exp.filter((x) => x !== id));
|
|
33
|
+
const choose = (n) => {
|
|
34
|
+
if (n.disabled)
|
|
35
|
+
return;
|
|
36
|
+
if (selected === undefined)
|
|
37
|
+
setInnerSel(n.id);
|
|
38
|
+
onSelect?.(n.id, n);
|
|
39
|
+
};
|
|
40
|
+
const focus = (id) => {
|
|
41
|
+
setFocusId(id);
|
|
42
|
+
root.current?.querySelector(`[data-id="${CSS.escape(id)}"]`)?.focus();
|
|
43
|
+
};
|
|
44
|
+
const onKeyDown = (e) => {
|
|
45
|
+
const i = visible.findIndex((v) => v.node.id === current);
|
|
46
|
+
const v = visible[i];
|
|
47
|
+
if (!v)
|
|
48
|
+
return;
|
|
49
|
+
const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
|
|
50
|
+
const inKey = rtl ? "ArrowLeft" : "ArrowRight";
|
|
51
|
+
const outKey = rtl ? "ArrowRight" : "ArrowLeft";
|
|
52
|
+
const hasKids = !!v.node.children?.length;
|
|
53
|
+
const open = exp.includes(v.node.id);
|
|
54
|
+
let handled = true;
|
|
55
|
+
if (e.key === "ArrowDown")
|
|
56
|
+
visible[i + 1] && focus(visible[i + 1].node.id);
|
|
57
|
+
else if (e.key === "ArrowUp")
|
|
58
|
+
visible[i - 1] && focus(visible[i - 1].node.id);
|
|
59
|
+
else if (e.key === "Home")
|
|
60
|
+
focus(visible[0].node.id);
|
|
61
|
+
else if (e.key === "End")
|
|
62
|
+
focus(visible[visible.length - 1].node.id);
|
|
63
|
+
else if (e.key === inKey) {
|
|
64
|
+
if (hasKids && !open)
|
|
65
|
+
toggle(v.node.id, true);
|
|
66
|
+
else if (hasKids)
|
|
67
|
+
focus(v.node.children[0].id);
|
|
68
|
+
}
|
|
69
|
+
else if (e.key === outKey) {
|
|
70
|
+
if (hasKids && open)
|
|
71
|
+
toggle(v.node.id, false);
|
|
72
|
+
else if (v.parent)
|
|
73
|
+
focus(v.parent);
|
|
74
|
+
}
|
|
75
|
+
else if (e.key === "Enter" || e.key === " ")
|
|
76
|
+
choose(v.node);
|
|
77
|
+
else
|
|
78
|
+
handled = false;
|
|
79
|
+
if (handled)
|
|
80
|
+
e.preventDefault();
|
|
81
|
+
};
|
|
82
|
+
const render = (nodes, level) => nodes.map((n) => {
|
|
83
|
+
const hasKids = !!n.children?.length;
|
|
84
|
+
const open = exp.includes(n.id);
|
|
85
|
+
return (_jsxs("li", { role: "treeitem", "data-id": n.id, className: "k-tree__item", "aria-level": level, "aria-expanded": hasKids ? open : undefined, "aria-selected": sel === n.id, "aria-disabled": n.disabled || undefined, tabIndex: current === n.id ? 0 : -1, onFocus: (e) => {
|
|
86
|
+
if (e.target === e.currentTarget)
|
|
87
|
+
setFocusId(n.id);
|
|
88
|
+
}, children: [_jsxs("div", { className: "k-tree__row", onClick: () => {
|
|
89
|
+
if (hasKids)
|
|
90
|
+
toggle(n.id);
|
|
91
|
+
choose(n);
|
|
92
|
+
focus(n.id);
|
|
93
|
+
}, children: [hasKids ? _jsx("span", { className: "k-tree__toggle", "aria-hidden": "true", children: _jsx(Chevron, {}) }) : _jsx("span", { className: "k-tree__spacer" }), n.icon && _jsx("span", { className: "k-tree__icon", "aria-hidden": "true", children: n.icon }), _jsx("span", { className: "k-tree__label", children: n.label }), n.meta && _jsx("span", { className: "k-tree__meta", children: n.meta })] }), hasKids && open && _jsx("ul", { role: "group", children: render(n.children, level + 1) })] }, n.id));
|
|
94
|
+
});
|
|
95
|
+
return (_jsx("ul", { ref: root, role: "tree", "aria-label": ariaLabel, className: cx("k-tree", className), onKeyDown: onKeyDown, children: render(items, 1) }));
|
|
96
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -98,3 +98,17 @@ export { PostalCodeInput } from "./PostalCodeInput.js";
|
|
|
98
98
|
export type { PostalCodeInputProps } from "./PostalCodeInput.js";
|
|
99
99
|
export { PlateInput } from "./PlateInput.js";
|
|
100
100
|
export type { PlateInputProps } from "./PlateInput.js";
|
|
101
|
+
export { TreeView } from "./TreeView.js";
|
|
102
|
+
export type { TreeNode, TreeViewProps } from "./TreeView.js";
|
|
103
|
+
export { ButtonGroup } from "./ButtonGroup.js";
|
|
104
|
+
export type { ButtonGroupProps } from "./ButtonGroup.js";
|
|
105
|
+
export { ChipGroup } from "./ChipGroup.js";
|
|
106
|
+
export type { ChipOption, ChipGroupProps } from "./ChipGroup.js";
|
|
107
|
+
export { PasswordStrength, defaultPasswordRules } from "./PasswordStrength.js";
|
|
108
|
+
export type { PasswordRule, PasswordStrengthProps } from "./PasswordStrength.js";
|
|
109
|
+
export { Countdown } from "./Countdown.js";
|
|
110
|
+
export type { CountdownProps } from "./Countdown.js";
|
|
111
|
+
export { MonthPicker } from "./MonthPicker.js";
|
|
112
|
+
export type { JalaliMonth, MonthPickerProps } from "./MonthPicker.js";
|
|
113
|
+
export { LandlineInput } from "./LandlineInput.js";
|
|
114
|
+
export type { LandlineInputProps } from "./LandlineInput.js";
|
package/dist/index.js
CHANGED
|
@@ -49,3 +49,10 @@ export { Rating } from "./Rating.js";
|
|
|
49
49
|
export { TimeInput } from "./TimeInput.js";
|
|
50
50
|
export { PostalCodeInput } from "./PostalCodeInput.js";
|
|
51
51
|
export { PlateInput } from "./PlateInput.js";
|
|
52
|
+
export { TreeView } from "./TreeView.js";
|
|
53
|
+
export { ButtonGroup } from "./ButtonGroup.js";
|
|
54
|
+
export { ChipGroup } from "./ChipGroup.js";
|
|
55
|
+
export { PasswordStrength, defaultPasswordRules } from "./PasswordStrength.js";
|
|
56
|
+
export { Countdown } from "./Countdown.js";
|
|
57
|
+
export { MonthPicker } from "./MonthPicker.js";
|
|
58
|
+
export { LandlineInput } from "./LandlineInput.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kashi-ui/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "کامپوننتهای React دیزاینسیستم کاشی",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"test": "node --test test/*.test.mjs"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@kashi-ui/css": "^0.
|
|
25
|
+
"@kashi-ui/css": "^0.11.0",
|
|
26
26
|
"react": ">=18"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@kashi-ui/bank-logos": "^0.
|
|
63
|
-
"@kashi-ui/persian": "^0.
|
|
62
|
+
"@kashi-ui/bank-logos": "^0.11.0",
|
|
63
|
+
"@kashi-ui/persian": "^0.11.0"
|
|
64
64
|
}
|
|
65
65
|
}
|