@kashi-ui/react 0.12.0 → 0.13.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 CHANGED
@@ -20,7 +20,7 @@ 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 · Combobox · CommandPalette · TagInput · FileUpload · Slider · NumberInput · Popover · StatCard · Timeline · SideNav · SegmentedControl · CopyButton · Banner · Rating · TreeView · ButtonGroup · ChipGroup · PasswordStrength · BarChart · LineChart · ContextMenu · InlineEdit
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 · SegmentedControl · CopyButton · Banner · Rating · TreeView · ButtonGroup · ChipGroup · PasswordStrength · BarChart · LineChart · ContextMenu · InlineEdit · PieChart · BarList · ProportionBar · Sparkline · Carousel · ColorPicker · Tour · Meter · Splitter
24
24
 
25
25
  فارسی: DatePicker و Calendar شمسی · DateRangePicker · TimeInput · PostalCodeInput · PlateInput · LandlineInput · MonthPicker · Countdown · ActivityHeatmap · ProvinceSelect · NationalIdInput · CardNumberInput · IbanInput · MobileInput · PriceInput · OtpInput
26
26
 
@@ -21,6 +21,11 @@ export interface CalendarProps {
21
21
  max?: Date;
22
22
  /** غیرفعال کردن روزهای خاص، مثلاً جمعه‌ها */
23
23
  isDateDisabled?: (date: Date) => boolean;
24
+ /**
25
+ * نمایش تعطیلات: true برای جمعه‌ها و تعطیلات ثابت ایران،
26
+ * یا تابعی که نام تعطیلی آن روز (یا null) را برمی‌گرداند، مثلاً با getIranHoliday و تعطیلات قمری همان سال
27
+ */
28
+ holidays?: boolean | ((date: Date) => string | null | false | undefined);
24
29
  /** @default "fa" */
25
30
  digits?: "fa" | "latin";
26
31
  /** فوکوس روی روز انتخاب‌شده (یا امروز) هنگام نمایش */
@@ -39,4 +44,4 @@ export interface CalendarProps {
39
44
  "aria-label"?: string;
40
45
  }
41
46
  /** تقویم شمسی با الگوی grid استاندارد WAI-ARIA و پیمایش کامل با کیبورد */
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;
47
+ export declare function Calendar({ value, defaultValue, onChange, min, max, isDateDisabled, holidays, digits, autoFocus, yearRange, labels, footer, range, className, "aria-label": ariaLabel, }: CalendarProps): import("react").JSX.Element;
package/dist/Calendar.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useRef, useState } from "react";
3
- import { JALALI_MONTHS, WEEKDAYS, WEEKDAYS_SHORT, formatJalali, jalaliMonthLength, jalaliWeekday, toFaDigits, toGregorian, toJalali, } from "@kashi-ui/persian";
3
+ import { JALALI_MONTHS, WEEKDAYS, WEEKDAYS_SHORT, formatJalali, getIranHoliday, jalaliMonthLength, jalaliWeekday, toFaDigits, toGregorian, toJalali, } from "@kashi-ui/persian";
4
4
  import { cx } from "./cx.js";
5
5
  export const sameDay = (a, b) => !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
6
6
  const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
@@ -22,7 +22,7 @@ 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, range, className, "aria-label": ariaLabel = "تقویم", }) {
25
+ export function Calendar({ value, defaultValue = null, onChange, min, max, isDateDisabled, holidays, 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;
@@ -106,7 +106,8 @@ export function Calendar({ value, defaultValue = null, onChange, min, max, isDat
106
106
  const [lo, hi] = rs && (re || previewEnd) ? [rs, (re ?? previewEnd)].sort((a, b) => +a - +b) : [null, null];
107
107
  const inRange = !!lo && !!hi && d >= lo && d <= hi;
108
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: () => {
109
+ const holiday = holidays === true ? getIranHoliday(d) : holidays ? holidays(d) || null : null;
110
+ 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 }) + (holiday ? `، تعطیل${holiday === "جمعه" ? "" : `: ${holiday}`}` : ""), title: holiday && holiday !== "جمعه" ? holiday : undefined, "data-holiday": holiday ? "" : undefined, "aria-current": sameDay(d, today) ? "date" : undefined, "aria-disabled": isDisabled || undefined, onClick: () => {
110
111
  setFocused(d);
111
112
  select(d);
112
113
  }, onKeyDown: onKeyDown, onPointerEnter: range ? () => setHover(d) : undefined, onFocus: range ? () => setHover(d) : undefined, children: n(toJalali(d).jd) }) }, di));
@@ -0,0 +1,22 @@
1
+ import { type ReactNode } from "react";
2
+ export interface CarouselProps {
3
+ /** هر فرزند یک اسلاید */
4
+ children: ReactNode;
5
+ /** نام اسلایدر، مثل «محصولات پیشنهادی» (الزامی) */
6
+ label: string;
7
+ /** تعداد اسلاید در هر نما @default 1 */
8
+ perView?: number;
9
+ /** نمایش نقطه‌ها @default true */
10
+ dots?: boolean;
11
+ className?: string;
12
+ labels?: {
13
+ prev?: string;
14
+ next?: string;
15
+ slide?: (n: number, total: number) => string;
16
+ };
17
+ }
18
+ /**
19
+ * اسلایدر روی scroll-snap بومی: با کشیدن، چرخ موس، دکمه‌ها و کلیدهای جهت کار می‌کند.
20
+ * چرخش خودکار ندارد، چون خواندن را برای همه سخت می‌کند (WCAG 2.2.2).
21
+ */
22
+ export declare function Carousel({ children, label, perView, dots, className, labels }: CarouselProps): import("react").JSX.Element;
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, useEffect, useId, useRef, useState } from "react";
3
+ import { toFaDigits } from "@kashi-ui/persian";
4
+ import { cx } from "./cx.js";
5
+ const Arrow = ({ next }) => (_jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", "data-k-mirror": "", children: _jsx("path", { d: next ? "m8 5 5 5-5 5" : "m12 5-5 5 5 5" }) }));
6
+ /**
7
+ * اسلایدر روی scroll-snap بومی: با کشیدن، چرخ موس، دکمه‌ها و کلیدهای جهت کار می‌کند.
8
+ * چرخش خودکار ندارد، چون خواندن را برای همه سخت می‌کند (WCAG 2.2.2).
9
+ */
10
+ export function Carousel({ children, label, perView = 1, dots = true, className, labels = {} }) {
11
+ const id = useId();
12
+ const { prev = "قبلی", next = "بعدی", slide = (n, t) => `${toFaDigits(n)} از ${toFaDigits(t)}` } = labels;
13
+ const slides = Children.toArray(children);
14
+ const track = useRef(null);
15
+ const [index, setIndex] = useState(0);
16
+ const pages = Math.max(1, slides.length - perView + 1);
17
+ // اسلاید فعال از روی موقعیت اسکرول
18
+ useEffect(() => {
19
+ const el = track.current;
20
+ if (!el)
21
+ return;
22
+ const items = [...el.children];
23
+ const io = new IntersectionObserver((entries) => {
24
+ const vis = entries.filter((e) => e.isIntersecting && e.intersectionRatio > 0.6).map((e) => items.indexOf(e.target));
25
+ if (vis.length)
26
+ setIndex(Math.min(...vis));
27
+ }, { root: el, threshold: [0.6, 1] });
28
+ items.forEach((s) => io.observe(s));
29
+ return () => io.disconnect();
30
+ }, [slides.length]);
31
+ const go = (i) => {
32
+ const n = Math.max(0, Math.min(pages - 1, i));
33
+ const el = track.current?.children[n];
34
+ if (!el || !track.current)
35
+ return;
36
+ // scrollIntoView صفحه را هم اسکرول می‌کند؛ فقط خود ریل را جابه‌جا می‌کنیم
37
+ const t = track.current;
38
+ const rtl = getComputedStyle(t).direction === "rtl";
39
+ const offset = rtl ? -(t.getBoundingClientRect().right - el.getBoundingClientRect().right) + t.scrollLeft : el.getBoundingClientRect().left - t.getBoundingClientRect().left + t.scrollLeft;
40
+ t.scrollTo({ left: offset });
41
+ setIndex(n);
42
+ };
43
+ return (_jsxs("section", { className: cx("k-carousel", className), "aria-roledescription": "\u0627\u0633\u0644\u0627\u06CC\u062F\u0631", "aria-label": label, style: { "--k-carousel-per-view": perView }, children: [_jsx("div", { ref: track, className: "k-carousel__track", tabIndex: 0, "aria-live": "polite", onKeyDown: (e) => {
44
+ const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
45
+ const step = { ArrowLeft: rtl ? 1 : -1, ArrowRight: rtl ? -1 : 1 }[e.key];
46
+ if (step) {
47
+ e.preventDefault();
48
+ go(index + step);
49
+ }
50
+ else if (e.key === "Home")
51
+ go(0);
52
+ else if (e.key === "End")
53
+ go(pages - 1);
54
+ }, children: slides.map((s, i) => (_jsx("div", { className: "k-carousel__slide", role: "group", "aria-roledescription": "\u0627\u0633\u0644\u0627\u06CC\u062F", "aria-label": slide(i + 1, slides.length), id: `${id}-s${i}`, children: s }, i))) }), pages > 1 && (_jsxs("div", { className: "k-carousel__bar", children: [dots ? (_jsx("ul", { className: "k-carousel__dots", "aria-label": `اسلایدهای ${label}`, children: Array.from({ length: pages }, (_, i) => (_jsx("li", { children: _jsx("button", { type: "button", className: "k-carousel__dot", "aria-label": slide(i + 1, pages), "aria-current": i === index, "aria-controls": `${id}-s${i}`, onClick: () => go(i) }) }, i))) })) : _jsx("span", {}), _jsxs("div", { className: "k-carousel__nav", children: [_jsx("button", { type: "button", className: "k-btn k-btn--secondary k-btn--icon k-btn--sm", "aria-label": prev, disabled: index === 0, onClick: () => go(index - 1), children: _jsx(Arrow, {}) }), _jsx("button", { type: "button", className: "k-btn k-btn--secondary k-btn--icon k-btn--sm", "aria-label": next, disabled: index >= pages - 1, onClick: () => go(index + 1), children: _jsx(Arrow, { next: true }) })] })] }))] }));
55
+ }
@@ -0,0 +1,23 @@
1
+ import { type ReactNode } from "react";
2
+ export interface ColorPickerProps {
3
+ label?: ReactNode;
4
+ hint?: ReactNode;
5
+ /** رنگ hex، مثل "#0fa89b" */
6
+ value?: string;
7
+ defaultValue?: string;
8
+ onChange?: (hex: string) => void;
9
+ /** رنگ‌های پیشنهادی؛ [] برای حذف */
10
+ swatches?: {
11
+ name: string;
12
+ value: string;
13
+ }[];
14
+ /** نمایش کنتراست با متن سفید و مشکی @default true */
15
+ showContrast?: boolean;
16
+ name?: string;
17
+ id?: string;
18
+ className?: string;
19
+ }
20
+ /** نسبت کنتراست WCAG */
21
+ export declare const contrastRatio: (a: string, b: string) => number;
22
+ /** انتخاب رنگ برند یا برچسب: نمونه‌رنگ‌ها، کد hex و انتخابگر بومی، با کنتراست متن روی آن */
23
+ export declare function ColorPicker({ label, hint, value, defaultValue, onChange, swatches, showContrast, name, id, className }: ColorPickerProps): import("react").JSX.Element;
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useId, useState } from "react";
3
+ import { toFaDigits } from "@kashi-ui/persian";
4
+ import { Field } from "./Field.js";
5
+ const DEFAULT_SWATCHES = [
6
+ { name: "فیروزه‌ای", value: "#0b8077" },
7
+ { name: "لاجوردی", value: "#2740ed" },
8
+ { name: "بنفش", value: "#7c3aed" },
9
+ { name: "اناری", value: "#e51d2a" },
10
+ { name: "زعفرانی", value: "#dd5e02" },
11
+ { name: "پسته‌ای", value: "#518b25" },
12
+ { name: "شب", value: "#2a2f3d" },
13
+ ];
14
+ const HEX = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i;
15
+ const norm = (v) => {
16
+ const m = v.trim().match(HEX);
17
+ if (!m)
18
+ return null;
19
+ const h = m[1].length === 3 ? [...m[1]].map((c) => c + c).join("") : m[1];
20
+ return `#${h.toLowerCase()}`;
21
+ };
22
+ const lum = (hex) => {
23
+ const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255).map((c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
24
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
25
+ };
26
+ /** نسبت کنتراست WCAG */
27
+ export const contrastRatio = (a, b) => {
28
+ a = norm(a) ?? a;
29
+ b = norm(b) ?? b;
30
+ const [x, y] = [lum(a), lum(b)].sort((m, n) => n - m);
31
+ return (x + 0.05) / (y + 0.05);
32
+ };
33
+ const Check = () => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 2.2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: "m5 10.5 3.2 3L15 7" }) });
34
+ /** انتخاب رنگ برند یا برچسب: نمونه‌رنگ‌ها، کد hex و انتخابگر بومی، با کنتراست متن روی آن */
35
+ export function ColorPicker({ label, hint, value, defaultValue = "#0b8077", onChange, swatches = DEFAULT_SWATCHES, showContrast = true, name, id, className }) {
36
+ const autoId = useId();
37
+ const fieldId = id ?? autoId;
38
+ const [inner, setInner] = useState(norm(defaultValue) ?? "#000000");
39
+ const current = norm(value ?? "") ?? inner;
40
+ const [text, setText] = useState(null);
41
+ const set = (hex) => {
42
+ if (value === undefined)
43
+ setInner(hex);
44
+ setText(null);
45
+ onChange?.(hex);
46
+ };
47
+ const white = contrastRatio(current, "#ffffff"), black = contrastRatio(current, "#000000");
48
+ const ink = white >= black ? "#ffffff" : "#000000";
49
+ const fmt = (r) => toFaDigits((Math.round(r * 10) / 10).toFixed(1)).replace(".", "٫");
50
+ const invalid = text !== null && !norm(text);
51
+ return (_jsx(Field, { id: `${fieldId}-hex`, label: label, hint: hint, error: invalid ? "کد رنگ معتبر نیست؛ مثل ‎#0fa89b‎ وارد کنید." : undefined, className: className, children: _jsxs("div", { className: "k-color", style: { "--_sw": current, "--_ink": ink }, children: [swatches.length > 0 && (_jsx("div", { className: "k-color__swatches", role: "radiogroup", "aria-label": "\u0631\u0646\u06AF\u200C\u0647\u0627\u06CC \u067E\u06CC\u0634\u0646\u0647\u0627\u062F\u06CC", children: swatches.map((s) => (_jsxs("label", { className: "k-color__swatch", style: { "--_sw": s.value, "--_ink": contrastRatio(s.value, "#ffffff") >= 3 ? "#fff" : "#000" }, title: s.name, children: [_jsx("input", { type: "radio", className: "k-sr-only", name: `${fieldId}-sw`, checked: norm(s.value) === current, "aria-label": s.name, onChange: () => set(norm(s.value)) }), _jsx(Check, {})] }, s.value))) })), _jsxs("div", { className: "k-color__row", children: [_jsxs("label", { className: "k-color__preview", title: "\u0627\u0646\u062A\u062E\u0627\u0628 \u0631\u0646\u06AF \u062F\u0644\u062E\u0648\u0627\u0647", children: [_jsx("span", { className: "k-sr-only", children: "\u0627\u0646\u062A\u062E\u0627\u0628 \u0631\u0646\u06AF \u062F\u0644\u062E\u0648\u0627\u0647" }), _jsx("input", { type: "color", value: current, onChange: (e) => set(e.target.value) })] }), _jsx("div", { className: "k-input", "data-state": invalid ? "invalid" : undefined, children: _jsx("input", { id: `${fieldId}-hex`, className: "k-input__control", dir: "ltr", spellCheck: false, autoComplete: "off", value: text ?? current, "aria-invalid": invalid || undefined, onChange: (e) => {
52
+ setText(e.target.value);
53
+ const h = norm(e.target.value);
54
+ if (h) {
55
+ if (value === undefined)
56
+ setInner(h);
57
+ onChange?.(h);
58
+ }
59
+ }, onBlur: () => !invalid && setText(null) }) })] }), showContrast && (_jsxs("p", { className: "k-color__contrast", "aria-live": "polite", children: [_jsx("span", { className: "k-color__sample", children: "\u0645\u062A\u0646 \u0646\u0645\u0648\u0646\u0647" }), _jsxs("span", { children: ["\u06A9\u0646\u062A\u0631\u0627\u0633\u062A \u0628\u0627 \u0645\u062A\u0646 ", ink === "#ffffff" ? "سفید" : "مشکی", ": ", fmt(Math.max(white, black)), " \u0628\u0647 \u06F1 ", Math.max(white, black) >= 4.5 ? "(AA)" : "(کمتر از AA)"] })] })), name && _jsx("input", { type: "hidden", name: name, value: current })] }) }));
60
+ }
@@ -0,0 +1,22 @@
1
+ import type { ReactNode } from "react";
2
+ export interface MeterProps {
3
+ label: ReactNode;
4
+ value: number;
5
+ /** @default 100 */
6
+ max?: number;
7
+ /** از این مقدار به بعد هشدار (زرد) @default ۸۰٪ max */
8
+ warning?: number;
9
+ /** از این مقدار به بعد بحرانی (قرمز) @default ۹۵٪ max */
10
+ critical?: number;
11
+ /** قالب مقدار، مثل «۴٫۲ گیگابایت» */
12
+ format?: (n: number) => string;
13
+ className?: string;
14
+ labels?: {
15
+ ok?: string;
16
+ warning?: string;
17
+ critical?: string;
18
+ of?: string;
19
+ };
20
+ }
21
+ /** سنجهٔ یک مقدار در برابر سقف، مثل فضای ذخیره یا سهمیهٔ پیامک؛ وضعیت با متن و آیکون، نه فقط رنگ */
22
+ export declare function Meter({ label, value, max, warning, critical, format, className, labels }: MeterProps): import("react").JSX.Element;
package/dist/Meter.js ADDED
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { formatNumber, toFaDigits } from "@kashi-ui/persian";
3
+ import { cx } from "./cx.js";
4
+ const Icon = ({ d }) => _jsx("svg", { viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: _jsx("path", { d: d }) });
5
+ /** سنجهٔ یک مقدار در برابر سقف، مثل فضای ذخیره یا سهمیهٔ پیامک؛ وضعیت با متن و آیکون، نه فقط رنگ */
6
+ export function Meter({ label, value, max = 100, warning = max * 0.8, critical = max * 0.95, format = (n) => formatNumber(n), className, labels = {} }) {
7
+ const { ok = "در محدودهٔ مجاز", warning: warnText = "نزدیک به سقف", critical: critText = "سقف تقریباً پر شده", of = "از" } = labels;
8
+ const v = Math.min(max, Math.max(0, value));
9
+ const status = v >= critical ? "critical" : v >= warning ? "warning" : "ok";
10
+ const pct = Math.round((v / max) * 100);
11
+ const text = { ok, warning: warnText, critical: critText }[status];
12
+ return (_jsxs("div", { className: cx("k-meter", className), "data-status": status, children: [_jsxs("div", { className: "k-meter__head", children: [_jsx("span", { className: "k-meter__label", children: label }), _jsxs("span", { className: "k-meter__value", children: [format(v), " ", _jsxs("span", { children: [of, " ", format(max)] })] })] }), _jsxs("div", { className: "k-meter__track", role: "meter", "aria-valuenow": v, "aria-valuemin": 0, "aria-valuemax": max, "aria-valuetext": `${format(v)} ${of} ${format(max)}، ${toFaDigits(pct)}٪، ${text}`, "aria-label": typeof label === "string" ? label : undefined, children: [_jsx("span", { className: "k-meter__fill", style: { inlineSize: `${pct}%` } }), _jsx("span", { className: "k-meter__mark", style: { insetInlineStart: `${(warning / max) * 100}%` }, "aria-hidden": "true" })] }), _jsxs("p", { className: "k-meter__status", "aria-hidden": "true", children: [_jsx(Icon, { d: status === "ok" ? "m5 10.5 3.2 3L15 7" : "M10 3 2.5 16.5h15ZM10 8v4M10 14.5h.01" }), text, " \u00B7 ", toFaDigits(pct), "\u066A"] })] }));
13
+ }
@@ -0,0 +1,22 @@
1
+ import { type ReactNode } from "react";
2
+ export interface SplitterProps {
3
+ /** دقیقاً دو فرزند: پنل ابتدا و پنل انتها */
4
+ children: [ReactNode, ReactNode];
5
+ /** «horizontal» کنار هم، «vertical» زیر هم @default "horizontal" */
6
+ orientation?: "horizontal" | "vertical";
7
+ /** اندازهٔ پنل اول به درصد */
8
+ size?: number;
9
+ defaultSize?: number;
10
+ onSizeChange?: (percent: number) => void;
11
+ /** @default 15 */
12
+ min?: number;
13
+ /** @default 85 */
14
+ max?: number;
15
+ /** نام دستگیره، مثل «اندازهٔ فهرست فایل‌ها» @default «تغییر اندازهٔ پنل‌ها» */
16
+ label?: string;
17
+ /** ارتفاع ظرف در حالت افقی */
18
+ height?: string;
19
+ className?: string;
20
+ }
21
+ /** دو پنل با مرز قابل‌کشیدن؛ با کیبورد: ←→ (یا ↑↓) پنج درصد، Home/End کمینه و بیشینه */
22
+ export declare function Splitter({ children, orientation, size, defaultSize, onSizeChange, min, max, label, height, className }: SplitterProps): import("react").JSX.Element;
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useRef, useState } from "react";
3
+ import { toFaDigits } from "@kashi-ui/persian";
4
+ import { cx } from "./cx.js";
5
+ /** دو پنل با مرز قابل‌کشیدن؛ با کیبورد: ←→ (یا ↑↓) پنج درصد، Home/End کمینه و بیشینه */
6
+ export function Splitter({ children, orientation = "horizontal", size, defaultSize = 40, onSizeChange, min = 15, max = 85, label = "تغییر اندازهٔ پنل‌ها", height, className }) {
7
+ const [inner, setInner] = useState(defaultSize);
8
+ const current = size ?? inner;
9
+ const [dragging, setDragging] = useState(false);
10
+ const box = useRef(null);
11
+ const vertical = orientation === "vertical";
12
+ const set = (p) => {
13
+ const v = Math.round(Math.min(max, Math.max(min, p)) * 10) / 10;
14
+ if (size === undefined)
15
+ setInner(v);
16
+ onSizeChange?.(v);
17
+ };
18
+ const fromPointer = (e) => {
19
+ const r = box.current.getBoundingClientRect();
20
+ if (vertical)
21
+ return set(((e.clientY - r.top) / r.height) * 100);
22
+ // در RTL پنل اول سمت راست است
23
+ const rtl = getComputedStyle(box.current).direction === "rtl";
24
+ set(((rtl ? r.right - e.clientX : e.clientX - r.left) / r.width) * 100);
25
+ };
26
+ const onKey = (e) => {
27
+ const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
28
+ const keys = vertical
29
+ ? { ArrowUp: -5, ArrowDown: 5 }
30
+ : { ArrowLeft: rtl ? 5 : -5, ArrowRight: rtl ? -5 : 5 };
31
+ if (e.key in keys)
32
+ set(current + keys[e.key]);
33
+ else if (e.key === "Home")
34
+ set(min);
35
+ else if (e.key === "End")
36
+ set(max);
37
+ else
38
+ return;
39
+ e.preventDefault();
40
+ };
41
+ return (_jsxs("div", { ref: box, className: cx("k-splitter", vertical && "k-splitter--vertical", className), "data-dragging": dragging ? "" : undefined, style: { blockSize: height }, children: [_jsx("div", { className: "k-splitter__pane", style: vertical ? { blockSize: `${current}%` } : { inlineSize: `${current}%` }, children: children[0] }), _jsx("div", { className: "k-splitter__handle", role: "separator", tabIndex: 0, "aria-orientation": vertical ? "horizontal" : "vertical", "aria-valuenow": current, "aria-valuemin": min, "aria-valuemax": max, "aria-valuetext": `${toFaDigits(Math.round(current))}٪`, "aria-label": label, "data-dragging": dragging ? "" : undefined, onKeyDown: onKey, onPointerDown: (e) => {
42
+ e.currentTarget.setPointerCapture(e.pointerId);
43
+ setDragging(true);
44
+ }, onPointerMove: (e) => dragging && fromPointer(e), onPointerUp: () => setDragging(false), onPointerCancel: () => setDragging(false), onDoubleClick: () => set(defaultSize) }), _jsx("div", { className: "k-splitter__pane", children: children[1] })] }));
45
+ }
package/dist/Tour.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { type ReactNode } from "react";
2
+ export interface TourStep {
3
+ /** CSS selector عنصری که این مرحله دربارهٔ آن است، مثل "#export-btn" */
4
+ target: string;
5
+ title: ReactNode;
6
+ content: ReactNode;
7
+ }
8
+ export interface TourProps {
9
+ steps: TourStep[];
10
+ open: boolean;
11
+ onOpenChange: (open: boolean) => void;
12
+ /** پس از آخرین مرحله */
13
+ onFinish?: () => void;
14
+ labels?: {
15
+ next?: string;
16
+ prev?: string;
17
+ done?: string;
18
+ skip?: string;
19
+ step?: (n: number, total: number) => string;
20
+ };
21
+ }
22
+ /**
23
+ * راهنمای قدم‌به‌قدم برای آشنایی با محصول: بخش هر مرحله روشن و بقیه کم‌رنگ می‌شود.
24
+ * Esc می‌بندد، ←→ بین مرحله‌ها و فوکوس پس از پایان به جای قبلی برمی‌گردد.
25
+ */
26
+ export declare function Tour({ steps, open, onOpenChange, onFinish, labels }: TourProps): import("react").JSX.Element | null;
package/dist/Tour.js ADDED
@@ -0,0 +1,73 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
3
+ import { toFaDigits } from "@kashi-ui/persian";
4
+ /**
5
+ * راهنمای قدم‌به‌قدم برای آشنایی با محصول: بخش هر مرحله روشن و بقیه کم‌رنگ می‌شود.
6
+ * Esc می‌بندد، ←→ بین مرحله‌ها و فوکوس پس از پایان به جای قبلی برمی‌گردد.
7
+ */
8
+ export function Tour({ steps, open, onOpenChange, onFinish, labels = {} }) {
9
+ const id = useId();
10
+ const { next = "بعدی", prev = "قبلی", done = "تمام", skip = "رد کردن", step: stepLabel = (n, t) => `مرحلهٔ ${toFaDigits(n)} از ${toFaDigits(t)}` } = labels;
11
+ const [i, setI] = useState(0);
12
+ const [rect, setRect] = useState(null);
13
+ const card = useRef(null);
14
+ const [cardPos, setCardPos] = useState({ top: 0, left: 0 });
15
+ const returnTo = useRef(null);
16
+ const s = steps[i];
17
+ useEffect(() => {
18
+ if (open) {
19
+ returnTo.current = document.activeElement;
20
+ setI(0);
21
+ }
22
+ else
23
+ returnTo.current?.focus?.();
24
+ }, [open]);
25
+ // جای عنصر هدف را دنبال می‌کند
26
+ useLayoutEffect(() => {
27
+ if (!open || !s)
28
+ return;
29
+ const el = document.querySelector(s.target);
30
+ if (!el)
31
+ return setRect(null);
32
+ el.scrollIntoView({ block: "center", behavior: matchMedia("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth" });
33
+ const update = () => setRect(el.getBoundingClientRect());
34
+ update();
35
+ const t = setTimeout(update, 400);
36
+ addEventListener("scroll", update, { passive: true });
37
+ addEventListener("resize", update);
38
+ return () => {
39
+ clearTimeout(t);
40
+ removeEventListener("scroll", update);
41
+ removeEventListener("resize", update);
42
+ };
43
+ }, [open, i, s?.target]);
44
+ // کارت زیر عنصر، یا بالای آن اگر جا نباشد
45
+ useLayoutEffect(() => {
46
+ if (!open || !card.current)
47
+ return;
48
+ const c = card.current.getBoundingClientRect();
49
+ if (!rect)
50
+ return setCardPos({ top: innerHeight / 2 - c.height / 2, left: innerWidth / 2 - c.width / 2 });
51
+ const below = rect.bottom + 12 + c.height < innerHeight;
52
+ const top = below ? rect.bottom + 12 : Math.max(12, rect.top - 12 - c.height);
53
+ const left = Math.min(innerWidth - c.width - 12, Math.max(12, rect.left + rect.width / 2 - c.width / 2));
54
+ setCardPos({ top, left });
55
+ card.current.focus({ preventScroll: true });
56
+ }, [rect, open, i]);
57
+ if (!open || !s)
58
+ return null;
59
+ const last = i === steps.length - 1;
60
+ const finish = () => {
61
+ onOpenChange(false);
62
+ onFinish?.();
63
+ };
64
+ return (_jsxs(_Fragment, { children: [rect && _jsx("div", { className: "k-tour__spot", "aria-hidden": "true", style: { top: rect.top - 6, left: rect.left - 6, inlineSize: rect.width + 12, blockSize: rect.height + 12 } }), _jsxs("div", { ref: card, className: "k-tour__card", role: "dialog", "aria-modal": "false", "aria-labelledby": `${id}-t`, "aria-describedby": `${id}-b`, tabIndex: -1, style: { top: cardPos.top, left: cardPos.left }, onKeyDown: (e) => {
65
+ if (e.key === "Escape")
66
+ onOpenChange(false);
67
+ const rtl = getComputedStyle(e.currentTarget).direction === "rtl";
68
+ if (e.key === (rtl ? "ArrowLeft" : "ArrowRight") && !last)
69
+ setI(i + 1);
70
+ if (e.key === (rtl ? "ArrowRight" : "ArrowLeft") && i > 0)
71
+ setI(i - 1);
72
+ }, children: [_jsx("span", { className: "k-tour__step", children: stepLabel(i + 1, steps.length) }), _jsx("p", { className: "k-tour__title", id: `${id}-t`, children: s.title }), _jsx("p", { className: "k-tour__body", id: `${id}-b`, children: s.content }), _jsxs("div", { className: "k-tour__actions", children: [_jsx("button", { type: "button", className: "k-btn k-btn--link k-tour__skip", onClick: () => onOpenChange(false), children: skip }), _jsx("span", { className: "k-tour__progress", "aria-hidden": "true", children: steps.map((_, k) => _jsx("span", { "data-on": k <= i ? "" : undefined }, k)) }), i > 0 && _jsx("button", { type: "button", className: "k-btn k-btn--secondary k-btn--sm", onClick: () => setI(i - 1), children: prev }), _jsx("button", { type: "button", className: "k-btn k-btn--primary k-btn--sm", onClick: () => (last ? finish() : setI(i + 1)), children: last ? done : next })] })] })] }));
73
+ }
package/dist/index.d.ts CHANGED
@@ -122,3 +122,13 @@ export { InlineEdit } from "./InlineEdit.js";
122
122
  export type { InlineEditProps } from "./InlineEdit.js";
123
123
  export { ProvinceSelect } from "./ProvinceSelect.js";
124
124
  export type { ProvinceSelectProps } from "./ProvinceSelect.js";
125
+ export { Carousel } from "./Carousel.js";
126
+ export type { CarouselProps } from "./Carousel.js";
127
+ export { ColorPicker, contrastRatio } from "./ColorPicker.js";
128
+ export type { ColorPickerProps } from "./ColorPicker.js";
129
+ export { Meter } from "./Meter.js";
130
+ export type { MeterProps } from "./Meter.js";
131
+ export { Splitter } from "./Splitter.js";
132
+ export type { SplitterProps } from "./Splitter.js";
133
+ export { Tour } from "./Tour.js";
134
+ export type { TourProps, TourStep } from "./Tour.js";
package/dist/index.js CHANGED
@@ -61,3 +61,8 @@ export { ActivityHeatmap } from "./ActivityHeatmap.js";
61
61
  export { ContextMenu } from "./ContextMenu.js";
62
62
  export { InlineEdit } from "./InlineEdit.js";
63
63
  export { ProvinceSelect } from "./ProvinceSelect.js";
64
+ export { Carousel } from "./Carousel.js";
65
+ export { ColorPicker, contrastRatio } from "./ColorPicker.js";
66
+ export { Meter } from "./Meter.js";
67
+ export { Splitter } from "./Splitter.js";
68
+ export { Tour } from "./Tour.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kashi-ui/react",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "description": "کامپوننت‌های React دیزاین‌سیستم کاشی",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,7 @@
22
22
  "test": "node --test test/*.test.mjs"
23
23
  },
24
24
  "peerDependencies": {
25
- "@kashi-ui/css": "^0.12.0",
25
+ "@kashi-ui/css": "^0.13.0",
26
26
  "react": ">=18"
27
27
  },
28
28
  "devDependencies": {
@@ -59,7 +59,7 @@
59
59
  }
60
60
  },
61
61
  "dependencies": {
62
- "@kashi-ui/bank-logos": "^0.12.0",
63
- "@kashi-ui/persian": "^0.12.0"
62
+ "@kashi-ui/bank-logos": "^0.13.0",
63
+ "@kashi-ui/persian": "^0.13.0"
64
64
  }
65
65
  }