@kashi-ui/react 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +2 -2
  2. package/dist/Accordion.d.ts +15 -0
  3. package/dist/Accordion.js +13 -0
  4. package/dist/Alert.d.ts +11 -0
  5. package/dist/Alert.js +2 -2
  6. package/dist/Avatar.d.ts +6 -0
  7. package/dist/Avatar.js +11 -2
  8. package/dist/Badge.d.ts +9 -1
  9. package/dist/Badge.js +3 -2
  10. package/dist/Breadcrumb.d.ts +23 -0
  11. package/dist/Breadcrumb.js +32 -0
  12. package/dist/Button.d.ts +15 -4
  13. package/dist/Button.js +12 -2
  14. package/dist/Card.d.ts +17 -3
  15. package/dist/Card.js +13 -4
  16. package/dist/Checkbox.d.ts +9 -0
  17. package/dist/Checkbox.js +6 -6
  18. package/dist/DataTable.d.ts +70 -0
  19. package/dist/DataTable.js +59 -0
  20. package/dist/Dialog.d.ts +4 -2
  21. package/dist/Dialog.js +2 -2
  22. package/dist/DropdownMenu.d.ts +35 -0
  23. package/dist/DropdownMenu.js +99 -0
  24. package/dist/Field.d.ts +15 -1
  25. package/dist/Field.js +4 -2
  26. package/dist/Input.d.ts +34 -0
  27. package/dist/Input.js +57 -6
  28. package/dist/Misc.d.ts +22 -0
  29. package/dist/Misc.js +16 -0
  30. package/dist/OtpInput.d.ts +28 -0
  31. package/dist/OtpInput.js +30 -0
  32. package/dist/Pagination.d.ts +25 -0
  33. package/dist/Pagination.js +28 -0
  34. package/dist/Progress.d.ts +24 -0
  35. package/dist/Progress.js +20 -0
  36. package/dist/Skeleton.d.ts +11 -0
  37. package/dist/Skeleton.js +11 -0
  38. package/dist/Stepper.d.ts +20 -0
  39. package/dist/Stepper.js +12 -0
  40. package/dist/Tabs.d.ts +5 -1
  41. package/dist/Tabs.js +8 -9
  42. package/dist/Toast.d.ts +22 -8
  43. package/dist/Toast.js +55 -12
  44. package/dist/Tooltip.d.ts +2 -2
  45. package/dist/Tooltip.js +1 -1
  46. package/dist/index.d.ts +26 -6
  47. package/dist/index.js +12 -2
  48. package/package.json +4 -4
@@ -0,0 +1,99 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Children, cloneElement, createContext, isValidElement, useContext, useEffect, useId, useRef, useState, } from "react";
3
+ import { cx } from "./cx.js";
4
+ const MenuCtx = createContext(null);
5
+ const items = (menu) => [...(menu?.querySelectorAll('[role^="menuitem"]:not([aria-disabled="true"])') ?? [])];
6
+ /**
7
+ * منوی کشویی با الگوی Menu Button در WAI-ARIA:
8
+ * Enter، Space یا ↓ باز می‌کند و اولین گزینه را فوکوس می‌کند، ↑ آخرین را؛
9
+ * ↑↓ و Home/End حرکت، حرف اول برای پرش، Esc بستن و برگشت به دکمه، Tab بستن.
10
+ */
11
+ export function DropdownMenu({ trigger, label, align = "start", children }) {
12
+ const id = useId();
13
+ const [open, setOpen] = useState(false);
14
+ const focusOnOpen = useRef("first");
15
+ const triggerRef = useRef(null);
16
+ const menuRef = useRef(null);
17
+ const anchorRef = useRef(null);
18
+ const close = (focusTrigger = true) => {
19
+ setOpen(false);
20
+ if (focusTrigger)
21
+ triggerRef.current?.focus();
22
+ };
23
+ useEffect(() => {
24
+ if (!open)
25
+ return;
26
+ const list = items(menuRef.current);
27
+ (focusOnOpen.current === "last" ? list[list.length - 1] : list[0])?.focus();
28
+ const onDown = (e) => {
29
+ if (!anchorRef.current?.contains(e.target))
30
+ setOpen(false);
31
+ };
32
+ document.addEventListener("pointerdown", onDown);
33
+ return () => document.removeEventListener("pointerdown", onDown);
34
+ }, [open]);
35
+ const openWith = (where) => {
36
+ focusOnOpen.current = where;
37
+ setOpen(true);
38
+ };
39
+ const onMenuKey = (e) => {
40
+ const list = items(menuRef.current);
41
+ const i = list.indexOf(document.activeElement);
42
+ const go = (j) => list[(j + list.length) % list.length]?.focus();
43
+ if (e.key === "ArrowDown")
44
+ go(i + 1);
45
+ else if (e.key === "ArrowUp")
46
+ go(i - 1);
47
+ else if (e.key === "Home")
48
+ go(0);
49
+ else if (e.key === "End")
50
+ go(list.length - 1);
51
+ else if (e.key === "Escape")
52
+ close();
53
+ else if (e.key === "Tab")
54
+ return setOpen(false);
55
+ else if (e.key.length === 1 && /\S/.test(e.key)) {
56
+ // پرش با حرف اول
57
+ const k = e.key.toLowerCase();
58
+ const start = i + 1;
59
+ const hit = [...list.slice(start), ...list.slice(0, start)].find((el) => el.textContent?.trim().toLowerCase().startsWith(k));
60
+ hit?.focus();
61
+ }
62
+ else
63
+ return;
64
+ e.preventDefault();
65
+ };
66
+ const t = isValidElement(trigger)
67
+ ? cloneElement(trigger, {
68
+ ref: triggerRef,
69
+ id: `${id}-trigger`,
70
+ "aria-haspopup": "menu",
71
+ "aria-expanded": open,
72
+ "aria-controls": open ? `${id}-menu` : undefined,
73
+ onClick: () => (open ? close(false) : openWith("first")),
74
+ onKeyDown: (e) => {
75
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
76
+ e.preventDefault();
77
+ openWith(e.key === "ArrowUp" ? "last" : "first");
78
+ }
79
+ },
80
+ })
81
+ : trigger;
82
+ return (_jsxs("span", { className: "k-menu-anchor", ref: anchorRef, children: [t, _jsx(MenuCtx.Provider, { value: { close }, children: _jsx("ul", { ref: menuRef, id: `${id}-menu`, role: "menu", "aria-label": label, "aria-labelledby": label ? undefined : `${id}-trigger`, className: cx("k-menu", align === "end" && "k-menu--end"), hidden: !open, onKeyDown: onMenuKey, children: Children.map(children, (c) => c) }) })] }));
83
+ }
84
+ export function MenuItem({ onSelect, icon, shortcut, tone = "default", disabled, href, checked, children }) {
85
+ const checkable = checked !== undefined;
86
+ const ctx = useContext(MenuCtx);
87
+ const cls = cx("k-menu__item", tone === "danger" && "k-menu__item--danger");
88
+ const content = (_jsxs(_Fragment, { children: [checkable && (_jsx("span", { className: "k-menu__check", "aria-hidden": "true", children: checked && _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", children: _jsx("path", { d: "m5 10.5 3.2 3L15 7" }) }) })), icon, _jsx("span", { children: children }), shortcut && _jsx("span", { className: "k-menu__shortcut", "aria-hidden": "true", children: shortcut })] }));
89
+ const select = () => {
90
+ if (disabled)
91
+ return;
92
+ onSelect?.();
93
+ if (!checkable)
94
+ ctx?.close();
95
+ };
96
+ return (_jsx("li", { role: "none", children: href && !disabled ? (_jsx("a", { role: "menuitem", tabIndex: -1, className: cls, href: href, onClick: () => ctx?.close(false), children: content })) : (_jsx("button", { type: "button", role: checkable ? "menuitemcheckbox" : "menuitem", "aria-checked": checkable ? checked : undefined, tabIndex: -1, className: cls, "aria-disabled": disabled || undefined, onClick: select, children: content })) }));
97
+ }
98
+ export const MenuSeparator = () => _jsx("li", { role: "separator", className: "k-menu__separator" });
99
+ export const MenuLabel = ({ children }) => _jsx("li", { role: "presentation", className: "k-menu__label", children: children });
package/dist/Field.d.ts CHANGED
@@ -1,11 +1,25 @@
1
1
  import { type ReactNode } from "react";
2
+ /** کلاس دلخواه برای هر بخش داخلی فیلد */
3
+ export interface FieldClassNames {
4
+ root?: string;
5
+ label?: string;
6
+ hint?: string;
7
+ error?: string;
8
+ }
2
9
  export interface FieldProps {
3
10
  id: string;
4
11
  label?: ReactNode;
5
12
  hint?: ReactNode;
6
13
  error?: ReactNode;
7
14
  required?: boolean;
15
+ /** نشان «اختیاری» کنار برچسب */
16
+ optional?: boolean | string;
17
+ /** محتوای انتهای ردیف برچسب، مثل شمارندهٔ نویسه یا لینک «فراموشی رمز» */
18
+ labelEnd?: ReactNode;
19
+ /** محتوای انتهای ردیف راهنما، مثل شمارنده */
20
+ hintEnd?: ReactNode;
8
21
  className?: string;
22
+ classNames?: FieldClassNames;
9
23
  children: ReactNode;
10
24
  }
11
25
  /** شناسهٔ متن‌های راهنما و خطا برای aria-describedby */
@@ -13,4 +27,4 @@ export declare const hintId: (id: string) => string;
13
27
  export declare const errorId: (id: string) => string;
14
28
  export declare function describedBy(id: string, hint: unknown, error: unknown, extra?: string): string | undefined;
15
29
  /** قالب مشترک برچسب + کنترل + راهنما/خطا */
16
- export declare function Field({ id, label, hint, error, required, className, children }: FieldProps): import("react").JSX.Element;
30
+ export declare function Field({ id, label, hint, error, required, optional, labelEnd, hintEnd, className, classNames, children }: FieldProps): import("react").JSX.Element;
package/dist/Field.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
2
3
  /** شناسهٔ متن‌های راهنما و خطا برای aria-describedby */
3
4
  export const hintId = (id) => `${id}-hint`;
4
5
  export const errorId = (id) => `${id}-error`;
@@ -6,6 +7,7 @@ export function describedBy(id, hint, error, extra) {
6
7
  return [extra, error ? errorId(id) : null, hint ? hintId(id) : null].filter(Boolean).join(" ") || undefined;
7
8
  }
8
9
  /** قالب مشترک برچسب + کنترل + راهنما/خطا */
9
- export function Field({ id, label, hint, error, required, className, children }) {
10
- return (_jsxs("div", { className: className ? `k-field ${className}` : "k-field", children: [label && (_jsxs("label", { className: "k-label", htmlFor: id, children: [label, required && _jsx("span", { className: "k-label__required", "aria-hidden": "true", children: "*" })] })), children, error && _jsx("p", { className: "k-hint k-hint--error", id: errorId(id), children: error }), hint && _jsx("p", { className: "k-hint", id: hintId(id), children: hint })] }));
10
+ export function Field({ id, label, hint, error, required, optional, labelEnd, hintEnd, className, classNames = {}, children }) {
11
+ const optionalText = optional === true ? "اختیاری" : optional;
12
+ return (_jsxs("div", { className: cx("k-field", className, classNames.root), "data-invalid": error ? "" : undefined, children: [(label || labelEnd) && (_jsxs("div", { className: "k-field__label-row", children: [label && (_jsxs("label", { className: cx("k-label", classNames.label), htmlFor: id, children: [label, required && _jsx("span", { className: "k-label__required", "aria-hidden": "true", children: "*" }), optionalText && _jsx("span", { className: "k-label__optional", children: optionalText })] })), labelEnd && _jsx("span", { className: "k-field__label-end", children: labelEnd })] })), children, (error || hint || hintEnd) && (_jsxs("div", { className: "k-field__hint-row", children: [_jsxs("div", { className: "k-field__hints", children: [error && _jsx("p", { className: cx("k-hint k-hint--error", classNames.error), id: errorId(id), children: error }), hint && _jsx("p", { className: cx("k-hint", classNames.hint), id: hintId(id), children: hint })] }), hintEnd] }))] }));
11
13
  }
package/dist/Input.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  import { type InputHTMLAttributes, type ReactNode, type TextareaHTMLAttributes } from "react";
2
+ import { type FieldClassNames } from "./Field.js";
2
3
  export type InputSize = "sm" | "md" | "lg";
4
+ /** کلاس دلخواه برای هر بخش داخلی فیلد */
5
+ export interface InputClassNames extends FieldClassNames {
6
+ /** کادر دور فیلد (k-input) */
7
+ box?: string;
8
+ /** خود input یا textarea */
9
+ control?: string;
10
+ addon?: string;
11
+ }
3
12
  interface FieldOwnProps {
4
13
  /** برچسب بالای فیلد — اگر نمی‌دهید حتماً aria-label بدهید */
5
14
  label?: ReactNode;
@@ -7,8 +16,15 @@ interface FieldOwnProps {
7
16
  hint?: ReactNode;
8
17
  /** پیام خطا؛ فیلد را aria-invalid می‌کند */
9
18
  error?: ReactNode;
19
+ /** نشان «اختیاری» کنار برچسب؛ رشته برای متن دلخواه */
20
+ optional?: boolean | string;
21
+ /** محتوای انتهای ردیف برچسب، مثل لینک «فراموشی رمز» */
22
+ labelEnd?: ReactNode;
23
+ /** نمایش شمارندهٔ نویسه؛ با maxLength به شکل «۱۲ / ۱۰۰» */
24
+ showCount?: boolean;
10
25
  /** کلاس روی ظرف بیرونی (k-field) */
11
26
  fieldClassName?: string;
27
+ classNames?: InputClassNames;
12
28
  }
13
29
  export interface InputProps extends FieldOwnProps, Omit<InputHTMLAttributes<HTMLInputElement>, "size"> {
14
30
  /** @default "md" */
@@ -17,9 +33,27 @@ export interface InputProps extends FieldOwnProps, Omit<InputHTMLAttributes<HTML
17
33
  addonStart?: ReactNode;
18
34
  /** آیکون یا متن انتهای فیلد */
19
35
  addonEnd?: ReactNode;
36
+ /** دکمهٔ پاک کردن وقتی فیلد مقدار دارد */
37
+ clearable?: boolean;
38
+ /** پس از پاک کردن */
39
+ onClear?: () => void;
40
+ /** برای type="password": دکمهٔ نمایش و پنهان کردن رمز @default true */
41
+ revealable?: boolean;
42
+ /** اسپینر در انتهای فیلد، مثلاً هنگام بررسی نام کاربری */
43
+ loading?: boolean;
44
+ labels?: {
45
+ clear?: string;
46
+ show?: string;
47
+ hide?: string;
48
+ loading?: string;
49
+ };
20
50
  }
21
51
  export declare const Input: import("react").ForwardRefExoticComponent<InputProps & import("react").RefAttributes<HTMLInputElement>>;
22
52
  export interface TextareaProps extends FieldOwnProps, TextareaHTMLAttributes<HTMLTextAreaElement> {
53
+ /** ارتفاع خودکار بر اساس متن */
54
+ autoResize?: boolean;
55
+ /** بیشترین تعداد خط در autoResize */
56
+ maxRows?: number;
23
57
  }
24
58
  export declare const Textarea: import("react").ForwardRefExoticComponent<TextareaProps & import("react").RefAttributes<HTMLTextAreaElement>>;
25
59
  export {};
package/dist/Input.js CHANGED
@@ -1,14 +1,65 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useId } from "react";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { forwardRef, useId, useRef, useState, } from "react";
3
+ import { toFaDigits } from "@kashi-ui/persian";
3
4
  import { cx } from "./cx.js";
4
5
  import { Field, describedBy } from "./Field.js";
5
- export const Input = forwardRef(function Input({ label, hint, error, size = "md", addonStart, addonEnd, required, id, className, fieldClassName, "aria-describedby": ariaDescribedBy, ...rest }, ref) {
6
+ import { mergeRefs, useIsomorphicLayoutEffect } from "./utils.js";
7
+ const Eye = ({ off }) => (_jsxs("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M1.8 10S4.8 4.5 10 4.5 18.2 10 18.2 10 15.2 15.5 10 15.5 1.8 10 1.8 10Z" }), _jsx("circle", { cx: "10", cy: "10", r: "2.5" }), off && _jsx("path", { d: "m3 3 14 14" })] }));
8
+ const X = () => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 6 8 8M14 6l-8 8" }) }));
9
+ /** طول متن فعلی، برای کنترل‌شده و کنترل‌نشده */
10
+ function useLength(value, defaultValue) {
11
+ const [len, setLen] = useState(() => String(defaultValue ?? "").length);
12
+ const controlled = value !== undefined;
13
+ return [controlled ? String(value ?? "").length : len, (e) => !controlled && setLen(e.target.value.length)];
14
+ }
15
+ /** مقدار input را از بیرون عوض می‌کند و رویداد input می‌فرستد تا onChange در React هم اجرا شود */
16
+ function setNativeValue(el, value) {
17
+ const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
18
+ Object.getOwnPropertyDescriptor(proto, "value")?.set?.call(el, value);
19
+ el.dispatchEvent(new Event("input", { bubbles: true }));
20
+ }
21
+ function Counter({ id, length, max }) {
22
+ return (_jsx("span", { className: "k-counter", id: id, "data-over": max !== undefined && length > max ? "" : undefined, children: max !== undefined ? `${toFaDigits(length)} / ${toFaDigits(max)}` : toFaDigits(length) }));
23
+ }
24
+ export const Input = forwardRef(function Input({ label, hint, error, optional, labelEnd, showCount, size = "md", addonStart, addonEnd, clearable, onClear, revealable = true, loading, labels = {}, required, id, type = "text", className, fieldClassName, classNames = {}, "aria-describedby": ariaDescribedBy, onChange, value, defaultValue, maxLength, disabled, readOnly, ...rest }, ref) {
6
25
  const autoId = useId();
7
26
  const inputId = id ?? autoId;
8
- return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, required: required, className: fieldClassName, children: _jsxs("div", { className: cx("k-input", size !== "md" && `k-input--${size}`, className), children: [addonStart && _jsx("span", { className: "k-input__addon", children: addonStart }), _jsx("input", { ref: ref, id: inputId, className: "k-input__control", required: required, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error, ariaDescribedBy), ...rest }), addonEnd && _jsx("span", { className: "k-input__addon", children: addonEnd })] }) }));
27
+ const inner = useRef(null);
28
+ const [revealed, setRevealed] = useState(false);
29
+ const [length, trackLength] = useLength(value, defaultValue);
30
+ const isPassword = type === "password";
31
+ const { clear = "پاک کردن", show = "نمایش رمز", hide = "پنهان کردن رمز", loading: loadingLabel = "در حال بررسی" } = labels;
32
+ const counterId = `${inputId}-count`;
33
+ const canClear = clearable && length > 0 && !disabled && !readOnly;
34
+ const end = (_jsxs(_Fragment, { children: [loading && _jsx("span", { className: "k-input__addon", children: _jsx("span", { className: "k-spinner k-spinner--sm", role: "status", "aria-label": loadingLabel }) }), canClear && (_jsx("button", { type: "button", className: "k-input__action", "aria-label": clear, onClick: () => {
35
+ if (inner.current)
36
+ setNativeValue(inner.current, "");
37
+ inner.current?.focus();
38
+ onClear?.();
39
+ }, children: _jsx(X, {}) })), isPassword && revealable && (_jsx("button", { type: "button", className: "k-input__action", "aria-label": revealed ? hide : show, "aria-pressed": revealed, onClick: () => setRevealed((r) => !r), children: _jsx(Eye, { off: revealed }) })), addonEnd && _jsx("span", { className: cx("k-input__addon", classNames.addon), children: addonEnd })] }));
40
+ return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, required: required, optional: optional, labelEnd: labelEnd, hintEnd: showCount ? _jsx(Counter, { id: counterId, length: length, max: maxLength }) : undefined, className: fieldClassName, classNames: classNames, children: _jsxs("div", { className: cx("k-input", size !== "md" && `k-input--${size}`, className, classNames.box), "data-size": size, "data-state": disabled ? "disabled" : error ? "invalid" : undefined, children: [addonStart && _jsx("span", { className: cx("k-input__addon", classNames.addon), children: addonStart }), _jsx("input", { ref: mergeRefs(ref, inner), id: inputId, className: cx("k-input__control", classNames.control), type: isPassword && revealed ? "text" : type, required: required, value: value, defaultValue: defaultValue, maxLength: maxLength, disabled: disabled, readOnly: readOnly, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error, [ariaDescribedBy, showCount ? counterId : undefined].filter(Boolean).join(" ") || undefined), onChange: (e) => {
41
+ trackLength(e);
42
+ onChange?.(e);
43
+ }, ...rest }), end] }) }));
9
44
  });
10
- export const Textarea = forwardRef(function Textarea({ label, hint, error, required, id, className, fieldClassName, "aria-describedby": ariaDescribedBy, ...rest }, ref) {
45
+ export const Textarea = forwardRef(function Textarea({ label, hint, error, optional, labelEnd, showCount, autoResize, maxRows, required, id, className, fieldClassName, classNames = {}, "aria-describedby": ariaDescribedBy, onChange, value, defaultValue, maxLength, rows = 4, style, ...rest }, ref) {
11
46
  const autoId = useId();
12
47
  const inputId = id ?? autoId;
13
- return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, required: required, className: fieldClassName, children: _jsx("div", { className: cx("k-input", "k-input--textarea", className), children: _jsx("textarea", { ref: ref, id: inputId, className: "k-input__control", required: required, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error, ariaDescribedBy), ...rest }) }) }));
48
+ const inner = useRef(null);
49
+ const [length, trackLength] = useLength(value, defaultValue);
50
+ const counterId = `${inputId}-count`;
51
+ // ارتفاع خودکار: در مرورگرهای جدید با field-sizing، وگرنه با اندازه‌گیری scrollHeight
52
+ const resize = () => {
53
+ const el = inner.current;
54
+ if (!el || !autoResize || CSS.supports?.("field-sizing", "content"))
55
+ return;
56
+ el.style.blockSize = "auto";
57
+ el.style.blockSize = `${el.scrollHeight}px`;
58
+ };
59
+ useIsomorphicLayoutEffect(resize, [value, autoResize]);
60
+ return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, required: required, optional: optional, labelEnd: labelEnd, hintEnd: showCount ? _jsx(Counter, { id: counterId, length: length, max: maxLength }) : undefined, className: fieldClassName, classNames: classNames, children: _jsx("div", { className: cx("k-input", "k-input--textarea", autoResize && "k-input--autoresize", className, classNames.box), "data-state": error ? "invalid" : undefined, children: _jsx("textarea", { ref: mergeRefs(ref, inner), id: inputId, className: cx("k-input__control", classNames.control), required: required, rows: rows, value: value, defaultValue: defaultValue, maxLength: maxLength, style: maxRows ? { ...style, maxBlockSize: `${maxRows * 1.75 + 0.25}em` } : style, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error, [ariaDescribedBy, showCount ? counterId : undefined].filter(Boolean).join(" ") || undefined), onChange: (e) => {
61
+ trackLength(e);
62
+ onChange?.(e);
63
+ resize();
64
+ }, ...rest }) }) }));
14
65
  });
package/dist/Misc.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { HTMLAttributes, ReactNode } from "react";
2
+ export interface DividerProps extends HTMLAttributes<HTMLDivElement> {
3
+ /** متن وسط خط، مثل «یا» */
4
+ label?: ReactNode;
5
+ vertical?: boolean;
6
+ }
7
+ export declare function Divider({ label, vertical, className, ...rest }: DividerProps): import("react").JSX.Element;
8
+ export interface KbdProps extends HTMLAttributes<HTMLElement> {
9
+ /** چند کلید، مثل ["Ctrl", "K"] */
10
+ keys?: string[];
11
+ }
12
+ /** کلید صفحه‌کلید */
13
+ export declare function Kbd({ keys, children, className, ...rest }: KbdProps): import("react").JSX.Element;
14
+ export interface EmptyStateProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
15
+ title: ReactNode;
16
+ description?: ReactNode;
17
+ icon?: ReactNode;
18
+ /** دکمه‌ها */
19
+ actions?: ReactNode;
20
+ }
21
+ /** حالت خالی: وقتی داده‌ای برای نمایش نیست */
22
+ export declare function EmptyState({ title, description, icon, actions, className, ...rest }: EmptyStateProps): import("react").JSX.Element;
package/dist/Misc.js ADDED
@@ -0,0 +1,16 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ export function Divider({ label, vertical, className, ...rest }) {
4
+ return (_jsx("div", { role: "separator", "aria-orientation": vertical ? "vertical" : undefined, className: cx("k-divider", vertical && "k-divider--vertical", className), ...rest, children: label && _jsx("span", { children: label }) }));
5
+ }
6
+ /** کلید صفحه‌کلید */
7
+ export function Kbd({ keys, children, className, ...rest }) {
8
+ if (keys) {
9
+ return (_jsx("span", { className: cx("k-kbd-combo", className), ...rest, children: keys.map((k, i) => _jsx("kbd", { className: "k-kbd", children: k }, i)) }));
10
+ }
11
+ return _jsx("kbd", { className: cx("k-kbd", className), ...rest, children: children });
12
+ }
13
+ /** حالت خالی: وقتی داده‌ای برای نمایش نیست */
14
+ export function EmptyState({ title, description, icon, actions, className, ...rest }) {
15
+ return (_jsxs("div", { className: cx("k-empty", className), ...rest, children: [icon && _jsx("span", { className: "k-empty__icon", "aria-hidden": "true", children: icon }), _jsx("p", { className: "k-empty__title", children: title }), description && _jsx("p", { className: "k-empty__description", children: description }), actions && _jsx("div", { className: "k-empty__actions", children: actions })] }));
16
+ }
@@ -0,0 +1,28 @@
1
+ import { type ReactNode } from "react";
2
+ export interface OtpInputProps {
3
+ label?: ReactNode;
4
+ hint?: ReactNode;
5
+ error?: ReactNode;
6
+ /** تعداد رقم @default 6 */
7
+ length?: number;
8
+ value?: string;
9
+ defaultValue?: string;
10
+ onChange?: (code: string) => void;
11
+ /** وقتی همهٔ رقم‌ها وارد شد */
12
+ onComplete?: (code: string) => void;
13
+ /** @default "fa" */
14
+ digits?: "fa" | "latin";
15
+ /** خط فاصله بعد از این تعداد رقم، مثلاً 3 برای ۱۲۳-۴۵۶ */
16
+ groupAfter?: number;
17
+ size?: "sm" | "md";
18
+ disabled?: boolean;
19
+ autoFocus?: boolean;
20
+ name?: string;
21
+ id?: string;
22
+ className?: string;
23
+ }
24
+ /**
25
+ * کد تأیید یک‌بارمصرف: یک input واقعی (نه شش input جدا)، پس چسباندن، پاک کردن،
26
+ * صفحه‌خوان و پر شدن خودکار کد پیامکی (autocomplete="one-time-code") بی‌نقص کار می‌کنند.
27
+ */
28
+ export declare const OtpInput: import("react").ForwardRefExoticComponent<OtpInputProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,30 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useId, useRef, useState } from "react";
3
+ import { onlyDigits, 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
+ * کد تأیید یک‌بارمصرف: یک input واقعی (نه شش input جدا)، پس چسباندن، پاک کردن،
9
+ * صفحه‌خوان و پر شدن خودکار کد پیامکی (autocomplete="one-time-code") بی‌نقص کار می‌کنند.
10
+ */
11
+ export const OtpInput = forwardRef(function OtpInput({ label, hint, error, length = 6, value, defaultValue = "", onChange, onComplete, digits = "fa", groupAfter, size = "md", disabled, autoFocus, name, id, className }, ref) {
12
+ const autoId = useId();
13
+ const inputId = id ?? autoId;
14
+ const [inner, setInner] = useState(() => onlyDigits(defaultValue).slice(0, length));
15
+ const code = value !== undefined ? onlyDigits(value).slice(0, length) : inner;
16
+ const [caret, setCaret] = useState(code.length);
17
+ const inputRef = useRef(null);
18
+ const d = (c) => (digits === "fa" ? toFaDigits(c) : c);
19
+ const active = Math.min(caret, length - 1);
20
+ const sync = () => setCaret(Math.min(inputRef.current?.selectionStart ?? code.length, length));
21
+ return (_jsxs(Field, { id: inputId, label: label, hint: hint, error: error, className: className, children: [_jsxs("div", { className: cx("k-otp", size === "sm" && "k-otp--sm", !!error && "k-otp--invalid"), onClick: () => inputRef.current?.focus(), children: [_jsx("input", { ref: mergeRefs(ref, inputRef), id: inputId, className: "k-otp__input", type: "text", inputMode: "numeric", autoComplete: "one-time-code", pattern: "\\d*", maxLength: length * 2 /* ارقام فارسی و فاصله‌های چسبانده‌شده */, value: code, disabled: disabled, autoFocus: autoFocus, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error), onChange: (e) => {
22
+ const next = onlyDigits(e.target.value).slice(0, length);
23
+ if (value === undefined)
24
+ setInner(next);
25
+ onChange?.(next);
26
+ setCaret(next.length);
27
+ if (next.length === length && next !== code)
28
+ onComplete?.(next);
29
+ }, onSelect: sync, onKeyUp: sync, onFocus: sync }), Array.from({ length }, (_, i) => (_jsxs("span", { style: { display: "contents" }, children: [groupAfter && i === groupAfter && _jsx("span", { className: "k-otp__sep", "aria-hidden": "true" }), _jsx("span", { className: "k-otp__slot", "aria-hidden": "true", "data-filled": code[i] ? "" : undefined, "data-active": i === active ? "" : undefined, children: code[i] ? d(code[i]) : "" })] }, i)))] }), name && _jsx("input", { type: "hidden", name: name, value: code })] }));
30
+ });
@@ -0,0 +1,25 @@
1
+ import type { ReactNode } from "react";
2
+ /** صفحه‌هایی که نمایش داده می‌شوند؛ null یعنی «…» */
3
+ export declare function pageRange(page: number, total: number, siblings?: number): (number | null)[];
4
+ export interface PaginationProps {
5
+ page: number;
6
+ total: number;
7
+ onChange?: (page: number) => void;
8
+ /** برای صفحه‌بندی با لینک (بهتر برای SEO)؛ در این حالت onChange لازم نیست */
9
+ getHref?: (page: number) => string;
10
+ /** تعداد صفحه‌های کنار صفحهٔ فعلی @default 1 */
11
+ siblings?: number;
12
+ /** متن خلاصه، مثل «نمایش ۱ تا ۱۰ از ۹۷» */
13
+ summary?: ReactNode;
14
+ /** @default "fa" */
15
+ digits?: "fa" | "latin";
16
+ labels?: {
17
+ nav?: string;
18
+ prev?: string;
19
+ next?: string;
20
+ page?: (n: string) => string;
21
+ };
22
+ className?: string;
23
+ }
24
+ /** صفحه‌بندی با ارقام فارسی؛ صفحهٔ فعلی با aria-current="page" */
25
+ export declare function Pagination({ page, total, onChange, getHref, siblings, summary, digits, labels, className }: PaginationProps): import("react").JSX.Element;
@@ -0,0 +1,28 @@
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
+ /** صفحه‌هایی که نمایش داده می‌شوند؛ null یعنی «…» */
5
+ export function pageRange(page, total, siblings = 1) {
6
+ const out = [];
7
+ const from = Math.max(2, page - siblings);
8
+ const to = Math.min(total - 1, page + siblings);
9
+ out.push(1);
10
+ if (from > 2)
11
+ out.push(from === 3 ? 2 : null);
12
+ for (let p = from; p <= to; p++)
13
+ out.push(p);
14
+ if (to < total - 1)
15
+ out.push(to === total - 2 ? total - 1 : null);
16
+ if (total > 1)
17
+ out.push(total);
18
+ return out;
19
+ }
20
+ 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" }) }));
21
+ /** صفحه‌بندی با ارقام فارسی؛ صفحهٔ فعلی با aria-current="page" */
22
+ export function Pagination({ page, total, onChange, getHref, siblings = 1, summary, digits = "fa", labels = {}, className }) {
23
+ const n = (v) => (digits === "fa" ? toFaDigits(v) : String(v));
24
+ const { nav = "صفحه‌بندی", prev = "قبلی", next = "بعدی", page: pageLabel = (x) => `صفحهٔ ${x}` } = labels;
25
+ // تابع معمولی، نه کامپوننت: تا دکمه‌ها با هر رندر دوباره ساخته نشوند و فوکوس کیبورد حفظ شود
26
+ 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 }));
27
+ return (_jsxs("nav", { className: cx("k-pagination", className), "aria-label": nav, children: [item({ to: page - 1, disabled: page <= 1, className: "k-btn k-btn--secondary k-btn--sm", children: _jsxs(_Fragment, { children: [_jsx(Chevron, { dir: "prev" }), prev] }) }), summary && _jsx("span", { className: "k-pagination__summary", children: summary }), _jsx("ul", { className: "k-pagination__pages", role: "list", children: pageRange(page, total, siblings).map((p, i) => (_jsx("li", { children: p === null ? (_jsx("span", { className: "k-pagination__ellipsis", "aria-hidden": "true", children: "\u2026" })) : (item({ to: p, current: p === page, aria: pageLabel(n(p)), className: "k-pagination__page", children: n(p) })) }, i))) }), item({ to: page + 1, disabled: page >= total, className: "k-btn k-btn--secondary k-btn--sm", children: _jsxs(_Fragment, { children: [next, _jsx(Chevron, { dir: "next" })] }) })] }));
28
+ }
@@ -0,0 +1,24 @@
1
+ import type { HTMLAttributes, ReactNode } from "react";
2
+ export interface ProgressProps extends HTMLAttributes<HTMLDivElement> {
3
+ /** مقدار؛ بدون آن نوار «نامعین» است */
4
+ value?: number;
5
+ /** @default 100 */
6
+ max?: number;
7
+ /** برچسب بالای نوار؛ اگر نمی‌دهید aria-label بدهید */
8
+ label?: ReactNode;
9
+ /** نمایش درصد کنار برچسب */
10
+ showValue?: boolean;
11
+ /** @default "md" */
12
+ size?: "sm" | "md" | "lg";
13
+ tone?: "brand" | "success" | "warning" | "error";
14
+ /** «circular»: حلقهٔ پیشرفت با درصد در وسط @default "linear" */
15
+ variant?: "linear" | "circular";
16
+ }
17
+ export declare function Progress({ value, max, label, showValue, size, tone, variant, className, "aria-label": ariaLabel, ...rest }: ProgressProps): import("react").JSX.Element;
18
+ export interface SpinnerProps extends HTMLAttributes<HTMLSpanElement> {
19
+ /** @default "در حال بارگذاری" */
20
+ label?: string;
21
+ size?: "sm" | "md" | "lg";
22
+ }
23
+ /** اسپینر با متن صفحه‌خوان */
24
+ export declare function Spinner({ label, size, className, ...rest }: SpinnerProps): import("react").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { toFaDigits } from "@kashi-ui/persian";
3
+ import { cx } from "./cx.js";
4
+ export function Progress({ value, max = 100, label, showValue, size = "md", tone = "brand", variant = "linear", className, "aria-label": ariaLabel, ...rest }) {
5
+ const pct = value === undefined ? undefined : Math.max(0, Math.min(100, (value / max) * 100));
6
+ const text = pct === undefined ? undefined : `${toFaDigits(Math.round(pct))}٪`;
7
+ if (variant === "circular") {
8
+ const r = 16;
9
+ const c = 2 * Math.PI * r;
10
+ return (_jsxs("div", { role: "progressbar", "aria-valuemin": 0, "aria-valuemax": max, "aria-valuenow": value, "aria-valuetext": text, "aria-label": ariaLabel ?? (typeof label === "string" ? label : undefined), className: cx("k-progress-ring", size !== "md" && `k-progress-ring--${size}`, tone !== "brand" && `k-progress--${tone}`, pct === undefined && "k-progress-ring--indeterminate", className), ...rest, children: [_jsxs("svg", { viewBox: "0 0 40 40", "aria-hidden": "true", children: [_jsx("circle", { className: "k-progress-ring__track", cx: "20", cy: "20", r: r }), _jsx("circle", { className: "k-progress-ring__bar", cx: "20", cy: "20", r: r, strokeDasharray: c, strokeDashoffset: pct === undefined ? c * 0.7 : c * (1 - pct / 100) })] }), showValue && text && _jsx("span", { className: "k-progress-ring__value", "aria-hidden": "true", children: text })] }));
11
+ }
12
+ const bar = (_jsx("div", { role: "progressbar", "aria-valuemin": 0, "aria-valuemax": max, "aria-valuenow": value, "aria-valuetext": text, "aria-label": ariaLabel ?? (typeof label === "string" ? label : undefined), className: cx("k-progress", size !== "md" && `k-progress--${size}`, tone !== "brand" && `k-progress--${tone}`, !label && className), ...rest, children: _jsx("div", { className: "k-progress__bar", style: pct === undefined ? undefined : { "--k-value": `${pct}%` } }) }));
13
+ if (!label)
14
+ return bar;
15
+ 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] }));
16
+ }
17
+ /** اسپینر با متن صفحه‌خوان */
18
+ export function Spinner({ label = "در حال بارگذاری", size = "md", className, ...rest }) {
19
+ 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 })] }));
20
+ }
@@ -0,0 +1,11 @@
1
+ export interface SkeletonProps {
2
+ width?: string | number;
3
+ height?: string | number;
4
+ /** شکل دایره، مثل جای آواتار */
5
+ circle?: boolean;
6
+ /** چند خط متن */
7
+ lines?: number;
8
+ className?: string;
9
+ }
10
+ /** جای خالی هنگام بارگذاری؛ تزئینی است — روی ظرف والد aria-busy="true" بگذارید */
11
+ export declare function Skeleton({ width, height, circle, lines, className }: SkeletonProps): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cx } from "./cx.js";
3
+ const size = (v) => (typeof v === "number" ? `${v}px` : v);
4
+ /** جای خالی هنگام بارگذاری؛ تزئینی است — روی ظرف والد aria-busy="true" بگذارید */
5
+ export function Skeleton({ width, height, circle, lines, className }) {
6
+ const style = { "--k-skeleton-width": size(width), "--k-skeleton-height": size(height ?? (circle ? width : undefined)) };
7
+ if (lines) {
8
+ return (_jsx("span", { className: cx("k-skeleton-group", className), "aria-hidden": "true", style: style, children: Array.from({ length: lines }, (_, i) => _jsx("span", { className: "k-skeleton k-skeleton--text" }, i)) }));
9
+ }
10
+ return _jsx("span", { className: cx("k-skeleton", circle && "k-skeleton--circle", className), "aria-hidden": "true", style: style });
11
+ }
@@ -0,0 +1,20 @@
1
+ import type { ReactNode } from "react";
2
+ export interface Step {
3
+ title: ReactNode;
4
+ description?: ReactNode;
5
+ }
6
+ export interface StepperProps {
7
+ steps: Step[];
8
+ /** شمارهٔ مرحلهٔ فعلی از صفر */
9
+ current: number;
10
+ orientation?: "horizontal" | "vertical";
11
+ /** @default "مراحل" */
12
+ label?: string;
13
+ labels?: {
14
+ complete?: string;
15
+ current?: string;
16
+ };
17
+ className?: string;
18
+ }
19
+ /** مراحل یک فرایند؛ مرحلهٔ فعلی با aria-current="step" و وضعیت هر مرحله برای صفحه‌خوان */
20
+ export declare function Stepper({ steps, current, orientation, label, labels, className }: StepperProps): import("react").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { toFaDigits } from "@kashi-ui/persian";
3
+ import { cx } from "./cx.js";
4
+ 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" }) }));
5
+ /** مراحل یک فرایند؛ مرحلهٔ فعلی با aria-current="step" و وضعیت هر مرحله برای صفحه‌خوان */
6
+ export function Stepper({ steps, current, orientation = "horizontal", label = "مراحل", labels = {}, className }) {
7
+ const { complete = "انجام شده", current: currentLabel = "مرحلهٔ فعلی" } = labels;
8
+ return (_jsx("ol", { className: cx("k-steps", orientation === "vertical" && "k-steps--vertical", className), "aria-label": label, children: steps.map((s, i) => {
9
+ const status = i < current ? "complete" : i === current ? "current" : "upcoming";
10
+ 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, {}) : toFaDigits(i + 1) }), _jsxs("span", { className: "k-steps__title", children: [s.title, status !== "upcoming" && _jsx("span", { className: "k-sr-only", children: `، ${status === "complete" ? complete : currentLabel}` })] }), s.description && _jsx("span", { className: "k-steps__description", children: s.description })] }, i));
11
+ }) }));
12
+ }
package/dist/Tabs.d.ts CHANGED
@@ -7,9 +7,13 @@ export interface TabsProps extends Omit<HTMLAttributes<HTMLDivElement>, "onChang
7
7
  variant?: "line" | "pill" | "segmented";
8
8
  /** زبانه‌ها تمام عرض را پر کنند */
9
9
  block?: boolean;
10
+ /** «vertical»: زبانه‌ها در ستون کناری، مثل صفحهٔ تنظیمات @default "horizontal" */
11
+ orientation?: "horizontal" | "vertical";
12
+ /** @default "md" */
13
+ size?: "sm" | "md";
10
14
  }
11
15
  /** زبانه‌ها با الگوی Tabs در WAI-ARIA؛ کلیدهای جهت‌دار در راست‌به‌چپ برعکس عمل می‌کنند */
12
- export declare function Tabs({ value, defaultValue, onChange, variant, block, className, children, ...rest }: TabsProps): import("react").JSX.Element;
16
+ export declare function Tabs({ value, defaultValue, onChange, variant, block, orientation, size, className, children, ...rest }: TabsProps): import("react").JSX.Element;
13
17
  export interface TabListProps extends HTMLAttributes<HTMLDivElement> {
14
18
  /** نام فهرست برای صفحه‌خوان، مثل «تنظیمات حساب» */
15
19
  "aria-label": string;