@farmzone/fz-react-ui 1.1.11 → 1.1.13

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 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
- const digitsOnly = sanitized.replace(/\D/g, "");
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(props) {
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) {
@@ -1925,15 +1998,16 @@ function ToastItemCard(props) {
1925
1998
  const { toast: toast2, onRemove } = props;
1926
1999
  const [isVisible, setIsVisible] = React6.useState(true);
1927
2000
  const removeTimeoutRef = React6.useRef(null);
2001
+ const EXIT_ANIMATION_MS = 400;
1928
2002
  React6.useEffect(() => {
1929
2003
  const duration = toast2.props.duration ?? 1500;
1930
- if (duration !== Infinity && duration > 300) {
1931
- const fadeOutTime = Math.max(0, duration - 300);
2004
+ if (duration !== Infinity && duration > EXIT_ANIMATION_MS) {
2005
+ const fadeOutTime = Math.max(0, duration - EXIT_ANIMATION_MS);
1932
2006
  const fadeOutTimer = setTimeout(() => {
1933
2007
  setIsVisible(false);
1934
2008
  removeTimeoutRef.current = setTimeout(() => {
1935
2009
  onRemove(toast2.id);
1936
- }, 300);
2010
+ }, EXIT_ANIMATION_MS);
1937
2011
  }, fadeOutTime);
1938
2012
  return () => {
1939
2013
  clearTimeout(fadeOutTimer);
@@ -1954,14 +2028,15 @@ function ToastItemCard(props) {
1954
2028
  }
1955
2029
  removeTimeoutRef.current = setTimeout(() => {
1956
2030
  onRemove(toast2.id);
1957
- }, 300);
2031
+ }, EXIT_ANIMATION_MS);
1958
2032
  };
1959
2033
  const handleCloseClick = (e) => {
1960
2034
  e.stopPropagation();
1961
2035
  handleClose();
1962
2036
  };
1963
- const getTypeStyles = (type) => {
2037
+ const getTypeStyles = (type, hasCustomStyle2) => {
1964
2038
  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";
2039
+ if (hasCustomStyle2) return baseStyles;
1965
2040
  const typeStyles = {
1966
2041
  success: "bg-green-50 border-green-200 text-green-800",
1967
2042
  error: "bg-red-50 border-red-200 text-red-800",
@@ -1971,7 +2046,7 @@ function ToastItemCard(props) {
1971
2046
  };
1972
2047
  return `${baseStyles} ${typeStyles[type]}`;
1973
2048
  };
1974
- const getDefaultIcon = (type) => {
2049
+ const getDefaultIcon = (type, iconTheme) => {
1975
2050
  const icons = {
1976
2051
  success: "\u2713",
1977
2052
  error: "\u2715",
@@ -1979,6 +2054,26 @@ function ToastItemCard(props) {
1979
2054
  info: "\u2139",
1980
2055
  loading: "\u27F3"
1981
2056
  };
2057
+ if (iconTheme) {
2058
+ const colorVars = {
2059
+ "--fz-toast-icon-primary": iconTheme.primary,
2060
+ "--fz-toast-icon-secondary": iconTheme.secondary
2061
+ };
2062
+ if (type === "loading") {
2063
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "fz-toast-icon-spinner", style: colorVars });
2064
+ }
2065
+ if (type === "success" || type === "error") {
2066
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: `fz-toast-icon-badge fz-toast-icon-badge--${type}`, style: colorVars });
2067
+ }
2068
+ return /* @__PURE__ */ jsxRuntime.jsx(
2069
+ "span",
2070
+ {
2071
+ className: "flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-xs font-bold",
2072
+ style: { backgroundColor: iconTheme.primary, color: iconTheme.secondary },
2073
+ children: icons[type]
2074
+ }
2075
+ );
2076
+ }
1982
2077
  return /* @__PURE__ */ jsxRuntime.jsx("span", { className: `text-lg ${type === "loading" ? "animate-spin" : ""}`, children: icons[type] });
1983
2078
  };
1984
2079
  const getCloseButtonStyles = (type) => {
@@ -1992,15 +2087,17 @@ function ToastItemCard(props) {
1992
2087
  };
1993
2088
  return `${baseStyles} ${typeStyles[type]}`;
1994
2089
  };
2090
+ const hasCustomStyle = Boolean(toast2.props.style && Object.keys(toast2.props.style).length > 0);
1995
2091
  return /* @__PURE__ */ jsxRuntime.jsxs(
1996
2092
  "div",
1997
2093
  {
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`,
2094
+ className: `${getTypeStyles(toast2.props.type || "info", hasCustomStyle)} ${isVisible ? "fz-toast-card-enter" : "fz-toast-card-exit"} mb-2 cursor-pointer ${toast2.props.className ?? ""}`,
2095
+ style: toast2.props.style,
1999
2096
  onClick: handleClick,
2000
2097
  children: [
2001
- toast2.props.icon || getDefaultIcon(toast2.props.type || "info"),
2098
+ toast2.props.icon || getDefaultIcon(toast2.props.type || "info", toast2.props.iconTheme),
2002
2099
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm font-medium", children: toast2.props.toast }),
2003
- toast2.props.showCloseButton !== false && /* @__PURE__ */ jsxRuntime.jsx(
2100
+ toast2.props.showCloseButton === true && /* @__PURE__ */ jsxRuntime.jsx(
2004
2101
  "button",
2005
2102
  {
2006
2103
  onClick: handleCloseClick,
@@ -2022,7 +2119,12 @@ var TOAST_POSITIONS = [
2022
2119
  "bottom-center",
2023
2120
  "bottom-right"
2024
2121
  ];
2025
- function ToastProvider() {
2122
+ function ToastProvider(props) {
2123
+ const { toastOptions } = props;
2124
+ React6.useEffect(() => {
2125
+ if (!toastOptions) return;
2126
+ ToastManager.getInstance().setDefaultOptions(toastOptions);
2127
+ }, [toastOptions]);
2026
2128
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: TOAST_POSITIONS.map((position) => /* @__PURE__ */ jsxRuntime.jsx(ToastContainer, { position }, position)) });
2027
2129
  }
2028
2130
 
@@ -6400,7 +6502,7 @@ var THREE_DIGIT_AREA_CODES = /* @__PURE__ */ new Set([
6400
6502
  "063"
6401
6503
  ]);
6402
6504
  function formatPhoneNumber(value) {
6403
- let digits = value.replace(/\D/g, "");
6505
+ const digits = value.replace(/\D/g, "");
6404
6506
  if (digits.startsWith("02")) {
6405
6507
  if (digits.length > 2 && digits.length <= 6) {
6406
6508
  return `${digits.slice(0, 2)}-${digits.slice(2)}`;
@@ -6437,6 +6539,12 @@ function formatNumberWithCommas(value) {
6437
6539
  parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
6438
6540
  return parts.join(".");
6439
6541
  }
6542
+ function parseFormattedNumber(value) {
6543
+ const digitsOnly = value.replace(/,/g, "").replace(/[^\d.]/g, "");
6544
+ if (digitsOnly === "" || digitsOnly === ".") return void 0;
6545
+ const num = Number(digitsOnly);
6546
+ return Number.isNaN(num) ? void 0 : num;
6547
+ }
6440
6548
  function removeNonNumeric(value, allowDecimal = false) {
6441
6549
  if (allowDecimal) {
6442
6550
  return value.replace(/[^\d.]/g, "").replace(/(\..*?)\./g, "$1");
@@ -12133,10 +12241,12 @@ exports.confirmModal = confirmModal;
12133
12241
  exports.findParentMenuItem = findParentMenuItem;
12134
12242
  exports.findParentMenuName = findParentMenuName;
12135
12243
  exports.formatDate = formatDate;
12244
+ exports.formatNumberWithCommas = formatNumberWithCommas;
12136
12245
  exports.getFileLabel = getFileLabel;
12137
12246
  exports.getPreviewFileType = getPreviewFileType;
12138
12247
  exports.isCalendarDayAfterMax = isCalendarDayAfterMax;
12139
12248
  exports.isDateInRange = isDateInRange;
12249
+ exports.parseFormattedNumber = parseFormattedNumber;
12140
12250
  exports.switchTrackSizes = switchTrackSizes;
12141
12251
  exports.textVariants = textVariants;
12142
12252
  exports.toast = toast;