@kashi-ui/react 0.7.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.
- package/dist/Alert.d.ts +11 -0
- package/dist/Alert.js +2 -2
- package/dist/Avatar.d.ts +6 -0
- package/dist/Avatar.js +11 -2
- package/dist/Badge.d.ts +9 -1
- package/dist/Badge.js +3 -2
- package/dist/Button.d.ts +15 -4
- package/dist/Button.js +12 -2
- package/dist/Card.d.ts +17 -3
- package/dist/Card.js +13 -4
- package/dist/Checkbox.d.ts +9 -0
- package/dist/Checkbox.js +6 -6
- package/dist/DataTable.d.ts +28 -1
- package/dist/DataTable.js +17 -10
- package/dist/Dialog.d.ts +4 -2
- package/dist/Dialog.js +2 -2
- package/dist/DropdownMenu.d.ts +3 -1
- package/dist/DropdownMenu.js +7 -5
- package/dist/Field.d.ts +15 -1
- package/dist/Field.js +4 -2
- package/dist/Input.d.ts +34 -0
- package/dist/Input.js +57 -6
- package/dist/Progress.d.ts +3 -1
- package/dist/Progress.js +6 -1
- package/dist/Tabs.d.ts +5 -1
- package/dist/Tabs.js +8 -9
- package/dist/Toast.d.ts +22 -8
- package/dist/Toast.js +55 -12
- package/dist/Tooltip.d.ts +2 -2
- package/dist/Tooltip.js +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -2
- package/package.json +4 -4
package/dist/Alert.d.ts
CHANGED
|
@@ -14,5 +14,16 @@ export interface AlertProps extends Omit<HTMLAttributes<HTMLDivElement>, "title"
|
|
|
14
14
|
closeLabel?: string;
|
|
15
15
|
/** پسزمینهٔ رنگی کمرنگ */
|
|
16
16
|
tinted?: boolean;
|
|
17
|
+
/** «banner»: تمامعرض بالای صفحه، بدون گوشهٔ گرد @default "card" */
|
|
18
|
+
layout?: "card" | "banner";
|
|
19
|
+
/** «sm»: فشرده، مناسب داخل فرمها @default "md" */
|
|
20
|
+
size?: "sm" | "md";
|
|
21
|
+
classNames?: {
|
|
22
|
+
root?: string;
|
|
23
|
+
icon?: string;
|
|
24
|
+
title?: string;
|
|
25
|
+
description?: string;
|
|
26
|
+
actions?: string;
|
|
27
|
+
};
|
|
17
28
|
}
|
|
18
29
|
export declare const Alert: import("react").ForwardRefExoticComponent<AlertProps & import("react").RefAttributes<HTMLDivElement>>;
|
package/dist/Alert.js
CHANGED
|
@@ -10,9 +10,9 @@ const ICONS = {
|
|
|
10
10
|
warning: WarningIcon,
|
|
11
11
|
error: ErrorIcon,
|
|
12
12
|
};
|
|
13
|
-
export const Alert = forwardRef(function Alert({ tone = "neutral", title, icon, actions, onClose, closeLabel = "بستن", tinted = false, role, className, children, ...rest }, ref) {
|
|
13
|
+
export const Alert = forwardRef(function Alert({ tone = "neutral", title, icon, actions, onClose, closeLabel = "بستن", tinted = false, layout = "card", size = "md", classNames = {}, role, className, children, ...rest }, ref) {
|
|
14
14
|
const Icon = ICONS[tone];
|
|
15
15
|
return (_jsxs("div", { ref: ref,
|
|
16
16
|
// خطا و هشدار فوراً خوانده میشوند؛ بقیه مؤدبانه
|
|
17
|
-
role: role ?? (tone === "error" || tone === "warning" ? "alert" : "status"), className: cx("k-alert", tone !== "neutral" && `k-alert--${tone}`, tinted && "k-alert--tinted", className), ...rest, children: [icon !== false && _jsx("span", { className: "k-alert__icon", "aria-hidden": "true", children: icon ?? _jsx(Icon, {}) }), _jsxs("div", { className: "k-alert__content", children: [title && _jsx("p", { className: "k-alert__title", children: title }), children && _jsx("div", { className: "k-alert__description", children: children }), actions && _jsx("div", { className: "k-alert__actions", children: actions })] }), onClose && (_jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm k-alert__close", "aria-label": closeLabel, onClick: onClose, children: _jsx(CloseIcon, {}) }))] }));
|
|
17
|
+
role: role ?? (tone === "error" || tone === "warning" ? "alert" : "status"), "data-tone": tone, className: cx("k-alert", tone !== "neutral" && `k-alert--${tone}`, tinted && "k-alert--tinted", layout === "banner" && "k-alert--banner", size === "sm" && "k-alert--sm", className, classNames.root), ...rest, children: [icon !== false && _jsx("span", { className: cx("k-alert__icon", classNames.icon), "aria-hidden": "true", children: icon ?? _jsx(Icon, {}) }), _jsxs("div", { className: "k-alert__content", children: [title && _jsx("p", { className: cx("k-alert__title", classNames.title), children: title }), children && _jsx("div", { className: cx("k-alert__description", classNames.description), children: children }), actions && _jsx("div", { className: cx("k-alert__actions", classNames.actions), children: actions })] }), onClose && (_jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm k-alert__close", "aria-label": closeLabel, onClick: onClose, children: _jsx(CloseIcon, {}) }))] }));
|
|
18
18
|
});
|
package/dist/Avatar.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ export type AvatarSize = "xs" | "sm" | "md" | "lg" | "xl" | "2xl";
|
|
|
3
3
|
export type AvatarStatus = "online" | "offline" | "busy" | "away";
|
|
4
4
|
/** حروف اول دو کلمهٔ اول؛ با نیمفاصله تا حروف فارسی به هم نچسبند */
|
|
5
5
|
export declare function initials(name: string): string;
|
|
6
|
+
declare const TONES: readonly ["brand", "info", "success", "warning", "error"];
|
|
7
|
+
/** رنگ ثابت از روی نام؛ یکسان در هر بار و هر دستگاه */
|
|
8
|
+
export declare function autoTone(name: string): (typeof TONES)[number];
|
|
6
9
|
export interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {
|
|
7
10
|
/** نام شخص — برای alt تصویر و حروف اول جایگزین */
|
|
8
11
|
name: string;
|
|
@@ -12,6 +15,8 @@ export interface AvatarProps extends HTMLAttributes<HTMLSpanElement> {
|
|
|
12
15
|
square?: boolean;
|
|
13
16
|
/** رنگ برند برای حالت حروف اول */
|
|
14
17
|
brand?: boolean;
|
|
18
|
+
/** «auto»: رنگ ثابت از روی نام (هر شخص همیشه یک رنگ)، یا یکی از رنگها */
|
|
19
|
+
color?: "auto" | "neutral" | "brand" | "info" | "success" | "warning" | "error";
|
|
15
20
|
status?: AvatarStatus;
|
|
16
21
|
/** برچسبهای وضعیت برای صفحهخوان (پیشفرض فارسی) */
|
|
17
22
|
statusLabels?: Partial<Record<AvatarStatus, string>>;
|
|
@@ -27,3 +32,4 @@ export interface AvatarGroupProps extends HTMLAttributes<HTMLDivElement> {
|
|
|
27
32
|
children: ReactNode;
|
|
28
33
|
}
|
|
29
34
|
export declare function AvatarGroup({ max, size, moreLabel, className, children, ...rest }: AvatarGroupProps): import("react").JSX.Element;
|
|
35
|
+
export {};
|
package/dist/Avatar.js
CHANGED
|
@@ -18,11 +18,20 @@ export function initials(name) {
|
|
|
18
18
|
.join("")
|
|
19
19
|
.toUpperCase();
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
const TONES = ["brand", "info", "success", "warning", "error"];
|
|
22
|
+
/** رنگ ثابت از روی نام؛ یکسان در هر بار و هر دستگاه */
|
|
23
|
+
export function autoTone(name) {
|
|
24
|
+
let h = 0;
|
|
25
|
+
for (const ch of name.trim())
|
|
26
|
+
h = (h * 31 + ch.codePointAt(0)) >>> 0;
|
|
27
|
+
return TONES[h % TONES.length];
|
|
28
|
+
}
|
|
29
|
+
export const Avatar = forwardRef(function Avatar({ name, src, size = "md", square = false, brand = false, color, status, statusLabels, className, ...rest }, ref) {
|
|
22
30
|
const [failed, setFailed] = useState(false);
|
|
23
31
|
const showImage = src && !failed;
|
|
32
|
+
const tone = color === "auto" ? autoTone(name) : color ?? (brand ? "brand" : "neutral");
|
|
24
33
|
const statusText = status ? (statusLabels?.[status] ?? STATUS_LABEL[status]) : undefined;
|
|
25
|
-
return (_jsxs("span", { ref: ref, role: "img", "aria-label": statusText ? `${name}، ${statusText}` : name, className: cx("k-avatar", size !== "md" && `k-avatar--${size}`, square && "k-avatar--square",
|
|
34
|
+
return (_jsxs("span", { ref: ref, role: "img", "aria-label": statusText ? `${name}، ${statusText}` : name, "data-tone": tone, className: cx("k-avatar", size !== "md" && `k-avatar--${size}`, square && "k-avatar--square", tone !== "neutral" && `k-avatar--${tone}`, className), ...rest, children: [showImage ? (_jsx("img", { className: "k-avatar__image", src: src, alt: "", onError: () => setFailed(true) })) : (_jsx("span", { "aria-hidden": "true", children: initials(name) })), status && _jsx("span", { className: `k-avatar__status k-avatar__status--${status}`, "aria-hidden": "true" })] }));
|
|
26
35
|
});
|
|
27
36
|
export function AvatarGroup({ max, size = "md", moreLabel = (n) => `${toFaDigits(n)} نفر دیگر`, className, children, ...rest }) {
|
|
28
37
|
const items = Children.toArray(children);
|
package/dist/Badge.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import { type HTMLAttributes } from "react";
|
|
1
|
+
import { type HTMLAttributes, type ReactNode } from "react";
|
|
2
2
|
export type BadgeTone = "neutral" | "brand" | "error" | "warning" | "success" | "info";
|
|
3
3
|
export interface BadgeProps extends HTMLAttributes<HTMLSpanElement> {
|
|
4
4
|
/** @default "neutral" */
|
|
5
5
|
tone?: BadgeTone;
|
|
6
|
+
/** «soft» پسزمینهٔ کمرنگ، «solid» پررنگ، «outline» فقط حاشیه @default "soft" */
|
|
7
|
+
variant?: "soft" | "solid" | "outline";
|
|
6
8
|
/** @default "md" */
|
|
7
9
|
size?: "sm" | "md" | "lg";
|
|
8
10
|
/** نقطهٔ رنگی ابتدای متن */
|
|
9
11
|
dot?: boolean;
|
|
12
|
+
/** آیکون ابتدای متن */
|
|
13
|
+
icon?: ReactNode;
|
|
10
14
|
/** گوشهٔ کم بهجای گرد */
|
|
11
15
|
square?: boolean;
|
|
16
|
+
/** با دادن این تابع، دکمهٔ حذف نمایش داده میشود (مثل برچسبهای فیلتر) */
|
|
17
|
+
onRemove?: () => void;
|
|
18
|
+
/** @default (متن) => «حذف {متن}» */
|
|
19
|
+
removeLabel?: string;
|
|
12
20
|
}
|
|
13
21
|
export declare const Badge: import("react").ForwardRefExoticComponent<BadgeProps & import("react").RefAttributes<HTMLSpanElement>>;
|
package/dist/Badge.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
|
-
export const Badge = forwardRef(function Badge({ tone = "neutral", size = "md", dot = false, square = false, className, children, ...rest }, ref) {
|
|
5
|
-
|
|
4
|
+
export const Badge = forwardRef(function Badge({ tone = "neutral", variant = "soft", size = "md", dot = false, icon, square = false, onRemove, removeLabel, className, children, ...rest }, ref) {
|
|
5
|
+
const label = removeLabel ?? (typeof children === "string" ? `حذف ${children}` : "حذف");
|
|
6
|
+
return (_jsxs("span", { ref: ref, "data-tone": tone, "data-variant": variant, className: cx("k-badge", tone !== "neutral" && `k-badge--${tone}`, variant !== "soft" && `k-badge--${variant}`, size !== "md" && `k-badge--${size}`, square && "k-badge--square", onRemove && "k-badge--removable", className), ...rest, children: [dot && _jsx("span", { className: "k-badge__dot", "aria-hidden": "true" }), icon && _jsx("span", { className: "k-badge__icon", "aria-hidden": "true", children: icon }), children, onRemove && (_jsx("button", { type: "button", className: "k-badge__remove", "aria-label": label, onClick: onRemove, children: _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 6 8 8M14 6l-8 8" }) }) }))] }));
|
|
6
7
|
});
|
package/dist/Button.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { type ButtonHTMLAttributes, type ReactNode } from "react";
|
|
1
|
+
import { type ButtonHTMLAttributes, type ElementType, type ReactNode } from "react";
|
|
2
2
|
export type ButtonVariant = "primary" | "secondary" | "tertiary" | "link" | "danger" | "danger-secondary";
|
|
3
|
-
export type ButtonSize = "sm" | "md" | "lg" | "xl";
|
|
4
|
-
export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
3
|
+
export type ButtonSize = "xs" | "sm" | "md" | "lg" | "xl";
|
|
4
|
+
export interface ButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, "type"> {
|
|
5
5
|
/** @default "secondary" */
|
|
6
6
|
variant?: ButtonVariant;
|
|
7
7
|
/** @default "md" */
|
|
8
8
|
size?: ButtonSize;
|
|
9
|
+
/** «pill» کاملاً گرد، «square» گوشهٔ کم @default "default" */
|
|
10
|
+
shape?: "default" | "pill" | "square";
|
|
9
11
|
/** نمایش اسپینر؛ دکمه فوکوسپذیر میماند ولی کلیک نمیگیرد */
|
|
10
12
|
loading?: boolean;
|
|
11
13
|
/** متنی که صفحهخوان هنگام بارگذاری میخواند @default "در حال بارگذاری" */
|
|
@@ -18,5 +20,14 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
|
18
20
|
iconStart?: ReactNode;
|
|
19
21
|
/** آیکون انتهای متن (در RTL سمت چپ) */
|
|
20
22
|
iconEnd?: ReactNode;
|
|
23
|
+
/** با href بهصورت لینک (<a>) رندر میشود */
|
|
24
|
+
href?: string;
|
|
25
|
+
target?: string;
|
|
26
|
+
rel?: string;
|
|
27
|
+
/** عنصر یا کامپوننت دلخواه، مثل Link در Next.js: as={Link} */
|
|
28
|
+
as?: ElementType;
|
|
29
|
+
type?: "button" | "submit" | "reset";
|
|
30
|
+
/** بقیهٔ props برای کامپوننت as، مثل prefetch */
|
|
31
|
+
[key: `data-${string}`]: unknown;
|
|
21
32
|
}
|
|
22
|
-
export declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<
|
|
33
|
+
export declare const Button: import("react").ForwardRefExoticComponent<ButtonProps & import("react").RefAttributes<HTMLElement>>;
|
package/dist/Button.js
CHANGED
|
@@ -2,9 +2,19 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
4
|
import { isDev } from "./utils.js";
|
|
5
|
-
export const Button = forwardRef(function Button({ variant = "secondary", size = "md", loading = false, loadingLabel = "در حال بارگذاری", block = false, iconOnly = false, iconStart, iconEnd, disabled, type = "button", className, children, onClick, ...rest }, ref) {
|
|
5
|
+
export const Button = forwardRef(function Button({ variant = "secondary", size = "md", shape = "default", loading = false, loadingLabel = "در حال بارگذاری", block = false, iconOnly = false, iconStart, iconEnd, disabled, type = "button", href, as, className, children, onClick, ...rest }, ref) {
|
|
6
6
|
if (isDev() && iconOnly && !rest["aria-label"] && !rest["aria-labelledby"]) {
|
|
7
7
|
console.warn("[kashi] <Button iconOnly> بدون aria-label برای صفحهخوانها بینام است.");
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
const Tag = as ?? (href ? "a" : "button");
|
|
10
|
+
const isNativeButton = Tag === "button";
|
|
11
|
+
const inactive = loading || (!isNativeButton && disabled);
|
|
12
|
+
const handleClick = (e) => {
|
|
13
|
+
if (inactive) {
|
|
14
|
+
e.preventDefault();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
onClick?.(e);
|
|
18
|
+
};
|
|
19
|
+
return (_jsxs(Tag, { ref: ref, ...(isNativeButton ? { type, disabled } : { href: inactive ? undefined : href, role: href ? undefined : "button" }), "aria-disabled": inactive || undefined, "aria-busy": loading || undefined, onClick: handleClick, "data-variant": variant, "data-size": size, className: cx("k-btn", `k-btn--${variant}`, size !== "md" && `k-btn--${size}`, shape !== "default" && `k-btn--${shape}`, block && "k-btn--block", iconOnly && "k-btn--icon", className), ...rest, children: [iconStart, children, iconEnd, loading && _jsx("span", { className: "k-sr-only", role: "status", children: loadingLabel })] }));
|
|
10
20
|
});
|
package/dist/Card.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ElementType, type HTMLAttributes } from "react";
|
|
1
|
+
import { type ElementType, type HTMLAttributes, type ImgHTMLAttributes, type ReactNode } from "react";
|
|
2
2
|
export interface CardProps extends HTMLAttributes<HTMLElement> {
|
|
3
3
|
/** @default "article" */
|
|
4
4
|
as?: ElementType;
|
|
@@ -6,11 +6,25 @@ export interface CardProps extends HTMLAttributes<HTMLElement> {
|
|
|
6
6
|
flat?: boolean;
|
|
7
7
|
/** کارت قابلکلیک؛ یک لینک یا دکمه با کلاس k-card__link داخلش بگذارید */
|
|
8
8
|
interactive?: boolean;
|
|
9
|
+
/** «outlined» حاشیه و سایهٔ کم، «elevated» سایهٔ بیشتر، «filled» پسزمینهٔ خاکستری بدون سایه @default "outlined" */
|
|
10
|
+
variant?: "outlined" | "elevated" | "filled";
|
|
11
|
+
/** فاصلهٔ داخلی بخشها @default "md" */
|
|
12
|
+
padding?: "none" | "sm" | "md" | "lg";
|
|
9
13
|
}
|
|
10
14
|
export declare const Card: import("react").ForwardRefExoticComponent<CardProps & import("react").RefAttributes<HTMLElement>>;
|
|
11
|
-
export
|
|
15
|
+
export interface CardHeaderProps extends HTMLAttributes<HTMLElement> {
|
|
12
16
|
as?: ElementType;
|
|
13
|
-
|
|
17
|
+
/** دکمه یا منو در انتهای سربرگ */
|
|
18
|
+
actions?: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
/** سربرگ کارت؛ با actions، عنوان و توضیح در یک ستون و عملها در انتها قرار میگیرند */
|
|
21
|
+
export declare const CardHeader: import("react").ForwardRefExoticComponent<CardHeaderProps & import("react").RefAttributes<HTMLElement>>;
|
|
22
|
+
export interface CardMediaProps extends ImgHTMLAttributes<HTMLImageElement> {
|
|
23
|
+
/** نسبت ابعاد، مثل "16 / 9" @default "16 / 9" */
|
|
24
|
+
ratio?: string;
|
|
25
|
+
}
|
|
26
|
+
/** تصویر کارت؛ alt را فراموش نکنید (برای تصویر تزئینی alt="") */
|
|
27
|
+
export declare function CardMedia({ ratio, className, style, ...rest }: CardMediaProps): import("react").JSX.Element;
|
|
14
28
|
/** پیشفرض h3؛ با as سطح عنوان را با ساختار صفحه هماهنگ کنید */
|
|
15
29
|
export declare const CardTitle: import("react").ForwardRefExoticComponent<HTMLAttributes<HTMLElement> & {
|
|
16
30
|
as?: ElementType;
|
package/dist/Card.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef } from "react";
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
|
-
export const Card = forwardRef(function Card({ as: Tag = "article", flat = false, interactive = false, className, ...rest }, ref) {
|
|
5
|
-
return _jsx(Tag, { ref: ref, className: cx("k-card", flat && "k-card--flat", interactive && "k-card--interactive", className), ...rest });
|
|
4
|
+
export const Card = forwardRef(function Card({ as: Tag = "article", flat = false, interactive = false, variant = "outlined", padding = "md", className, ...rest }, ref) {
|
|
5
|
+
return (_jsx(Tag, { ref: ref, "data-variant": variant, className: cx("k-card", flat && "k-card--flat", interactive && "k-card--interactive", variant !== "outlined" && `k-card--${variant}`, padding !== "md" && `k-card--pad-${padding}`, className), ...rest }));
|
|
6
6
|
});
|
|
7
|
+
/** سربرگ کارت؛ با actions، عنوان و توضیح در یک ستون و عملها در انتها قرار میگیرند */
|
|
8
|
+
export const CardHeader = forwardRef(function CardHeader({ as: Tag = "header", actions, className, children, ...rest }, ref) {
|
|
9
|
+
if (!actions)
|
|
10
|
+
return _jsx(Tag, { ref: ref, className: cx("k-card__header", className), ...rest, children: children });
|
|
11
|
+
return (_jsxs(Tag, { ref: ref, className: cx("k-card__header", "k-card__header--actions", className), ...rest, children: [_jsx("div", { className: "k-card__heading", children: children }), _jsx("div", { className: "k-card__actions", children: actions })] }));
|
|
12
|
+
});
|
|
13
|
+
/** تصویر کارت؛ alt را فراموش نکنید (برای تصویر تزئینی alt="") */
|
|
14
|
+
export function CardMedia({ ratio = "16 / 9", className, style, ...rest }) {
|
|
15
|
+
return _jsx("img", { className: cx("k-card__media", className), style: { aspectRatio: ratio, ...style }, ...rest });
|
|
16
|
+
}
|
|
7
17
|
const part = (tag, base, name) => {
|
|
8
18
|
const Part = forwardRef(function Part({ as: Tag = tag, className, ...rest }, ref) {
|
|
9
19
|
return _jsx(Tag, { ref: ref, className: cx(base, className), ...rest });
|
|
@@ -11,7 +21,6 @@ const part = (tag, base, name) => {
|
|
|
11
21
|
Part.displayName = name;
|
|
12
22
|
return Part;
|
|
13
23
|
};
|
|
14
|
-
export const CardHeader = part("header", "k-card__header", "CardHeader");
|
|
15
24
|
/** پیشفرض h3؛ با as سطح عنوان را با ساختار صفحه هماهنگ کنید */
|
|
16
25
|
export const CardTitle = part("h3", "k-card__title", "CardTitle");
|
|
17
26
|
export const CardDescription = part("p", "k-card__description", "CardDescription");
|
package/dist/Checkbox.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { type InputHTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
export interface CheckClassNames {
|
|
3
|
+
root?: string;
|
|
4
|
+
control?: string;
|
|
5
|
+
label?: string;
|
|
6
|
+
description?: string;
|
|
7
|
+
}
|
|
2
8
|
interface CheckOwnProps {
|
|
9
|
+
/** «start»: برچسب پیش از کنترل و کشیده تا انتهای ردیف (مثل صفحهٔ تنظیمات) @default "end" */
|
|
10
|
+
labelPosition?: "start" | "end";
|
|
11
|
+
classNames?: CheckClassNames;
|
|
3
12
|
/** برچسب کنار کنترل */
|
|
4
13
|
label?: ReactNode;
|
|
5
14
|
/** توضیح زیر برچسب */
|
package/dist/Checkbox.js
CHANGED
|
@@ -3,12 +3,12 @@ import { forwardRef, useEffect, useId, useRef } from "react";
|
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
4
|
import { mergeRefs } from "./utils.js";
|
|
5
5
|
/** برچسب و توضیح مشترک بین Checkbox و Switch */
|
|
6
|
-
function CheckLabel({ id, label, description, className, children }) {
|
|
6
|
+
function CheckLabel({ id, label, description, className, classNames = {}, labelPosition = "end", children }) {
|
|
7
7
|
if (!label && !description)
|
|
8
8
|
return _jsx(_Fragment, { children: children });
|
|
9
|
-
return (_jsxs("label", { className: cx("k-check", className), htmlFor: id, children: [children, _jsxs("span", { className: "k-check__text", children: [label && _jsx("span", { className: "k-check__label", children: label }), description && _jsx("span", { className: "k-check__description", id: `${id}-desc`, children: description })] })] }));
|
|
9
|
+
return (_jsxs("label", { className: cx("k-check", labelPosition === "start" && "k-check--start", className, classNames.root), htmlFor: id, children: [children, _jsxs("span", { className: "k-check__text", children: [label && _jsx("span", { className: cx("k-check__label", classNames.label), children: label }), description && _jsx("span", { className: cx("k-check__description", classNames.description), id: `${id}-desc`, children: description })] })] }));
|
|
10
10
|
}
|
|
11
|
-
export const Checkbox = forwardRef(function Checkbox({ label, description, invalid, indeterminate = false, size = "md", id, className, ...rest }, ref) {
|
|
11
|
+
export const Checkbox = forwardRef(function Checkbox({ label, description, invalid, indeterminate = false, size = "md", id, className, classNames, labelPosition, ...rest }, ref) {
|
|
12
12
|
const autoId = useId();
|
|
13
13
|
const inputId = id ?? autoId;
|
|
14
14
|
const inner = useRef(null);
|
|
@@ -17,10 +17,10 @@ export const Checkbox = forwardRef(function Checkbox({ label, description, inval
|
|
|
17
17
|
if (inner.current)
|
|
18
18
|
inner.current.indeterminate = indeterminate;
|
|
19
19
|
}, [indeterminate]);
|
|
20
|
-
return (_jsx(CheckLabel, { id: inputId, label: label, description: description, className: className, children: _jsx("input", { ref: mergeRefs(ref, inner), type: "checkbox", id: inputId, className: cx("k-checkbox", size === "lg" && "k-checkbox--lg", !label && !description && className), "aria-invalid": invalid || undefined, "aria-describedby": description ? `${inputId}-desc` : undefined, "data-indeterminate": indeterminate || undefined, ...rest }) }));
|
|
20
|
+
return (_jsx(CheckLabel, { id: inputId, label: label, description: description, className: className, classNames: classNames, labelPosition: labelPosition, children: _jsx("input", { ref: mergeRefs(ref, inner), type: "checkbox", id: inputId, className: cx("k-checkbox", size === "lg" && "k-checkbox--lg", !label && !description && className, classNames?.control), "aria-invalid": invalid || undefined, "aria-describedby": description ? `${inputId}-desc` : undefined, "data-indeterminate": indeterminate || undefined, ...rest }) }));
|
|
21
21
|
});
|
|
22
|
-
export const Switch = forwardRef(function Switch({ label, description, invalid, size = "md", id, className, ...rest }, ref) {
|
|
22
|
+
export const Switch = forwardRef(function Switch({ label, description, invalid, size = "md", id, className, classNames, labelPosition, ...rest }, ref) {
|
|
23
23
|
const autoId = useId();
|
|
24
24
|
const inputId = id ?? autoId;
|
|
25
|
-
return (_jsx(CheckLabel, { id: inputId, label: label, description: description, className: className, children: _jsx("input", { ref: ref, type: "checkbox", role: "switch", id: inputId, className: cx("k-switch", size !== "md" && `k-switch--${size}`, !label && !description && className), "aria-invalid": invalid || undefined, "aria-describedby": description ? `${inputId}-desc` : undefined, ...rest }) }));
|
|
25
|
+
return (_jsx(CheckLabel, { id: inputId, label: label, description: description, className: className, classNames: classNames, labelPosition: labelPosition, children: _jsx("input", { ref: ref, type: "checkbox", role: "switch", id: inputId, className: cx("k-switch", size !== "md" && `k-switch--${size}`, !label && !description && className, classNames?.control), "aria-invalid": invalid || undefined, "aria-describedby": description ? `${inputId}-desc` : undefined, ...rest }) }));
|
|
26
26
|
});
|
package/dist/DataTable.d.ts
CHANGED
|
@@ -9,7 +9,13 @@ export interface Column<T> {
|
|
|
9
9
|
sortable?: boolean;
|
|
10
10
|
/** عدد و مبلغ: چپچین در RTL با ارقام همعرض */
|
|
11
11
|
numeric?: boolean;
|
|
12
|
+
/** چینش خانهها؛ numeric خودکار «end» است */
|
|
13
|
+
align?: "start" | "center" | "end";
|
|
12
14
|
width?: string;
|
|
15
|
+
/** پنهان کردن ستون در صفحههای باریک */
|
|
16
|
+
hideBelow?: "sm" | "md";
|
|
17
|
+
/** کلاس خانههای این ستون */
|
|
18
|
+
className?: string;
|
|
13
19
|
}
|
|
14
20
|
export type SortState = {
|
|
15
21
|
key: string;
|
|
@@ -33,11 +39,32 @@ export interface DataTableProps<T> {
|
|
|
33
39
|
/** وقتی ردیفی نیست */
|
|
34
40
|
empty?: ReactNode;
|
|
35
41
|
compact?: boolean;
|
|
42
|
+
/** ردیفهای راهراه */
|
|
43
|
+
striped?: boolean;
|
|
44
|
+
/** سرستون هنگام اسکرول ثابت بماند؛ با maxHeight */
|
|
45
|
+
stickyHeader?: boolean;
|
|
46
|
+
/** بیشترین ارتفاع جدول (مثل "24rem")؛ بیشتر از آن اسکرول میخورد */
|
|
47
|
+
maxHeight?: string;
|
|
48
|
+
/** نمایش ردیفهای اسکلت بهجای داده */
|
|
49
|
+
loading?: boolean | number;
|
|
50
|
+
/** کلیک روی ردیف؛ برای ناوبری بهتر است در یک خانه لینک واقعی هم بگذارید */
|
|
51
|
+
onRowClick?: (row: T) => void;
|
|
52
|
+
/** محتوای پایین جدول، مثل صفحهبندی */
|
|
53
|
+
footer?: ReactNode;
|
|
36
54
|
labels?: {
|
|
37
55
|
selectAll?: string;
|
|
38
56
|
selectRow?: (row: T) => string;
|
|
57
|
+
loading?: string;
|
|
58
|
+
};
|
|
59
|
+
classNames?: {
|
|
60
|
+
root?: string;
|
|
61
|
+
table?: string;
|
|
62
|
+
row?: string;
|
|
63
|
+
cell?: string;
|
|
64
|
+
header?: string;
|
|
65
|
+
footer?: string;
|
|
39
66
|
};
|
|
40
67
|
className?: string;
|
|
41
68
|
}
|
|
42
69
|
/** جدول داده با مرتبسازی (aria-sort)، انتخاب ردیفها و حالت خالی */
|
|
43
|
-
export declare function DataTable<T extends Record<string, unknown>>({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort, onSortChange, empty, compact, labels, className, }: DataTableProps<T>): import("react").JSX.Element;
|
|
70
|
+
export declare function DataTable<T extends Record<string, unknown>>({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort, onSortChange, empty, compact, striped, stickyHeader, maxHeight, loading, onRowClick, footer, labels, classNames, className, }: DataTableProps<T>): import("react").JSX.Element;
|
package/dist/DataTable.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
4
|
/** جدول داده با مرتبسازی (aria-sort)، انتخاب ردیفها و حالت خالی */
|
|
5
|
-
export function DataTable({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort = null, onSortChange, empty, compact, labels = {}, className, }) {
|
|
5
|
+
export function DataTable({ columns, rows, getRowId, caption, description, hideCaption, selectable, selected, onSelectedChange, sort, defaultSort = null, onSortChange, empty, compact, striped, stickyHeader, maxHeight, loading, onRowClick, footer, labels = {}, classNames = {}, className, }) {
|
|
6
6
|
const id = useId();
|
|
7
7
|
const [innerSort, setInnerSort] = useState(defaultSort);
|
|
8
8
|
const [innerSel, setInnerSel] = useState([]);
|
|
@@ -39,14 +39,21 @@ export function DataTable({ columns, rows, getRowId, caption, description, hideC
|
|
|
39
39
|
if (allRef.current)
|
|
40
40
|
allRef.current.indeterminate = some;
|
|
41
41
|
}, [some]);
|
|
42
|
-
const { selectAll = "انتخاب همهٔ ردیفها", selectRow = () => "انتخاب ردیف" } = labels;
|
|
42
|
+
const { selectAll = "انتخاب همهٔ ردیفها", selectRow = () => "انتخاب ردیف", loading: loadingLabel = "در حال بارگذاری" } = labels;
|
|
43
|
+
const loadingRows = loading === true ? 5 : typeof loading === "number" ? loading : 0;
|
|
44
|
+
const cellCls = (c) => cx(c.numeric && "k-table__num", c.align && !c.numeric && `k-table__align-${c.align}`, c.hideBelow && `k-table__hide-${c.hideBelow}`, c.className, classNames.cell) || undefined;
|
|
43
45
|
const colCount = columns.length + (selectable ? 1 : 0);
|
|
44
|
-
return (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
return (_jsxs("div", { className: cx("k-table-wrap", stickyHeader && "k-table-wrap--sticky", className, classNames.root), role: "region", "aria-labelledby": `${id}-caption`, "aria-busy": loadingRows > 0 || undefined, tabIndex: 0, style: maxHeight ? { maxBlockSize: maxHeight } : undefined, children: [_jsxs("table", { className: cx("k-table", compact && "k-table--compact", striped && "k-table--striped", onRowClick && "k-table--clickable", classNames.table), children: [_jsxs("caption", { id: `${id}-caption`, className: hideCaption ? "k-sr-only" : undefined, children: [_jsx("span", { className: "k-table__caption-title", children: caption }), description && _jsx("span", { className: "k-table__caption-desc", children: description })] }), _jsx("thead", { children: _jsxs("tr", { children: [selectable && (_jsx("th", { scope: "col", className: "k-table__check", children: _jsx("input", { ref: allRef, type: "checkbox", className: "k-checkbox", "aria-label": selectAll, checked: all, onChange: () => setSel(all ? [] : ids) }) })), columns.map((c) => {
|
|
47
|
+
const s = activeSort?.key === c.key ? activeSort.direction : undefined;
|
|
48
|
+
return (_jsx("th", { scope: "col", "aria-sort": c.sortable ? (s ?? "none") : undefined, className: cx(cellCls(c), classNames.header) || undefined, style: c.width ? { inlineSize: c.width } : undefined, children: c.sortable ? _jsx("button", { type: "button", className: "k-table__sort", onClick: () => setSort(c.key), children: c.header }) : c.header }, c.key));
|
|
49
|
+
})] }) }), _jsx("tbody", { children: loadingRows > 0 ? (Array.from({ length: loadingRows }, (_, i) => (_jsxs("tr", { "aria-hidden": "true", children: [selectable && _jsx("td", { className: "k-table__check", children: _jsx("span", { className: "k-skeleton", style: { inlineSize: "1.125rem", blockSize: "1.125rem" } }) }), columns.map((c) => (_jsx("td", { className: cellCls(c), children: _jsx("span", { className: "k-skeleton", style: { inlineSize: `${50 + ((i * 17 + c.key.length * 11) % 40)}%` } }) }, c.key)))] }, `sk-${i}`)))) : sorted.length === 0 ? (_jsx("tr", { className: "k-table__empty", children: _jsx("td", { colSpan: colCount, children: empty ?? _jsx("p", { style: { padding: "2rem", margin: 0, textAlign: "center" }, children: "\u062F\u0627\u062F\u0647\u200C\u0627\u06CC \u0648\u062C\u0648\u062F \u0646\u062F\u0627\u0631\u062F." }) }) })) : (sorted.map((r) => {
|
|
50
|
+
const rid = getRowId(r);
|
|
51
|
+
const on = sel.includes(rid);
|
|
52
|
+
return (_jsxs("tr", { "aria-selected": selectable ? on : undefined, className: classNames.row, onClick: onRowClick ? (e) => {
|
|
53
|
+
// کلیک روی چکباکس، دکمه یا لینک داخل ردیف را ردیف نگیرد
|
|
54
|
+
if (e.target.closest("a, button, input, label, select, textarea"))
|
|
55
|
+
return;
|
|
56
|
+
onRowClick(r);
|
|
57
|
+
} : undefined, children: [selectable && (_jsx("td", { className: "k-table__check", children: _jsx("input", { type: "checkbox", className: "k-checkbox", "aria-label": selectRow(r), checked: on, onChange: () => setSel(on ? sel.filter((x) => x !== rid) : [...sel, rid]) }) })), columns.map((c) => (_jsx("td", { className: cellCls(c), children: c.render ? c.render(r) : r[c.key] }, c.key)))] }, rid));
|
|
58
|
+
})) })] }), loadingRows > 0 && _jsx("span", { className: "k-sr-only", role: "status", children: loadingLabel }), footer && _jsx("div", { className: cx("k-table__footer", classNames.footer), children: footer })] }));
|
|
52
59
|
}
|
package/dist/Dialog.d.ts
CHANGED
|
@@ -9,7 +9,9 @@ export interface DialogProps {
|
|
|
9
9
|
/** «danger» برای تأیید عملیات مخرب */
|
|
10
10
|
tone?: "default" | "danger";
|
|
11
11
|
/** @default "md" */
|
|
12
|
-
size?: "sm" | "md" | "lg";
|
|
12
|
+
size?: "sm" | "md" | "lg" | "full";
|
|
13
|
+
/** «center» پنجرهٔ وسط، «start»/«end» کشوی کناری، «bottom» برگهٔ پایین (مناسب گوشی) @default "center" */
|
|
14
|
+
placement?: "center" | "start" | "end" | "bottom";
|
|
13
15
|
/** دکمههای پایین پنجره */
|
|
14
16
|
footer?: ReactNode;
|
|
15
17
|
/** بستن با کلیک روی پسزمینه @default true */
|
|
@@ -24,4 +26,4 @@ export interface DialogProps {
|
|
|
24
26
|
* فوکوس داخل پنجره میماند، Esc میبندد، بقیهٔ صفحه از دسترس صفحهخوان خارج میشود
|
|
25
27
|
* و پس از بستن، فوکوس به عنصری که پنجره را باز کرده برمیگردد.
|
|
26
28
|
*/
|
|
27
|
-
export declare function Dialog({ open, onOpenChange, title, description, icon, tone, size, footer, dismissible, closeLabel, className, children, }: DialogProps): import("react").JSX.Element;
|
|
29
|
+
export declare function Dialog({ open, onOpenChange, title, description, icon, tone, size, footer, dismissible, closeLabel, placement, className, children, }: DialogProps): import("react").JSX.Element;
|
package/dist/Dialog.js
CHANGED
|
@@ -7,7 +7,7 @@ import { CloseIcon } from "./icons.js";
|
|
|
7
7
|
* فوکوس داخل پنجره میماند، Esc میبندد، بقیهٔ صفحه از دسترس صفحهخوان خارج میشود
|
|
8
8
|
* و پس از بستن، فوکوس به عنصری که پنجره را باز کرده برمیگردد.
|
|
9
9
|
*/
|
|
10
|
-
export function Dialog({ open, onOpenChange, title, description, icon, tone = "default", size = "md", footer, dismissible = true, closeLabel = "بستن", className, children, }) {
|
|
10
|
+
export function Dialog({ open, onOpenChange, title, description, icon, tone = "default", size = "md", footer, dismissible = true, closeLabel = "بستن", placement = "center", className, children, }) {
|
|
11
11
|
const ref = useRef(null);
|
|
12
12
|
const opener = useRef(null);
|
|
13
13
|
const id = useId();
|
|
@@ -23,7 +23,7 @@ export function Dialog({ open, onOpenChange, title, description, icon, tone = "d
|
|
|
23
23
|
d.close();
|
|
24
24
|
}
|
|
25
25
|
}, [open]);
|
|
26
|
-
return (_jsxs("dialog", { ref: ref, className: cx("k-dialog", size !== "md" && `k-dialog--${size}`, tone === "danger" && "k-dialog--danger", className), "aria-labelledby": `${id}-title`, "aria-describedby": description ? `${id}-desc` : undefined, onClose: () => {
|
|
26
|
+
return (_jsxs("dialog", { ref: ref, "data-placement": placement, className: cx("k-dialog", size !== "md" && `k-dialog--${size}`, placement !== "center" && `k-dialog--${placement}`, tone === "danger" && "k-dialog--danger", className), "aria-labelledby": `${id}-title`, "aria-describedby": description ? `${id}-desc` : undefined, onClose: () => {
|
|
27
27
|
onOpenChange(false);
|
|
28
28
|
opener.current?.focus?.();
|
|
29
29
|
}, onCancel: (e) => {
|
package/dist/DropdownMenu.d.ts
CHANGED
|
@@ -24,9 +24,11 @@ export interface MenuItemProps {
|
|
|
24
24
|
disabled?: boolean;
|
|
25
25
|
/** لینک بهجای عمل */
|
|
26
26
|
href?: string;
|
|
27
|
+
/** گزینهٔ تیکدار (menuitemcheckbox)، مثل «نمایش ستون تاریخ»؛ منو پس از انتخاب باز میماند */
|
|
28
|
+
checked?: boolean;
|
|
27
29
|
children: ReactNode;
|
|
28
30
|
}
|
|
29
|
-
export declare function MenuItem({ onSelect, icon, shortcut, tone, disabled, href, children }: MenuItemProps): import("react").JSX.Element;
|
|
31
|
+
export declare function MenuItem({ onSelect, icon, shortcut, tone, disabled, href, checked, children }: MenuItemProps): import("react").JSX.Element;
|
|
30
32
|
export declare const MenuSeparator: () => import("react").JSX.Element;
|
|
31
33
|
export declare const MenuLabel: ({ children }: {
|
|
32
34
|
children: ReactNode;
|
package/dist/DropdownMenu.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
2
2
|
import { Children, cloneElement, createContext, isValidElement, useContext, useEffect, useId, useRef, useState, } from "react";
|
|
3
3
|
import { cx } from "./cx.js";
|
|
4
4
|
const MenuCtx = createContext(null);
|
|
5
|
-
const items = (menu) => [...(menu?.querySelectorAll('[role
|
|
5
|
+
const items = (menu) => [...(menu?.querySelectorAll('[role^="menuitem"]:not([aria-disabled="true"])') ?? [])];
|
|
6
6
|
/**
|
|
7
7
|
* منوی کشویی با الگوی Menu Button در WAI-ARIA:
|
|
8
8
|
* Enter، Space یا ↓ باز میکند و اولین گزینه را فوکوس میکند، ↑ آخرین را؛
|
|
@@ -81,17 +81,19 @@ export function DropdownMenu({ trigger, label, align = "start", children }) {
|
|
|
81
81
|
: trigger;
|
|
82
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
83
|
}
|
|
84
|
-
export function MenuItem({ onSelect, icon, shortcut, tone = "default", disabled, href, children }) {
|
|
84
|
+
export function MenuItem({ onSelect, icon, shortcut, tone = "default", disabled, href, checked, children }) {
|
|
85
|
+
const checkable = checked !== undefined;
|
|
85
86
|
const ctx = useContext(MenuCtx);
|
|
86
87
|
const cls = cx("k-menu__item", tone === "danger" && "k-menu__item--danger");
|
|
87
|
-
const content = (_jsxs(_Fragment, { children: [icon, _jsx("span", { children: children }), shortcut && _jsx("span", { className: "k-menu__shortcut", "aria-hidden": "true", children: shortcut })] }));
|
|
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 })] }));
|
|
88
89
|
const select = () => {
|
|
89
90
|
if (disabled)
|
|
90
91
|
return;
|
|
91
92
|
onSelect?.();
|
|
92
|
-
|
|
93
|
+
if (!checkable)
|
|
94
|
+
ctx?.close();
|
|
93
95
|
};
|
|
94
|
-
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: "menuitem", tabIndex: -1, className: cls, "aria-disabled": disabled || undefined, onClick: select, children: content })) }));
|
|
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 })) }));
|
|
95
97
|
}
|
|
96
98
|
export const MenuSeparator = () => _jsx("li", { role: "separator", className: "k-menu__separator" });
|
|
97
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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/Progress.d.ts
CHANGED
|
@@ -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;
|
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
|
-
|
|
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();
|
package/dist/Toast.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
export type ToastTone = "neutral" | "success" | "error" | "warning" | "info";
|
|
3
3
|
export interface ToastOptions {
|
|
4
|
+
/** شناسهٔ دلخواه؛ toast() با همین شناسه اعلان قبلی را بهروز میکند */
|
|
5
|
+
id?: number | string;
|
|
4
6
|
title: ReactNode;
|
|
5
7
|
description?: ReactNode;
|
|
6
8
|
tone?: ToastTone;
|
|
@@ -12,21 +14,33 @@ export interface ToastOptions {
|
|
|
12
14
|
};
|
|
13
15
|
}
|
|
14
16
|
/** نمایش اعلان کوتاه؛ شناسهٔ آن را برمیگرداند */
|
|
15
|
-
export declare function toast(options: ToastOptions | string): number;
|
|
17
|
+
export declare function toast(options: ToastOptions | string): number | string;
|
|
16
18
|
export declare namespace toast {
|
|
17
|
-
var success: (title: ReactNode, o?: Omit<ToastOptions, "title" | "tone">) => number;
|
|
18
|
-
var error: (title: ReactNode, o?: Omit<ToastOptions, "title" | "tone">) => number;
|
|
19
|
-
var warning: (title: ReactNode, o?: Omit<ToastOptions, "title" | "tone">) => number;
|
|
20
|
-
var info: (title: ReactNode, o?: Omit<ToastOptions, "title" | "tone">) => number;
|
|
21
|
-
var dismiss: (id: number) => void;
|
|
19
|
+
var success: (title: ReactNode, o?: Omit<ToastOptions, "title" | "tone">) => string | number;
|
|
20
|
+
var error: (title: ReactNode, o?: Omit<ToastOptions, "title" | "tone">) => string | number;
|
|
21
|
+
var warning: (title: ReactNode, o?: Omit<ToastOptions, "title" | "tone">) => string | number;
|
|
22
|
+
var info: (title: ReactNode, o?: Omit<ToastOptions, "title" | "tone">) => string | number;
|
|
23
|
+
var dismiss: (id: number | string) => void;
|
|
24
|
+
var promise: <T>(promise: Promise<T>, msgs: {
|
|
25
|
+
loading: ReactNode;
|
|
26
|
+
success: Msg<T>;
|
|
27
|
+
error: Msg<unknown>;
|
|
28
|
+
}) => Promise<T>;
|
|
22
29
|
}
|
|
30
|
+
type Msg<T> = ReactNode | ((value: T) => ReactNode);
|
|
31
|
+
export type ToastPlacement = "top-start" | "top-center" | "top-end" | "bottom-start" | "bottom-center" | "bottom-end";
|
|
23
32
|
export interface ToasterProps {
|
|
24
|
-
/** @default "bottom" */
|
|
33
|
+
/** جای اعلانها؛ در RTL «end» سمت چپ است @default "bottom-end" */
|
|
34
|
+
placement?: ToastPlacement;
|
|
35
|
+
/** @deprecated از placement استفاده کنید */
|
|
25
36
|
position?: "top" | "bottom";
|
|
37
|
+
/** بیشترین تعداد اعلان همزمان؛ قدیمیترها پنهان میشوند @default 5 */
|
|
38
|
+
max?: number;
|
|
26
39
|
/** @default "اعلانها" */
|
|
27
40
|
label?: string;
|
|
28
41
|
/** @default "بستن اعلان" */
|
|
29
42
|
closeLabel?: string;
|
|
30
43
|
}
|
|
31
44
|
/** محل نمایش اعلانها؛ یک بار در ریشهٔ برنامه قرار دهید */
|
|
32
|
-
export declare function Toaster({ position, label, closeLabel }: ToasterProps): import("react").JSX.Element;
|
|
45
|
+
export declare function Toaster({ placement, position, max, label, closeLabel }: ToasterProps): import("react").JSX.Element;
|
|
46
|
+
export {};
|
package/dist/Toast.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState, useSyncExternalStore } from "react";
|
|
2
|
+
import { useEffect, useId, useRef, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import { isDev } from "./utils.js";
|
|
3
4
|
import { cx } from "./cx.js";
|
|
4
5
|
import { CloseIcon, ErrorIcon, InfoIcon, SuccessIcon, WarningIcon } from "./icons.js";
|
|
5
6
|
// مخزن سادهٔ سراسری؛ هر جای برنامه میتواند toast() را صدا بزند
|
|
@@ -19,25 +20,43 @@ function dismiss(id) {
|
|
|
19
20
|
emit();
|
|
20
21
|
}, 200);
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
items =
|
|
23
|
+
function upsert(o) {
|
|
24
|
+
const id = o.id ?? nextId++;
|
|
25
|
+
const existing = items.find((t) => t.id === id);
|
|
26
|
+
const item = { ...o, id, closing: false, version: (existing?.version ?? 0) + 1 };
|
|
27
|
+
items = existing ? items.map((t) => (t.id === id ? item : t)) : [...items, item];
|
|
27
28
|
emit();
|
|
28
29
|
return id;
|
|
29
30
|
}
|
|
31
|
+
/** نمایش اعلان کوتاه؛ شناسهٔ آن را برمیگرداند */
|
|
32
|
+
export function toast(options) {
|
|
33
|
+
return upsert(typeof options === "string" ? { title: options } : options);
|
|
34
|
+
}
|
|
30
35
|
toast.success = (title, o = {}) => toast({ ...o, title, tone: "success" });
|
|
31
36
|
toast.error = (title, o = {}) => toast({ ...o, title, tone: "error" });
|
|
32
37
|
toast.warning = (title, o = {}) => toast({ ...o, title, tone: "warning" });
|
|
33
38
|
toast.info = (title, o = {}) => toast({ ...o, title, tone: "info" });
|
|
34
39
|
toast.dismiss = dismiss;
|
|
40
|
+
/**
|
|
41
|
+
* اعلان برای کار زمانبر: «در حال ذخیره…» و سپس «ذخیره شد» یا پیام خطا، در همان اعلان.
|
|
42
|
+
* toast.promise(save(), { loading: "در حال ذخیره…", success: "ذخیره شد", error: (e) => e.message })
|
|
43
|
+
*/
|
|
44
|
+
toast.promise = (promise, msgs) => {
|
|
45
|
+
const id = upsert({ title: msgs.loading, tone: "info", duration: Infinity, loading: true });
|
|
46
|
+
const show = (m, v) => (typeof m === "function" ? m(v) : m);
|
|
47
|
+
promise.then((v) => upsert({ id, title: show(msgs.success, v), tone: "success" }), (e) => upsert({ id, title: show(msgs.error, e), tone: "error" }));
|
|
48
|
+
return promise;
|
|
49
|
+
};
|
|
35
50
|
const ICONS = {
|
|
36
51
|
neutral: InfoIcon, info: InfoIcon, success: SuccessIcon, warning: WarningIcon, error: ErrorIcon,
|
|
37
52
|
};
|
|
38
53
|
function ToastView({ t, closeLabel }) {
|
|
39
54
|
const duration = t.duration ?? (t.action ? Infinity : 5000);
|
|
40
55
|
const remaining = useRef(duration);
|
|
56
|
+
// اعلان بهروزشده (مثلاً پس از toast.promise) زمانش از نو شروع میشود
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
remaining.current = duration;
|
|
59
|
+
}, [t.version]);
|
|
41
60
|
const started = useRef(0);
|
|
42
61
|
const timer = useRef();
|
|
43
62
|
const [paused, setPaused] = useState(false);
|
|
@@ -51,15 +70,39 @@ function ToastView({ t, closeLabel }) {
|
|
|
51
70
|
clearTimeout(timer.current);
|
|
52
71
|
remaining.current -= Date.now() - started.current;
|
|
53
72
|
};
|
|
54
|
-
}, [paused, t.closing]);
|
|
73
|
+
}, [paused, t.closing, t.version]);
|
|
55
74
|
const Icon = ICONS[t.tone ?? "neutral"];
|
|
56
|
-
|
|
75
|
+
const icon = t.loading ? _jsx("span", { className: "k-spinner k-spinner--sm", style: { color: "inherit" } }) : _jsx(Icon, {});
|
|
76
|
+
return (_jsxs("li", { className: cx("k-toast", t.tone && t.tone !== "neutral" && `k-toast--${t.tone}`), "data-state": t.closing ? "closing" : "open", role: t.tone === "error" ? "alert" : "status", onMouseEnter: () => setPaused(true), onMouseLeave: () => setPaused(false), onFocus: () => setPaused(true), onBlur: () => setPaused(false), onKeyDown: (e) => e.key === "Escape" && dismiss(t.id), children: [_jsx("span", { className: "k-toast__icon", "aria-hidden": "true", children: icon }), _jsxs("div", { className: "k-toast__content", children: [_jsx("p", { className: "k-toast__title", children: t.title }), t.description && _jsx("p", { className: "k-toast__description", children: t.description }), t.action && (_jsx("button", { type: "button", className: "k-btn k-btn--link k-toast__action", onClick: () => {
|
|
57
77
|
t.action.onClick();
|
|
58
78
|
dismiss(t.id);
|
|
59
|
-
}, children: t.action.label }))] }), _jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm k-toast__close", "aria-label": closeLabel, onClick: () => dismiss(t.id), children: _jsx(CloseIcon, {}) }), Number.isFinite(duration) && _jsx("span", { className: "k-toast__progress", "aria-hidden": "true", style: { animationDuration: `${duration}ms` } })] }));
|
|
79
|
+
}, children: t.action.label }))] }), _jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm k-toast__close", "aria-label": closeLabel, onClick: () => dismiss(t.id), children: _jsx(CloseIcon, {}) }), Number.isFinite(duration) && _jsx("span", { className: "k-toast__progress", "aria-hidden": "true", style: { animationDuration: `${duration}ms` } }, t.version)] }));
|
|
60
80
|
}
|
|
81
|
+
// اگر چند Toaster همزمان در صفحه باشد، فقط آخرینِ نصبشده اعلانها را نشان میدهد تا تکراری نشوند
|
|
82
|
+
let toasters = [];
|
|
83
|
+
const toasterListeners = new Set();
|
|
84
|
+
const emitToasters = () => toasterListeners.forEach((l) => l());
|
|
85
|
+
const subscribeToasters = (l) => {
|
|
86
|
+
toasterListeners.add(l);
|
|
87
|
+
return () => toasterListeners.delete(l);
|
|
88
|
+
};
|
|
61
89
|
/** محل نمایش اعلانها؛ یک بار در ریشهٔ برنامه قرار دهید */
|
|
62
|
-
export function Toaster({ position =
|
|
63
|
-
const
|
|
64
|
-
|
|
90
|
+
export function Toaster({ placement, position, max = 5, label = "اعلانها", closeLabel = "بستن اعلان" }) {
|
|
91
|
+
const id = useId();
|
|
92
|
+
const all = useSyncExternalStore(subscribe, () => items, () => items);
|
|
93
|
+
const active = useSyncExternalStore(subscribeToasters, () => toasters[toasters.length - 1], () => undefined);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
toasters = [...toasters, id];
|
|
96
|
+
if (isDev() && toasters.length > 1)
|
|
97
|
+
console.warn("[kashi] بیش از یک <Toaster> در صفحه است؛ فقط آخرین آنها اعلانها را نشان میدهد.");
|
|
98
|
+
emitToasters();
|
|
99
|
+
return () => {
|
|
100
|
+
toasters = toasters.filter((t) => t !== id);
|
|
101
|
+
emitToasters();
|
|
102
|
+
};
|
|
103
|
+
}, [id]);
|
|
104
|
+
// تا وقتی Toasterی ثبت نشده (مثلاً رندر سرور) همین Toaster نشان میدهد
|
|
105
|
+
const list = active === undefined || active === id ? all.slice(-max) : [];
|
|
106
|
+
const place = placement ?? (position === "top" ? "top-end" : "bottom-end");
|
|
107
|
+
return (_jsx("section", { "aria-label": label, children: _jsx("ol", { className: cx("k-toaster", `k-toaster--${place}`), "data-placement": place, "aria-live": "polite", children: list.map((t) => _jsx(ToastView, { t: t, closeLabel: closeLabel }, t.id)) }) }));
|
|
65
108
|
}
|
package/dist/Tooltip.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ export interface TooltipProps {
|
|
|
4
4
|
content: ReactNode;
|
|
5
5
|
/** عنصر فوکوسپذیر، معمولاً یک دکمه */
|
|
6
6
|
children: ReactElement;
|
|
7
|
-
/** @default "top" */
|
|
8
|
-
placement?: "top" | "bottom";
|
|
7
|
+
/** «start»/«end» کنار عنصر؛ در RTL «start» سمت راست است @default "top" */
|
|
8
|
+
placement?: "top" | "bottom" | "start" | "end";
|
|
9
9
|
/** تأخیر نمایش با hover بر حسب میلیثانیه @default 300 */
|
|
10
10
|
delay?: number;
|
|
11
11
|
}
|
package/dist/Tooltip.js
CHANGED
|
@@ -30,5 +30,5 @@ export function Tooltip({ content, children, placement = "top", delay = 300 }) {
|
|
|
30
30
|
"aria-describedby": [children.props["aria-describedby"], id].filter(Boolean).join(" "),
|
|
31
31
|
})
|
|
32
32
|
: children;
|
|
33
|
-
return (_jsxs("span", { className: "k-tooltip-anchor", onMouseEnter: () => show(delay), onMouseLeave: hide, onFocus: () => show(0), onBlur: hide, children: [child, _jsx("span", { role: "tooltip", id: id, className: cx("k-tooltip", placement
|
|
33
|
+
return (_jsxs("span", { className: "k-tooltip-anchor", onMouseEnter: () => show(delay), onMouseLeave: hide, onFocus: () => show(0), onBlur: hide, children: [child, _jsx("span", { role: "tooltip", id: id, className: cx("k-tooltip", placement !== "top" && `k-tooltip--${placement}`), hidden: !open, children: content })] }));
|
|
34
34
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export { Button } from "./Button.js";
|
|
2
2
|
export type { ButtonProps, ButtonVariant, ButtonSize } from "./Button.js";
|
|
3
3
|
export { Input, Textarea } from "./Input.js";
|
|
4
|
-
export type { InputProps, InputSize, TextareaProps } from "./Input.js";
|
|
4
|
+
export type { InputProps, InputSize, InputClassNames, TextareaProps } from "./Input.js";
|
|
5
5
|
export { Badge } from "./Badge.js";
|
|
6
6
|
export type { BadgeProps, BadgeTone } from "./Badge.js";
|
|
7
|
-
export { Card, CardHeader, CardTitle, CardDescription, CardBody, CardFooter } from "./Card.js";
|
|
8
|
-
export type { CardProps } from "./Card.js";
|
|
7
|
+
export { Card, CardHeader, CardTitle, CardDescription, CardBody, CardFooter, CardMedia } from "./Card.js";
|
|
8
|
+
export type { CardProps, CardHeaderProps, CardMediaProps } from "./Card.js";
|
|
9
9
|
export { Alert } from "./Alert.js";
|
|
10
10
|
export type { AlertProps, AlertTone } from "./Alert.js";
|
|
11
|
-
export { Avatar, AvatarGroup, initials } from "./Avatar.js";
|
|
11
|
+
export { Avatar, AvatarGroup, initials, autoTone } from "./Avatar.js";
|
|
12
12
|
export type { AvatarProps, AvatarGroupProps, AvatarSize, AvatarStatus } from "./Avatar.js";
|
|
13
13
|
export { Checkbox, Switch } from "./Checkbox.js";
|
|
14
|
-
export type { CheckboxProps, SwitchProps } from "./Checkbox.js";
|
|
14
|
+
export type { CheckboxProps, SwitchProps, CheckClassNames } from "./Checkbox.js";
|
|
15
15
|
export { cx } from "./cx.js";
|
|
16
16
|
export { toFaDigits } from "./utils.js";
|
|
17
17
|
export { NationalIdInput } from "./NationalIdInput.js";
|
|
@@ -37,7 +37,7 @@ export type { TabsProps, TabListProps, TabProps, TabPanelProps } from "./Tabs.js
|
|
|
37
37
|
export { Dialog } from "./Dialog.js";
|
|
38
38
|
export type { DialogProps } from "./Dialog.js";
|
|
39
39
|
export { Toaster, toast } from "./Toast.js";
|
|
40
|
-
export type { ToasterProps, ToastOptions, ToastTone } from "./Toast.js";
|
|
40
|
+
export type { ToasterProps, ToastOptions, ToastTone, ToastPlacement } from "./Toast.js";
|
|
41
41
|
export { Tooltip } from "./Tooltip.js";
|
|
42
42
|
export type { TooltipProps } from "./Tooltip.js";
|
|
43
43
|
export { RelativeTime } from "./RelativeTime.js";
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { Button } from "./Button.js";
|
|
2
2
|
export { Input, Textarea } from "./Input.js";
|
|
3
3
|
export { Badge } from "./Badge.js";
|
|
4
|
-
export { Card, CardHeader, CardTitle, CardDescription, CardBody, CardFooter } from "./Card.js";
|
|
4
|
+
export { Card, CardHeader, CardTitle, CardDescription, CardBody, CardFooter, CardMedia } from "./Card.js";
|
|
5
5
|
export { Alert } from "./Alert.js";
|
|
6
|
-
export { Avatar, AvatarGroup, initials } from "./Avatar.js";
|
|
6
|
+
export { Avatar, AvatarGroup, initials, autoTone } from "./Avatar.js";
|
|
7
7
|
export { Checkbox, Switch } from "./Checkbox.js";
|
|
8
8
|
export { cx } from "./cx.js";
|
|
9
9
|
export { toFaDigits } from "./utils.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kashi-ui/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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.8.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.8.0",
|
|
63
|
+
"@kashi-ui/persian": "^0.8.0"
|
|
64
64
|
}
|
|
65
65
|
}
|