@kashi-ui/react 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/Accordion.d.ts +15 -0
- package/dist/Accordion.js +13 -0
- 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/Breadcrumb.d.ts +23 -0
- package/dist/Breadcrumb.js +32 -0
- 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 +70 -0
- package/dist/DataTable.js +59 -0
- package/dist/Dialog.d.ts +4 -2
- package/dist/Dialog.js +2 -2
- package/dist/DropdownMenu.d.ts +35 -0
- package/dist/DropdownMenu.js +99 -0
- 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/Misc.d.ts +22 -0
- package/dist/Misc.js +16 -0
- package/dist/OtpInput.d.ts +28 -0
- package/dist/OtpInput.js +30 -0
- package/dist/Pagination.d.ts +25 -0
- package/dist/Pagination.js +28 -0
- package/dist/Progress.d.ts +24 -0
- package/dist/Progress.js +20 -0
- package/dist/Skeleton.d.ts +11 -0
- package/dist/Skeleton.js +11 -0
- package/dist/Stepper.d.ts +20 -0
- package/dist/Stepper.js +12 -0
- 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 +26 -6
- package/dist/index.js +12 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -20,8 +20,8 @@ export function SignUp() {
|
|
|
20
20
|
}
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
کامپوننتها: Button · Input · Textarea · Select · Checkbox · RadioGroup · Switch · Badge · Card · Alert · Avatar · AvatarGroup · Tabs · Dialog · Toast · Tooltip · RelativeTime
|
|
23
|
+
کامپوننتها: Button · Input · Textarea · Select · Checkbox · RadioGroup · Switch · Badge · Card · Alert · Avatar · AvatarGroup · Tabs · Dialog · Toast · Tooltip · DropdownMenu · DataTable · Pagination · Breadcrumb · Accordion · Stepper · Progress · Spinner · Skeleton · EmptyState · Divider · Kbd · RelativeTime
|
|
24
24
|
|
|
25
|
-
فارسی: DatePicker و Calendar شمسی · NationalIdInput · CardNumberInput · IbanInput · MobileInput · PriceInput
|
|
25
|
+
فارسی: DatePicker و Calendar شمسی · NationalIdInput · CardNumberInput · IbanInput · MobileInput · PriceInput · OtpInput
|
|
26
26
|
|
|
27
27
|
نیازمند React ۱۸ یا بالاتر. مستندات کامل: [kashi.sepantapouya.com](https://kashi.sepantapouya.com) · کد: [GitHub](https://github.com/Sepantapouya/Kashi) · لایسنس MIT
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type DetailsHTMLAttributes, type HTMLAttributes, type ReactNode } from "react";
|
|
2
|
+
export interface AccordionProps extends HTMLAttributes<HTMLDivElement> {
|
|
3
|
+
/** «single»: باز شدن هر بخش بقیه را میبندد (با name مشترک روی details) @default "multiple" */
|
|
4
|
+
type?: "single" | "multiple";
|
|
5
|
+
/** بدون حاشیه و پسزمینه */
|
|
6
|
+
flush?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/** آکاردئون روی <details> بومی: بدون JavaScript، با کیبورد و صفحهخوان کامل */
|
|
9
|
+
export declare function Accordion({ type, flush, className, children, ...rest }: AccordionProps): import("react").JSX.Element;
|
|
10
|
+
export interface AccordionItemProps extends Omit<DetailsHTMLAttributes<HTMLDetailsElement>, "title"> {
|
|
11
|
+
title: ReactNode;
|
|
12
|
+
defaultOpen?: boolean;
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
export declare function AccordionItem({ title, defaultOpen, className, children, ...rest }: AccordionItemProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useId } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
const AccCtx = createContext({});
|
|
5
|
+
/** آکاردئون روی <details> بومی: بدون JavaScript، با کیبورد و صفحهخوان کامل */
|
|
6
|
+
export function Accordion({ type = "multiple", flush, className, children, ...rest }) {
|
|
7
|
+
const id = useId();
|
|
8
|
+
return (_jsx(AccCtx.Provider, { value: { name: type === "single" ? `k-acc-${id}` : undefined }, children: _jsx("div", { className: cx("k-accordion", flush && "k-accordion--flush", className), ...rest, children: children }) }));
|
|
9
|
+
}
|
|
10
|
+
export function AccordionItem({ title, defaultOpen, className, children, ...rest }) {
|
|
11
|
+
const { name } = useContext(AccCtx);
|
|
12
|
+
return (_jsxs("details", { className: cx("k-accordion__item", className), name: name, open: defaultOpen, ...rest, children: [_jsx("summary", { className: "k-accordion__trigger", children: title }), _jsx("div", { className: "k-accordion__content", children: children })] }));
|
|
13
|
+
}
|
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
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface BreadcrumbItem {
|
|
3
|
+
label: ReactNode;
|
|
4
|
+
href?: string;
|
|
5
|
+
icon?: ReactNode;
|
|
6
|
+
/** فقط آیکون نمایش داده شود؛ برچسب برای صفحهخوان میماند (مثل «خانه») */
|
|
7
|
+
hideLabel?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface BreadcrumbProps {
|
|
10
|
+
/** آخرین مورد صفحهٔ فعلی است */
|
|
11
|
+
items: BreadcrumbItem[];
|
|
12
|
+
/** اگر موارد بیشتر بود، وسط مسیر به «…» جمع میشود */
|
|
13
|
+
maxItems?: number;
|
|
14
|
+
/** @default "chevron" */
|
|
15
|
+
separator?: "chevron" | "slash";
|
|
16
|
+
/** @default "مسیر" */
|
|
17
|
+
label?: string;
|
|
18
|
+
/** @default "نمایش مسیر کامل" */
|
|
19
|
+
expandLabel?: string;
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
/** مسیر صفحه؛ آخرین مورد با aria-current="page" مشخص میشود و مسیرهای بلند جمع میشوند */
|
|
23
|
+
export declare function Breadcrumb({ items, maxItems, separator, label, expandLabel, className }: BreadcrumbProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
/** مسیر صفحه؛ آخرین مورد با aria-current="page" مشخص میشود و مسیرهای بلند جمع میشوند */
|
|
5
|
+
export function Breadcrumb({ items, maxItems, separator = "chevron", label = "مسیر", expandLabel = "نمایش مسیر کامل", className }) {
|
|
6
|
+
const [expanded, setExpanded] = useState(false);
|
|
7
|
+
const listRef = useRef(null);
|
|
8
|
+
const justExpanded = useRef(false);
|
|
9
|
+
// دکمهٔ «…» پس از باز شدن حذف میشود؛ فوکوس به اولین مورد تازهنمایان میرود تا گم نشود
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (!justExpanded.current)
|
|
12
|
+
return;
|
|
13
|
+
justExpanded.current = false;
|
|
14
|
+
listRef.current?.querySelectorAll(".k-breadcrumb__link")[1]?.focus();
|
|
15
|
+
}, [expanded]);
|
|
16
|
+
const collapse = !expanded && maxItems !== undefined && maxItems >= 2 && items.length > maxItems;
|
|
17
|
+
// اولی + «…» + آخرینها
|
|
18
|
+
const visible = collapse
|
|
19
|
+
? [items[0], "ellipsis", ...items.slice(items.length - (maxItems - 1))]
|
|
20
|
+
: items;
|
|
21
|
+
return (_jsx("nav", { className: cx("k-breadcrumb", separator === "slash" && "k-breadcrumb--slash", className), "aria-label": label, children: _jsx("ol", { ref: listRef, children: visible.map((item, i) => {
|
|
22
|
+
if (item === "ellipsis") {
|
|
23
|
+
return (_jsx("li", { children: _jsx("button", { type: "button", className: "k-breadcrumb__link", "aria-label": expandLabel, onClick: () => { justExpanded.current = true; setExpanded(true); }, children: "\u2026" }) }, "ellipsis"));
|
|
24
|
+
}
|
|
25
|
+
const last = item === items[items.length - 1];
|
|
26
|
+
const iconOnly = !!item.icon && item.hideLabel;
|
|
27
|
+
const cls = cx("k-breadcrumb__link", iconOnly && "k-breadcrumb__link--icon");
|
|
28
|
+
const title = typeof item.label === "string" && !iconOnly ? item.label : undefined;
|
|
29
|
+
const content = (_jsxs(_Fragment, { children: [item.icon, _jsx("span", { className: iconOnly ? "k-sr-only" : "k-breadcrumb__text", children: item.label })] }));
|
|
30
|
+
return (_jsx("li", { children: last || !item.href ? (_jsx("span", { className: cls, "aria-current": last ? "page" : undefined, title: title, children: content })) : (_jsx("a", { className: cls, href: item.href, title: title, children: content })) }, i));
|
|
31
|
+
}) }) }));
|
|
32
|
+
}
|
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
|
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface Column<T> {
|
|
3
|
+
key: string;
|
|
4
|
+
header: ReactNode;
|
|
5
|
+
/** محتوای خانه؛ پیشفرض row[key] */
|
|
6
|
+
render?: (row: T) => ReactNode;
|
|
7
|
+
/** مقدار برای مرتبسازی؛ پیشفرض row[key] */
|
|
8
|
+
sortValue?: (row: T) => string | number;
|
|
9
|
+
sortable?: boolean;
|
|
10
|
+
/** عدد و مبلغ: چپچین در RTL با ارقام همعرض */
|
|
11
|
+
numeric?: boolean;
|
|
12
|
+
/** چینش خانهها؛ numeric خودکار «end» است */
|
|
13
|
+
align?: "start" | "center" | "end";
|
|
14
|
+
width?: string;
|
|
15
|
+
/** پنهان کردن ستون در صفحههای باریک */
|
|
16
|
+
hideBelow?: "sm" | "md";
|
|
17
|
+
/** کلاس خانههای این ستون */
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
export type SortState = {
|
|
21
|
+
key: string;
|
|
22
|
+
direction: "ascending" | "descending";
|
|
23
|
+
} | null;
|
|
24
|
+
export interface DataTableProps<T> {
|
|
25
|
+
columns: Column<T>[];
|
|
26
|
+
rows: T[];
|
|
27
|
+
getRowId: (row: T) => string;
|
|
28
|
+
/** عنوان جدول (caption)؛ برای صفحهخوان ضروری است */
|
|
29
|
+
caption: ReactNode;
|
|
30
|
+
description?: ReactNode;
|
|
31
|
+
/** پنهان کردن عنوان از دید (صفحهخوان همچنان میخواند) */
|
|
32
|
+
hideCaption?: boolean;
|
|
33
|
+
selectable?: boolean;
|
|
34
|
+
selected?: string[];
|
|
35
|
+
onSelectedChange?: (ids: string[]) => void;
|
|
36
|
+
sort?: SortState;
|
|
37
|
+
defaultSort?: SortState;
|
|
38
|
+
onSortChange?: (sort: SortState) => void;
|
|
39
|
+
/** وقتی ردیفی نیست */
|
|
40
|
+
empty?: ReactNode;
|
|
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;
|
|
54
|
+
labels?: {
|
|
55
|
+
selectAll?: string;
|
|
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;
|
|
66
|
+
};
|
|
67
|
+
className?: string;
|
|
68
|
+
}
|
|
69
|
+
/** جدول داده با مرتبسازی (aria-sort)، انتخاب ردیفها و حالت خالی */
|
|
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;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { cx } from "./cx.js";
|
|
4
|
+
/** جدول داده با مرتبسازی (aria-sort)، انتخاب ردیفها و حالت خالی */
|
|
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
|
+
const id = useId();
|
|
7
|
+
const [innerSort, setInnerSort] = useState(defaultSort);
|
|
8
|
+
const [innerSel, setInnerSel] = useState([]);
|
|
9
|
+
const activeSort = sort !== undefined ? sort : innerSort;
|
|
10
|
+
const sel = selected ?? innerSel;
|
|
11
|
+
const allRef = useRef(null);
|
|
12
|
+
const sorted = useMemo(() => {
|
|
13
|
+
if (!activeSort)
|
|
14
|
+
return rows;
|
|
15
|
+
const col = columns.find((c) => c.key === activeSort.key);
|
|
16
|
+
const val = (r) => (col?.sortValue ? col.sortValue(r) : r[activeSort.key]);
|
|
17
|
+
const dir = activeSort.direction === "ascending" ? 1 : -1;
|
|
18
|
+
return [...rows].sort((a, b) => {
|
|
19
|
+
const x = val(a);
|
|
20
|
+
const y = val(b);
|
|
21
|
+
return (typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y), "fa")) * dir;
|
|
22
|
+
});
|
|
23
|
+
}, [rows, activeSort, columns]);
|
|
24
|
+
const setSort = (key) => {
|
|
25
|
+
const next = activeSort?.key === key && activeSort.direction === "ascending" ? { key, direction: "descending" } : { key, direction: "ascending" };
|
|
26
|
+
if (sort === undefined)
|
|
27
|
+
setInnerSort(next);
|
|
28
|
+
onSortChange?.(next);
|
|
29
|
+
};
|
|
30
|
+
const setSel = (ids) => {
|
|
31
|
+
if (selected === undefined)
|
|
32
|
+
setInnerSel(ids);
|
|
33
|
+
onSelectedChange?.(ids);
|
|
34
|
+
};
|
|
35
|
+
const ids = rows.map(getRowId);
|
|
36
|
+
const all = ids.length > 0 && ids.every((x) => sel.includes(x));
|
|
37
|
+
const some = !all && ids.some((x) => sel.includes(x));
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (allRef.current)
|
|
40
|
+
allRef.current.indeterminate = some;
|
|
41
|
+
}, [some]);
|
|
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;
|
|
45
|
+
const colCount = columns.length + (selectable ? 1 : 0);
|
|
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 })] }));
|
|
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) => {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from "react";
|
|
2
|
+
export interface DropdownMenuProps {
|
|
3
|
+
/** دکمهای که منو را باز میکند */
|
|
4
|
+
trigger: ReactElement;
|
|
5
|
+
/** نام منو برای صفحهخوان؛ پیشفرض متن دکمه */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** همترازی با لبهٔ ابتدا یا انتهای دکمه @default "start" */
|
|
8
|
+
align?: "start" | "end";
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* منوی کشویی با الگوی Menu Button در WAI-ARIA:
|
|
13
|
+
* Enter، Space یا ↓ باز میکند و اولین گزینه را فوکوس میکند، ↑ آخرین را؛
|
|
14
|
+
* ↑↓ و Home/End حرکت، حرف اول برای پرش، Esc بستن و برگشت به دکمه، Tab بستن.
|
|
15
|
+
*/
|
|
16
|
+
export declare function DropdownMenu({ trigger, label, align, children }: DropdownMenuProps): import("react").JSX.Element;
|
|
17
|
+
export interface MenuItemProps {
|
|
18
|
+
onSelect?: () => void;
|
|
19
|
+
icon?: ReactNode;
|
|
20
|
+
/** میانبر نمایشی، مثل "Ctrl+D" */
|
|
21
|
+
shortcut?: string;
|
|
22
|
+
/** «danger» برای عملیات مخرب */
|
|
23
|
+
tone?: "default" | "danger";
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** لینک بهجای عمل */
|
|
26
|
+
href?: string;
|
|
27
|
+
/** گزینهٔ تیکدار (menuitemcheckbox)، مثل «نمایش ستون تاریخ»؛ منو پس از انتخاب باز میماند */
|
|
28
|
+
checked?: boolean;
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
}
|
|
31
|
+
export declare function MenuItem({ onSelect, icon, shortcut, tone, disabled, href, checked, children }: MenuItemProps): import("react").JSX.Element;
|
|
32
|
+
export declare const MenuSeparator: () => import("react").JSX.Element;
|
|
33
|
+
export declare const MenuLabel: ({ children }: {
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
}) => import("react").JSX.Element;
|