@farmzone/fz-react-ui 1.0.7 → 1.0.8

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
@@ -499,12 +499,10 @@ function Input2(props) {
499
499
  const actualType = type === "password" && showPassword ? "text" : type;
500
500
  const handlePasswordToggle = () => setShowPassword((prev) => !prev);
501
501
  const finalRightIcon = rightIcon || (shouldShowPasswordToggle ? /* @__PURE__ */ jsxRuntime.jsx(
502
- "button",
502
+ "div",
503
503
  {
504
- type: "button",
505
504
  onClick: handlePasswordToggle,
506
505
  className: "text-muted-foreground hover:text-foreground cursor-pointer transition-colors",
507
- disabled,
508
506
  children: showPassword ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOff, { className: "h-4 w-4" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { className: "h-4 w-4" })
509
507
  }
510
508
  ) : null);
@@ -3963,8 +3961,6 @@ function ArrowIcon(props) {
3963
3961
  }
3964
3962
  );
3965
3963
  }
3966
- var DEFAULT_SORT_KEY = "";
3967
- var DEFAULT_SORT_ORDER = "asc";
3968
3964
  var DEFAULT_SORT_OPTIONS = {
3969
3965
  visibleType: "always",
3970
3966
  sortKey: "",
@@ -4013,27 +4009,18 @@ function TableHeader(props) {
4013
4009
  if (onSortChange) {
4014
4010
  const isActive = sortOption?.sortKey === columnKey;
4015
4011
  const currentOrder = sortOption?.sortOrder;
4016
- if (isActive) {
4017
- if (currentOrder === "desc") {
4018
- onSortChange(columnKey, "asc");
4019
- } else if (currentOrder === "asc") {
4020
- onSortChange(DEFAULT_SORT_KEY, DEFAULT_SORT_ORDER);
4021
- } else {
4022
- onSortChange(columnKey, "desc");
4023
- }
4012
+ if (isActive && currentOrder === "desc") {
4013
+ onSortChange(columnKey, "asc");
4024
4014
  } else {
4025
4015
  onSortChange(columnKey, "desc");
4026
4016
  }
4027
4017
  return;
4028
4018
  }
4029
4019
  setInternalSortState((prev) => {
4030
- if (prev.columnKey !== columnKey) {
4031
- return { columnKey, order: "desc" };
4032
- }
4033
- if (prev.order === "desc") {
4020
+ if (prev.columnKey === columnKey && prev.order === "desc") {
4034
4021
  return { columnKey, order: "asc" };
4035
4022
  }
4036
- return { columnKey: null, order: null };
4023
+ return { columnKey, order: "desc" };
4037
4024
  });
4038
4025
  };
4039
4026
  const renderSortIcon = (columnKey) => {
@@ -4669,9 +4656,11 @@ function Table(props) {
4669
4656
  paginationInfo,
4670
4657
  renderFooter,
4671
4658
  tooltipConfig = "overflow",
4672
- isDynamicHeight = true
4659
+ isDynamicHeight = true,
4660
+ showHorizontalDivider = true,
4661
+ showVerticalDivider = true
4673
4662
  } = props;
4674
- const { fixed = false, onSelectionChange, selectedKeys = [] } = checkboxInfo ?? {};
4663
+ const { fixed = false, onSelectionChange, selectedKeys = [], disabledKeys = [], disabledTooltip } = checkboxInfo ?? {};
4675
4664
  const scrollRef = React6.useRef(null);
4676
4665
  const footerRef = React6.useRef(null);
4677
4666
  const [tableHeight, setTableHeight] = React6.useState(500);
@@ -4713,11 +4702,14 @@ function Table(props) {
4713
4702
  const footerH = footerRef.current?.getBoundingClientRect().height ?? 0;
4714
4703
  setTableHeight(window.innerHeight - top - footerH - 24);
4715
4704
  }, [showSkeleton, showEmpty]);
4716
- const isAllSelected = data.length > 0 && selectedKeys.length === data.length;
4717
4705
  const selectedKeysRef = React6.useRef(selectedKeys);
4718
4706
  selectedKeysRef.current = selectedKeys;
4719
4707
  const onSelectionChangeRef = React6.useRef(onSelectionChange);
4720
4708
  onSelectionChangeRef.current = onSelectionChange;
4709
+ const disabledKeysRef = React6.useRef(disabledKeys);
4710
+ disabledKeysRef.current = disabledKeys;
4711
+ const disabledTooltipRef = React6.useRef(disabledTooltip);
4712
+ disabledTooltipRef.current = disabledTooltip;
4721
4713
  const dataRef = React6.useRef(data);
4722
4714
  dataRef.current = data;
4723
4715
  const onRowClickRef = React6.useRef(onRowClick);
@@ -4732,6 +4724,8 @@ function Table(props) {
4732
4724
  },
4733
4725
  [rowKey]
4734
4726
  );
4727
+ const selectableKeys = data.map((record, index) => getRowKey(record, index)).filter((key) => !disabledKeys.includes(key));
4728
+ const isAllSelected = selectableKeys.length > 0 && selectableKeys.every((key) => selectedKeys.includes(key));
4735
4729
  const allColumns = React6.useMemo(() => {
4736
4730
  const checkboxCol = {
4737
4731
  key: "__checkbox__",
@@ -4746,19 +4740,24 @@ function Table(props) {
4746
4740
  checked: isAllSelected,
4747
4741
  onChange: () => {
4748
4742
  if (!onSelectionChangeRef.current) return;
4749
- const allKeys = dataRef.current.map((record, index) => getRowKey(record, index));
4743
+ const allKeys = dataRef.current.map((record, index) => getRowKey(record, index)).filter((key) => !disabledKeysRef.current.includes(key));
4750
4744
  onSelectionChangeRef.current(isAllSelected ? [] : allKeys);
4751
4745
  }
4752
4746
  }
4753
4747
  ),
4754
4748
  render: (_value, record, rowIdx) => {
4755
4749
  const key = getRowKey(record, rowIdx);
4750
+ const isDisabled = disabledKeysRef.current.includes(key);
4751
+ const tooltip = disabledTooltipRef.current;
4752
+ const tooltipContent = isDisabled && tooltip ? typeof tooltip === "function" ? tooltip(key) : tooltip : void 0;
4756
4753
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-full w-full items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
4757
4754
  Checkbox,
4758
4755
  {
4759
4756
  checked: selectedKeysRef.current.includes(key),
4757
+ disabled: isDisabled,
4758
+ tooltipConfig: tooltipContent ? { content: tooltipContent, position: "bottom" } : void 0,
4760
4759
  onChange: () => {
4761
- if (!onSelectionChangeRef.current) return;
4760
+ if (!onSelectionChangeRef.current || isDisabled) return;
4762
4761
  const cur = selectedKeysRef.current;
4763
4762
  const next = cur.includes(key) ? cur.filter((k) => k !== key) : [...cur, key];
4764
4763
  onSelectionChangeRef.current(next);
@@ -5019,7 +5018,7 @@ function Table(props) {
5019
5018
  id: `${col.key}-body`,
5020
5019
  "data-row-cell": "true",
5021
5020
  "data-col-key": col.key,
5022
- className: `${isCheckbox ? "p-0" : "p-3"} whitespace-nowrap text-sm text-gray-900 border-r border-b border-gray-300/70 last:border-r-0 bg-inherit group-hover:bg-gray-100 transition-all`,
5021
+ className: `${isCheckbox ? "p-0" : "p-3"} whitespace-nowrap text-sm text-gray-900 border-gray-300/70 last:border-r-0 bg-inherit group-hover:bg-gray-100 transition-all ${showVerticalDivider ? "border-r" : ""} ${showHorizontalDivider ? "border-b" : ""}`,
5023
5022
  style: {
5024
5023
  width,
5025
5024
  minWidth: minWidth || width,