@farmzone/fz-react-ui 1.1.11 → 1.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +120 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +44 -3
- package/dist/index.d.ts +44 -3
- package/dist/index.js +119 -10
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -488,6 +488,12 @@ function Input2(props) {
|
|
|
488
488
|
clearable = false,
|
|
489
489
|
onClear,
|
|
490
490
|
onChange,
|
|
491
|
+
onKeyDown,
|
|
492
|
+
onBlur,
|
|
493
|
+
maxLength,
|
|
494
|
+
allowLeadingSpace = true,
|
|
495
|
+
allowMiddleSpace = true,
|
|
496
|
+
allowTrailingSpace = true,
|
|
491
497
|
...rest
|
|
492
498
|
} = props;
|
|
493
499
|
const randomId = React6.useId();
|
|
@@ -534,6 +540,15 @@ function Input2(props) {
|
|
|
534
540
|
children: showPassword ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOff, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { className: "h-4 w-4" })
|
|
535
541
|
}
|
|
536
542
|
) : null);
|
|
543
|
+
const splitSpaceRuns = (value) => {
|
|
544
|
+
const core = value.trim();
|
|
545
|
+
if (core === "") {
|
|
546
|
+
return { leading: value, core: "", trailing: "" };
|
|
547
|
+
}
|
|
548
|
+
const leading = value.slice(0, value.length - value.trimStart().length);
|
|
549
|
+
const trailing = value.slice(value.trimEnd().length);
|
|
550
|
+
return { leading, core, trailing };
|
|
551
|
+
};
|
|
537
552
|
const handleChange = (event) => {
|
|
538
553
|
const { value } = event.target;
|
|
539
554
|
if (type === "number" || type === "money") {
|
|
@@ -543,7 +558,9 @@ function Input2(props) {
|
|
|
543
558
|
sanitized = parts[0] + "." + parts.slice(1).join("");
|
|
544
559
|
}
|
|
545
560
|
if (type === "money") {
|
|
546
|
-
|
|
561
|
+
let digitsOnly = sanitized.replace(/\D/g, "");
|
|
562
|
+
digitsOnly = digitsOnly.replace(/^0+/, "");
|
|
563
|
+
digitsOnly = digitsOnly.slice(0, maxLength);
|
|
547
564
|
if (digitsOnly.length === 0) {
|
|
548
565
|
event.target.value = "";
|
|
549
566
|
} else {
|
|
@@ -553,11 +570,39 @@ function Input2(props) {
|
|
|
553
570
|
} else {
|
|
554
571
|
event.target.value = sanitized;
|
|
555
572
|
}
|
|
573
|
+
} else if (!allowLeadingSpace || !allowMiddleSpace) {
|
|
574
|
+
const { leading, core, trailing } = splitSpaceRuns(value);
|
|
575
|
+
const nextLeading = allowLeadingSpace ? leading : "";
|
|
576
|
+
const nextCore = allowMiddleSpace ? core : core.replace(/ /g, "");
|
|
577
|
+
const sanitized = nextLeading + nextCore + trailing;
|
|
578
|
+
if (sanitized !== value) {
|
|
579
|
+
event.target.value = sanitized;
|
|
580
|
+
}
|
|
556
581
|
}
|
|
557
582
|
if (onChange) {
|
|
558
583
|
onChange(event);
|
|
559
584
|
}
|
|
560
585
|
};
|
|
586
|
+
const handleKeyDown = (event) => {
|
|
587
|
+
if (event.key === " ") {
|
|
588
|
+
if (type === "number" || type === "money") {
|
|
589
|
+
event.preventDefault();
|
|
590
|
+
} else if (!allowLeadingSpace && event.currentTarget.selectionStart === 0) {
|
|
591
|
+
event.preventDefault();
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
onKeyDown?.(event);
|
|
595
|
+
};
|
|
596
|
+
const handleBlur = (event) => {
|
|
597
|
+
if (!allowTrailingSpace && type !== "number" && type !== "money") {
|
|
598
|
+
const trimmed = event.currentTarget.value.replace(/ +$/, "");
|
|
599
|
+
if (trimmed !== event.currentTarget.value) {
|
|
600
|
+
event.currentTarget.value = trimmed;
|
|
601
|
+
onChange?.(event);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
onBlur?.(event);
|
|
605
|
+
};
|
|
561
606
|
const inputBlock = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative m-0", children: [
|
|
562
607
|
leftIcon && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-muted-foreground absolute top-1/2 left-3 -translate-y-1/2 transform", children: leftIcon }),
|
|
563
608
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -569,7 +614,10 @@ function Input2(props) {
|
|
|
569
614
|
placeholder,
|
|
570
615
|
disabled,
|
|
571
616
|
ref,
|
|
617
|
+
maxLength: type === "money" ? void 0 : maxLength,
|
|
572
618
|
onChange: handleChange,
|
|
619
|
+
onKeyDown: handleKeyDown,
|
|
620
|
+
onBlur: handleBlur,
|
|
573
621
|
...rest
|
|
574
622
|
}
|
|
575
623
|
),
|
|
@@ -1714,12 +1762,36 @@ var ToastManager = class _ToastManager {
|
|
|
1714
1762
|
static instance;
|
|
1715
1763
|
containers = /* @__PURE__ */ new Map();
|
|
1716
1764
|
toasts = /* @__PURE__ */ new Map();
|
|
1765
|
+
// ToastProvider가 마운트/prop 변경 시 넣어주는 전역 기본값 — 개별 toast() 호출의 props가 항상 우선한다.
|
|
1766
|
+
defaultOptions = {};
|
|
1717
1767
|
static getInstance() {
|
|
1718
1768
|
if (!_ToastManager.instance) {
|
|
1719
1769
|
_ToastManager.instance = new _ToastManager();
|
|
1720
1770
|
}
|
|
1721
1771
|
return _ToastManager.instance;
|
|
1722
1772
|
}
|
|
1773
|
+
setDefaultOptions(options) {
|
|
1774
|
+
this.defaultOptions = options;
|
|
1775
|
+
}
|
|
1776
|
+
getDefaultOptions() {
|
|
1777
|
+
return this.defaultOptions;
|
|
1778
|
+
}
|
|
1779
|
+
// 호출 시점 props를 전역 기본값(및 상태별 기본값)과 합쳐 최종 props를 만든다. 우선순위는
|
|
1780
|
+
// 호출 props > 상태별 기본값(options[type]) > 공통 기본값(options.*) > 하드코딩 폴백.
|
|
1781
|
+
resolveProps(props) {
|
|
1782
|
+
const type = props.type ?? "info";
|
|
1783
|
+
const base = this.defaultOptions;
|
|
1784
|
+
const perType = base[type] ?? {};
|
|
1785
|
+
const style = { ...base.style, ...perType.style, ...props.style };
|
|
1786
|
+
const className = [base.className, perType.className, props.className].filter((value) => Boolean(value)).join(" ");
|
|
1787
|
+
return {
|
|
1788
|
+
...props,
|
|
1789
|
+
duration: props.duration ?? perType.duration ?? base.duration ?? 1500,
|
|
1790
|
+
style: Object.keys(style).length > 0 ? style : void 0,
|
|
1791
|
+
className: className || void 0,
|
|
1792
|
+
iconTheme: props.iconTheme ?? perType.iconTheme ?? base.iconTheme
|
|
1793
|
+
};
|
|
1794
|
+
}
|
|
1723
1795
|
registerContainer(position, setToasts) {
|
|
1724
1796
|
this.containers.set(position, setToasts);
|
|
1725
1797
|
const existingToasts = this.toasts.get(position) || [];
|
|
@@ -1729,7 +1801,8 @@ var ToastManager = class _ToastManager {
|
|
|
1729
1801
|
setToasts([]);
|
|
1730
1802
|
}
|
|
1731
1803
|
}
|
|
1732
|
-
addToast(
|
|
1804
|
+
addToast(rawProps) {
|
|
1805
|
+
const props = this.resolveProps(rawProps);
|
|
1733
1806
|
const position = props.position || "top-center";
|
|
1734
1807
|
const duration = props.duration !== void 0 ? props.duration : 1500;
|
|
1735
1808
|
if (props.id) {
|
|
@@ -1960,8 +2033,9 @@ function ToastItemCard(props) {
|
|
|
1960
2033
|
e.stopPropagation();
|
|
1961
2034
|
handleClose();
|
|
1962
2035
|
};
|
|
1963
|
-
const getTypeStyles = (type) => {
|
|
2036
|
+
const getTypeStyles = (type, hasCustomStyle2) => {
|
|
1964
2037
|
const baseStyles = "px-4 py-3 rounded-lg shadow-lg border flex items-center gap-3 min-w-[300px] max-w-[500px] pointer-events-auto";
|
|
2038
|
+
if (hasCustomStyle2) return baseStyles;
|
|
1965
2039
|
const typeStyles = {
|
|
1966
2040
|
success: "bg-green-50 border-green-200 text-green-800",
|
|
1967
2041
|
error: "bg-red-50 border-red-200 text-red-800",
|
|
@@ -1971,7 +2045,7 @@ function ToastItemCard(props) {
|
|
|
1971
2045
|
};
|
|
1972
2046
|
return `${baseStyles} ${typeStyles[type]}`;
|
|
1973
2047
|
};
|
|
1974
|
-
const getDefaultIcon = (type) => {
|
|
2048
|
+
const getDefaultIcon = (type, iconTheme) => {
|
|
1975
2049
|
const icons = {
|
|
1976
2050
|
success: "\u2713",
|
|
1977
2051
|
error: "\u2715",
|
|
@@ -1979,6 +2053,28 @@ function ToastItemCard(props) {
|
|
|
1979
2053
|
info: "\u2139",
|
|
1980
2054
|
loading: "\u27F3"
|
|
1981
2055
|
};
|
|
2056
|
+
if (iconTheme) {
|
|
2057
|
+
if (type === "loading") {
|
|
2058
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2059
|
+
"span",
|
|
2060
|
+
{
|
|
2061
|
+
className: "h-4 w-4 shrink-0 animate-spin rounded-full",
|
|
2062
|
+
style: {
|
|
2063
|
+
border: `2px solid ${iconTheme.secondary}`,
|
|
2064
|
+
borderRightColor: iconTheme.primary
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
);
|
|
2068
|
+
}
|
|
2069
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2070
|
+
"span",
|
|
2071
|
+
{
|
|
2072
|
+
className: "flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-xs font-bold",
|
|
2073
|
+
style: { backgroundColor: iconTheme.primary, color: iconTheme.secondary },
|
|
2074
|
+
children: icons[type]
|
|
2075
|
+
}
|
|
2076
|
+
);
|
|
2077
|
+
}
|
|
1982
2078
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: `text-lg ${type === "loading" ? "animate-spin" : ""}`, children: icons[type] });
|
|
1983
2079
|
};
|
|
1984
2080
|
const getCloseButtonStyles = (type) => {
|
|
@@ -1992,15 +2088,17 @@ function ToastItemCard(props) {
|
|
|
1992
2088
|
};
|
|
1993
2089
|
return `${baseStyles} ${typeStyles[type]}`;
|
|
1994
2090
|
};
|
|
2091
|
+
const hasCustomStyle = Boolean(toast2.props.style && Object.keys(toast2.props.style).length > 0);
|
|
1995
2092
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1996
2093
|
"div",
|
|
1997
2094
|
{
|
|
1998
|
-
className: `${getTypeStyles(toast2.props.type || "info")} transition-all duration-300 ${isVisible ? "animate-in slide-in-from-top-2 fade-in-0 duration-300 opacity-100" : "animate-out slide-out-to-top-2 fade-out-0 duration-300 opacity-0"} mb-2 cursor-pointer`,
|
|
2095
|
+
className: `${getTypeStyles(toast2.props.type || "info", hasCustomStyle)} transition-all duration-300 ${isVisible ? "animate-in slide-in-from-top-2 fade-in-0 duration-300 opacity-100" : "animate-out slide-out-to-top-2 fade-out-0 duration-300 opacity-0"} mb-2 cursor-pointer ${toast2.props.className ?? ""}`,
|
|
2096
|
+
style: toast2.props.style,
|
|
1999
2097
|
onClick: handleClick,
|
|
2000
2098
|
children: [
|
|
2001
|
-
toast2.props.icon || getDefaultIcon(toast2.props.type || "info"),
|
|
2099
|
+
toast2.props.icon || getDefaultIcon(toast2.props.type || "info", toast2.props.iconTheme),
|
|
2002
2100
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm font-medium", children: toast2.props.toast }),
|
|
2003
|
-
toast2.props.showCloseButton
|
|
2101
|
+
toast2.props.showCloseButton === true && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2004
2102
|
"button",
|
|
2005
2103
|
{
|
|
2006
2104
|
onClick: handleCloseClick,
|
|
@@ -2022,7 +2120,12 @@ var TOAST_POSITIONS = [
|
|
|
2022
2120
|
"bottom-center",
|
|
2023
2121
|
"bottom-right"
|
|
2024
2122
|
];
|
|
2025
|
-
function ToastProvider() {
|
|
2123
|
+
function ToastProvider(props) {
|
|
2124
|
+
const { toastOptions } = props;
|
|
2125
|
+
React6.useEffect(() => {
|
|
2126
|
+
if (!toastOptions) return;
|
|
2127
|
+
ToastManager.getInstance().setDefaultOptions(toastOptions);
|
|
2128
|
+
}, [toastOptions]);
|
|
2026
2129
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: TOAST_POSITIONS.map((position) => /* @__PURE__ */ jsxRuntime.jsx(ToastContainer, { position }, position)) });
|
|
2027
2130
|
}
|
|
2028
2131
|
|
|
@@ -6400,7 +6503,7 @@ var THREE_DIGIT_AREA_CODES = /* @__PURE__ */ new Set([
|
|
|
6400
6503
|
"063"
|
|
6401
6504
|
]);
|
|
6402
6505
|
function formatPhoneNumber(value) {
|
|
6403
|
-
|
|
6506
|
+
const digits = value.replace(/\D/g, "");
|
|
6404
6507
|
if (digits.startsWith("02")) {
|
|
6405
6508
|
if (digits.length > 2 && digits.length <= 6) {
|
|
6406
6509
|
return `${digits.slice(0, 2)}-${digits.slice(2)}`;
|
|
@@ -6437,6 +6540,12 @@ function formatNumberWithCommas(value) {
|
|
|
6437
6540
|
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
6438
6541
|
return parts.join(".");
|
|
6439
6542
|
}
|
|
6543
|
+
function parseFormattedNumber(value) {
|
|
6544
|
+
const digitsOnly = value.replace(/,/g, "").replace(/[^\d.]/g, "");
|
|
6545
|
+
if (digitsOnly === "" || digitsOnly === ".") return void 0;
|
|
6546
|
+
const num = Number(digitsOnly);
|
|
6547
|
+
return Number.isNaN(num) ? void 0 : num;
|
|
6548
|
+
}
|
|
6440
6549
|
function removeNonNumeric(value, allowDecimal = false) {
|
|
6441
6550
|
if (allowDecimal) {
|
|
6442
6551
|
return value.replace(/[^\d.]/g, "").replace(/(\..*?)\./g, "$1");
|
|
@@ -12133,10 +12242,12 @@ exports.confirmModal = confirmModal;
|
|
|
12133
12242
|
exports.findParentMenuItem = findParentMenuItem;
|
|
12134
12243
|
exports.findParentMenuName = findParentMenuName;
|
|
12135
12244
|
exports.formatDate = formatDate;
|
|
12245
|
+
exports.formatNumberWithCommas = formatNumberWithCommas;
|
|
12136
12246
|
exports.getFileLabel = getFileLabel;
|
|
12137
12247
|
exports.getPreviewFileType = getPreviewFileType;
|
|
12138
12248
|
exports.isCalendarDayAfterMax = isCalendarDayAfterMax;
|
|
12139
12249
|
exports.isDateInRange = isDateInRange;
|
|
12250
|
+
exports.parseFormattedNumber = parseFormattedNumber;
|
|
12140
12251
|
exports.switchTrackSizes = switchTrackSizes;
|
|
12141
12252
|
exports.textVariants = textVariants;
|
|
12142
12253
|
exports.toast = toast;
|