@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.d.cts CHANGED
@@ -650,6 +650,8 @@ interface CheckboxInfo {
650
650
  selectedKeys: Array<string | number>;
651
651
  onSelectionChange: (keys: Array<string | number>) => void;
652
652
  fixed?: boolean;
653
+ disabledKeys?: Array<string | number>;
654
+ disabledTooltip?: React.ReactNode | ((key: string | number) => React.ReactNode);
653
655
  }
654
656
  type DragEndResult = {
655
657
  type: "row" | "column";
@@ -674,6 +676,8 @@ interface TableProps<T> {
674
676
  onColumnDragEnd?: (result: DragEndResult) => void;
675
677
  tooltipConfig?: "always" | "overflow" | false;
676
678
  isDynamicHeight?: boolean;
679
+ showHorizontalDivider?: boolean;
680
+ showVerticalDivider?: boolean;
677
681
  }
678
682
  declare function Table<T>(props: TableProps<T>): react.JSX.Element;
679
683
 
package/dist/index.d.ts CHANGED
@@ -650,6 +650,8 @@ interface CheckboxInfo {
650
650
  selectedKeys: Array<string | number>;
651
651
  onSelectionChange: (keys: Array<string | number>) => void;
652
652
  fixed?: boolean;
653
+ disabledKeys?: Array<string | number>;
654
+ disabledTooltip?: React.ReactNode | ((key: string | number) => React.ReactNode);
653
655
  }
654
656
  type DragEndResult = {
655
657
  type: "row" | "column";
@@ -674,6 +676,8 @@ interface TableProps<T> {
674
676
  onColumnDragEnd?: (result: DragEndResult) => void;
675
677
  tooltipConfig?: "always" | "overflow" | false;
676
678
  isDynamicHeight?: boolean;
679
+ showHorizontalDivider?: boolean;
680
+ showVerticalDivider?: boolean;
677
681
  }
678
682
  declare function Table<T>(props: TableProps<T>): react.JSX.Element;
679
683
 
package/dist/index.js CHANGED
@@ -465,12 +465,10 @@ function Input2(props) {
465
465
  const actualType = type === "password" && showPassword ? "text" : type;
466
466
  const handlePasswordToggle = () => setShowPassword((prev) => !prev);
467
467
  const finalRightIcon = rightIcon || (shouldShowPasswordToggle ? /* @__PURE__ */ jsx(
468
- "button",
468
+ "div",
469
469
  {
470
- type: "button",
471
470
  onClick: handlePasswordToggle,
472
471
  className: "text-muted-foreground hover:text-foreground cursor-pointer transition-colors",
473
- disabled,
474
472
  children: showPassword ? /* @__PURE__ */ jsx(EyeOff, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(Eye, { className: "h-4 w-4" })
475
473
  }
476
474
  ) : null);
@@ -3929,8 +3927,6 @@ function ArrowIcon(props) {
3929
3927
  }
3930
3928
  );
3931
3929
  }
3932
- var DEFAULT_SORT_KEY = "";
3933
- var DEFAULT_SORT_ORDER = "asc";
3934
3930
  var DEFAULT_SORT_OPTIONS = {
3935
3931
  visibleType: "always",
3936
3932
  sortKey: "",
@@ -3979,27 +3975,18 @@ function TableHeader(props) {
3979
3975
  if (onSortChange) {
3980
3976
  const isActive = sortOption?.sortKey === columnKey;
3981
3977
  const currentOrder = sortOption?.sortOrder;
3982
- if (isActive) {
3983
- if (currentOrder === "desc") {
3984
- onSortChange(columnKey, "asc");
3985
- } else if (currentOrder === "asc") {
3986
- onSortChange(DEFAULT_SORT_KEY, DEFAULT_SORT_ORDER);
3987
- } else {
3988
- onSortChange(columnKey, "desc");
3989
- }
3978
+ if (isActive && currentOrder === "desc") {
3979
+ onSortChange(columnKey, "asc");
3990
3980
  } else {
3991
3981
  onSortChange(columnKey, "desc");
3992
3982
  }
3993
3983
  return;
3994
3984
  }
3995
3985
  setInternalSortState((prev) => {
3996
- if (prev.columnKey !== columnKey) {
3997
- return { columnKey, order: "desc" };
3998
- }
3999
- if (prev.order === "desc") {
3986
+ if (prev.columnKey === columnKey && prev.order === "desc") {
4000
3987
  return { columnKey, order: "asc" };
4001
3988
  }
4002
- return { columnKey: null, order: null };
3989
+ return { columnKey, order: "desc" };
4003
3990
  });
4004
3991
  };
4005
3992
  const renderSortIcon = (columnKey) => {
@@ -4635,9 +4622,11 @@ function Table(props) {
4635
4622
  paginationInfo,
4636
4623
  renderFooter,
4637
4624
  tooltipConfig = "overflow",
4638
- isDynamicHeight = true
4625
+ isDynamicHeight = true,
4626
+ showHorizontalDivider = true,
4627
+ showVerticalDivider = true
4639
4628
  } = props;
4640
- const { fixed = false, onSelectionChange, selectedKeys = [] } = checkboxInfo ?? {};
4629
+ const { fixed = false, onSelectionChange, selectedKeys = [], disabledKeys = [], disabledTooltip } = checkboxInfo ?? {};
4641
4630
  const scrollRef = useRef(null);
4642
4631
  const footerRef = useRef(null);
4643
4632
  const [tableHeight, setTableHeight] = useState(500);
@@ -4679,11 +4668,14 @@ function Table(props) {
4679
4668
  const footerH = footerRef.current?.getBoundingClientRect().height ?? 0;
4680
4669
  setTableHeight(window.innerHeight - top - footerH - 24);
4681
4670
  }, [showSkeleton, showEmpty]);
4682
- const isAllSelected = data.length > 0 && selectedKeys.length === data.length;
4683
4671
  const selectedKeysRef = useRef(selectedKeys);
4684
4672
  selectedKeysRef.current = selectedKeys;
4685
4673
  const onSelectionChangeRef = useRef(onSelectionChange);
4686
4674
  onSelectionChangeRef.current = onSelectionChange;
4675
+ const disabledKeysRef = useRef(disabledKeys);
4676
+ disabledKeysRef.current = disabledKeys;
4677
+ const disabledTooltipRef = useRef(disabledTooltip);
4678
+ disabledTooltipRef.current = disabledTooltip;
4687
4679
  const dataRef = useRef(data);
4688
4680
  dataRef.current = data;
4689
4681
  const onRowClickRef = useRef(onRowClick);
@@ -4698,6 +4690,8 @@ function Table(props) {
4698
4690
  },
4699
4691
  [rowKey]
4700
4692
  );
4693
+ const selectableKeys = data.map((record, index) => getRowKey(record, index)).filter((key) => !disabledKeys.includes(key));
4694
+ const isAllSelected = selectableKeys.length > 0 && selectableKeys.every((key) => selectedKeys.includes(key));
4701
4695
  const allColumns = useMemo(() => {
4702
4696
  const checkboxCol = {
4703
4697
  key: "__checkbox__",
@@ -4712,19 +4706,24 @@ function Table(props) {
4712
4706
  checked: isAllSelected,
4713
4707
  onChange: () => {
4714
4708
  if (!onSelectionChangeRef.current) return;
4715
- const allKeys = dataRef.current.map((record, index) => getRowKey(record, index));
4709
+ const allKeys = dataRef.current.map((record, index) => getRowKey(record, index)).filter((key) => !disabledKeysRef.current.includes(key));
4716
4710
  onSelectionChangeRef.current(isAllSelected ? [] : allKeys);
4717
4711
  }
4718
4712
  }
4719
4713
  ),
4720
4714
  render: (_value, record, rowIdx) => {
4721
4715
  const key = getRowKey(record, rowIdx);
4716
+ const isDisabled = disabledKeysRef.current.includes(key);
4717
+ const tooltip = disabledTooltipRef.current;
4718
+ const tooltipContent = isDisabled && tooltip ? typeof tooltip === "function" ? tooltip(key) : tooltip : void 0;
4722
4719
  return /* @__PURE__ */ jsx("div", { className: "flex h-full w-full items-center justify-center", children: /* @__PURE__ */ jsx(
4723
4720
  Checkbox,
4724
4721
  {
4725
4722
  checked: selectedKeysRef.current.includes(key),
4723
+ disabled: isDisabled,
4724
+ tooltipConfig: tooltipContent ? { content: tooltipContent, position: "bottom" } : void 0,
4726
4725
  onChange: () => {
4727
- if (!onSelectionChangeRef.current) return;
4726
+ if (!onSelectionChangeRef.current || isDisabled) return;
4728
4727
  const cur = selectedKeysRef.current;
4729
4728
  const next = cur.includes(key) ? cur.filter((k) => k !== key) : [...cur, key];
4730
4729
  onSelectionChangeRef.current(next);
@@ -4985,7 +4984,7 @@ function Table(props) {
4985
4984
  id: `${col.key}-body`,
4986
4985
  "data-row-cell": "true",
4987
4986
  "data-col-key": col.key,
4988
- 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`,
4987
+ 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" : ""}`,
4989
4988
  style: {
4990
4989
  width,
4991
4990
  minWidth: minWidth || width,