@farmzone/fz-react-ui 1.0.17 → 1.0.18

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.js CHANGED
@@ -4105,45 +4105,15 @@ function TableHeader(props) {
4105
4105
  };
4106
4106
  };
4107
4107
  const renderColumnTitle = (column, isClickableHead) => {
4108
- const baseClasses = "pt-0.5 select-none";
4108
+ const baseClasses = "pt-0.5 select-none truncate";
4109
4109
  const subTitleClasses = column.key === "subTitle" ? "inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-blue-100 text-blue-800" : "";
4110
- if (column.align === "left") {
4111
- return /* @__PURE__ */ jsxs("div", { className: "flex item-center w-full", children: [
4112
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ jsx("span", { className: `pl-3 truncate ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title }) }),
4113
- column.sortable && /* @__PURE__ */ jsx(
4114
- "div",
4115
- {
4116
- className: `w-5 flex flex-col gap-[1.5px] items-center justify-center cursor-pointer ${isClickableHead}`,
4117
- children: renderSortIcon(column.key)
4118
- }
4119
- )
4120
- ] });
4121
- }
4122
- if (column.align === "center") {
4123
- return /* @__PURE__ */ jsxs("div", { className: "flex justify-center w-full", children: [
4124
- /* @__PURE__ */ jsx("div", { className: `flex items-center justify-center ${column.sortable ? "pl-5" : ""}`, children: /* @__PURE__ */ jsx("span", { className: `whitespace-nowrap ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title }) }),
4125
- column.sortable && /* @__PURE__ */ jsx(
4126
- "div",
4127
- {
4128
- className: `w-5 flex flex-col gap-[1.5px] items-center justify-center cursor-pointer ${isClickableHead}`,
4129
- children: renderSortIcon(column.key)
4130
- }
4131
- )
4132
- ] });
4133
- }
4134
- if (column.align === "right") {
4135
- return /* @__PURE__ */ jsxs("div", { className: "flex justify-end w-full", children: [
4136
- column.sortable && /* @__PURE__ */ jsx(
4137
- "div",
4138
- {
4139
- className: `w-5 flex flex-col gap-[1.5px] items-center justify-center cursor-pointer ${isClickableHead}`,
4140
- children: renderSortIcon(column.key)
4141
- }
4142
- ),
4143
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ jsx("span", { className: `pr-3 truncate ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title }) })
4144
- ] });
4145
- }
4146
- return /* @__PURE__ */ jsx("span", { className: `px-1.5 truncate ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title });
4110
+ const hasSortIcon = column.sortable;
4111
+ const textAlignClass = column.align === "center" ? "text-center" : column.align === "right" ? "text-right" : "text-left";
4112
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center w-full", children: [
4113
+ hasSortIcon && column.align === "center" && /* @__PURE__ */ jsx("div", { className: "w-5 shrink-0" }),
4114
+ /* @__PURE__ */ jsx("span", { className: `flex-1 px-3 ${textAlignClass} ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title }),
4115
+ hasSortIcon && /* @__PURE__ */ jsx("div", { className: `w-6 shrink-0 flex items-center justify-center cursor-pointer ${isClickableHead}`, children: renderSortIcon(column.key) })
4116
+ ] });
4147
4117
  };
4148
4118
  const createGroupHeaders = () => {
4149
4119
  const mainGroups2 = {};
@@ -4563,32 +4533,64 @@ function TableEmpty(props) {
4563
4533
  /* @__PURE__ */ jsx("span", { className: "text-md text-gray-500", children: "\uB4F1\uB85D\uB41C \uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4." })
4564
4534
  ] }) }) });
4565
4535
  }
4536
+ function TableCellTooltip({ children, content }) {
4537
+ return /* @__PURE__ */ jsx(TooltipPrimitive.Provider, { delayDuration: 0, children: /* @__PURE__ */ jsxs(TooltipPrimitive.Root, { children: [
4538
+ /* @__PURE__ */ jsx(TooltipPrimitive.Trigger, { asChild: true, children }),
4539
+ /* @__PURE__ */ jsx(TooltipPrimitive.Portal, { children: /* @__PURE__ */ jsxs(
4540
+ TooltipPrimitive.Content,
4541
+ {
4542
+ side: "bottom",
4543
+ sideOffset: 5,
4544
+ collisionPadding: 8,
4545
+ className: "relative animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 z-50 w-full max-w-[500px] origin-(--radix-tooltip-content-transform-origin) rounded-md bg-neutral-700 text-sm font-medium text-white",
4546
+ style: { zIndex: Z_INDEX.TOOLTIP },
4547
+ children: [
4548
+ /* @__PURE__ */ jsx(
4549
+ "div",
4550
+ {
4551
+ className: "px-3 py-[5px] break-words whitespace-normal custom-view-scrollbar",
4552
+ style: { overflowY: "auto", maxHeight: "250px" },
4553
+ children: content
4554
+ }
4555
+ ),
4556
+ /* @__PURE__ */ jsx(
4557
+ TooltipPrimitive.Arrow,
4558
+ {
4559
+ className: cn(
4560
+ "z-50 w-2.5 h-2.5 translate-y-[calc(-50%_-_0px)] rotate-45 rounded-[2px]",
4561
+ "bg-neutral-700 !fill-neutral-700"
4562
+ ),
4563
+ style: { fill: "currentColor" }
4564
+ }
4565
+ )
4566
+ ]
4567
+ }
4568
+ ) })
4569
+ ] }) });
4570
+ }
4566
4571
  function TableCellContent(props) {
4567
4572
  const { cellContent, tooltipText, align, tooltipConfig, onCellClick } = props;
4568
- const textRef = useRef(null);
4569
4573
  const [isOverflowing, setIsOverflowing] = useState(false);
4570
- useEffect(() => {
4571
- if (tooltipConfig !== "overflow") return;
4572
- const el = textRef.current;
4573
- if (!el) return;
4574
- const check = () => setIsOverflowing(el.scrollWidth > el.clientWidth);
4575
- check();
4576
- const observer = new ResizeObserver(check);
4577
- observer.observe(el);
4578
- return () => observer.disconnect();
4579
- }, [tooltipConfig]);
4574
+ const observerRef = useRef(null);
4575
+ const refCallback = useCallback(
4576
+ (el) => {
4577
+ observerRef.current?.disconnect();
4578
+ observerRef.current = null;
4579
+ if (!el || tooltipConfig !== "overflow") return;
4580
+ const check = () => setIsOverflowing(el.scrollWidth > el.clientWidth);
4581
+ const observer = new ResizeObserver(check);
4582
+ observer.observe(el);
4583
+ observerRef.current = observer;
4584
+ },
4585
+ [tooltipConfig]
4586
+ );
4580
4587
  const shouldShowTooltip = tooltipConfig === "always" || tooltipConfig === "overflow" && isOverflowing;
4581
4588
  const textAlign = align === "center" ? "center" : align === "right" ? "right" : "left";
4582
- return /* @__PURE__ */ jsx(
4583
- "div",
4584
- {
4585
- ref: textRef,
4586
- className: `ellipsis-1-line table-item w-full min-w-0 ${onCellClick ? "hover:text-main cursor-pointer" : "cursor-default"}`,
4587
- style: { textAlign },
4588
- onClick: onCellClick,
4589
- children: shouldShowTooltip ? /* @__PURE__ */ jsx(Tooltip2, { content: tooltipText, position: "bottom", asChild: true, children: /* @__PURE__ */ jsx("span", { children: cellContent }) }) : cellContent
4590
- }
4591
- );
4589
+ const divClassName = `ellipsis-1-line table-item w-full min-w-0 ${onCellClick ? "hover:text-main cursor-pointer" : "cursor-default"}`;
4590
+ if (!shouldShowTooltip) {
4591
+ return /* @__PURE__ */ jsx("div", { ref: refCallback, className: divClassName, style: { textAlign }, onClick: onCellClick, children: cellContent });
4592
+ }
4593
+ return /* @__PURE__ */ jsx(TableCellTooltip, { content: tooltipText, children: /* @__PURE__ */ jsx("div", { ref: refCallback, className: divClassName, style: { textAlign }, onClick: onCellClick, children: cellContent }) });
4592
4594
  }
4593
4595
 
4594
4596
  // src/components/Table/config/utils.ts
@@ -5018,6 +5020,11 @@ function Table(props) {
5018
5020
  }
5019
5021
  }
5020
5022
  }, [orderedColumns]);
5023
+ const tableMinWidth = useMemo(() => {
5024
+ const allUserColsHaveWidth = orderedColumns.every((col) => col.key === "__checkbox__" || col.width !== void 0);
5025
+ if (!allUserColsHaveWidth) return void 0;
5026
+ return orderedColumns.reduce((sum, col) => sum + parseColPx(col), 0);
5027
+ }, [orderedColumns]);
5021
5028
  const estimatedLeadingPinnedWidth = useMemo(
5022
5029
  () => leadingPinnedCols.reduce((sum, col) => sum + parseColPx(col), 0),
5023
5030
  [leadingPinnedCols]
@@ -5187,51 +5194,63 @@ function Table(props) {
5187
5194
  ref: scrollRef,
5188
5195
  className: "relative w-full overflow-y-auto overflow-x-auto custom-view-scrollbar bg-white",
5189
5196
  style: { height: `${tableHeight}px` },
5190
- children: /* @__PURE__ */ jsxs("table", { className: "w-full table-fixed border-spacing-0", children: [
5191
- /* @__PURE__ */ jsx(
5192
- TableHeader,
5193
- {
5194
- columns: orderedColumns,
5195
- getAlignStyle,
5196
- sortOption,
5197
- onSortChange,
5198
- onColumnDragStartCapture: handleColumnDragStartCapture,
5199
- onColumnDragStart: handleColumnDragStart,
5200
- onColumnDrop: handleColumnDrop,
5201
- onColumnDragEnd: handleColumnDragEnd,
5202
- onColumnDragOver: handleColumnDragOver,
5203
- isColumnDraggable
5204
- }
5205
- ),
5206
- /* @__PURE__ */ jsx("tbody", { className: "w-full h-full", children: showSkeleton ? Array.from({ length: 3 }).map((_, rowIdx) => /* @__PURE__ */ jsxs("tr", { className: "hover:bg-gray-50", children: [
5207
- leadingPinnedCols.map((col, idx) => /* @__PURE__ */ jsx(SkeletonTd, { col, showSquare: idx === 0 && !!checkboxInfo }, `leading-${idx}`)),
5208
- leftColspan > 0 && /* @__PURE__ */ jsx("td", { colSpan: leftColspan, style: { padding: 0, border: "none" } }),
5209
- virtualItems.map((vc) => /* @__PURE__ */ jsx(SkeletonTd, { col: groupCols[vc.index] }, `group-${vc.index}`)),
5210
- rightColspan > 0 && /* @__PURE__ */ jsx("td", { colSpan: rightColspan, style: { padding: 0, border: "none" } }),
5211
- trailingPinnedCols.map((col, idx) => /* @__PURE__ */ jsx(SkeletonTd, { col }, `trailing-${idx}`))
5212
- ] }, rowIdx)) : showEmpty ? /* @__PURE__ */ jsx(TableEmpty, { columnCount: allColumns.length }) : rows.map((row) => {
5213
- const rowId = String(getRowKey(row.original, row.index));
5214
- return /* @__PURE__ */ jsx(
5215
- TableDataRow,
5216
- {
5217
- record: row.original,
5218
- rowIdx: row.index,
5219
- rowId,
5220
- draggable: rowDraggable && !showSkeleton,
5221
- onDragStart: handleRowDragStart,
5222
- onDragOver: handleRowDragOver,
5223
- onDrop: handleRowDrop,
5224
- onDragEnd: handleRowDragEnd,
5225
- leftColspan,
5226
- rightColspan,
5227
- renderLeadingPinnedCols,
5228
- renderVisibleGroupCols,
5229
- renderTrailingPinnedCols
5230
- },
5231
- row.id
5232
- );
5233
- }) })
5234
- ] })
5197
+ children: /* @__PURE__ */ jsxs(
5198
+ "table",
5199
+ {
5200
+ className: `table-fixed border-spacing-0${tableMinWidth === void 0 ? " w-full" : ""}`,
5201
+ style: tableMinWidth !== void 0 ? { width: tableMinWidth, minWidth: tableMinWidth } : {
5202
+ minWidth: orderedColumns.reduce(
5203
+ (sum, col) => sum + (col.key === "__checkbox__" || col.width !== void 0 ? parseColPx(col) : 80),
5204
+ 0
5205
+ )
5206
+ },
5207
+ children: [
5208
+ /* @__PURE__ */ jsx(
5209
+ TableHeader,
5210
+ {
5211
+ columns: orderedColumns,
5212
+ getAlignStyle,
5213
+ sortOption,
5214
+ onSortChange,
5215
+ onColumnDragStartCapture: handleColumnDragStartCapture,
5216
+ onColumnDragStart: handleColumnDragStart,
5217
+ onColumnDrop: handleColumnDrop,
5218
+ onColumnDragEnd: handleColumnDragEnd,
5219
+ onColumnDragOver: handleColumnDragOver,
5220
+ isColumnDraggable
5221
+ }
5222
+ ),
5223
+ /* @__PURE__ */ jsx("tbody", { className: "w-full h-full", children: showSkeleton ? Array.from({ length: 3 }).map((_, rowIdx) => /* @__PURE__ */ jsxs("tr", { className: "hover:bg-gray-50", children: [
5224
+ leadingPinnedCols.map((col, idx) => /* @__PURE__ */ jsx(SkeletonTd, { col, showSquare: idx === 0 && !!checkboxInfo }, `leading-${idx}`)),
5225
+ leftColspan > 0 && /* @__PURE__ */ jsx("td", { colSpan: leftColspan, style: { padding: 0, border: "none" } }),
5226
+ virtualItems.map((vc) => /* @__PURE__ */ jsx(SkeletonTd, { col: groupCols[vc.index] }, `group-${vc.index}`)),
5227
+ rightColspan > 0 && /* @__PURE__ */ jsx("td", { colSpan: rightColspan, style: { padding: 0, border: "none" } }),
5228
+ trailingPinnedCols.map((col, idx) => /* @__PURE__ */ jsx(SkeletonTd, { col }, `trailing-${idx}`))
5229
+ ] }, rowIdx)) : showEmpty ? /* @__PURE__ */ jsx(TableEmpty, { columnCount: allColumns.length }) : rows.map((row) => {
5230
+ const rowId = String(getRowKey(row.original, row.index));
5231
+ return /* @__PURE__ */ jsx(
5232
+ TableDataRow,
5233
+ {
5234
+ record: row.original,
5235
+ rowIdx: row.index,
5236
+ rowId,
5237
+ draggable: rowDraggable && !showSkeleton,
5238
+ onDragStart: handleRowDragStart,
5239
+ onDragOver: handleRowDragOver,
5240
+ onDrop: handleRowDrop,
5241
+ onDragEnd: handleRowDragEnd,
5242
+ leftColspan,
5243
+ rightColspan,
5244
+ renderLeadingPinnedCols,
5245
+ renderVisibleGroupCols,
5246
+ renderTrailingPinnedCols
5247
+ },
5248
+ row.id
5249
+ );
5250
+ }) })
5251
+ ]
5252
+ }
5253
+ )
5235
5254
  }
5236
5255
  ),
5237
5256
  !showSkeleton && (paginationInfo || renderFooter?.renderLeft || renderFooter?.renderRight) && /* @__PURE__ */ jsx("div", { ref: footerRef, children: /* @__PURE__ */ jsx(
@@ -7750,12 +7769,22 @@ function PageFilter(props) {
7750
7769
  primaryColor
7751
7770
  } = props;
7752
7771
  const initialValuesRef = useRef(values);
7772
+ const pendingAutoSubmitRef = useRef(null);
7773
+ const onSubmitRef = useRef(onSubmit);
7774
+ onSubmitRef.current = onSubmit;
7775
+ useEffect(() => {
7776
+ const pending = pendingAutoSubmitRef.current;
7777
+ if (pending && String(values[pending.key] ?? "") === pending.value) {
7778
+ pendingAutoSubmitRef.current = null;
7779
+ onSubmitRef.current();
7780
+ }
7781
+ }, [values]);
7753
7782
  const handleInputChange = (key) => (e) => {
7754
7783
  onChange({ [key]: e.target.value });
7755
7784
  };
7756
7785
  const handleSelectChange = (key, autoSubmit) => (value) => {
7757
7786
  onChange({ [key]: value });
7758
- if (autoSubmit) onSubmit();
7787
+ if (autoSubmit) pendingAutoSubmitRef.current = { key, value };
7759
7788
  };
7760
7789
  const handleRadioChange = (key) => (value) => {
7761
7790
  onChange({ [key]: value });
@@ -7770,9 +7799,11 @@ function PageFilter(props) {
7770
7799
  onChange({ [key]: checked ? "true" : "false" });
7771
7800
  };
7772
7801
  const handleSubmit = () => {
7802
+ pendingAutoSubmitRef.current = null;
7773
7803
  onSubmit();
7774
7804
  };
7775
7805
  const handleReset = () => {
7806
+ pendingAutoSubmitRef.current = null;
7776
7807
  onChange(initialValuesRef.current);
7777
7808
  onReset?.();
7778
7809
  };