@farmzone/fz-react-ui 1.0.16 → 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.cjs CHANGED
@@ -4139,45 +4139,15 @@ function TableHeader(props) {
4139
4139
  };
4140
4140
  };
4141
4141
  const renderColumnTitle = (column, isClickableHead) => {
4142
- const baseClasses = "pt-0.5 select-none";
4142
+ const baseClasses = "pt-0.5 select-none truncate";
4143
4143
  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" : "";
4144
- if (column.align === "left") {
4145
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex item-center w-full", children: [
4146
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: `pl-3 truncate ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title }) }),
4147
- column.sortable && /* @__PURE__ */ jsxRuntime.jsx(
4148
- "div",
4149
- {
4150
- className: `w-5 flex flex-col gap-[1.5px] items-center justify-center cursor-pointer ${isClickableHead}`,
4151
- children: renderSortIcon(column.key)
4152
- }
4153
- )
4154
- ] });
4155
- }
4156
- if (column.align === "center") {
4157
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-center w-full", children: [
4158
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: `flex items-center justify-center ${column.sortable ? "pl-5" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: `whitespace-nowrap ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title }) }),
4159
- column.sortable && /* @__PURE__ */ jsxRuntime.jsx(
4160
- "div",
4161
- {
4162
- className: `w-5 flex flex-col gap-[1.5px] items-center justify-center cursor-pointer ${isClickableHead}`,
4163
- children: renderSortIcon(column.key)
4164
- }
4165
- )
4166
- ] });
4167
- }
4168
- if (column.align === "right") {
4169
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end w-full", children: [
4170
- column.sortable && /* @__PURE__ */ jsxRuntime.jsx(
4171
- "div",
4172
- {
4173
- className: `w-5 flex flex-col gap-[1.5px] items-center justify-center cursor-pointer ${isClickableHead}`,
4174
- children: renderSortIcon(column.key)
4175
- }
4176
- ),
4177
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: `pr-3 truncate ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title }) })
4178
- ] });
4179
- }
4180
- return /* @__PURE__ */ jsxRuntime.jsx("span", { className: `px-1.5 truncate ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title });
4144
+ const hasSortIcon = column.sortable;
4145
+ const textAlignClass = column.align === "center" ? "text-center" : column.align === "right" ? "text-right" : "text-left";
4146
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center w-full", children: [
4147
+ hasSortIcon && column.align === "center" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 shrink-0" }),
4148
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: `flex-1 px-3 ${textAlignClass} ${baseClasses} ${isClickableHead} ${subTitleClasses}`, children: column.title }),
4149
+ hasSortIcon && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-6 shrink-0 flex items-center justify-center cursor-pointer ${isClickableHead}`, children: renderSortIcon(column.key) })
4150
+ ] });
4181
4151
  };
4182
4152
  const createGroupHeaders = () => {
4183
4153
  const mainGroups2 = {};
@@ -4597,32 +4567,64 @@ function TableEmpty(props) {
4597
4567
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-md text-gray-500", children: "\uB4F1\uB85D\uB41C \uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4." })
4598
4568
  ] }) }) });
4599
4569
  }
4570
+ function TableCellTooltip({ children, content }) {
4571
+ return /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Provider, { delayDuration: 0, children: /* @__PURE__ */ jsxRuntime.jsxs(TooltipPrimitive__namespace.Root, { children: [
4572
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Trigger, { asChild: true, children }),
4573
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
4574
+ TooltipPrimitive__namespace.Content,
4575
+ {
4576
+ side: "bottom",
4577
+ sideOffset: 5,
4578
+ collisionPadding: 8,
4579
+ 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",
4580
+ style: { zIndex: Z_INDEX.TOOLTIP },
4581
+ children: [
4582
+ /* @__PURE__ */ jsxRuntime.jsx(
4583
+ "div",
4584
+ {
4585
+ className: "px-3 py-[5px] break-words whitespace-normal custom-view-scrollbar",
4586
+ style: { overflowY: "auto", maxHeight: "250px" },
4587
+ children: content
4588
+ }
4589
+ ),
4590
+ /* @__PURE__ */ jsxRuntime.jsx(
4591
+ TooltipPrimitive__namespace.Arrow,
4592
+ {
4593
+ className: cn(
4594
+ "z-50 w-2.5 h-2.5 translate-y-[calc(-50%_-_0px)] rotate-45 rounded-[2px]",
4595
+ "bg-neutral-700 !fill-neutral-700"
4596
+ ),
4597
+ style: { fill: "currentColor" }
4598
+ }
4599
+ )
4600
+ ]
4601
+ }
4602
+ ) })
4603
+ ] }) });
4604
+ }
4600
4605
  function TableCellContent(props) {
4601
4606
  const { cellContent, tooltipText, align, tooltipConfig, onCellClick } = props;
4602
- const textRef = React6.useRef(null);
4603
4607
  const [isOverflowing, setIsOverflowing] = React6.useState(false);
4604
- React6.useEffect(() => {
4605
- if (tooltipConfig !== "overflow") return;
4606
- const el = textRef.current;
4607
- if (!el) return;
4608
- const check = () => setIsOverflowing(el.scrollWidth > el.clientWidth);
4609
- check();
4610
- const observer = new ResizeObserver(check);
4611
- observer.observe(el);
4612
- return () => observer.disconnect();
4613
- }, [tooltipConfig]);
4608
+ const observerRef = React6.useRef(null);
4609
+ const refCallback = React6.useCallback(
4610
+ (el) => {
4611
+ observerRef.current?.disconnect();
4612
+ observerRef.current = null;
4613
+ if (!el || tooltipConfig !== "overflow") return;
4614
+ const check = () => setIsOverflowing(el.scrollWidth > el.clientWidth);
4615
+ const observer = new ResizeObserver(check);
4616
+ observer.observe(el);
4617
+ observerRef.current = observer;
4618
+ },
4619
+ [tooltipConfig]
4620
+ );
4614
4621
  const shouldShowTooltip = tooltipConfig === "always" || tooltipConfig === "overflow" && isOverflowing;
4615
4622
  const textAlign = align === "center" ? "center" : align === "right" ? "right" : "left";
4616
- return /* @__PURE__ */ jsxRuntime.jsx(
4617
- "div",
4618
- {
4619
- ref: textRef,
4620
- className: `ellipsis-1-line table-item w-full min-w-0 ${onCellClick ? "hover:text-main cursor-pointer" : "cursor-default"}`,
4621
- style: { textAlign },
4622
- onClick: onCellClick,
4623
- children: shouldShowTooltip ? /* @__PURE__ */ jsxRuntime.jsx(Tooltip2, { content: tooltipText, position: "bottom", asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: cellContent }) }) : cellContent
4624
- }
4625
- );
4623
+ const divClassName = `ellipsis-1-line table-item w-full min-w-0 ${onCellClick ? "hover:text-main cursor-pointer" : "cursor-default"}`;
4624
+ if (!shouldShowTooltip) {
4625
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { ref: refCallback, className: divClassName, style: { textAlign }, onClick: onCellClick, children: cellContent });
4626
+ }
4627
+ return /* @__PURE__ */ jsxRuntime.jsx(TableCellTooltip, { content: tooltipText, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: refCallback, className: divClassName, style: { textAlign }, onClick: onCellClick, children: cellContent }) });
4626
4628
  }
4627
4629
 
4628
4630
  // src/components/Table/config/utils.ts
@@ -4740,7 +4742,13 @@ function Table(props) {
4740
4742
  showHorizontalDivider = true,
4741
4743
  showVerticalDivider = true
4742
4744
  } = props;
4743
- const { fixed = false, onSelectionChange, selectedKeys = [], disabledKeys = [], disabledTooltip } = checkboxInfo ?? {};
4745
+ const {
4746
+ fixed = false,
4747
+ onSelectionChange,
4748
+ selectedKeys = [],
4749
+ disabledKeys = [],
4750
+ disabledTooltip
4751
+ } = checkboxInfo ?? {};
4744
4752
  const scrollRef = React6.useRef(null);
4745
4753
  const footerRef = React6.useRef(null);
4746
4754
  const [tableHeight, setTableHeight] = React6.useState(500);
@@ -5046,6 +5054,11 @@ function Table(props) {
5046
5054
  }
5047
5055
  }
5048
5056
  }, [orderedColumns]);
5057
+ const tableMinWidth = React6.useMemo(() => {
5058
+ const allUserColsHaveWidth = orderedColumns.every((col) => col.key === "__checkbox__" || col.width !== void 0);
5059
+ if (!allUserColsHaveWidth) return void 0;
5060
+ return orderedColumns.reduce((sum, col) => sum + parseColPx(col), 0);
5061
+ }, [orderedColumns]);
5049
5062
  const estimatedLeadingPinnedWidth = React6.useMemo(
5050
5063
  () => leadingPinnedCols.reduce((sum, col) => sum + parseColPx(col), 0),
5051
5064
  [leadingPinnedCols]
@@ -5129,7 +5142,7 @@ function Table(props) {
5129
5142
  TableCellContent,
5130
5143
  {
5131
5144
  cellContent,
5132
- tooltipText: String(record[col.key] ?? ""),
5145
+ tooltipText: col.tooltipText ? col.tooltipText(record[col.key], record, rowIdx) : String(record[col.key] ?? ""),
5133
5146
  align: align ?? "",
5134
5147
  tooltipConfig: col.key === "__checkbox__" ? false : tooltipConfig,
5135
5148
  onCellClick: col.key !== "__checkbox__" && onRowClickRef.current ? () => onRowClickRef.current?.(record, rowIdx) : void 0
@@ -5215,51 +5228,63 @@ function Table(props) {
5215
5228
  ref: scrollRef,
5216
5229
  className: "relative w-full overflow-y-auto overflow-x-auto custom-view-scrollbar bg-white",
5217
5230
  style: { height: `${tableHeight}px` },
5218
- children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "w-full table-fixed border-spacing-0", children: [
5219
- /* @__PURE__ */ jsxRuntime.jsx(
5220
- TableHeader,
5221
- {
5222
- columns: orderedColumns,
5223
- getAlignStyle,
5224
- sortOption,
5225
- onSortChange,
5226
- onColumnDragStartCapture: handleColumnDragStartCapture,
5227
- onColumnDragStart: handleColumnDragStart,
5228
- onColumnDrop: handleColumnDrop,
5229
- onColumnDragEnd: handleColumnDragEnd,
5230
- onColumnDragOver: handleColumnDragOver,
5231
- isColumnDraggable
5232
- }
5233
- ),
5234
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "w-full h-full", children: showSkeleton ? Array.from({ length: 3 }).map((_, rowIdx) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "hover:bg-gray-50", children: [
5235
- leadingPinnedCols.map((col, idx) => /* @__PURE__ */ jsxRuntime.jsx(SkeletonTd, { col, showSquare: idx === 0 && !!checkboxInfo }, `leading-${idx}`)),
5236
- leftColspan > 0 && /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: leftColspan, style: { padding: 0, border: "none" } }),
5237
- virtualItems.map((vc) => /* @__PURE__ */ jsxRuntime.jsx(SkeletonTd, { col: groupCols[vc.index] }, `group-${vc.index}`)),
5238
- rightColspan > 0 && /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: rightColspan, style: { padding: 0, border: "none" } }),
5239
- trailingPinnedCols.map((col, idx) => /* @__PURE__ */ jsxRuntime.jsx(SkeletonTd, { col }, `trailing-${idx}`))
5240
- ] }, rowIdx)) : showEmpty ? /* @__PURE__ */ jsxRuntime.jsx(TableEmpty, { columnCount: allColumns.length }) : rows.map((row) => {
5241
- const rowId = String(getRowKey(row.original, row.index));
5242
- return /* @__PURE__ */ jsxRuntime.jsx(
5243
- TableDataRow,
5244
- {
5245
- record: row.original,
5246
- rowIdx: row.index,
5247
- rowId,
5248
- draggable: rowDraggable && !showSkeleton,
5249
- onDragStart: handleRowDragStart,
5250
- onDragOver: handleRowDragOver,
5251
- onDrop: handleRowDrop,
5252
- onDragEnd: handleRowDragEnd,
5253
- leftColspan,
5254
- rightColspan,
5255
- renderLeadingPinnedCols,
5256
- renderVisibleGroupCols,
5257
- renderTrailingPinnedCols
5258
- },
5259
- row.id
5260
- );
5261
- }) })
5262
- ] })
5231
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
5232
+ "table",
5233
+ {
5234
+ className: `table-fixed border-spacing-0${tableMinWidth === void 0 ? " w-full" : ""}`,
5235
+ style: tableMinWidth !== void 0 ? { width: tableMinWidth, minWidth: tableMinWidth } : {
5236
+ minWidth: orderedColumns.reduce(
5237
+ (sum, col) => sum + (col.key === "__checkbox__" || col.width !== void 0 ? parseColPx(col) : 80),
5238
+ 0
5239
+ )
5240
+ },
5241
+ children: [
5242
+ /* @__PURE__ */ jsxRuntime.jsx(
5243
+ TableHeader,
5244
+ {
5245
+ columns: orderedColumns,
5246
+ getAlignStyle,
5247
+ sortOption,
5248
+ onSortChange,
5249
+ onColumnDragStartCapture: handleColumnDragStartCapture,
5250
+ onColumnDragStart: handleColumnDragStart,
5251
+ onColumnDrop: handleColumnDrop,
5252
+ onColumnDragEnd: handleColumnDragEnd,
5253
+ onColumnDragOver: handleColumnDragOver,
5254
+ isColumnDraggable
5255
+ }
5256
+ ),
5257
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { className: "w-full h-full", children: showSkeleton ? Array.from({ length: 3 }).map((_, rowIdx) => /* @__PURE__ */ jsxRuntime.jsxs("tr", { className: "hover:bg-gray-50", children: [
5258
+ leadingPinnedCols.map((col, idx) => /* @__PURE__ */ jsxRuntime.jsx(SkeletonTd, { col, showSquare: idx === 0 && !!checkboxInfo }, `leading-${idx}`)),
5259
+ leftColspan > 0 && /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: leftColspan, style: { padding: 0, border: "none" } }),
5260
+ virtualItems.map((vc) => /* @__PURE__ */ jsxRuntime.jsx(SkeletonTd, { col: groupCols[vc.index] }, `group-${vc.index}`)),
5261
+ rightColspan > 0 && /* @__PURE__ */ jsxRuntime.jsx("td", { colSpan: rightColspan, style: { padding: 0, border: "none" } }),
5262
+ trailingPinnedCols.map((col, idx) => /* @__PURE__ */ jsxRuntime.jsx(SkeletonTd, { col }, `trailing-${idx}`))
5263
+ ] }, rowIdx)) : showEmpty ? /* @__PURE__ */ jsxRuntime.jsx(TableEmpty, { columnCount: allColumns.length }) : rows.map((row) => {
5264
+ const rowId = String(getRowKey(row.original, row.index));
5265
+ return /* @__PURE__ */ jsxRuntime.jsx(
5266
+ TableDataRow,
5267
+ {
5268
+ record: row.original,
5269
+ rowIdx: row.index,
5270
+ rowId,
5271
+ draggable: rowDraggable && !showSkeleton,
5272
+ onDragStart: handleRowDragStart,
5273
+ onDragOver: handleRowDragOver,
5274
+ onDrop: handleRowDrop,
5275
+ onDragEnd: handleRowDragEnd,
5276
+ leftColspan,
5277
+ rightColspan,
5278
+ renderLeadingPinnedCols,
5279
+ renderVisibleGroupCols,
5280
+ renderTrailingPinnedCols
5281
+ },
5282
+ row.id
5283
+ );
5284
+ }) })
5285
+ ]
5286
+ }
5287
+ )
5263
5288
  }
5264
5289
  ),
5265
5290
  !showSkeleton && (paginationInfo || renderFooter?.renderLeft || renderFooter?.renderRight) && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: footerRef, children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -7778,11 +7803,22 @@ function PageFilter(props) {
7778
7803
  primaryColor
7779
7804
  } = props;
7780
7805
  const initialValuesRef = React6.useRef(values);
7806
+ const pendingAutoSubmitRef = React6.useRef(null);
7807
+ const onSubmitRef = React6.useRef(onSubmit);
7808
+ onSubmitRef.current = onSubmit;
7809
+ React6.useEffect(() => {
7810
+ const pending = pendingAutoSubmitRef.current;
7811
+ if (pending && String(values[pending.key] ?? "") === pending.value) {
7812
+ pendingAutoSubmitRef.current = null;
7813
+ onSubmitRef.current();
7814
+ }
7815
+ }, [values]);
7781
7816
  const handleInputChange = (key) => (e) => {
7782
7817
  onChange({ [key]: e.target.value });
7783
7818
  };
7784
- const handleSelectChange = (key) => (value) => {
7819
+ const handleSelectChange = (key, autoSubmit) => (value) => {
7785
7820
  onChange({ [key]: value });
7821
+ if (autoSubmit) pendingAutoSubmitRef.current = { key, value };
7786
7822
  };
7787
7823
  const handleRadioChange = (key) => (value) => {
7788
7824
  onChange({ [key]: value });
@@ -7797,9 +7833,11 @@ function PageFilter(props) {
7797
7833
  onChange({ [key]: checked ? "true" : "false" });
7798
7834
  };
7799
7835
  const handleSubmit = () => {
7836
+ pendingAutoSubmitRef.current = null;
7800
7837
  onSubmit();
7801
7838
  };
7802
7839
  const handleReset = () => {
7840
+ pendingAutoSubmitRef.current = null;
7803
7841
  onChange(initialValuesRef.current);
7804
7842
  onReset?.();
7805
7843
  };
@@ -7825,7 +7863,7 @@ function PageFilter(props) {
7825
7863
  Select2,
7826
7864
  {
7827
7865
  value: currentValue,
7828
- onChange: handleSelectChange(optionKey),
7866
+ onChange: handleSelectChange(optionKey, option.autoSubmit),
7829
7867
  options: option.options,
7830
7868
  placeholder: option.placeholder || "\uC120\uD0DD",
7831
7869
  canReset: option.canReset ?? true,