@underverse-ui/underverse 0.2.64 → 0.2.66

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
@@ -1668,6 +1668,8 @@ type DataTableColumn<T> = {
1668
1668
  };
1669
1669
  render?: (value: any, record: T, index: number) => React__default.ReactNode;
1670
1670
  visible?: boolean;
1671
+ /** Cố định cột bên trái hoặc phải khi cuộn ngang */
1672
+ fixed?: "left" | "right";
1671
1673
  };
1672
1674
  type Sorter = {
1673
1675
  key: string;
package/dist/index.d.ts CHANGED
@@ -1668,6 +1668,8 @@ type DataTableColumn<T> = {
1668
1668
  };
1669
1669
  render?: (value: any, record: T, index: number) => React__default.ReactNode;
1670
1670
  visible?: boolean;
1671
+ /** Cố định cột bên trái hoặc phải khi cuộn ngang */
1672
+ fixed?: "left" | "right";
1671
1673
  };
1672
1674
  type Sorter = {
1673
1675
  key: string;
package/dist/index.js CHANGED
@@ -12972,6 +12972,45 @@ function DataTable({
12972
12972
  const cellPadding = density === "compact" ? "py-1.5 px-3" : density === "comfortable" ? "py-3 px-4" : "py-2.5 px-4";
12973
12973
  const visibleColsSet = React48.useMemo(() => new Set(visibleCols), [visibleCols]);
12974
12974
  const visibleColumns = columns.filter((c) => visibleColsSet.has(c.key));
12975
+ const stickyPositions = React48.useMemo(() => {
12976
+ const positions = {};
12977
+ let leftOffset = 0;
12978
+ for (const col of visibleColumns) {
12979
+ if (col.fixed === "left") {
12980
+ positions[col.key] = { left: leftOffset };
12981
+ const colWidth = typeof col.width === "number" ? col.width : parseInt(String(col.width) || "150", 10);
12982
+ leftOffset += colWidth;
12983
+ }
12984
+ }
12985
+ let rightOffset = 0;
12986
+ for (let i = visibleColumns.length - 1; i >= 0; i--) {
12987
+ const col = visibleColumns[i];
12988
+ if (col.fixed === "right") {
12989
+ positions[col.key] = { right: rightOffset };
12990
+ const colWidth = typeof col.width === "number" ? col.width : parseInt(String(col.width) || "150", 10);
12991
+ rightOffset += colWidth;
12992
+ }
12993
+ }
12994
+ return positions;
12995
+ }, [visibleColumns]);
12996
+ const getStickyColumnClass = (col, isHeader = false) => {
12997
+ if (!col.fixed) return "";
12998
+ return cn(
12999
+ "sticky z-10 bg-background",
13000
+ col.fixed === "left" && "shadow-[2px_0_5px_-2px_rgba(0,0,0,0.1)]",
13001
+ col.fixed === "right" && "shadow-[-2px_0_5px_-2px_rgba(0,0,0,0.1)]",
13002
+ isHeader && "z-20"
13003
+ // Header cần z-index cao hơn
13004
+ );
13005
+ };
13006
+ const getStickyColumnStyle = (col) => {
13007
+ if (!col.fixed) return {};
13008
+ const pos = stickyPositions[col.key];
13009
+ return {
13010
+ ...pos?.left !== void 0 && { left: pos.left },
13011
+ ...pos?.right !== void 0 && { right: pos.right }
13012
+ };
13013
+ };
12975
13014
  const getRowKey = (row, idx) => {
12976
13015
  if (!rowKey) return String(idx);
12977
13016
  if (typeof rowKey === "function") return String(rowKey(row));
@@ -13032,12 +13071,13 @@ function DataTable({
13032
13071
  const renderHeader = /* @__PURE__ */ jsx57(TableRow, { children: visibleColumns.map((col, colIdx) => /* @__PURE__ */ jsx57(
13033
13072
  TableHead,
13034
13073
  {
13035
- style: { width: col.width },
13074
+ style: { width: col.width, ...getStickyColumnStyle(col) },
13036
13075
  className: cn(
13037
13076
  // Use column-specific align if defined, otherwise use global headerAlign
13038
13077
  (col.align === "right" || !col.align && headerAlign === "right") && "text-right",
13039
13078
  (col.align === "center" || !col.align && headerAlign === "center") && "text-center",
13040
- columnDividers && colIdx > 0 && "border-l border-border/60"
13079
+ columnDividers && colIdx > 0 && "border-l border-border/60",
13080
+ getStickyColumnClass(col, true)
13041
13081
  ),
13042
13082
  children: (() => {
13043
13083
  const isRightAlign = col.align === "right" || !col.align && headerAlign === "right";
@@ -13294,13 +13334,17 @@ function DataTable({
13294
13334
  return /* @__PURE__ */ jsx57(
13295
13335
  TableCell,
13296
13336
  {
13337
+ style: getStickyColumnStyle(col),
13297
13338
  className: cn(
13298
13339
  cellPadding,
13299
13340
  col.align === "right" && "text-right",
13300
13341
  col.align === "center" && "text-center",
13301
13342
  columnDividers && colIdx > 0 && "border-l border-border/60",
13302
13343
  isLastRow && col === visibleColumns[0] && "rounded-bl-2xl md:rounded-bl-3xl",
13303
- isLastRow && col === visibleColumns[visibleColumns.length - 1] && "rounded-br-2xl md:rounded-br-3xl"
13344
+ isLastRow && col === visibleColumns[visibleColumns.length - 1] && "rounded-br-2xl md:rounded-br-3xl",
13345
+ getStickyColumnClass(col),
13346
+ // Giữ màu nền striped cho cột cố định
13347
+ col.fixed && striped && idx % 2 === 0 && "bg-muted/50!"
13304
13348
  ),
13305
13349
  children: col.render ? col.render(value, row, idx) : String(value ?? "")
13306
13350
  },