@dmsi/wedgekit-react 0.0.179 → 0.0.180

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.
@@ -5,7 +5,13 @@ import clsx from "clsx";
5
5
  import { getSortIcon } from "./utils";
6
6
  import React from "react";
7
7
  import { TableBody } from "./TableBody";
8
+ import { ColumnSelectorHeaderCell } from "./ColumnSelectorHeaderCell";
8
9
  interface PinnedColumnsProps<TData extends RowData> {
10
+ id?: string;
11
+
12
+ toggleColumnVisibility?: (columnId: string, isVisible: boolean) => void;
13
+ resetColumnVisibility?: () => void;
14
+
9
15
  pinDirection: "left" | "right";
10
16
  table: Table<TData>;
11
17
  tableContainerRef: React.RefObject<HTMLDivElement | null>;
@@ -22,6 +28,7 @@ interface PinnedColumnsProps<TData extends RowData> {
22
28
  }
23
29
 
24
30
  export function PinnedColumns<TData>({
31
+ id,
25
32
  pinDirection = "left",
26
33
  table,
27
34
  centerHeader,
@@ -29,6 +36,9 @@ export function PinnedColumns<TData>({
29
36
  someSelectedAcrossPages,
30
37
  toggleSelectAllAcrossPages,
31
38
  testid,
39
+ enableColumnSelector,
40
+ toggleColumnVisibility,
41
+ resetColumnVisibility,
32
42
  ...props
33
43
  }: PinnedColumnsProps<TData>) {
34
44
  const headerGroups =
@@ -38,128 +48,136 @@ export function PinnedColumns<TData>({
38
48
 
39
49
  const pinnedTestId = testid ? `${pinDirection}-pinned-${testid}` : undefined;
40
50
 
51
+ const hasAnyHeaders = headerGroups[0]?.headers.length > 0;
52
+
53
+ if (!hasAnyHeaders && !enableColumnSelector) return;
54
+
41
55
  return (
42
- headerGroups[0]?.headers.length > 0 && (
43
- <table
44
- className={clsx(
45
- "flex flex-col min-h-min sticky z-20",
46
- pinDirection === "left" ? "left-0" : "right-0",
47
- )}
48
- data-testid={pinnedTestId}
49
- >
50
- <thead className="sticky top-0 z-20 grid">
51
- {headerGroups.map((headerGroup) => {
52
- return (
53
- <tr
54
- key={headerGroup.id}
55
- data-testid={
56
- pinnedTestId
57
- ? `${pinnedTestId}-header-row-${headerGroup.id}`
58
- : undefined
56
+ <table
57
+ className={clsx(
58
+ "flex flex-col min-h-min sticky z-20",
59
+ pinDirection === "left" ? "left-0" : "right-0",
60
+ )}
61
+ data-testid={pinnedTestId}
62
+ >
63
+ <thead className="sticky top-0 z-20 grid">
64
+ {headerGroups.map((headerGroup) => {
65
+ return (
66
+ <tr
67
+ key={headerGroup.id}
68
+ data-testid={
69
+ pinnedTestId
70
+ ? `${pinnedTestId}-header-row-${headerGroup.id}`
71
+ : undefined
72
+ }
73
+ className="flex w-full"
74
+ >
75
+ {headerGroup.headers.map((header) => {
76
+ if (!header) {
77
+ return;
59
78
  }
60
- className="flex w-full"
61
- >
62
- {headerGroup.headers.map((header) => {
63
- if (!header) {
64
- return;
65
- }
66
79
 
67
- if (typeof header.column.columnDef.header === "string") {
68
- return (
69
- <DataCellHeader
70
- locked
71
- key={header.id}
72
- testid={
73
- pinnedTestId
74
- ? `${pinnedTestId}-header-${header.id}`
75
- : undefined
76
- }
77
- header={header}
78
- center={centerHeader}
79
- width={
80
- (header.column.columnDef.meta?.headerWidth as
81
- | string
82
- | undefined) ?? `${header.column.getSize()}px`
83
- }
84
- className={clsx(
85
- header.column.getCanSort()
86
- ? "cursor-pointer"
87
- : "cursor-grab",
88
- "group",
89
- )}
90
- >
91
- <Subheader tall>
92
- {header.column.columnDef.header}
93
- </Subheader>
80
+ if (typeof header.column.columnDef.header === "string") {
81
+ const customHeaderWidth =
82
+ header.column.columnDef.meta?.headerWidth;
94
83
 
95
- {getSortIcon(header.column.getIsSorted())}
84
+ return (
85
+ <DataCellHeader
86
+ locked
87
+ key={header.id}
88
+ testid={
89
+ pinnedTestId
90
+ ? `${pinnedTestId}-header-${header.id}`
91
+ : undefined
92
+ }
93
+ header={header}
94
+ center={centerHeader}
95
+ width={customHeaderWidth}
96
+ className={clsx(
97
+ header.column.getCanSort()
98
+ ? "cursor-pointer"
99
+ : "cursor-grab",
100
+ "group",
101
+ )}
102
+ >
103
+ <Subheader tall>
104
+ {header.column.columnDef.header}
105
+ </Subheader>
96
106
 
97
- {!header.column.getIsSorted() &&
98
- header.column.getCanSort() &&
99
- getSortIcon(
100
- header.column.getNextSortingOrder(),
101
- true,
102
- )}
107
+ {getSortIcon(header.column.getIsSorted())}
103
108
 
104
- {header.column.getSortIndex() !== -1 &&
105
- table.getState().sorting.length > 1 && (
106
- <Subheader tall>
107
- {header.column.getSortIndex() + 1}
108
- </Subheader>
109
- )}
109
+ {!header.column.getIsSorted() &&
110
+ header.column.getCanSort() &&
111
+ getSortIcon(header.column.getNextSortingOrder(), true)}
110
112
 
111
- {!header.column.columnDef.meta?.locked && (
112
- <div
113
- onDoubleClick={(e) => {
114
- e.stopPropagation();
115
- header.column.resetSize();
116
- }}
117
- onMouseDown={(e) => {
118
- e.stopPropagation();
119
- header.getResizeHandler()(e);
120
- }}
121
- onTouchStart={(e) => {
122
- e.stopPropagation();
123
- header.getResizeHandler()(e);
124
- }}
125
- className="absolute right-0 inset-y-0 w-px bg-black cursor-col-resize"
126
- />
113
+ {header.column.getSortIndex() !== -1 &&
114
+ table.getState().sorting.length > 1 && (
115
+ <Subheader tall>
116
+ {header.column.getSortIndex() + 1}
117
+ </Subheader>
127
118
  )}
128
- </DataCellHeader>
129
- );
130
- }
131
- return (
132
- <React.Fragment key={header.id}>
133
- {header.column.columnDef.meta?.checkbox ? (
134
- <DataGridCell type="header" component="checkbox" locked>
135
- <Checkbox
136
- checked={allSelectedAcrossPages}
137
- indeterminate={someSelectedAcrossPages}
138
- onChange={toggleSelectAllAcrossPages}
139
- />
140
- </DataGridCell>
141
- ) : (
142
- flexRender(
143
- header.column.columnDef.header,
144
- header.getContext(),
145
- )
119
+
120
+ {!header.column.columnDef.meta?.locked && (
121
+ <div
122
+ onDoubleClick={(e) => {
123
+ e.stopPropagation();
124
+ header.column.resetSize();
125
+ }}
126
+ onMouseDown={(e) => {
127
+ e.stopPropagation();
128
+ header.getResizeHandler()(e);
129
+ }}
130
+ onTouchStart={(e) => {
131
+ e.stopPropagation();
132
+ header.getResizeHandler()(e);
133
+ }}
134
+ className="absolute right-0 inset-y-0 w-px bg-black cursor-col-resize"
135
+ />
146
136
  )}
147
- </React.Fragment>
137
+ </DataCellHeader>
148
138
  );
149
- })}
150
- </tr>
151
- );
152
- })}
153
- </thead>
139
+ }
140
+ return (
141
+ <React.Fragment key={header.id}>
142
+ {header.column.columnDef.meta?.checkbox ? (
143
+ <DataGridCell type="header" component="checkbox" locked>
144
+ <Checkbox
145
+ checked={allSelectedAcrossPages}
146
+ indeterminate={someSelectedAcrossPages}
147
+ onChange={toggleSelectAllAcrossPages}
148
+ />
149
+ </DataGridCell>
150
+ ) : (
151
+ flexRender(
152
+ header.column.columnDef.header,
153
+ header.getContext(),
154
+ )
155
+ )}
156
+ </React.Fragment>
157
+ );
158
+ })}
159
+
160
+ {enableColumnSelector && (
161
+ <ColumnSelectorHeaderCell
162
+ id={id ? `${id}-column-selector` : undefined}
163
+ testid={testid ? `${testid}-column-selector` : undefined}
164
+ table={table}
165
+ toggleColumnVisibility={toggleColumnVisibility ?? (() => {})}
166
+ resetColumnVisibility={resetColumnVisibility ?? (() => {})}
167
+ />
168
+ )}
169
+ </tr>
170
+ );
171
+ })}
172
+ </thead>
154
173
 
155
- <TableBody
156
- testid={pinnedTestId}
157
- {...props}
158
- table={table}
159
- locked={true}
160
- pinDirection={pinDirection}
161
- />
162
- </table>
163
- )
174
+ <TableBody
175
+ testid={pinnedTestId}
176
+ {...props}
177
+ table={table}
178
+ locked={true}
179
+ pinDirection={pinDirection}
180
+ />
181
+ </table>
164
182
  );
165
183
  }
@@ -349,7 +349,6 @@ export function DataGrid<T extends Record<string, unknown>>({
349
349
  isLoadingMore={isLoadingMore}
350
350
  hasMore={hasMore}
351
351
  showFilterRow={showFilterRow}
352
- enableColumnSelector={enableColumnSelector}
353
352
  />
354
353
 
355
354
  <table className="flex-1 flex flex-col min-h-min">
@@ -497,17 +496,6 @@ export function DataGrid<T extends Record<string, unknown>>({
497
496
  style={{ display: "flex", width: virtualPaddingRight }}
498
497
  />
499
498
  ) : null}
500
- {enableColumnSelector && (
501
- <ColumnSelectorHeaderCell
502
- id={id ? `${id}-column-selector` : undefined}
503
- testid={
504
- testid ? `${testid}-column-selector` : undefined
505
- }
506
- table={table}
507
- toggleColumnVisibility={toggleColumnVisibility}
508
- resetColumnVisibility={resetColumnVisibility}
509
- />
510
- )}
511
499
  </tr>
512
500
  ))}
513
501
  </thead>
@@ -529,6 +517,10 @@ export function DataGrid<T extends Record<string, unknown>>({
529
517
  </table>
530
518
 
531
519
  <PinnedColumns
520
+ id={id}
521
+ enableColumnSelector={enableColumnSelector}
522
+ toggleColumnVisibility={toggleColumnVisibility}
523
+ resetColumnVisibility={resetColumnVisibility}
532
524
  testid={testid}
533
525
  pinDirection="right"
534
526
  table={table}
@@ -537,7 +529,6 @@ export function DataGrid<T extends Record<string, unknown>>({
537
529
  isLoadingMore={isLoadingMore}
538
530
  hasMore={hasMore}
539
531
  showFilterRow={showFilterRow}
540
- enableColumnSelector={enableColumnSelector}
541
532
  />
542
533
  </div>
543
534
 
@@ -1,11 +1,11 @@
1
- import {
2
- Label
3
- } from "./chunk-JWCT72WR.js";
4
1
  import {
5
2
  formatCurrencyDisplay,
6
3
  formatDecimalValue,
7
4
  getDecimalPlaceholder
8
5
  } from "./chunk-5UH6QUFB.js";
6
+ import {
7
+ Label
8
+ } from "./chunk-JWCT72WR.js";
9
9
  import {
10
10
  Icon
11
11
  } from "./chunk-NKUETCDA.js";
@@ -13,12 +13,12 @@ import {
13
13
  import {
14
14
  ModalScrim
15
15
  } from "./chunk-ZFOANBWG.js";
16
- import {
17
- findDocumentRoot
18
- } from "./chunk-6LN6QT6M.js";
19
16
  import {
20
17
  useMatchesMobile
21
18
  } from "./chunk-WNQ53SVY.js";
19
+ import {
20
+ findDocumentRoot
21
+ } from "./chunk-6LN6QT6M.js";
22
22
 
23
23
  // src/components/Modal.tsx
24
24
  import clsx from "clsx";
@@ -1,9 +1,9 @@
1
- import {
2
- Label
3
- } from "./chunk-JWCT72WR.js";
4
1
  import {
5
2
  useMatchesMobile
6
3
  } from "./chunk-WNQ53SVY.js";
4
+ import {
5
+ Label
6
+ } from "./chunk-JWCT72WR.js";
7
7
  import {
8
8
  Paragraph
9
9
  } from "./chunk-HVI3CL7Y.js";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  useMenuPosition
3
3
  } from "./chunk-5GUW4DUY.js";
4
- import {
5
- findDocumentRoot
6
- } from "./chunk-6LN6QT6M.js";
7
4
  import {
8
5
  useMatchesMobile
9
6
  } from "./chunk-WNQ53SVY.js";
7
+ import {
8
+ findDocumentRoot
9
+ } from "./chunk-6LN6QT6M.js";
10
10
  import {
11
11
  __objRest,
12
12
  __spreadProps,