@kashi-ui/react 0.14.0 → 0.15.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.
@@ -1,4 +1,6 @@
1
1
  import type { Bank } from "@kashi-ui/persian";
2
+ /** لوگوی بانک را فقط هنگام نیاز بارگذاری می‌کند (code-split)، تا حجم اولیهٔ برنامه زیاد نشود */
3
+ export declare function useBankLogo(slug: string | undefined, enabled: boolean): string | null;
2
4
  /** نام و لوگوی بانک داخل فیلد؛ نام با id به فیلد متصل می‌شود و لوگو تزئینی است */
3
5
  export declare function BankBadge({ bank, id, showLogo }: {
4
6
  bank: Bank | null;
package/dist/BankBadge.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { useEffect, useState } from "react";
3
3
  /** لوگوی بانک را فقط هنگام نیاز بارگذاری می‌کند (code-split)، تا حجم اولیهٔ برنامه زیاد نشود */
4
- function useBankLogo(slug, enabled) {
4
+ export function useBankLogo(slug, enabled) {
5
5
  const [uri, setUri] = useState(null);
6
6
  useEffect(() => {
7
7
  if (!slug || !enabled) {
@@ -0,0 +1,23 @@
1
+ import { type HTMLAttributes, type ReactNode } from "react";
2
+ import { type Bank } from "@kashi-ui/persian";
3
+ export interface BankCardProps extends Omit<HTMLAttributes<HTMLElement>, "children"> {
4
+ /** شمارهٔ کارت با هر خطی؛ بانک از شش رقم اول تشخیص داده می‌شود */
5
+ number: string;
6
+ /** نام دارندهٔ کارت */
7
+ holder?: ReactNode;
8
+ /** تاریخ انقضا: «۰۸/۰۵» یا { year: 1408, month: 5 } */
9
+ expiry?: string | {
10
+ year: number;
11
+ month: number;
12
+ };
13
+ /** پنهان کردن ارقام میانی: ۶۱۰۴ ۳۳** **** ۱۲۳۴ @default false */
14
+ masked?: boolean;
15
+ /** بانک دستی، اگر از روی شماره تشخیص داده نشود */
16
+ bank?: Bank | null;
17
+ /** @default "fa" */
18
+ digits?: "fa" | "latin";
19
+ /** نمایش لوگوی بانک @default true */
20
+ showLogo?: boolean;
21
+ }
22
+ /** نمایش کارت بانکی با رنگ و لوگوی بانک، شمارهٔ چهاررقمی و تاریخ انقضا؛ برای کیف پول و انتخاب کارت ذخیره‌شده */
23
+ export declare const BankCard: import("react").ForwardRefExoticComponent<BankCardProps & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { formatCardNumber, getBankByCard, onlyDigits, toFaDigits } from "@kashi-ui/persian";
4
+ import { useBankLogo } from "./BankBadge.js";
5
+ import { cx } from "./cx.js";
6
+ // رنگ تقریبی هویت بصری بانک‌ها؛ برای بقیه رنگ برند کاشی
7
+ const COLORS = {
8
+ mellat: "#b5172b", melli: "#0b3f7d", saderat: "#203b8c", tejarat: "#173c7a", sepah: "#0d56a0", pasargad: "#2a2418",
9
+ saman: "#0a78b8", parsian: "#7f1c3c", keshavarzi: "#0d6b3a", maskan: "#d4600a", refah: "#0a5a94", "eghtesad-novin": "#5d2a86",
10
+ ayandeh: "#5a3a26", shahr: "#b3232a", resalat: "#23853a", postbank: "#0a703a", dey: "#00676d", sina: "#1d4a92",
11
+ karafarin: "#00877c", "mehr-iran": "#178e42", tosee: "#3b3f8f", gardeshgari: "#8a1f4c", "iran-zamin": "#6a1f7a", sarmayeh: "#2b2b6e",
12
+ };
13
+ const Chip = () => (_jsxs("svg", { className: "k-bankcard__chip", viewBox: "0 0 40 30", "aria-hidden": "true", children: [_jsx("rect", { x: "0.5", y: "0.5", width: "39", height: "29", rx: "5" }), _jsx("path", { d: "M14 1v28M26 1v28M1 10h13M26 10h13M1 20h13M26 20h13" })] }));
14
+ /** نمایش کارت بانکی با رنگ و لوگوی بانک، شمارهٔ چهاررقمی و تاریخ انقضا؛ برای کیف پول و انتخاب کارت ذخیره‌شده */
15
+ export const BankCard = forwardRef(function BankCard({ number, holder, expiry, masked, bank, digits = "fa", showLogo = true, className, style, ...rest }, ref) {
16
+ const raw = onlyDigits(number).slice(0, 16);
17
+ const detected = bank === undefined ? getBankByCard(raw) : bank;
18
+ const logo = useBankLogo(detected?.slug, showLogo);
19
+ const shownRaw = masked && raw.length === 16 ? `${raw.slice(0, 6)}******${raw.slice(12)}` : raw;
20
+ const grouped = shownRaw.replace(/(.{4})(?=.)/g, "$1 ");
21
+ const pad = (n) => String(n).padStart(2, "0");
22
+ const exp = typeof expiry === "object" ? `${pad(expiry.year % 100)}/${pad(expiry.month)}` : expiry;
23
+ const d = (s) => (digits === "fa" ? toFaDigits(s) : s);
24
+ const spokenNumber = masked ? `مختوم به ${toFaDigits(raw.slice(-4))}` : toFaDigits(formatCardNumber(raw));
25
+ const color = detected ? COLORS[detected.slug] : undefined;
26
+ return (_jsxs("figure", { ref: ref, className: cx("k-bankcard", className), style: color ? { ...style, ["--k-bankcard-color"]: color } : style, "aria-label": `کارت ${detected?.name ?? "بانکی"}، ${spokenNumber}`, ...rest, children: [_jsxs("div", { className: "k-bankcard__top", children: [_jsxs("span", { className: "k-bankcard__bank", children: [logo && _jsx("img", { className: "k-bankcard__logo", src: logo, alt: "", width: 28, height: 28 }), detected?.name ?? "کارت بانکی"] }), _jsx(Chip, {})] }), _jsx("div", { className: "k-bankcard__number", dir: "ltr", "aria-hidden": "true", children: d(grouped) }), _jsxs("div", { className: "k-bankcard__bottom", "aria-hidden": holder || exp ? undefined : true, children: [holder && _jsx("span", { className: "k-bankcard__holder", children: holder }), exp && _jsxs("span", { className: "k-bankcard__exp", children: [_jsx("small", { children: "\u0627\u0646\u0642\u0636\u0627" }), _jsx("span", { dir: "ltr", children: d(exp) })] })] })] }));
27
+ });
@@ -0,0 +1,12 @@
1
+ import { type HTMLAttributes } from "react";
2
+ import { type HolidayOptions } from "@kashi-ui/persian";
3
+ export interface DateTileProps extends Omit<HTMLAttributes<HTMLElement>, "children"> {
4
+ date: Date;
5
+ /** نمایش مناسبت تعطیل رسمی؛ true یا تنظیمات getIranHoliday @default true */
6
+ holidays?: boolean | HolidayOptions;
7
+ /** تاریخ میلادی معادل در پایین @default true */
8
+ gregorian?: boolean;
9
+ size?: "sm" | "md" | "lg";
10
+ }
11
+ /** کاشی تاریخ شمسی به شکل برگ تقویم: روز، ماه، روز هفته، مناسبت تعطیل و معادل میلادی */
12
+ export declare const DateTile: import("react").ForwardRefExoticComponent<DateTileProps & import("react").RefAttributes<HTMLTimeElement>>;
@@ -0,0 +1,12 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { getIranHoliday, JALALI_MONTHS, jalaliWeekday, toFaDigits, toISODate, toJalali, WEEKDAYS } from "@kashi-ui/persian";
4
+ import { cx } from "./cx.js";
5
+ const gregFmt = new Intl.DateTimeFormat("fa-IR-u-ca-gregory-nu-arabext", { day: "numeric", month: "long", year: "numeric" });
6
+ /** کاشی تاریخ شمسی به شکل برگ تقویم: روز، ماه، روز هفته، مناسبت تعطیل و معادل میلادی */
7
+ export const DateTile = forwardRef(function DateTile({ date, holidays = true, gregorian = true, size = "md", className, ...rest }, ref) {
8
+ const { jy, jm, jd } = toJalali(date);
9
+ const holiday = holidays ? getIranHoliday(date, holidays === true ? {} : holidays) : null;
10
+ const occasion = holiday && holiday !== "جمعه" ? holiday : null;
11
+ return (_jsxs("time", { ref: ref, dateTime: toISODate(date), className: cx("k-datetile", `k-datetile--${size}`, className), "data-holiday": holiday ? "" : undefined, ...rest, children: [_jsxs("span", { className: "k-datetile__head", children: [JALALI_MONTHS[jm - 1], " ", toFaDigits(jy)] }), _jsx("span", { className: "k-datetile__day", children: toFaDigits(jd) }), _jsx("span", { className: "k-datetile__weekday", children: WEEKDAYS[jalaliWeekday(date)] }), occasion && _jsx("span", { className: "k-datetile__occasion", children: occasion }), gregorian && _jsx("span", { className: "k-datetile__greg", children: gregFmt.format(date) })] }));
12
+ });
@@ -0,0 +1,18 @@
1
+ import { type ReactNode } from "react";
2
+ import { type InputProps } from "./Input.js";
3
+ type Base = Omit<InputProps, "value" | "defaultValue" | "onChange">;
4
+ export interface KeyboardFixInputProps extends Base {
5
+ value?: string;
6
+ defaultValue?: string;
7
+ onValueChange?: (value: string) => void;
8
+ /** "auto": فقط وقتی متن مشکوک است (looksLikeWrongLayout) — "always": برای هر متن لاتین @default "auto" */
9
+ suggest?: "auto" | "always";
10
+ /** متن پیشنهاد؛ fixed متن تبدیل‌شده است @default منظورتان «…» بود؟ */
11
+ renderSuggestion?: (fixed: string, apply: () => void) => ReactNode;
12
+ }
13
+ /**
14
+ * فیلدی که اگر کاربر فارسی را با صفحه‌کلید انگلیسی تایپ کرده باشد («sghl»)، شکل درست («سلام») را پیشنهاد می‌دهد.
15
+ * مناسب جستجو و فرم‌هایی که کاربر زبان صفحه‌کلید را عوض نکرده است.
16
+ */
17
+ export declare const KeyboardFixInput: import("react").ForwardRefExoticComponent<KeyboardFixInputProps & import("react").RefAttributes<HTMLInputElement>>;
18
+ export {};
@@ -0,0 +1,27 @@
1
+ import { jsxs as _jsxs, Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef, useRef, useState } from "react";
3
+ import { fixKeyboardLayout, looksLikeWrongLayout } from "@kashi-ui/persian";
4
+ import { Input } from "./Input.js";
5
+ import { mergeRefs } from "./utils.js";
6
+ /**
7
+ * فیلدی که اگر کاربر فارسی را با صفحه‌کلید انگلیسی تایپ کرده باشد («sghl»)، شکل درست («سلام») را پیشنهاد می‌دهد.
8
+ * مناسب جستجو و فرم‌هایی که کاربر زبان صفحه‌کلید را عوض نکرده است.
9
+ */
10
+ export const KeyboardFixInput = forwardRef(function KeyboardFixInput({ value, defaultValue = "", onValueChange, suggest = "auto", renderSuggestion, hint, ...rest }, ref) {
11
+ const [inner, setInner] = useState(defaultValue);
12
+ const current = value ?? inner;
13
+ const el = useRef(null);
14
+ const latin = /[a-z]/i.test(current) && !/[؀-ۿ]/.test(current);
15
+ const show = suggest === "always" ? latin : looksLikeWrongLayout(current);
16
+ const fixed = show ? fixKeyboardLayout(current) : "";
17
+ const update = (next) => {
18
+ if (value === undefined)
19
+ setInner(next);
20
+ onValueChange?.(next);
21
+ };
22
+ const apply = () => {
23
+ update(fixed);
24
+ el.current?.focus();
25
+ };
26
+ return (_jsx(Input, { ref: mergeRefs(ref, el), dir: "auto", value: current, onChange: (e) => update(e.target.value), hint: show ? (_jsx("span", { className: "k-kbfix", role: "status", children: renderSuggestion ? renderSuggestion(fixed, apply) : _jsxs(_Fragment, { children: ["\u0645\u0646\u0638\u0648\u0631\u062A\u0627\u0646 ", _jsxs("button", { type: "button", className: "k-kbfix__btn", onClick: apply, children: ["\u00AB", fixed, "\u00BB"] }), " \u0628\u0648\u062F\u061F"] }) })) : hint, ...rest }));
27
+ });
@@ -0,0 +1,16 @@
1
+ import { type ReactNode } from "react";
2
+ import { type InputProps } from "./Input.js";
3
+ type Base = Omit<InputProps, "value" | "defaultValue" | "onChange" | "type" | "inputMode">;
4
+ export interface LegalIdInputProps extends Base {
5
+ /** مقدار کنترل‌شده با ارقام لاتین، مثل "10380284790" */
6
+ value?: string;
7
+ defaultValue?: string;
8
+ onValueChange?: (value: string, valid: boolean) => void;
9
+ /** @default "fa" */
10
+ digits?: "fa" | "latin";
11
+ /** @default "شناسهٔ ملی معتبر نیست." */
12
+ invalidMessage?: ReactNode;
13
+ }
14
+ /** شناسهٔ ملی اشخاص حقوقی (شرکت‌ها): ۱۱ رقم با بررسی رقم کنترل */
15
+ export declare const LegalIdInput: import("react").ForwardRefExoticComponent<LegalIdInputProps & import("react").RefAttributes<HTMLInputElement>>;
16
+ export {};
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useState } from "react";
3
+ import { isValidLegalId, onlyDigits, toFaDigits } from "@kashi-ui/persian";
4
+ import { Input } from "./Input.js";
5
+ /** شناسهٔ ملی اشخاص حقوقی (شرکت‌ها): ۱۱ رقم با بررسی رقم کنترل */
6
+ export const LegalIdInput = forwardRef(function LegalIdInput({ value, defaultValue = "", onValueChange, digits = "fa", invalidMessage = "شناسهٔ ملی معتبر نیست.", error, name, onBlur, placeholder, ...rest }, ref) {
7
+ const [inner, setInner] = useState(() => onlyDigits(defaultValue).slice(0, 11));
8
+ const [touched, setTouched] = useState(false);
9
+ const raw = value !== undefined ? onlyDigits(value).slice(0, 11) : inner;
10
+ const showInvalid = raw.length > 0 && (touched || raw.length === 11) && !isValidLegalId(raw);
11
+ return (_jsxs(_Fragment, { children: [_jsx(Input, { ref: ref, type: "text", inputMode: "numeric", autoComplete: "off", dir: "ltr", placeholder: placeholder ?? (digits === "fa" ? "۰۰۰۰۰۰۰۰۰۰۰" : "00000000000"), value: digits === "fa" ? toFaDigits(raw) : raw, onChange: (e) => {
12
+ const next = onlyDigits(e.target.value).slice(0, 11);
13
+ if (value === undefined)
14
+ setInner(next);
15
+ onValueChange?.(next, isValidLegalId(next));
16
+ }, onBlur: (e) => {
17
+ setTouched(true);
18
+ onBlur?.(e);
19
+ }, error: error ?? (showInvalid ? invalidMessage : undefined), ...rest }), name && _jsx("input", { type: "hidden", name: name, value: raw })] }));
20
+ });
@@ -0,0 +1,12 @@
1
+ import { type HTMLAttributes } from "react";
2
+ import { type FormatMoneyOptions } from "@kashi-ui/persian";
3
+ export interface MoneyProps extends Omit<HTMLAttributes<HTMLElement>, "children">, Pick<FormatMoneyOptions, "unit" | "from" | "compact" | "digits"> {
4
+ value: number;
5
+ /** رنگ سبز برای مثبت و قرمز برای منفی، با علامت + @default false */
6
+ signed?: boolean;
7
+ /** مبلغ به حروف در title و برای صفحه‌خوان @default true */
8
+ words?: boolean;
9
+ size?: "sm" | "md" | "lg" | "xl";
10
+ }
11
+ /** نمایش مبلغ با تومان یا ریال، حالت خلاصه (۱٫۲ میلیون) و مبلغ به حروف برای صفحه‌خوان */
12
+ export declare const Money: import("react").ForwardRefExoticComponent<MoneyProps & import("react").RefAttributes<HTMLElement>>;
package/dist/Money.js ADDED
@@ -0,0 +1,14 @@
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { formatMoney, numberToWords, rialToToman, tomanToRial } from "@kashi-ui/persian";
4
+ import { cx } from "./cx.js";
5
+ /** نمایش مبلغ با تومان یا ریال، حالت خلاصه (۱٫۲ میلیون) و مبلغ به حروف برای صفحه‌خوان */
6
+ export const Money = forwardRef(function Money({ value, unit = "toman", from = "toman", compact, digits = "fa", signed, words = true, size = "md", className, ...rest }, ref) {
7
+ const n = from === unit ? value : from === "rial" ? rialToToman(value) : tomanToRial(value);
8
+ const amount = formatMoney(n, { unit, compact, digits, showUnit: false });
9
+ const full = formatMoney(n, { unit, compact });
10
+ const unitText = full.endsWith("همت") ? null : unit === "toman" ? "تومان" : "ریال";
11
+ const spoken = words && Number.isSafeInteger(Math.round(n)) ? `${numberToWords(Math.round(n))} ${unit === "toman" ? "تومان" : "ریال"}` : undefined;
12
+ const tone = signed ? (n > 0 ? "positive" : n < 0 ? "negative" : undefined) : undefined;
13
+ return (_jsxs("data", { ref: ref, value: String(n), className: cx("k-money", `k-money--${size}`, className), "data-tone": tone, title: spoken, ...rest, children: [_jsxs("span", { className: "k-money__amount", "aria-hidden": spoken ? true : undefined, children: [signed && n > 0 ? "+" : "", amount] }), unitText && _jsx("span", { className: "k-money__unit", "aria-hidden": spoken ? true : undefined, children: unitText }), spoken && _jsxs("span", { className: "k-sr-only", children: [n < 0 ? "" : signed && n > 0 ? "مثبت " : "", spoken] })] }));
14
+ });
@@ -0,0 +1,26 @@
1
+ import { type HTMLAttributes, type ReactNode } from "react";
2
+ export type ReceiptStatus = "success" | "failed" | "pending";
3
+ export interface PaymentReceiptProps extends Omit<HTMLAttributes<HTMLElement>, "title"> {
4
+ status: ReceiptStatus;
5
+ /** مبلغ به تومان (یا unit) */
6
+ amount: number;
7
+ unit?: "toman" | "rial";
8
+ /** عنوان؛ پیش‌فرض بر اساس وضعیت */
9
+ title?: ReactNode;
10
+ /** توضیح کوتاه زیر عنوان، مثل علت خطا */
11
+ description?: ReactNode;
12
+ merchant?: ReactNode;
13
+ /** کد پیگیری؛ دکمهٔ کپی دارد */
14
+ trackingCode?: string;
15
+ /** شمارهٔ مرجع */
16
+ referenceId?: string;
17
+ /** شمارهٔ کارت؛ خودکار پوشانده و بانکش تشخیص داده می‌شود */
18
+ cardNumber?: string;
19
+ date?: Date;
20
+ /** ردیف‌های دیگر */
21
+ rows?: [ReactNode, ReactNode][];
22
+ /** دکمه‌ها، مثل بازگشت به فروشگاه */
23
+ children?: ReactNode;
24
+ }
25
+ /** رسید پرداخت: وضعیت، مبلغ به عدد و حروف، کد پیگیری با دکمهٔ کپی، کارت پوشانده با لوگوی بانک و تاریخ شمسی */
26
+ export declare const PaymentReceipt: import("react").ForwardRefExoticComponent<PaymentReceiptProps & import("react").RefAttributes<HTMLElement>>;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useId } from "react";
3
+ import { formatJalali, formatTime, getBankByCard, numberToWords, onlyDigits, toFaDigits } from "@kashi-ui/persian";
4
+ import { useBankLogo } from "./BankBadge.js";
5
+ import { CopyButton } from "./CopyButton.js";
6
+ import { cx } from "./cx.js";
7
+ import { ErrorIcon, SuccessIcon, WarningIcon } from "./icons.js";
8
+ import { Money } from "./Money.js";
9
+ const TITLES = { success: "پرداخت موفق", failed: "پرداخت ناموفق", pending: "در انتظار تأیید بانک" };
10
+ const ICONS = { success: SuccessIcon, failed: ErrorIcon, pending: WarningIcon };
11
+ /** رسید پرداخت: وضعیت، مبلغ به عدد و حروف، کد پیگیری با دکمهٔ کپی، کارت پوشانده با لوگوی بانک و تاریخ شمسی */
12
+ export const PaymentReceipt = forwardRef(function PaymentReceipt({ status, amount, unit = "toman", title, description, merchant, trackingCode, referenceId, cardNumber, date, rows = [], children, className, ...rest }, ref) {
13
+ const id = useId();
14
+ const card = cardNumber ? onlyDigits(cardNumber) : "";
15
+ const bank = card ? getBankByCard(card) : null;
16
+ const logo = useBankLogo(bank?.slug, Boolean(bank));
17
+ const Icon = ICONS[status];
18
+ const all = [
19
+ ...(merchant ? [["پذیرنده", merchant]] : []),
20
+ ...(trackingCode ? [["کد پیگیری", _jsxs("span", { className: "k-receipt__code", children: [_jsx("span", { dir: "ltr", children: toFaDigits(trackingCode) }), _jsx(CopyButton, { value: trackingCode, iconOnly: true, size: "xs", variant: "tertiary", labels: { copy: "کپی کد پیگیری" } })] })]] : []),
21
+ ...(referenceId ? [["شمارهٔ مرجع", _jsx("span", { dir: "ltr", children: toFaDigits(referenceId) })]] : []),
22
+ ...(card ? [["کارت", _jsxs("span", { className: "k-receipt__card", children: [logo && _jsx("img", { src: logo, alt: "", width: 20, height: 20 }), _jsx("span", { dir: "ltr", "aria-label": `${bank?.name ?? "کارت"} مختوم به ${toFaDigits(card.slice(-4))}`, children: toFaDigits(`${card.slice(0, 4)}-${card.slice(4, 6)}**-****-${card.slice(-4)}`) })] })]] : []),
23
+ ...(date ? [["تاریخ", `${formatJalali(date, { style: "long" })}، ساعت ${toFaDigits(formatTime({ hours: date.getHours(), minutes: date.getMinutes() }))}`]] : []),
24
+ ...rows,
25
+ ];
26
+ return (_jsxs("section", { ref: ref, className: cx("k-receipt", className), "data-status": status, "aria-labelledby": `${id}-t`, ...rest, children: [_jsxs("div", { className: "k-receipt__head", children: [_jsx("span", { className: "k-receipt__icon", children: _jsx(Icon, {}) }), _jsx("h2", { className: "k-receipt__title", id: `${id}-t`, children: title ?? TITLES[status] }), description && _jsx("p", { className: "k-receipt__desc", children: description }), _jsx(Money, { className: "k-receipt__amount", value: amount, unit: unit, from: unit, size: "xl", words: false }), _jsxs("p", { className: "k-receipt__words", children: [numberToWords(Math.round(amount)), " ", unit === "toman" ? "تومان" : "ریال"] })] }), all.length > 0 && (_jsx("dl", { className: "k-receipt__rows", children: all.map(([k, v], i) => _jsxs("div", { className: "k-receipt__row", children: [_jsx("dt", { children: k }), _jsx("dd", { children: v })] }, i)) })), children && _jsx("div", { className: "k-receipt__actions", children: children })] }));
27
+ });
@@ -0,0 +1,38 @@
1
+ import { type CardNumberInputProps } from "./CardNumberInput.js";
2
+ import { type IbanInputProps } from "./IbanInput.js";
3
+ import { type KeyboardFixInputProps } from "./KeyboardFixInput.js";
4
+ import { type LandlineInputProps } from "./LandlineInput.js";
5
+ import { type LegalIdInputProps } from "./LegalIdInput.js";
6
+ import { type MobileInputProps } from "./MobileInput.js";
7
+ import { type NationalIdInputProps } from "./NationalIdInput.js";
8
+ import { type PostalCodeInputProps } from "./PostalCodeInput.js";
9
+ import { type PlateInputProps } from "./PlateInput.js";
10
+ import { type PriceInputProps } from "./PriceInput.js";
11
+ import { type TimeInputProps } from "./TimeInput.js";
12
+ /** نوع‌های پشتیبانی‌شده و ویژگی‌های هر کدام؛ همان ویژگی‌های کامپوننت تخصصی */
13
+ export interface PersianInputKinds {
14
+ text: KeyboardFixInputProps;
15
+ "national-id": NationalIdInputProps;
16
+ "legal-id": LegalIdInputProps;
17
+ mobile: MobileInputProps;
18
+ landline: LandlineInputProps;
19
+ card: CardNumberInputProps;
20
+ iban: IbanInputProps;
21
+ price: PriceInputProps;
22
+ postal: PostalCodeInputProps;
23
+ time: TimeInputProps;
24
+ plate: PlateInputProps;
25
+ }
26
+ export type PersianInputKind = keyof PersianInputKinds;
27
+ export type PersianInputProps = {
28
+ [K in PersianInputKind]: {
29
+ kind: K;
30
+ } & PersianInputKinds[K];
31
+ }[PersianInputKind];
32
+ /** برچسب پیش‌فرض هر نوع، اگر label یا aria-label داده نشود */
33
+ export declare const PERSIAN_INPUT_LABELS: Record<PersianInputKind, string>;
34
+ /**
35
+ * یک فیلد برای همهٔ داده‌های فارسی (کد ملی، شبا، کارت، مبلغ، کد پستی، ساعت، پلاک و…): نوع را با kind انتخاب کنید و بقیهٔ ویژگی‌ها همان کامپوننت تخصصی است.
36
+ * `<PersianInput kind="iban" />` همان `<IbanInput />` است. برای حجم کمتر، کامپوننت تخصصی را مستقیم import کنید.
37
+ */
38
+ export declare const PersianInput: import("react").ForwardRefExoticComponent<PersianInputProps & import("react").RefAttributes<HTMLInputElement>>;
@@ -0,0 +1,51 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { forwardRef } from "react";
3
+ import { CardNumberInput } from "./CardNumberInput.js";
4
+ import { IbanInput } from "./IbanInput.js";
5
+ import { KeyboardFixInput } from "./KeyboardFixInput.js";
6
+ import { LandlineInput } from "./LandlineInput.js";
7
+ import { LegalIdInput } from "./LegalIdInput.js";
8
+ import { MobileInput } from "./MobileInput.js";
9
+ import { NationalIdInput } from "./NationalIdInput.js";
10
+ import { PostalCodeInput } from "./PostalCodeInput.js";
11
+ import { PlateInput } from "./PlateInput.js";
12
+ import { PriceInput } from "./PriceInput.js";
13
+ import { TimeInput } from "./TimeInput.js";
14
+ /** برچسب پیش‌فرض هر نوع، اگر label یا aria-label داده نشود */
15
+ export const PERSIAN_INPUT_LABELS = {
16
+ text: "متن",
17
+ "national-id": "کد ملی",
18
+ "legal-id": "شناسهٔ ملی شرکت",
19
+ mobile: "شمارهٔ موبایل",
20
+ landline: "تلفن ثابت",
21
+ card: "شمارهٔ کارت",
22
+ iban: "شمارهٔ شبا",
23
+ price: "مبلغ",
24
+ postal: "کد پستی",
25
+ time: "ساعت",
26
+ plate: "پلاک خودرو",
27
+ };
28
+ const COMPONENTS = {
29
+ text: KeyboardFixInput,
30
+ "national-id": NationalIdInput,
31
+ "legal-id": LegalIdInput,
32
+ mobile: MobileInput,
33
+ landline: LandlineInput,
34
+ card: CardNumberInput,
35
+ iban: IbanInput,
36
+ price: PriceInput,
37
+ postal: PostalCodeInput,
38
+ time: TimeInput,
39
+ plate: PlateInput,
40
+ };
41
+ /**
42
+ * یک فیلد برای همهٔ داده‌های فارسی (کد ملی، شبا، کارت، مبلغ، کد پستی، ساعت، پلاک و…): نوع را با kind انتخاب کنید و بقیهٔ ویژگی‌ها همان کامپوننت تخصصی است.
43
+ * `<PersianInput kind="iban" />` همان `<IbanInput />` است. برای حجم کمتر، کامپوننت تخصصی را مستقیم import کنید.
44
+ */
45
+ export const PersianInput = forwardRef(function PersianInput({ kind, ...rest }, ref) {
46
+ const Component = COMPONENTS[kind];
47
+ const props = rest;
48
+ const label = props.label ?? (props["aria-label"] ? undefined : PERSIAN_INPUT_LABELS[kind]);
49
+ // PlateInput چند فیلد دارد و ref نمی‌گیرد
50
+ return _jsx(Component, { ref: kind === "plate" ? undefined : ref, ...props, label: label, "data-kind": kind });
51
+ });
@@ -0,0 +1,18 @@
1
+ import { type TextareaProps } from "./Input.js";
2
+ type Base = Omit<TextareaProps, "value" | "defaultValue" | "onChange">;
3
+ export interface PersianTextareaProps extends Base {
4
+ value?: string;
5
+ defaultValue?: string;
6
+ onValueChange?: (value: string) => void;
7
+ /** تبدیل ارقام لاتین داخل متن فارسی @default true */
8
+ fixDigits?: boolean;
9
+ /** اصلاح خودکار هنگام خروج از فیلد @default false */
10
+ fixOnBlur?: boolean;
11
+ labels?: {
12
+ fix?: string;
13
+ clean?: string;
14
+ };
15
+ }
16
+ /** ناحیهٔ متن با ویرایش نگارشی فارسی: «ي/ك» عربی، نیم‌فاصله، ویرگول و علامت سؤال فارسی و ارقام */
17
+ export declare const PersianTextarea: import("react").ForwardRefExoticComponent<PersianTextareaProps & import("react").RefAttributes<HTMLTextAreaElement>>;
18
+ export {};
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { forwardRef, useMemo, useState } from "react";
3
+ import { fixPersianText, toFaDigits } from "@kashi-ui/persian";
4
+ import { Button } from "./Button.js";
5
+ import { Textarea } from "./Input.js";
6
+ const KINDS = { arabic: "حرف عربی", zwnj: "نیم‌فاصله", punctuation: "علامت", digits: "رقم", spacing: "فاصله" };
7
+ /** ناحیهٔ متن با ویرایش نگارشی فارسی: «ي/ك» عربی، نیم‌فاصله، ویرگول و علامت سؤال فارسی و ارقام */
8
+ export const PersianTextarea = forwardRef(function PersianTextarea({ value, defaultValue = "", onValueChange, fixDigits = true, fixOnBlur = false, labels = {}, hint, onBlur, ...rest }, ref) {
9
+ const { fix = "اصلاح نگارش", clean = "نگارش متن درست است." } = labels;
10
+ const [inner, setInner] = useState(defaultValue);
11
+ const current = value ?? inner;
12
+ const result = useMemo(() => fixPersianText(current, { digits: fixDigits }), [current, fixDigits]);
13
+ const update = (next) => {
14
+ if (value === undefined)
15
+ setInner(next);
16
+ onValueChange?.(next);
17
+ };
18
+ const summary = Object.keys(KINDS)
19
+ .filter((k) => result.fixes[k])
20
+ .map((k) => `${toFaDigits(result.fixes[k])} ${KINDS[k]}`)
21
+ .join("، ");
22
+ return (_jsx(Textarea, { ref: ref, value: current, onChange: (e) => update(e.target.value), onBlur: (e) => {
23
+ if (fixOnBlur && result.count)
24
+ update(result.text);
25
+ onBlur?.(e);
26
+ }, hint: current.trim() ? (_jsxs("span", { className: "k-textfix", "data-state": result.count ? "fix" : "clean", children: [_jsx("span", { className: "k-textfix__text", children: result.count ? `${toFaDigits(result.count)} مورد قابل اصلاح: ${summary}` : clean }), result.count > 0 && _jsx(Button, { size: "xs", variant: "tertiary", onClick: () => update(result.text), children: fix })] })) : hint, ...rest }));
27
+ });
package/dist/index.d.ts CHANGED
@@ -134,3 +134,19 @@ export { Tour } from "./Tour.js";
134
134
  export type { TourProps, TourStep } from "./Tour.js";
135
135
  export { MultiSelect } from "./MultiSelect.js";
136
136
  export type { MultiSelectProps } from "./MultiSelect.js";
137
+ export { LegalIdInput } from "./LegalIdInput.js";
138
+ export type { LegalIdInputProps } from "./LegalIdInput.js";
139
+ export { KeyboardFixInput } from "./KeyboardFixInput.js";
140
+ export type { KeyboardFixInputProps } from "./KeyboardFixInput.js";
141
+ export { PersianTextarea } from "./PersianTextarea.js";
142
+ export type { PersianTextareaProps } from "./PersianTextarea.js";
143
+ export { Money } from "./Money.js";
144
+ export type { MoneyProps } from "./Money.js";
145
+ export { BankCard } from "./BankCard.js";
146
+ export type { BankCardProps } from "./BankCard.js";
147
+ export { DateTile } from "./DateTile.js";
148
+ export type { DateTileProps } from "./DateTile.js";
149
+ export { PaymentReceipt } from "./PaymentReceipt.js";
150
+ export type { PaymentReceiptProps, ReceiptStatus } from "./PaymentReceipt.js";
151
+ export { PersianInput, PERSIAN_INPUT_LABELS } from "./PersianInput.js";
152
+ export type { PersianInputKind, PersianInputKinds, PersianInputProps } from "./PersianInput.js";
package/dist/index.js CHANGED
@@ -67,3 +67,11 @@ export { Meter } from "./Meter.js";
67
67
  export { Splitter } from "./Splitter.js";
68
68
  export { Tour } from "./Tour.js";
69
69
  export { MultiSelect } from "./MultiSelect.js";
70
+ export { LegalIdInput } from "./LegalIdInput.js";
71
+ export { KeyboardFixInput } from "./KeyboardFixInput.js";
72
+ export { PersianTextarea } from "./PersianTextarea.js";
73
+ export { Money } from "./Money.js";
74
+ export { BankCard } from "./BankCard.js";
75
+ export { DateTile } from "./DateTile.js";
76
+ export { PaymentReceipt } from "./PaymentReceipt.js";
77
+ export { PersianInput, PERSIAN_INPUT_LABELS } from "./PersianInput.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kashi-ui/react",
3
- "version": "0.14.0",
3
+ "version": "0.15.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.14.0",
25
+ "@kashi-ui/css": "^0.15.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.14.0",
63
- "@kashi-ui/persian": "^0.14.0"
62
+ "@kashi-ui/bank-logos": "^0.15.0",
63
+ "@kashi-ui/persian": "^0.15.0"
64
64
  }
65
65
  }