@polastack/design-system 0.1.35 → 0.1.37
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.ts +2 -1
- package/dist/index.js +31 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -463,12 +463,13 @@ interface DataTableProps<TData> {
|
|
|
463
463
|
enablePagination?: boolean;
|
|
464
464
|
pageSize?: number;
|
|
465
465
|
pageSizeOptions?: number[];
|
|
466
|
+
stickyColumns?: number;
|
|
466
467
|
onRowSelectionChange?: (selectedRows: TData[]) => void;
|
|
467
468
|
emptyState?: React.ReactNode;
|
|
468
469
|
className?: string;
|
|
469
470
|
'aria-label'?: string;
|
|
470
471
|
}
|
|
471
|
-
declare function DataTable<TData>({ columns, data, variant, enableSorting, enableRowSelection, enableColumnVisibility, enablePagination, pageSize, pageSizeOptions, onRowSelectionChange, emptyState, className, 'aria-label': ariaLabel, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
|
|
472
|
+
declare function DataTable<TData>({ columns, data, variant, enableSorting, enableRowSelection, enableColumnVisibility, enablePagination, pageSize, pageSizeOptions, stickyColumns, onRowSelectionChange, emptyState, className, 'aria-label': ariaLabel, }: DataTableProps<TData>): react_jsx_runtime.JSX.Element;
|
|
472
473
|
declare namespace DataTable {
|
|
473
474
|
var displayName: string;
|
|
474
475
|
}
|
package/dist/index.js
CHANGED
|
@@ -2467,7 +2467,7 @@ var Table = React31.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */
|
|
|
2467
2467
|
}
|
|
2468
2468
|
) }));
|
|
2469
2469
|
Table.displayName = "Table";
|
|
2470
|
-
var TableHeader = React31.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx30("thead", { ref, className: cn("[&_tr]:border-b", className), ...props }));
|
|
2470
|
+
var TableHeader = React31.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx30("thead", { ref, className: cn("[&_tr]:border-b bg-[var(--color-surface-sunken)]", className), ...props }));
|
|
2471
2471
|
TableHeader.displayName = "TableHeader";
|
|
2472
2472
|
var TableBody = React31.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx30(
|
|
2473
2473
|
"tbody",
|
|
@@ -2703,6 +2703,7 @@ function DataTable({
|
|
|
2703
2703
|
enablePagination = false,
|
|
2704
2704
|
pageSize = 10,
|
|
2705
2705
|
pageSizeOptions,
|
|
2706
|
+
stickyColumns = 0,
|
|
2706
2707
|
onRowSelectionChange,
|
|
2707
2708
|
emptyState,
|
|
2708
2709
|
className,
|
|
@@ -2711,6 +2712,8 @@ function DataTable({
|
|
|
2711
2712
|
const isGrid = variant === "grid";
|
|
2712
2713
|
const gridCellClass = isGrid ? "border-r border-[var(--color-border)] last:border-r-0" : "";
|
|
2713
2714
|
const [sorting, setSorting] = React33.useState([]);
|
|
2715
|
+
const headerRowRef = React33.useRef(null);
|
|
2716
|
+
const [stickyOffsets, setStickyOffsets] = React33.useState([]);
|
|
2714
2717
|
const [rowSelection, setRowSelection] = React33.useState({});
|
|
2715
2718
|
const [columnVisibility, setColumnVisibility] = React33.useState({});
|
|
2716
2719
|
const allColumns = React33.useMemo(() => {
|
|
@@ -2759,6 +2762,28 @@ function DataTable({
|
|
|
2759
2762
|
onRowSelectionChange(selectedRows);
|
|
2760
2763
|
}
|
|
2761
2764
|
}, [rowSelection, table, onRowSelectionChange]);
|
|
2765
|
+
React33.useEffect(() => {
|
|
2766
|
+
if (stickyColumns > 0 && headerRowRef.current) {
|
|
2767
|
+
const ths = headerRowRef.current.querySelectorAll("th");
|
|
2768
|
+
const offsets = [];
|
|
2769
|
+
let left = 0;
|
|
2770
|
+
for (let i = 0; i < stickyColumns && i < ths.length; i++) {
|
|
2771
|
+
offsets.push(left);
|
|
2772
|
+
left += ths[i].offsetWidth;
|
|
2773
|
+
}
|
|
2774
|
+
setStickyOffsets(offsets);
|
|
2775
|
+
}
|
|
2776
|
+
}, [stickyColumns, columnVisibility]);
|
|
2777
|
+
const getStickyStyle = (colIndex) => {
|
|
2778
|
+
if (colIndex >= stickyColumns || stickyOffsets.length === 0) return void 0;
|
|
2779
|
+
return {
|
|
2780
|
+
position: "sticky",
|
|
2781
|
+
left: stickyOffsets[colIndex] ?? 0,
|
|
2782
|
+
zIndex: 1
|
|
2783
|
+
};
|
|
2784
|
+
};
|
|
2785
|
+
const stickyCellClass = (colIndex) => colIndex < stickyColumns ? "bg-[var(--color-surface)] [tr:hover>&]:bg-[var(--color-surface-muted)] [tr[data-state=selected]>&]:bg-[var(--color-surface-accent)]" : "";
|
|
2786
|
+
const stickyHeadClass = (colIndex) => colIndex < stickyColumns ? "bg-[var(--color-surface-sunken)]" : "";
|
|
2762
2787
|
const showToolbar = enableRowSelection || enableColumnVisibility;
|
|
2763
2788
|
return /* @__PURE__ */ jsxs14("div", { className: cn("rounded-md border border-[var(--color-border)]", className), children: [
|
|
2764
2789
|
showToolbar && /* @__PURE__ */ jsx33(
|
|
@@ -2769,7 +2794,7 @@ function DataTable({
|
|
|
2769
2794
|
}
|
|
2770
2795
|
),
|
|
2771
2796
|
/* @__PURE__ */ jsxs14(Table, { "aria-label": ariaLabel, children: [
|
|
2772
|
-
/* @__PURE__ */ jsx33(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx33(TableRow, { children: headerGroup.headers.map((header) => /* @__PURE__ */ jsx33(TableHead, { className: gridCellClass, children: header.isPlaceholder ? null : header.column.getCanSort() ? /* @__PURE__ */ jsxs14(
|
|
2797
|
+
/* @__PURE__ */ jsx33(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx33(TableRow, { ref: headerRowRef, children: headerGroup.headers.map((header, colIndex) => /* @__PURE__ */ jsx33(TableHead, { className: cn(gridCellClass, stickyHeadClass(colIndex)), style: getStickyStyle(colIndex), children: header.isPlaceholder ? null : header.column.getCanSort() ? /* @__PURE__ */ jsxs14(
|
|
2773
2798
|
"button",
|
|
2774
2799
|
{
|
|
2775
2800
|
className: "flex items-center gap-1 -ml-2 px-2 py-1 rounded-md hover:bg-[var(--color-surface-muted)] transition-colors duration-fast",
|
|
@@ -2803,7 +2828,7 @@ function DataTable({
|
|
|
2803
2828
|
onClick: () => row.toggleSelected(),
|
|
2804
2829
|
className: "cursor-pointer"
|
|
2805
2830
|
},
|
|
2806
|
-
children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx33(TableCell, { className: gridCellClass, children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))
|
|
2831
|
+
children: row.getVisibleCells().map((cell, colIndex) => /* @__PURE__ */ jsx33(TableCell, { className: cn(gridCellClass, stickyCellClass(colIndex)), style: getStickyStyle(colIndex), children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))
|
|
2807
2832
|
},
|
|
2808
2833
|
row.id
|
|
2809
2834
|
)) : /* @__PURE__ */ jsx33(TableRow, { children: /* @__PURE__ */ jsx33(
|
|
@@ -3000,10 +3025,10 @@ function FilterSelector({
|
|
|
3000
3025
|
]
|
|
3001
3026
|
}
|
|
3002
3027
|
),
|
|
3003
|
-
open && /* @__PURE__ */ jsx35("div", { className: "absolute
|
|
3028
|
+
open && /* @__PURE__ */ jsx35("div", { className: "absolute right-0 top-full z-popover mt-1 min-w-[10rem] rounded-md border border-[var(--color-border)] bg-[var(--color-surface-raised)] p-1 shadow-md", children: options.map((opt) => /* @__PURE__ */ jsxs16(
|
|
3004
3029
|
"label",
|
|
3005
3030
|
{
|
|
3006
|
-
className: "flex items-center gap-2 rounded px-2 py-1 text-sm hover:bg-[var(--color-surface-sunken)] cursor-pointer",
|
|
3031
|
+
className: "flex items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-[var(--color-surface-sunken)] cursor-pointer",
|
|
3007
3032
|
children: [
|
|
3008
3033
|
/* @__PURE__ */ jsx35(
|
|
3009
3034
|
"input",
|
|
@@ -3011,7 +3036,7 @@ function FilterSelector({
|
|
|
3011
3036
|
type: "checkbox",
|
|
3012
3037
|
checked: selected.includes(opt.id),
|
|
3013
3038
|
onChange: (e) => onToggle(opt.id, e.target.checked),
|
|
3014
|
-
className: "h-4 w-4"
|
|
3039
|
+
className: "h-4 w-4 cursor-pointer"
|
|
3015
3040
|
}
|
|
3016
3041
|
),
|
|
3017
3042
|
opt.label
|