@farmzone/fz-react-ui 1.1.4 → 1.1.6

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
@@ -482,6 +482,8 @@ function Input2(props) {
482
482
  leftIcon,
483
483
  rightIcon,
484
484
  showPasswordToggle = true,
485
+ clearable = false,
486
+ onClear,
485
487
  onChange,
486
488
  ...rest
487
489
  } = props;
@@ -511,7 +513,16 @@ function Input2(props) {
511
513
  const shouldShowPasswordToggle = type === "password" && showPasswordToggle;
512
514
  const actualType = type === "password" && showPassword ? "text" : type;
513
515
  const handlePasswordToggle = () => setShowPassword((prev) => !prev);
514
- const finalRightIcon = rightIcon || (shouldShowPasswordToggle ? /* @__PURE__ */ jsxRuntime.jsx(
516
+ const handleClear = () => onClear?.();
517
+ const shouldShowClearButton = clearable && !disabled && typeof rest.value === "string" && rest.value.length > 0;
518
+ const finalRightIcon = rightIcon || (shouldShowClearButton ? /* @__PURE__ */ jsxRuntime.jsx(
519
+ "div",
520
+ {
521
+ onClick: handleClear,
522
+ className: "text-muted-foreground hover:text-foreground cursor-pointer transition-colors",
523
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { className: "h-4 w-4" })
524
+ }
525
+ ) : null) || (shouldShowPasswordToggle ? /* @__PURE__ */ jsxRuntime.jsx(
515
526
  "div",
516
527
  {
517
528
  onClick: handlePasswordToggle,
@@ -977,6 +988,29 @@ function SelectScrollDownButton({
977
988
  }
978
989
  );
979
990
  }
991
+ function SelectOptionVisual(props) {
992
+ const { icon, avatarUrl, avatarAlt, fallbackLabel } = props;
993
+ const [hasAvatarError, setHasAvatarError] = React6.useState(false);
994
+ const handleAvatarError = () => setHasAvatarError(true);
995
+ if (avatarUrl && !hasAvatarError) {
996
+ return /* @__PURE__ */ jsxRuntime.jsx(
997
+ "img",
998
+ {
999
+ src: avatarUrl,
1000
+ alt: avatarAlt ?? "",
1001
+ className: "size-5 shrink-0 rounded-full object-cover",
1002
+ onError: handleAvatarError
1003
+ }
1004
+ );
1005
+ }
1006
+ if (avatarUrl && hasAvatarError) {
1007
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex size-5 shrink-0 items-center justify-center rounded-full bg-gray-200 text-[10px] font-medium text-gray-500", children: fallbackLabel?.charAt(0).toUpperCase() ?? "?" });
1008
+ }
1009
+ if (icon) {
1010
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex size-4 shrink-0 items-center justify-center text-gray-500", children: icon });
1011
+ }
1012
+ return null;
1013
+ }
980
1014
 
981
1015
  // src/components/Select/config/default.ts
982
1016
  var SELECT_BORDER_COLORS = {
@@ -1068,7 +1102,18 @@ function Select2(props) {
1068
1102
  itemClassName,
1069
1103
  option.disabled && cn("opacity-50 cursor-not-allowed text-gray-300 bg-white", disabledItemClassName)
1070
1104
  ),
1071
- children: option.label
1105
+ children: /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex w-full min-w-0 items-center gap-2", children: [
1106
+ /* @__PURE__ */ jsxRuntime.jsx(
1107
+ SelectOptionVisual,
1108
+ {
1109
+ icon: option.icon,
1110
+ avatarUrl: option.avatarUrl,
1111
+ avatarAlt: option.avatarAlt,
1112
+ fallbackLabel: typeof option.label === "string" ? option.label : void 0
1113
+ }
1114
+ ),
1115
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: option.label })
1116
+ ] })
1072
1117
  },
1073
1118
  String(option.value)
1074
1119
  )) })
@@ -7884,6 +7929,9 @@ function PageFilter(props) {
7884
7929
  const handleInputChange = (key) => (e) => {
7885
7930
  onChange({ [key]: e.target.value });
7886
7931
  };
7932
+ const handleInputClear = (key) => () => {
7933
+ onChange({ [key]: "" });
7934
+ };
7887
7935
  const handleSelectChange = (key, autoSubmit) => (value) => {
7888
7936
  onChange({ [key]: value });
7889
7937
  if (autoSubmit) pendingAutoSubmitRef.current = { key, value };
@@ -7927,7 +7975,10 @@ function PageFilter(props) {
7927
7975
  onKeyDown: (e) => {
7928
7976
  if (e.key === "Enter") handleSubmit();
7929
7977
  },
7930
- leftIcon: option.leftIcon !== false ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, { size: 16 }) : void 0
7978
+ leftIcon: option.leftIcon !== false ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, { size: 16 }) : void 0,
7979
+ clearable: option.canReset ?? true,
7980
+ onClear: handleInputClear(optionKey),
7981
+ className: option.className
7931
7982
  }
7932
7983
  ) }, String(optionKey));
7933
7984
  case "select":
@@ -7939,7 +7990,8 @@ function PageFilter(props) {
7939
7990
  options: option.options,
7940
7991
  placeholder: option.placeholder || "\uC120\uD0DD",
7941
7992
  canReset: option.canReset ?? true,
7942
- containerClassName: option.containerClassName ?? "w-30"
7993
+ containerClassName: option.containerClassName ?? "w-30",
7994
+ className: option.className
7943
7995
  }
7944
7996
  ) }, String(optionKey));
7945
7997
  case "radio":
@@ -7950,7 +8002,8 @@ function PageFilter(props) {
7950
8002
  value: currentValue,
7951
8003
  onChange: handleRadioChange(optionKey, option.autoSubmit),
7952
8004
  options: option.options,
7953
- direction: "horizontal"
8005
+ direction: "horizontal",
8006
+ containerClassName: option.className
7954
8007
  }
7955
8008
  ) }, String(optionKey));
7956
8009
  case "date":
@@ -7960,7 +8013,8 @@ function PageFilter(props) {
7960
8013
  value: currentValue,
7961
8014
  onChange: handleDateChange(optionKey),
7962
8015
  placeholder: option.placeholder,
7963
- onKeyDownEnter: handleSubmit
8016
+ onKeyDownEnter: handleSubmit,
8017
+ className: option.className
7964
8018
  }
7965
8019
  ) }, String(optionKey));
7966
8020
  case "date-range":
@@ -7970,7 +8024,8 @@ function PageFilter(props) {
7970
8024
  startValue: currentValue,
7971
8025
  endValue: String(values[option.endKey] ?? ""),
7972
8026
  onRangeChange: handleRangeChangeCurried(optionKey, option.endKey),
7973
- onKeyDownEnter: handleSubmit
8027
+ onKeyDownEnter: handleSubmit,
8028
+ className: option.className
7974
8029
  }
7975
8030
  ) }, String(optionKey));
7976
8031
  case "checkbox":
@@ -7981,7 +8036,8 @@ function PageFilter(props) {
7981
8036
  name: String(optionKey),
7982
8037
  value: currentValue,
7983
8038
  label: option.label,
7984
- onChange: handleCheckboxChange(optionKey, option.autoSubmit)
8039
+ onChange: handleCheckboxChange(optionKey, option.autoSubmit),
8040
+ className: option.className
7985
8041
  }
7986
8042
  ) }, String(optionKey));
7987
8043
  default: {