@kashi-ui/react 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +2 -2
  2. package/dist/Alert.d.ts +11 -0
  3. package/dist/Alert.js +2 -2
  4. package/dist/Avatar.d.ts +6 -0
  5. package/dist/Avatar.js +11 -2
  6. package/dist/Badge.d.ts +9 -1
  7. package/dist/Badge.js +3 -2
  8. package/dist/Button.d.ts +15 -4
  9. package/dist/Button.js +12 -2
  10. package/dist/Calendar.d.ts +6 -1
  11. package/dist/Calendar.js +12 -5
  12. package/dist/Card.d.ts +17 -3
  13. package/dist/Card.js +13 -4
  14. package/dist/Checkbox.d.ts +9 -0
  15. package/dist/Checkbox.js +6 -6
  16. package/dist/Combobox.d.ts +48 -0
  17. package/dist/Combobox.js +143 -0
  18. package/dist/CommandPalette.d.ts +37 -0
  19. package/dist/CommandPalette.js +95 -0
  20. package/dist/DataTable.d.ts +28 -1
  21. package/dist/DataTable.js +17 -10
  22. package/dist/DateRangePicker.d.ts +50 -0
  23. package/dist/DateRangePicker.js +94 -0
  24. package/dist/Dialog.d.ts +4 -2
  25. package/dist/Dialog.js +2 -2
  26. package/dist/DropdownMenu.d.ts +3 -1
  27. package/dist/DropdownMenu.js +7 -5
  28. package/dist/Field.d.ts +15 -1
  29. package/dist/Field.js +4 -2
  30. package/dist/FileUpload.d.ts +39 -0
  31. package/dist/FileUpload.js +90 -0
  32. package/dist/Input.d.ts +34 -0
  33. package/dist/Input.js +57 -6
  34. package/dist/NumberInput.d.ts +29 -0
  35. package/dist/NumberInput.js +56 -0
  36. package/dist/Popover.d.ts +19 -0
  37. package/dist/Popover.js +58 -0
  38. package/dist/Progress.d.ts +3 -1
  39. package/dist/Progress.js +6 -1
  40. package/dist/SideNav.d.ts +28 -0
  41. package/dist/SideNav.js +22 -0
  42. package/dist/Slider.d.ts +32 -0
  43. package/dist/Slider.js +33 -0
  44. package/dist/Stat.d.ts +24 -0
  45. package/dist/Stat.js +17 -0
  46. package/dist/Tabs.d.ts +5 -1
  47. package/dist/Tabs.js +8 -9
  48. package/dist/TagInput.d.ts +33 -0
  49. package/dist/TagInput.js +88 -0
  50. package/dist/Timeline.d.ts +19 -0
  51. package/dist/Timeline.js +8 -0
  52. package/dist/Toast.d.ts +22 -8
  53. package/dist/Toast.js +55 -12
  54. package/dist/Tooltip.d.ts +2 -2
  55. package/dist/Tooltip.js +1 -1
  56. package/dist/index.d.ts +28 -6
  57. package/dist/index.js +13 -2
  58. package/package.json +4 -4
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
  });
@@ -0,0 +1,29 @@
1
+ import { type ReactNode } from "react";
2
+ export interface NumberInputProps {
3
+ label?: ReactNode;
4
+ hint?: ReactNode;
5
+ error?: ReactNode;
6
+ value?: number | null;
7
+ defaultValue?: number | null;
8
+ onChange?: (value: number | null) => void;
9
+ min?: number;
10
+ max?: number;
11
+ /** @default 1 */
12
+ step?: number;
13
+ /** جداکنندهٔ هزارگان */
14
+ thousands?: boolean;
15
+ /** @default "fa" */
16
+ digits?: "fa" | "latin";
17
+ /** واحد کنار عدد، مثل «نفر» */
18
+ unit?: ReactNode;
19
+ disabled?: boolean;
20
+ name?: string;
21
+ id?: string;
22
+ className?: string;
23
+ labels?: {
24
+ increment?: string;
25
+ decrement?: string;
26
+ };
27
+ }
28
+ /** ورودی عدد با دکمه‌های + و −؛ ↑↓ یک گام، PageUp/PageDown ده گام، Home/End کمینه و بیشینه */
29
+ export declare const NumberInput: import("react").ForwardRefExoticComponent<NumberInputProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,56 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useId, useState } from "react";
3
+ import { formatNumber, onlyDigits, toFaDigits } from "@kashi-ui/persian";
4
+ import { cx } from "./cx.js";
5
+ import { Field, describedBy } from "./Field.js";
6
+ 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" }) });
7
+ 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" }) });
8
+ /** ورودی عدد با دکمه‌های + و −؛ ↑↓ یک گام، PageUp/PageDown ده گام، Home/End کمینه و بیشینه */
9
+ export const NumberInput = forwardRef(function NumberInput({ label, hint, error, value, defaultValue = null, onChange, min, max, step = 1, thousands, digits = "fa", unit, disabled, name, id, className, labels = {} }, ref) {
10
+ const autoId = useId();
11
+ const inputId = id ?? autoId;
12
+ const [inner, setInner] = useState(defaultValue);
13
+ const current = value !== undefined ? value : inner;
14
+ const [draft, setDraft] = useState(null);
15
+ const { increment = "افزایش", decrement = "کاهش" } = labels;
16
+ const clamp = (n) => Math.min(max ?? Infinity, Math.max(min ?? -Infinity, n));
17
+ const show = (n) => {
18
+ if (n === null)
19
+ return "";
20
+ const s = thousands ? formatNumber(n, { digits: "latin" }) : String(n);
21
+ return digits === "fa" ? toFaDigits(s).replace(/,/g, "٬") : s;
22
+ };
23
+ const set = (n) => {
24
+ // هنگام تایپ محدود نمی‌شود تا عدد نیمه‌کاره پاک نشود؛ محدودسازی در blur و دکمه‌ها
25
+ if (value === undefined)
26
+ setInner(n);
27
+ onChange?.(n);
28
+ };
29
+ const bump = (k) => set(clamp((current ?? min ?? 0) + k * step));
30
+ const onKeyDown = (e) => {
31
+ const keys = {
32
+ ArrowUp: () => bump(1),
33
+ ArrowDown: () => bump(-1),
34
+ PageUp: () => bump(10),
35
+ PageDown: () => bump(-10),
36
+ Home: () => min !== undefined && set(min),
37
+ End: () => max !== undefined && set(max),
38
+ };
39
+ if (!keys[e.key])
40
+ return;
41
+ e.preventDefault();
42
+ keys[e.key]();
43
+ setDraft(null);
44
+ };
45
+ return (_jsxs(Field, { id: inputId, label: label, hint: hint, error: error, className: className, children: [_jsx("div", { className: cx("k-number"), children: _jsxs("div", { className: "k-input", "data-state": error ? "invalid" : disabled ? "disabled" : undefined, children: [_jsx("button", { type: "button", className: "k-number__step", tabIndex: -1, "aria-label": decrement, disabled: disabled || (min !== undefined && (current ?? 0) <= min), onClick: () => bump(-1), children: _jsx(Minus, {}) }), _jsx("input", { ref: ref, id: inputId, className: "k-input__control", type: "text", inputMode: "decimal", role: "spinbutton", "aria-valuenow": current ?? undefined, "aria-valuemin": min, "aria-valuemax": max, "aria-valuetext": current === null ? undefined : show(current), "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error), disabled: disabled, dir: "ltr", value: draft ?? show(current), onChange: (e) => {
46
+ const raw = e.target.value;
47
+ const neg = /^\s*[-−]/.test(raw);
48
+ const d = onlyDigits(raw);
49
+ setDraft(raw);
50
+ set(d ? (neg ? -1 : 1) * Number(d) : null);
51
+ }, onBlur: () => {
52
+ setDraft(null);
53
+ if (current !== null && current !== clamp(current))
54
+ set(clamp(current));
55
+ }, onKeyDown: onKeyDown }), unit && _jsx("span", { className: "k-input__addon", children: unit }), _jsx("button", { type: "button", className: "k-number__step", tabIndex: -1, "aria-label": increment, disabled: disabled || (max !== undefined && (current ?? 0) >= max), onClick: () => bump(1), children: _jsx(Plus, {}) })] }) }), name && _jsx("input", { type: "hidden", name: name, value: current ?? "" })] }));
56
+ });
@@ -0,0 +1,19 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ export interface PopoverProps {
3
+ /** دکمه‌ای که پنجره را باز می‌کند */
4
+ trigger: ReactElement;
5
+ title?: ReactNode;
6
+ children: ReactNode;
7
+ open?: boolean;
8
+ onOpenChange?: (open: boolean) => void;
9
+ /** @default "bottom-start" */
10
+ placement?: "bottom-start" | "bottom-end" | "top-start" | "top-end";
11
+ /** نام پنجره اگر title ندارد */
12
+ "aria-label"?: string;
13
+ className?: string;
14
+ }
15
+ /**
16
+ * پنجرهٔ شناور غیرمودال کنار یک دکمه؛ برای فرم کوتاه، فیلتر یا توضیح.
17
+ * فوکوس به داخل می‌رود، Esc و کلیک بیرون می‌بندد و فوکوس به دکمه برمی‌گردد.
18
+ */
19
+ export declare function Popover({ trigger, title, children, open, onOpenChange, placement, "aria-label": ariaLabel, className }: PopoverProps): import("react").JSX.Element;
@@ -0,0 +1,58 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cloneElement, isValidElement, useEffect, useId, useRef, useState } from "react";
3
+ import { cx } from "./cx.js";
4
+ const FOCUSABLE = 'a[href], button:not([disabled]), input:not([disabled]), select, textarea, [tabindex]:not([tabindex="-1"])';
5
+ /**
6
+ * پنجرهٔ شناور غیرمودال کنار یک دکمه؛ برای فرم کوتاه، فیلتر یا توضیح.
7
+ * فوکوس به داخل می‌رود، Esc و کلیک بیرون می‌بندد و فوکوس به دکمه برمی‌گردد.
8
+ */
9
+ export function Popover({ trigger, title, children, open, onOpenChange, placement = "bottom-start", "aria-label": ariaLabel, className }) {
10
+ const id = useId();
11
+ const [inner, setInner] = useState(false);
12
+ const isOpen = open ?? inner;
13
+ const anchor = useRef(null);
14
+ const panel = useRef(null);
15
+ const triggerRef = useRef(null);
16
+ const set = (v, focusTrigger = false) => {
17
+ if (open === undefined)
18
+ setInner(v);
19
+ onOpenChange?.(v);
20
+ if (!v && focusTrigger)
21
+ triggerRef.current?.focus();
22
+ };
23
+ useEffect(() => {
24
+ if (!isOpen)
25
+ return;
26
+ const p = panel.current;
27
+ (p?.querySelector(FOCUSABLE) ?? p)?.focus();
28
+ const onDown = (e) => {
29
+ if (!anchor.current?.contains(e.target))
30
+ set(false);
31
+ };
32
+ document.addEventListener("pointerdown", onDown);
33
+ return () => document.removeEventListener("pointerdown", onDown);
34
+ }, [isOpen]);
35
+ const t = isValidElement(trigger)
36
+ ? cloneElement(trigger, {
37
+ ref: triggerRef,
38
+ "aria-haspopup": "dialog",
39
+ "aria-expanded": isOpen,
40
+ "aria-controls": isOpen ? `${id}-panel` : undefined,
41
+ onClick: (e) => {
42
+ trigger.props.onClick?.(e);
43
+ set(!isOpen);
44
+ },
45
+ })
46
+ : trigger;
47
+ const [side, align] = placement.split("-");
48
+ return (_jsxs("span", { className: "k-popover-anchor", ref: anchor, children: [t, _jsxs("div", { ref: panel, id: `${id}-panel`, role: "dialog", "aria-labelledby": title ? `${id}-title` : undefined, "aria-label": title ? undefined : ariaLabel, tabIndex: -1, hidden: !isOpen, className: cx("k-popover", side === "top" && "k-popover--top", align === "end" && "k-popover--end", className), onKeyDown: (e) => {
49
+ if (e.key === "Escape") {
50
+ e.stopPropagation();
51
+ set(false, true);
52
+ }
53
+ }, onBlur: (e) => {
54
+ const next = e.relatedTarget;
55
+ if (next && !anchor.current?.contains(next))
56
+ set(false);
57
+ }, children: [title && _jsx("p", { className: "k-popover__title", id: `${id}-title`, children: title }), _jsx("div", { className: "k-popover__body", children: children })] })] }));
58
+ }
@@ -11,8 +11,10 @@ export interface ProgressProps extends HTMLAttributes<HTMLDivElement> {
11
11
  /** @default "md" */
12
12
  size?: "sm" | "md" | "lg";
13
13
  tone?: "brand" | "success" | "warning" | "error";
14
+ /** «circular»: حلقهٔ پیشرفت با درصد در وسط @default "linear" */
15
+ variant?: "linear" | "circular";
14
16
  }
15
- export declare function Progress({ value, max, label, showValue, size, tone, className, "aria-label": ariaLabel, ...rest }: ProgressProps): import("react").JSX.Element;
17
+ export declare function Progress({ value, max, label, showValue, size, tone, variant, className, "aria-label": ariaLabel, ...rest }: ProgressProps): import("react").JSX.Element;
16
18
  export interface SpinnerProps extends HTMLAttributes<HTMLSpanElement> {
17
19
  /** @default "در حال بارگذاری" */
18
20
  label?: string;
package/dist/Progress.js CHANGED
@@ -1,9 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { toFaDigits } from "@kashi-ui/persian";
3
3
  import { cx } from "./cx.js";
4
- export function Progress({ value, max = 100, label, showValue, size = "md", tone = "brand", className, "aria-label": ariaLabel, ...rest }) {
4
+ export function Progress({ value, max = 100, label, showValue, size = "md", tone = "brand", variant = "linear", className, "aria-label": ariaLabel, ...rest }) {
5
5
  const pct = value === undefined ? undefined : Math.max(0, Math.min(100, (value / max) * 100));
6
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
+ }
7
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}%` } }) }));
8
13
  if (!label)
9
14
  return bar;
@@ -0,0 +1,28 @@
1
+ import { type ReactNode } from "react";
2
+ export interface SideNavItem {
3
+ label: string;
4
+ href?: string;
5
+ icon?: ReactNode;
6
+ /** نشان کنار مورد، مثل تعداد */
7
+ badge?: ReactNode;
8
+ current?: boolean;
9
+ onClick?: () => void;
10
+ /** زیرمنو؛ مورد والد به دکمهٔ باز و بسته تبدیل می‌شود */
11
+ items?: SideNavItem[];
12
+ }
13
+ export interface SideNavSection {
14
+ label?: string;
15
+ items: SideNavItem[];
16
+ }
17
+ export interface SideNavProps {
18
+ sections: SideNavSection[];
19
+ header?: ReactNode;
20
+ footer?: ReactNode;
21
+ /** فقط آیکون‌ها؛ نام هر مورد با aria-label و title حفظ می‌شود */
22
+ collapsed?: boolean;
23
+ /** @default "اصلی" */
24
+ "aria-label"?: string;
25
+ className?: string;
26
+ }
27
+ /** ناوبری کناری پنل مدیریت با گروه، زیرمنو، نشان و حالت جمع‌شده */
28
+ export declare function SideNav({ sections, header, footer, collapsed, "aria-label": ariaLabel, className }: SideNavProps): import("react").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useState } from "react";
3
+ import { cx } from "./cx.js";
4
+ 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" }) }));
5
+ const hasCurrent = (it) => Boolean(it.current || it.items?.some(hasCurrent));
6
+ function Item({ item, collapsed }) {
7
+ const id = useId();
8
+ // زیرمنویی که صفحهٔ فعلی در آن است از اول باز است
9
+ const [open, setOpen] = useState(() => Boolean(item.items?.some(hasCurrent)));
10
+ const a11y = collapsed ? { "aria-label": item.label, title: item.label } : {};
11
+ const inner = (_jsxs(_Fragment, { children: [item.icon, _jsx("span", { className: "k-sidenav__text", children: item.label }), item.badge] }));
12
+ if (item.items?.length) {
13
+ return (_jsxs("li", { children: [_jsxs("button", { type: "button", className: "k-sidenav__item", "aria-expanded": open, "aria-controls": `${id}-sub`, onClick: () => setOpen((o) => !o), ...a11y, children: [inner, _jsx(Chevron, {})] }), _jsx("ul", { className: "k-sidenav__sub", id: `${id}-sub`, role: "list", hidden: !open, children: item.items.map((s) => _jsx(Item, { item: s, collapsed: collapsed }, s.label)) })] }));
14
+ }
15
+ const props = { className: "k-sidenav__item", "aria-current": item.current ? "page" : undefined, onClick: item.onClick, ...a11y };
16
+ return _jsx("li", { children: item.href ? _jsx("a", { href: item.href, ...props, children: inner }) : _jsx("button", { type: "button", ...props, children: inner }) });
17
+ }
18
+ /** ناوبری کناری پنل مدیریت با گروه، زیرمنو، نشان و حالت جمع‌شده */
19
+ export function SideNav({ sections, header, footer, collapsed, "aria-label": ariaLabel = "اصلی", className }) {
20
+ const id = useId();
21
+ 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 })] }));
22
+ }
@@ -0,0 +1,32 @@
1
+ import { type ReactNode } from "react";
2
+ type Val = number | [number, number];
3
+ export interface SliderProps<V extends Val = Val> {
4
+ label?: ReactNode;
5
+ /** یک عدد، یا [از، تا] برای بازه */
6
+ value?: V;
7
+ defaultValue?: V;
8
+ onChange?: (value: V) => void;
9
+ /** @default 0 */
10
+ min?: number;
11
+ /** @default 100 */
12
+ max?: number;
13
+ /** @default 1 */
14
+ step?: number;
15
+ /** نمایش مقدار کنار برچسب @default true */
16
+ showValue?: boolean;
17
+ /** قالب نمایش؛ پیش‌فرض ارقام فارسی با جداکنندهٔ هزارگان */
18
+ format?: (n: number) => string;
19
+ /** برچسب‌های زیر نوار، مثل [0, 50, 100] */
20
+ marks?: number[];
21
+ disabled?: boolean;
22
+ name?: string;
23
+ className?: string;
24
+ labels?: {
25
+ from?: string;
26
+ to?: string;
27
+ separator?: string;
28
+ };
29
+ }
30
+ /** لغزنده روی <input type="range"> بومی؛ با آرایهٔ دوتایی، بازه با دو دستگیره */
31
+ export declare function Slider<V extends Val>({ label, value, defaultValue, onChange, min, max, step, showValue, format, marks, disabled, name, className, labels, }: SliderProps<V>): import("react").JSX.Element;
32
+ export {};
package/dist/Slider.js ADDED
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useState } from "react";
3
+ import { formatNumber } from "@kashi-ui/persian";
4
+ import { cx } from "./cx.js";
5
+ /** لغزنده روی <input type="range"> بومی؛ با آرایهٔ دوتایی، بازه با دو دستگیره */
6
+ export function Slider({ label, value, defaultValue, onChange, min = 0, max = 100, step = 1, showValue = true, format = (n) => formatNumber(n), marks, disabled, name, className, labels = {}, }) {
7
+ const id = useId();
8
+ const isRange = Array.isArray(value ?? defaultValue);
9
+ const [inner, setInner] = useState(defaultValue ?? (isRange ? [min, max] : min));
10
+ const current = (value ?? inner);
11
+ const [lo, hi] = Array.isArray(current) ? current : [min, current];
12
+ const pct = (n) => `${((n - min) / (max - min)) * 100}%`;
13
+ const { from = "حداقل", to = "حداکثر", separator = " تا " } = labels;
14
+ const set = (next) => {
15
+ if (value === undefined)
16
+ setInner(next);
17
+ onChange?.(next);
18
+ };
19
+ const fill = { "--_from": isRange ? pct(lo) : "0%", "--_to": pct(hi) };
20
+ const labelId = `${id}-label`;
21
+ const input = (which) => {
22
+ const v = which === "lo" ? lo : hi;
23
+ return (_jsx("input", { type: "range", className: "k-slider__input", min: min, max: max, step: step, value: v, disabled: disabled, name: name ? (isRange ? `${name}_${which === "lo" ? "min" : "max"}` : name) : undefined, "aria-labelledby": isRange ? undefined : label ? labelId : undefined, "aria-label": isRange ? `${which === "lo" ? from : to}${typeof label === "string" ? ` ${label}` : ""}` : undefined, "aria-valuetext": format(v), onChange: (e) => {
24
+ const n = Number(e.target.value);
25
+ // دستگیره‌ها از روی هم رد نمی‌شوند
26
+ if (!isRange)
27
+ set(n);
28
+ else
29
+ set(which === "lo" ? [Math.min(n, hi), hi] : [lo, Math.max(n, lo)]);
30
+ } }));
31
+ };
32
+ return (_jsxs("div", { className: cx("k-slider", className), "data-range": isRange ? "" : undefined, children: [(label || showValue) && (_jsxs("div", { className: "k-slider__head", children: [label && _jsx("span", { className: "k-label", id: labelId, children: label }), showValue && _jsx("span", { className: "k-slider__value", "aria-hidden": "true", children: isRange ? `${format(lo)}${separator}${format(hi)}` : format(hi) })] })), _jsxs("div", { className: "k-slider__track", style: fill, children: [_jsx("span", { className: "k-slider__fill", "aria-hidden": "true" }), isRange && input("lo"), input("hi")] }), marks && (_jsx("div", { className: "k-slider__marks", "aria-hidden": "true", children: marks.map((m) => _jsx("span", { children: format(m) }, m)) }))] }));
33
+ }
package/dist/Stat.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { type HTMLAttributes, type ReactNode } from "react";
2
+ export interface StatCardProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"> {
3
+ label: ReactNode;
4
+ value: ReactNode;
5
+ /** واحد کوچک کنار عدد، مثل «تومان» یا «نفر» */
6
+ unit?: ReactNode;
7
+ icon?: ReactNode;
8
+ /** درصد تغییر؛ مثبت افزایش، منفی کاهش */
9
+ change?: number;
10
+ /** برای شاخص‌هایی که کاهش در آن‌ها خوب است، مثل نرخ خطا */
11
+ invertTrend?: boolean;
12
+ /** متن کنار روند، مثل «نسبت به ماه قبل» */
13
+ caption?: ReactNode;
14
+ /** نمودار کوچک یا هر محتوای دیگر در پایین کارت */
15
+ children?: ReactNode;
16
+ labels?: {
17
+ up?: string;
18
+ down?: string;
19
+ flat?: string;
20
+ };
21
+ }
22
+ /** کارت شاخص کلیدی (KPI) با روند؛ صفحه‌خوان روند را به شکل «۱۲٪ افزایش» می‌خواند */
23
+ export declare const StatCard: import("react").ForwardRefExoticComponent<StatCardProps & import("react").RefAttributes<HTMLDivElement>>;
24
+ export declare function StatGrid({ className, ...rest }: HTMLAttributes<HTMLDivElement>): import("react").JSX.Element;
package/dist/Stat.js ADDED
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { toFaDigits } from "@kashi-ui/persian";
4
+ import { cx } from "./cx.js";
5
+ 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" }) }));
6
+ /** کارت شاخص کلیدی (KPI) با روند؛ صفحه‌خوان روند را به شکل «۱۲٪ افزایش» می‌خواند */
7
+ export const StatCard = forwardRef(function StatCard({ label, value, unit, icon, change, invertTrend, caption, children, labels = {}, className, ...rest }, ref) {
8
+ const { up = "افزایش", down = "کاهش", flat = "بدون تغییر" } = labels;
9
+ const dir = change === undefined ? null : change > 0 ? "up" : change < 0 ? "down" : "flat";
10
+ // رنگ بر اساس خوب یا بد بودن، نه جهت
11
+ const good = dir === "flat" ? "flat" : (dir === "up") !== Boolean(invertTrend) ? "up" : "down";
12
+ const pct = change === undefined ? "" : `${toFaDigits(Math.abs(Math.round(change * 10) / 10)).replace(".", "٫")}٪`;
13
+ 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 })] }));
14
+ });
15
+ export function StatGrid({ className, ...rest }) {
16
+ return _jsx("div", { className: cx("k-stat-grid", className), ...rest });
17
+ }
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;
package/dist/Tabs.js CHANGED
@@ -9,34 +9,33 @@ const useTabs = () => {
9
9
  return ctx;
10
10
  };
11
11
  /** زبانه‌ها با الگوی Tabs در WAI-ARIA؛ کلیدهای جهت‌دار در راست‌به‌چپ برعکس عمل می‌کنند */
12
- export function Tabs({ value, defaultValue = "", onChange, variant = "line", block, className, children, ...rest }) {
12
+ export function Tabs({ value, defaultValue = "", onChange, variant = "line", block, orientation = "horizontal", size = "md", className, children, ...rest }) {
13
13
  const id = useId();
14
14
  const [inner, setInner] = useState(defaultValue);
15
15
  const selected = value !== undefined ? value : inner;
16
16
  return (_jsx(TabsCtx.Provider, { value: {
17
17
  id,
18
18
  selected,
19
+ orientation,
19
20
  select: (v) => {
20
21
  if (value === undefined)
21
22
  setInner(v);
22
23
  onChange?.(v);
23
24
  },
24
- }, children: _jsx("div", { className: cx("k-tabs", `k-tabs--${variant}`, block && "k-tabs--block", className), ...rest, children: children }) }));
25
+ }, children: _jsx("div", { className: cx("k-tabs", `k-tabs--${variant}`, block && "k-tabs--block", orientation === "vertical" && "k-tabs--vertical", size === "sm" && "k-tabs--sm", className), "data-orientation": orientation, ...rest, children: children }) }));
25
26
  }
26
27
  export function TabList({ className, children, ...rest }) {
27
28
  const ref = useRef(null);
29
+ const { orientation } = useTabs();
28
30
  const onKeyDown = (e) => {
29
31
  const tabs = [...(ref.current?.querySelectorAll('[role="tab"]:not(:disabled)') ?? [])];
30
32
  const i = tabs.indexOf(document.activeElement);
31
33
  if (i < 0)
32
34
  return;
33
35
  const rtl = getComputedStyle(ref.current).direction === "rtl";
34
- const moves = {
35
- ArrowLeft: rtl ? i + 1 : i - 1,
36
- ArrowRight: rtl ? i - 1 : i + 1,
37
- Home: 0,
38
- End: tabs.length - 1,
39
- };
36
+ const moves = orientation === "vertical"
37
+ ? { ArrowDown: i + 1, ArrowUp: i - 1, Home: 0, End: tabs.length - 1 }
38
+ : { ArrowLeft: rtl ? i + 1 : i - 1, ArrowRight: rtl ? i - 1 : i + 1, Home: 0, End: tabs.length - 1 };
40
39
  if (!(e.key in moves))
41
40
  return;
42
41
  e.preventDefault();
@@ -44,7 +43,7 @@ export function TabList({ className, children, ...rest }) {
44
43
  next.focus();
45
44
  next.click(); // فعال‌سازی خودکار با فوکوس
46
45
  };
47
- return (_jsx("div", { ref: ref, role: "tablist", className: cx("k-tabs__list", className), onKeyDown: onKeyDown, ...rest, children: children }));
46
+ return (_jsx("div", { ref: ref, role: "tablist", "aria-orientation": orientation, className: cx("k-tabs__list", className), onKeyDown: onKeyDown, ...rest, children: children }));
48
47
  }
49
48
  export function Tab({ value, className, children, disabled, ...rest }) {
50
49
  const { id, selected, select } = useTabs();
@@ -0,0 +1,33 @@
1
+ import { type ReactNode } from "react";
2
+ import { type BadgeTone } from "./Badge.js";
3
+ export interface TagInputProps {
4
+ label?: ReactNode;
5
+ hint?: ReactNode;
6
+ error?: ReactNode;
7
+ value?: string[];
8
+ defaultValue?: string[];
9
+ onChange?: (tags: string[]) => void;
10
+ placeholder?: string;
11
+ /** کلیدهایی که برچسب را ثبت می‌کنند @default ["Enter", ",", "،"] */
12
+ separators?: string[];
13
+ /** بررسی هر برچسب؛ متن خطا برمی‌گرداند یا undefined */
14
+ validate?: (tag: string) => string | undefined;
15
+ /** بیشترین تعداد */
16
+ max?: number;
17
+ /** @default false */
18
+ allowDuplicates?: boolean;
19
+ tone?: BadgeTone;
20
+ disabled?: boolean;
21
+ name?: string;
22
+ id?: string;
23
+ className?: string;
24
+ labels?: {
25
+ added?: (t: string) => string;
26
+ removed?: (t: string) => string;
27
+ remove?: (t: string) => string;
28
+ max?: (n: number) => string;
29
+ duplicate?: string;
30
+ };
31
+ }
32
+ /** ورود چند مقدار، مثل مهارت‌ها یا ایمیل‌ها؛ Enter یا ویرگول (, یا ،) ثبت می‌کند و Backspace آخری را حذف می‌کند */
33
+ export declare const TagInput: import("react").ForwardRefExoticComponent<TagInputProps & import("react").RefAttributes<HTMLInputElement>>;