@kashi-ui/react 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- 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/Calendar.d.ts +6 -1
- package/dist/Calendar.js +12 -5
- 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/Combobox.d.ts +48 -0
- package/dist/Combobox.js +143 -0
- package/dist/CommandPalette.d.ts +37 -0
- package/dist/CommandPalette.js +95 -0
- package/dist/DataTable.d.ts +28 -1
- package/dist/DataTable.js +17 -10
- package/dist/DateRangePicker.d.ts +50 -0
- package/dist/DateRangePicker.js +94 -0
- 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/FileUpload.d.ts +39 -0
- package/dist/FileUpload.js +90 -0
- package/dist/Input.d.ts +34 -0
- package/dist/Input.js +57 -6
- package/dist/NumberInput.d.ts +29 -0
- package/dist/NumberInput.js +56 -0
- package/dist/Popover.d.ts +19 -0
- package/dist/Popover.js +58 -0
- package/dist/Progress.d.ts +3 -1
- package/dist/Progress.js +6 -1
- package/dist/SideNav.d.ts +28 -0
- package/dist/SideNav.js +22 -0
- package/dist/Slider.d.ts +32 -0
- package/dist/Slider.js +33 -0
- package/dist/Stat.d.ts +24 -0
- package/dist/Stat.js +17 -0
- package/dist/Tabs.d.ts +5 -1
- package/dist/Tabs.js +8 -9
- package/dist/TagInput.d.ts +33 -0
- package/dist/TagInput.js +88 -0
- package/dist/Timeline.d.ts +19 -0
- package/dist/Timeline.js +8 -0
- 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 +28 -6
- package/dist/index.js +13 -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 · DropdownMenu · DataTable · Pagination · Breadcrumb · Accordion · Stepper · Progress · Spinner · Skeleton · EmptyState · Divider · Kbd · 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 · Combobox · CommandPalette · TagInput · FileUpload · Slider · NumberInput · Popover · StatCard · Timeline · SideNav
|
|
24
24
|
|
|
25
|
-
فارسی: DatePicker و Calendar شمسی · NationalIdInput · CardNumberInput · IbanInput · MobileInput · PriceInput · OtpInput
|
|
25
|
+
فارسی: DatePicker و Calendar شمسی · DateRangePicker · 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
|
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/Calendar.d.ts
CHANGED
|
@@ -30,8 +30,13 @@ export interface CalendarProps {
|
|
|
30
30
|
labels?: CalendarLabels;
|
|
31
31
|
/** محتوای پایین تقویم، مثل دکمهٔ «امروز» */
|
|
32
32
|
footer?: ReactNode;
|
|
33
|
+
/** حالت بازه: روزهای بین start و end برجسته میشوند؛ با start بدون end، hover پیشنمایش میدهد */
|
|
34
|
+
range?: {
|
|
35
|
+
start: Date | null;
|
|
36
|
+
end: Date | null;
|
|
37
|
+
};
|
|
33
38
|
className?: string;
|
|
34
39
|
"aria-label"?: string;
|
|
35
40
|
}
|
|
36
41
|
/** تقویم شمسی با الگوی grid استاندارد WAI-ARIA و پیمایش کامل با کیبورد */
|
|
37
|
-
export declare function Calendar({ value, defaultValue, onChange, min, max, isDateDisabled, digits, autoFocus, yearRange, labels, footer, className, "aria-label": ariaLabel, }: CalendarProps): import("react").JSX.Element;
|
|
42
|
+
export declare function Calendar({ value, defaultValue, onChange, min, max, isDateDisabled, digits, autoFocus, yearRange, labels, footer, range, className, "aria-label": ariaLabel, }: CalendarProps): import("react").JSX.Element;
|
package/dist/Calendar.js
CHANGED
|
@@ -22,12 +22,13 @@ function clamp(d, min, max) {
|
|
|
22
22
|
return d;
|
|
23
23
|
}
|
|
24
24
|
/** تقویم شمسی با الگوی grid استاندارد WAI-ARIA و پیمایش کامل با کیبورد */
|
|
25
|
-
export function Calendar({ value, defaultValue = null, onChange, min, max, isDateDisabled, digits = "fa", autoFocus = false, yearRange, labels = {}, footer, className, "aria-label": ariaLabel = "تقویم", }) {
|
|
25
|
+
export function Calendar({ value, defaultValue = null, onChange, min, max, isDateDisabled, digits = "fa", autoFocus = false, yearRange, labels = {}, footer, range, className, "aria-label": ariaLabel = "تقویم", }) {
|
|
26
26
|
const id = useId();
|
|
27
27
|
const [inner, setInner] = useState(defaultValue);
|
|
28
28
|
const selected = value !== undefined ? value : inner;
|
|
29
29
|
const [today] = useState(() => startOfDay(new Date()));
|
|
30
|
-
const [focused, setFocused] = useState(() => clamp(startOfDay(selected ?? today), min, max));
|
|
30
|
+
const [focused, setFocused] = useState(() => clamp(startOfDay(range?.start ?? selected ?? today), min, max));
|
|
31
|
+
const [hover, setHover] = useState(null);
|
|
31
32
|
const moveFocus = useRef(autoFocus);
|
|
32
33
|
const grid = useRef(null);
|
|
33
34
|
const n = (v) => (digits === "fa" ? toFaDigits(v) : String(v));
|
|
@@ -97,11 +98,17 @@ export function Calendar({ value, defaultValue = null, onChange, min, max, isDat
|
|
|
97
98
|
return (_jsxs("div", { className: cx("k-calendar", className), role: "group", "aria-label": ariaLabel, children: [_jsxs("div", { className: "k-calendar__header", children: [_jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": prevMonth, disabled: prevDisabled, onClick: () => go(addJalaliMonths(focused, -1), false), children: _jsx("svg", { "data-k-mirror": "", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m12 5-5 5 5 5" }) }) }), _jsxs("div", { className: "k-calendar__selects", children: [_jsx("select", { className: "k-calendar__select", "aria-label": monthLabel, value: jm, onChange: (e) => go(toGregorian(jy, Number(e.target.value), Math.min(toJalali(focused).jd, jalaliMonthLength(jy, Number(e.target.value)))), false), children: JALALI_MONTHS.map((name, i) => _jsx("option", { value: i + 1, children: name }, name)) }), _jsx("select", { className: "k-calendar__select", "aria-label": yearLabel, value: jy, onChange: (e) => go(toGregorian(Number(e.target.value), jm, Math.min(toJalali(focused).jd, jalaliMonthLength(Number(e.target.value), jm))), false), children: years.sort((a, b) => a - b).map((y) => _jsx("option", { value: y, children: n(y) }, y)) })] }), _jsx("button", { type: "button", className: "k-btn k-btn--tertiary k-btn--icon k-btn--sm", "aria-label": nextMonth, disabled: nextDisabled, onClick: () => go(addJalaliMonths(focused, 1), false), children: _jsx("svg", { "data-k-mirror": "", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m8 5 5 5-5 5" }) }) })] }), _jsx("h2", { className: "k-sr-only", id: `${id}-title`, "aria-live": "polite", children: `${JALALI_MONTHS[jm - 1]} ${n(jy)}` }), _jsxs("table", { className: "k-calendar__grid", role: "grid", "aria-labelledby": `${id}-title`, ref: grid, children: [_jsx("thead", { children: _jsx("tr", { children: WEEKDAYS_SHORT.map((s, i) => (_jsx("th", { scope: "col", abbr: WEEKDAYS[i], children: s }, s))) }) }), _jsx("tbody", { children: weeks.map((week, wi) => (_jsx("tr", { children: week.map((d, di) => {
|
|
98
99
|
if (!d)
|
|
99
100
|
return _jsx("td", { role: "gridcell" }, di);
|
|
100
|
-
const isSelected = sameDay(d, selected);
|
|
101
101
|
const isDisabled = disabled(d);
|
|
102
|
-
|
|
102
|
+
// حالت بازه
|
|
103
|
+
const rs = range?.start ? startOfDay(range.start) : null;
|
|
104
|
+
const re = range?.end ? startOfDay(range.end) : null;
|
|
105
|
+
const previewEnd = rs && !re && hover ? hover : null;
|
|
106
|
+
const [lo, hi] = rs && (re || previewEnd) ? [rs, (re ?? previewEnd)].sort((a, b) => +a - +b) : [null, null];
|
|
107
|
+
const inRange = !!lo && !!hi && d >= lo && d <= hi;
|
|
108
|
+
const isSelected = range ? inRange || sameDay(d, rs) : sameDay(d, selected);
|
|
109
|
+
return (_jsx("td", { role: "gridcell", "aria-selected": isSelected, "data-in-range": range && inRange && re ? "" : undefined, "data-preview": range && inRange && !re ? "" : undefined, "data-range-start": range && (lo ? sameDay(d, lo) : sameDay(d, rs)) ? "" : undefined, "data-range-end": range && (hi ? sameDay(d, hi) : sameDay(d, rs)) ? "" : undefined, children: _jsx("button", { type: "button", className: "k-calendar__day", "data-day": dayKey(d), tabIndex: sameDay(d, focused) ? 0 : -1, "aria-label": formatJalali(d, { style: "full", digits }), "aria-current": sameDay(d, today) ? "date" : undefined, "aria-disabled": isDisabled || undefined, onClick: () => {
|
|
103
110
|
setFocused(d);
|
|
104
111
|
select(d);
|
|
105
|
-
}, onKeyDown: onKeyDown, children: n(toJalali(d).jd) }) }, di));
|
|
112
|
+
}, onKeyDown: onKeyDown, onPointerEnter: range ? () => setHover(d) : undefined, onFocus: range ? () => setHover(d) : undefined, children: n(toJalali(d).jd) }) }, di));
|
|
106
113
|
}) }, wi))) })] }), footer && _jsx("div", { className: "k-calendar__footer", children: footer })] }));
|
|
107
114
|
}
|
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,48 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface ComboboxOption {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** نام گروه برای دستهبندی گزینهها */
|
|
9
|
+
group?: string;
|
|
10
|
+
/** کلمههای اضافه برای جستجو، مثل نام انگلیسی */
|
|
11
|
+
keywords?: string[];
|
|
12
|
+
}
|
|
13
|
+
/** متن یکدست برای جستجو: ي/ی، ك/ک، ارقام، حروف کوچک */
|
|
14
|
+
export declare const searchText: (s: string) => string;
|
|
15
|
+
export declare function defaultFilter(option: ComboboxOption, query: string): boolean;
|
|
16
|
+
/** بخش منطبق با جستجو را با <mark> برجسته میکند */
|
|
17
|
+
export declare function highlight(text: string, query: string): ReactNode;
|
|
18
|
+
export interface ComboboxProps {
|
|
19
|
+
label?: ReactNode;
|
|
20
|
+
hint?: ReactNode;
|
|
21
|
+
error?: ReactNode;
|
|
22
|
+
options: ComboboxOption[];
|
|
23
|
+
value?: string | null;
|
|
24
|
+
defaultValue?: string | null;
|
|
25
|
+
onChange?: (value: string | null) => void;
|
|
26
|
+
/** وقتی متن جستجو عوض میشود؛ برای جستجوی سمت سرور */
|
|
27
|
+
onInputChange?: (query: string) => void;
|
|
28
|
+
placeholder?: string;
|
|
29
|
+
/** جستجوی سفارشی؛ پیشفرض با یکدستسازی فارسی */
|
|
30
|
+
filter?: (option: ComboboxOption, query: string) => boolean;
|
|
31
|
+
/** @default "نتیجهای پیدا نشد." */
|
|
32
|
+
emptyMessage?: ReactNode;
|
|
33
|
+
/** نمایش اسپینر، مثلاً هنگام جستجوی سمت سرور */
|
|
34
|
+
loading?: boolean;
|
|
35
|
+
required?: boolean;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
name?: string;
|
|
38
|
+
id?: string;
|
|
39
|
+
className?: string;
|
|
40
|
+
/** @default (n) => «n نتیجه» */
|
|
41
|
+
resultsLabel?: (count: number) => string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* جستجو و انتخاب با الگوی Combobox در WAI-ARIA:
|
|
45
|
+
* تایپ فهرست را فیلتر میکند، ↑↓ حرکت، Enter انتخاب، Esc بستن (و در حالت بسته، پاک کردن).
|
|
46
|
+
* جستجو «علي» و «علی» را یکی میداند.
|
|
47
|
+
*/
|
|
48
|
+
export declare const Combobox: import("react").ForwardRefExoticComponent<ComboboxProps & import("react").RefAttributes<HTMLInputElement>>;
|
package/dist/Combobox.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef, useEffect, useId, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { normalizePersian, toFaDigits } from "@kashi-ui/persian";
|
|
4
|
+
import { cx } from "./cx.js";
|
|
5
|
+
import { Field, describedBy } from "./Field.js";
|
|
6
|
+
import { mergeRefs } from "./utils.js";
|
|
7
|
+
/** متن یکدست برای جستجو: ي/ی، ك/ک، ارقام، حروف کوچک */
|
|
8
|
+
export const searchText = (s) => normalizePersian(s, { digits: "latin" }).toLowerCase();
|
|
9
|
+
export function defaultFilter(option, query) {
|
|
10
|
+
const q = searchText(query.trim());
|
|
11
|
+
if (!q)
|
|
12
|
+
return true;
|
|
13
|
+
return [option.label, option.description ?? "", ...(option.keywords ?? [])].some((t) => searchText(t).includes(q));
|
|
14
|
+
}
|
|
15
|
+
/** بخش منطبق با جستجو را با <mark> برجسته میکند */
|
|
16
|
+
export function highlight(text, query) {
|
|
17
|
+
const q = searchText(query.trim());
|
|
18
|
+
if (!q)
|
|
19
|
+
return text;
|
|
20
|
+
const i = searchText(text).indexOf(q);
|
|
21
|
+
if (i < 0)
|
|
22
|
+
return text;
|
|
23
|
+
return (_jsxs(_Fragment, { children: [text.slice(0, i), _jsx("mark", { children: text.slice(i, i + q.length) }), text.slice(i + q.length)] }));
|
|
24
|
+
}
|
|
25
|
+
const Check = () => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m5 10.5 3.2 3L15 7" }) }));
|
|
26
|
+
/**
|
|
27
|
+
* جستجو و انتخاب با الگوی Combobox در WAI-ARIA:
|
|
28
|
+
* تایپ فهرست را فیلتر میکند، ↑↓ حرکت، Enter انتخاب، Esc بستن (و در حالت بسته، پاک کردن).
|
|
29
|
+
* جستجو «علي» و «علی» را یکی میداند.
|
|
30
|
+
*/
|
|
31
|
+
export const Combobox = forwardRef(function Combobox({ label, hint, error, options, value, defaultValue = null, onChange, onInputChange, placeholder, filter = defaultFilter, emptyMessage = "نتیجهای پیدا نشد.", loading, required, disabled, name, id, className, resultsLabel = (n) => `${toFaDigits(n)} نتیجه`, }, ref) {
|
|
32
|
+
const autoId = useId();
|
|
33
|
+
const inputId = id ?? autoId;
|
|
34
|
+
const listId = `${inputId}-list`;
|
|
35
|
+
const [inner, setInner] = useState(defaultValue);
|
|
36
|
+
const selected = value !== undefined ? value : inner;
|
|
37
|
+
const selectedOption = options.find((o) => o.value === selected) ?? null;
|
|
38
|
+
const [query, setQuery] = useState(selectedOption?.label ?? "");
|
|
39
|
+
const [open, setOpen] = useState(false);
|
|
40
|
+
const [typing, setTyping] = useState(false);
|
|
41
|
+
const [active, setActive] = useState(-1);
|
|
42
|
+
const inputRef = useRef(null);
|
|
43
|
+
const wrapRef = useRef(null);
|
|
44
|
+
// وقتی مقدار از بیرون عوض شد، متن فیلد هم هماهنگ شود
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!typing)
|
|
47
|
+
setQuery(selectedOption?.label ?? "");
|
|
48
|
+
}, [selectedOption?.label]);
|
|
49
|
+
const filtered = useMemo(() => (typing ? options.filter((o) => filter(o, query)) : options), [options, query, typing, filter]);
|
|
50
|
+
const enabled = filtered.map((o, i) => (o.disabled ? -1 : i)).filter((i) => i >= 0);
|
|
51
|
+
const commit = (o) => {
|
|
52
|
+
if (value === undefined)
|
|
53
|
+
setInner(o?.value ?? null);
|
|
54
|
+
onChange?.(o?.value ?? null);
|
|
55
|
+
setQuery(o?.label ?? "");
|
|
56
|
+
setTyping(false);
|
|
57
|
+
setOpen(false);
|
|
58
|
+
setActive(-1);
|
|
59
|
+
};
|
|
60
|
+
const openList = (at = "selected") => {
|
|
61
|
+
if (disabled)
|
|
62
|
+
return;
|
|
63
|
+
setOpen(true);
|
|
64
|
+
const sel = filtered.findIndex((o) => o.value === selected);
|
|
65
|
+
setActive(at === "last" ? enabled[enabled.length - 1] ?? -1 : at === "first" || sel < 0 ? enabled[0] ?? -1 : sel);
|
|
66
|
+
};
|
|
67
|
+
const move = (delta) => {
|
|
68
|
+
if (!enabled.length)
|
|
69
|
+
return;
|
|
70
|
+
const pos = enabled.indexOf(active);
|
|
71
|
+
setActive(enabled[(pos + delta + enabled.length) % enabled.length]);
|
|
72
|
+
};
|
|
73
|
+
// گزینهٔ فعال همیشه دیده شود
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
if (active < 0)
|
|
76
|
+
return;
|
|
77
|
+
document.getElementById(`${listId}-${active}`)?.scrollIntoView({ block: "nearest" });
|
|
78
|
+
}, [active, listId]);
|
|
79
|
+
const onKeyDown = (e) => {
|
|
80
|
+
if (e.key === "ArrowDown") {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
open ? move(1) : openList(e.altKey ? "selected" : "first");
|
|
83
|
+
}
|
|
84
|
+
else if (e.key === "ArrowUp") {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
open ? move(-1) : openList("last");
|
|
87
|
+
}
|
|
88
|
+
else if (e.key === "Enter" && open && active >= 0) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
commit(filtered[active]);
|
|
91
|
+
}
|
|
92
|
+
else if (e.key === "Escape") {
|
|
93
|
+
if (open) {
|
|
94
|
+
e.preventDefault();
|
|
95
|
+
setOpen(false);
|
|
96
|
+
setTyping(false);
|
|
97
|
+
setQuery(selectedOption?.label ?? "");
|
|
98
|
+
}
|
|
99
|
+
else if (query) {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
commit(null);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (e.key === "Home" || e.key === "End") {
|
|
105
|
+
if (!open)
|
|
106
|
+
return;
|
|
107
|
+
e.preventDefault();
|
|
108
|
+
setActive(e.key === "Home" ? enabled[0] : enabled[enabled.length - 1]);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
let lastGroup;
|
|
112
|
+
return (_jsx(Field, { id: inputId, label: label, hint: hint, error: error, required: required, className: className, children: _jsxs("div", { ref: wrapRef, className: "k-combobox", "data-open": open ? "" : undefined, onBlur: (e) => {
|
|
113
|
+
if (wrapRef.current?.contains(e.relatedTarget))
|
|
114
|
+
return;
|
|
115
|
+
setOpen(false);
|
|
116
|
+
// متن نیمهکاره به گزینهٔ انتخابشده برمیگردد
|
|
117
|
+
if (typing) {
|
|
118
|
+
setTyping(false);
|
|
119
|
+
setQuery(selectedOption?.label ?? "");
|
|
120
|
+
}
|
|
121
|
+
}, children: [_jsxs("div", { className: cx("k-input"), "data-state": error ? "invalid" : undefined, children: [_jsx("input", { ref: mergeRefs(ref, inputRef), id: inputId, className: "k-input__control", type: "text", role: "combobox", "aria-autocomplete": "list", "aria-expanded": open, "aria-controls": listId, "aria-activedescendant": open && active >= 0 ? `${listId}-${active}` : undefined, "aria-invalid": error ? true : undefined, "aria-describedby": describedBy(inputId, hint, error), autoComplete: "off", placeholder: placeholder, value: query, required: required, disabled: disabled, onChange: (e) => {
|
|
122
|
+
setQuery(e.target.value);
|
|
123
|
+
setTyping(true);
|
|
124
|
+
setOpen(true);
|
|
125
|
+
setActive(-1);
|
|
126
|
+
onInputChange?.(e.target.value);
|
|
127
|
+
}, onKeyDown: onKeyDown, onClick: () => !open && openList() }), loading && _jsx("span", { className: "k-input__addon", children: _jsx("span", { className: "k-spinner k-spinner--sm", "aria-hidden": "true" }) }), _jsx("button", { type: "button", tabIndex: -1, className: "k-input__action k-combobox__toggle", "aria-label": "\u0646\u0645\u0627\u06CC\u0634 \u06AF\u0632\u06CC\u0646\u0647\u200C\u0647\u0627", disabled: disabled, onClick: () => {
|
|
128
|
+
if (open)
|
|
129
|
+
setOpen(false);
|
|
130
|
+
else {
|
|
131
|
+
setTyping(false);
|
|
132
|
+
openList();
|
|
133
|
+
inputRef.current?.focus();
|
|
134
|
+
}
|
|
135
|
+
}, children: _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m6 8 4 4 4-4" }) }) })] }), _jsxs("ul", { id: listId, role: "listbox", "aria-labelledby": label ? undefined : inputId, "aria-label": typeof label === "string" ? label : undefined, className: "k-listbox", hidden: !open, style: { insetBlockStart: "calc(100% + 6px)" }, children: [filtered.length === 0 && _jsx("li", { className: "k-listbox__empty", role: "presentation", children: loading ? "در حال جستجو…" : emptyMessage }), filtered.map((o, i) => {
|
|
136
|
+
const header = o.group && o.group !== lastGroup ? o.group : null;
|
|
137
|
+
lastGroup = o.group;
|
|
138
|
+
return [
|
|
139
|
+
header && _jsx("li", { role: "presentation", className: "k-listbox__group", children: header }, `g-${header}`),
|
|
140
|
+
_jsxs("li", { id: `${listId}-${i}`, role: "option", "aria-selected": o.value === selected, "aria-disabled": o.disabled || undefined, "data-active": i === active ? "" : undefined, className: "k-option", onPointerDown: (e) => e.preventDefault() /* فوکوس در فیلد بماند */, onClick: () => !o.disabled && commit(o), onPointerMove: () => !o.disabled && active !== i && setActive(i), children: [o.icon, _jsxs("span", { className: "k-option__body", children: [_jsx("span", { children: highlight(o.label, typing ? query : "") }), o.description && _jsx("span", { className: "k-option__desc", children: o.description })] }), o.value === selected && _jsx("span", { className: "k-option__check", children: _jsx(Check, {}) })] }, o.value),
|
|
141
|
+
];
|
|
142
|
+
})] }), _jsx("span", { className: "k-sr-only", "aria-live": "polite", children: open && typing ? resultsLabel(filtered.length) : "" }), name && _jsx("input", { type: "hidden", name: name, value: selected ?? "" })] }) }));
|
|
143
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface CommandItem {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
group?: string;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
/** میانبر نمایشی، مثل "Ctrl+N" */
|
|
8
|
+
shortcut?: string;
|
|
9
|
+
/** کلمههای اضافه برای جستجو */
|
|
10
|
+
keywords?: string[];
|
|
11
|
+
description?: string;
|
|
12
|
+
onSelect?: () => void;
|
|
13
|
+
/** بهجای onSelect، رفتن به یک آدرس */
|
|
14
|
+
href?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface CommandPaletteProps {
|
|
17
|
+
open: boolean;
|
|
18
|
+
onOpenChange: (open: boolean) => void;
|
|
19
|
+
items: CommandItem[];
|
|
20
|
+
/** باز کردن با Ctrl+K یا ⌘K @default true */
|
|
21
|
+
shortcut?: boolean;
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
emptyMessage?: ReactNode;
|
|
24
|
+
labels?: {
|
|
25
|
+
title?: string;
|
|
26
|
+
navigate?: string;
|
|
27
|
+
select?: string;
|
|
28
|
+
close?: string;
|
|
29
|
+
results?: (n: number) => string;
|
|
30
|
+
};
|
|
31
|
+
className?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* پالت فرمان: جستجوی سریع در عملها و صفحهها با Ctrl+K.
|
|
35
|
+
* پنجره روی <dialog> بومی است (تلهٔ فوکوس و Esc) و فهرست با الگوی combobox/listbox پیمایش میشود.
|
|
36
|
+
*/
|
|
37
|
+
export declare function CommandPalette({ open, onOpenChange, items, shortcut, placeholder, emptyMessage, labels, className, }: CommandPaletteProps): import("react").JSX.Element;
|