@purpurds/table 7.0.0 → 7.1.0
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/LICENSE.txt +16 -16
- package/dist/styles.css +1 -1
- package/dist/table.cjs.js +42 -42
- package/dist/table.cjs.js.map +1 -1
- package/dist/table.es.js +683 -683
- package/dist/table.es.js.map +1 -1
- package/package.json +23 -23
- package/src/cell-types/body-text-cell.test.tsx +65 -0
- package/src/cell-types/body-text-cell.tsx +1 -1
- package/src/cell-types/lead-text-cell.test.tsx +65 -0
- package/src/cell-types/lead-text-cell.tsx +1 -1
- package/src/table-export-drawer.test.tsx +1 -1
- package/src/table-settings-drawer.test.tsx +0 -4
- package/src/table.module.scss +24 -14
- package/src/table.tsx +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purpurds/table",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "./dist/table.cjs.js",
|
|
6
6
|
"types": "./dist/table.d.ts",
|
|
@@ -17,22 +17,22 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@tanstack/react-table": "~8.21.2",
|
|
19
19
|
"classnames": "~2.5.0",
|
|
20
|
-
"@purpurds/badge": "7.
|
|
21
|
-
"@purpurds/
|
|
22
|
-
"@purpurds/
|
|
23
|
-
"@purpurds/
|
|
24
|
-
"@purpurds/drawer": "7.
|
|
25
|
-
"@purpurds/heading": "7.
|
|
26
|
-
"@purpurds/icon": "7.
|
|
27
|
-
"@purpurds/link": "7.
|
|
28
|
-
"@purpurds/paragraph": "7.
|
|
29
|
-
"@purpurds/
|
|
30
|
-
"@purpurds/
|
|
31
|
-
"@purpurds/text-field": "7.
|
|
32
|
-
"@purpurds/
|
|
33
|
-
"@purpurds/tokens": "7.
|
|
34
|
-
"@purpurds/
|
|
35
|
-
"@purpurds/
|
|
20
|
+
"@purpurds/badge": "7.1.0",
|
|
21
|
+
"@purpurds/button": "7.1.0",
|
|
22
|
+
"@purpurds/checkbox": "7.1.0",
|
|
23
|
+
"@purpurds/cta-link": "7.1.0",
|
|
24
|
+
"@purpurds/drawer": "7.1.0",
|
|
25
|
+
"@purpurds/heading": "7.1.0",
|
|
26
|
+
"@purpurds/icon": "7.1.0",
|
|
27
|
+
"@purpurds/link": "7.1.0",
|
|
28
|
+
"@purpurds/paragraph": "7.1.0",
|
|
29
|
+
"@purpurds/select": "7.1.0",
|
|
30
|
+
"@purpurds/skeleton": "7.1.0",
|
|
31
|
+
"@purpurds/text-field": "7.1.0",
|
|
32
|
+
"@purpurds/toggle": "7.1.0",
|
|
33
|
+
"@purpurds/tokens": "7.1.0",
|
|
34
|
+
"@purpurds/tooltip": "7.1.0",
|
|
35
|
+
"@purpurds/visually-hidden": "7.1.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@rushstack/eslint-patch": "~1.10.0",
|
|
@@ -57,13 +57,13 @@
|
|
|
57
57
|
"vitest": "^3.1.2",
|
|
58
58
|
"vitest-axe": "~0.1.0",
|
|
59
59
|
"vitest-canvas-mock": "~0.3.3",
|
|
60
|
-
"@purpurds/autocomplete": "7.
|
|
60
|
+
"@purpurds/autocomplete": "7.1.0",
|
|
61
61
|
"@purpurds/component-rig": "1.0.0",
|
|
62
|
-
"@purpurds/grid": "7.
|
|
63
|
-
"@purpurds/illustrative-icon": "7.
|
|
64
|
-
"@purpurds/listbox": "7.
|
|
65
|
-
"@purpurds/pagination": "7.
|
|
66
|
-
"@purpurds/label": "7.
|
|
62
|
+
"@purpurds/grid": "7.1.0",
|
|
63
|
+
"@purpurds/illustrative-icon": "7.1.0",
|
|
64
|
+
"@purpurds/listbox": "7.1.0",
|
|
65
|
+
"@purpurds/pagination": "7.1.0",
|
|
66
|
+
"@purpurds/label": "7.1.0"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"build:dev": "vite",
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Cell } from "@tanstack/react-table";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import { vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { BodyTextCell } from "./body-text-cell";
|
|
7
|
+
|
|
8
|
+
// Mock the useTruncatedTooltip hook
|
|
9
|
+
vi.mock("../use-truncated-hook", () => ({
|
|
10
|
+
default: vi.fn(() => ({
|
|
11
|
+
showPopover: false,
|
|
12
|
+
containerRef: { current: null },
|
|
13
|
+
onMouseEnter: vi.fn(),
|
|
14
|
+
onMouseLeave: vi.fn(),
|
|
15
|
+
})),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const createMockCell = (value: unknown) =>
|
|
19
|
+
({
|
|
20
|
+
getValue: vi.fn().mockReturnValue(value),
|
|
21
|
+
getContext: vi.fn(),
|
|
22
|
+
id: "test-id",
|
|
23
|
+
renderValue: vi.fn(),
|
|
24
|
+
row: { original: {} },
|
|
25
|
+
column: {
|
|
26
|
+
getSize: vi.fn().mockReturnValue(100),
|
|
27
|
+
},
|
|
28
|
+
} as unknown as Cell<unknown, unknown>);
|
|
29
|
+
|
|
30
|
+
describe("BodyTextCell", () => {
|
|
31
|
+
it("renders text value correctly", () => {
|
|
32
|
+
const cell = createMockCell("Test Value");
|
|
33
|
+
render(<BodyTextCell cell={cell} />);
|
|
34
|
+
|
|
35
|
+
expect(screen.getByText("Test Value")).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("renders number 0 correctly", () => {
|
|
39
|
+
const cell = createMockCell(0);
|
|
40
|
+
render(<BodyTextCell cell={cell} />);
|
|
41
|
+
|
|
42
|
+
expect(screen.getByText(0)).toBeInTheDocument();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("renders EmptyCell when value is null", () => {
|
|
46
|
+
const cell = createMockCell(null);
|
|
47
|
+
const { container } = render(<BodyTextCell cell={cell} />);
|
|
48
|
+
|
|
49
|
+
expect(container.querySelector("p")).toHaveTextContent("-");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("renders EmptyCell when value is undefined", () => {
|
|
53
|
+
const cell = createMockCell(undefined);
|
|
54
|
+
const { container } = render(<BodyTextCell cell={cell} />);
|
|
55
|
+
|
|
56
|
+
expect(container.querySelector("p")).toHaveTextContent("-");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("renders EmptyCell when value is an empty string", () => {
|
|
60
|
+
const cell = createMockCell("");
|
|
61
|
+
const { container } = render(<BodyTextCell cell={cell} />);
|
|
62
|
+
|
|
63
|
+
expect(container.querySelector("p")).toHaveTextContent("-");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -18,7 +18,7 @@ export const BodyTextCell = <TData extends RowData>({ cell }: BodyTextCellProps<
|
|
|
18
18
|
const value = cell.getValue<string>();
|
|
19
19
|
const { showPopover, containerRef, onMouseEnter, onMouseLeave } = useTruncatedTooltip();
|
|
20
20
|
|
|
21
|
-
if (
|
|
21
|
+
if (value === null || value === undefined || value === "") {
|
|
22
22
|
return <EmptyCell />;
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Cell } from "@tanstack/react-table";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import { vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import { LeadTextCell } from "./lead-text-cell";
|
|
7
|
+
|
|
8
|
+
// Mock the useTruncatedTooltip hook
|
|
9
|
+
vi.mock("../use-truncated-hook", () => ({
|
|
10
|
+
default: vi.fn(() => ({
|
|
11
|
+
showPopover: false,
|
|
12
|
+
containerRef: { current: null },
|
|
13
|
+
onMouseEnter: vi.fn(),
|
|
14
|
+
onMouseLeave: vi.fn(),
|
|
15
|
+
})),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
const createMockCell = (value: unknown) =>
|
|
19
|
+
({
|
|
20
|
+
getValue: vi.fn().mockReturnValue(value),
|
|
21
|
+
getContext: vi.fn(),
|
|
22
|
+
id: "test-id",
|
|
23
|
+
renderValue: vi.fn(),
|
|
24
|
+
row: { original: {} },
|
|
25
|
+
column: {
|
|
26
|
+
getSize: vi.fn().mockReturnValue(100),
|
|
27
|
+
},
|
|
28
|
+
} as unknown as Cell<unknown, unknown>);
|
|
29
|
+
|
|
30
|
+
describe("LeadTextCell", () => {
|
|
31
|
+
it("renders text value correctly", () => {
|
|
32
|
+
const cell = createMockCell("Test Value");
|
|
33
|
+
render(<LeadTextCell cell={cell} />);
|
|
34
|
+
|
|
35
|
+
expect(screen.getByText("Test Value")).toBeInTheDocument();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("renders number 0 correctly", () => {
|
|
39
|
+
const cell = createMockCell(0);
|
|
40
|
+
render(<LeadTextCell cell={cell} />);
|
|
41
|
+
|
|
42
|
+
expect(screen.getByText(0)).toBeInTheDocument();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("renders EmptyCell when value is null", () => {
|
|
46
|
+
const cell = createMockCell(null);
|
|
47
|
+
const { container } = render(<LeadTextCell cell={cell} />);
|
|
48
|
+
|
|
49
|
+
expect(container.querySelector("p")).toHaveTextContent("-");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("renders EmptyCell when value is undefined", () => {
|
|
53
|
+
const cell = createMockCell(undefined);
|
|
54
|
+
const { container } = render(<LeadTextCell cell={cell} />);
|
|
55
|
+
|
|
56
|
+
expect(container.querySelector("p")).toHaveTextContent("-");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("renders EmptyCell when value is an empty string", () => {
|
|
60
|
+
const cell = createMockCell("");
|
|
61
|
+
const { container } = render(<LeadTextCell cell={cell} />);
|
|
62
|
+
|
|
63
|
+
expect(container.querySelector("p")).toHaveTextContent("-");
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -11,7 +11,7 @@ export type LeadTextCellProps<TData> = {
|
|
|
11
11
|
export const LeadTextCell = <TData extends RowData>({ cell }: LeadTextCellProps<TData>) => {
|
|
12
12
|
const value = cell.getValue<string>();
|
|
13
13
|
|
|
14
|
-
if (
|
|
14
|
+
if (value === null || value === undefined || value === "") {
|
|
15
15
|
return <EmptyCell />;
|
|
16
16
|
}
|
|
17
17
|
|
|
@@ -46,7 +46,7 @@ describe("Data table - Export drawer", () => {
|
|
|
46
46
|
const closeButton = within(screen.getByTestId(Selectors.EXPORT_DRAWER.HEADER_ROW)).getByRole(
|
|
47
47
|
"button"
|
|
48
48
|
);
|
|
49
|
-
expect(closeButton).
|
|
49
|
+
expect(closeButton).toBeInTheDocument();
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
it("should send an 'onClose' event when closeButton clicked", async () => {
|
|
@@ -87,10 +87,6 @@ describe("Data Table - Settings drawer", () => {
|
|
|
87
87
|
).toHaveTextContent("Reset settings");
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
it("should have a close drawer button", () => {
|
|
91
|
-
expect(closeButton).toHaveAttribute("aria-label", "Close drawer");
|
|
92
|
-
});
|
|
93
|
-
|
|
94
90
|
it("should be possible to close the drawer", async () => {
|
|
95
91
|
await userEvent.click(closeButton);
|
|
96
92
|
expect(screen.queryByTestId(Selectors.SETTINGS_DRAWER.CONTENT)).toBeNull();
|
package/src/table.module.scss
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
overflow: hidden;
|
|
8
8
|
flex-direction: column;
|
|
9
9
|
gap: var(--purpur-spacing-200);
|
|
10
|
-
z-index: 1;
|
|
11
10
|
background-color: inherit;
|
|
12
11
|
}
|
|
13
12
|
|
|
@@ -156,23 +155,32 @@
|
|
|
156
155
|
|
|
157
156
|
&:has(.purpur-table-row-cell__row-selection),
|
|
158
157
|
&:has(.purpur-table-row-cell__row-toggle) {
|
|
159
|
-
.purpur-table-row-cell:
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
158
|
+
.purpur-table-row-cell:first-of-type {
|
|
159
|
+
transform: translateZ(0);
|
|
160
|
+
|
|
161
|
+
&::after {
|
|
162
|
+
content: "";
|
|
163
|
+
position: absolute;
|
|
164
|
+
left: calc(-1 * var(--purpur-border-width-xs));
|
|
165
|
+
top: 0;
|
|
166
|
+
bottom: 0;
|
|
167
|
+
width: var(--purpur-border-width-md);
|
|
168
|
+
opacity: 0;
|
|
169
|
+
transition: opacity var(--purpur-motion-duration-150) ease;
|
|
170
|
+
background-color: var(--purpur-color-border-weak);
|
|
171
|
+
pointer-events: none;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
&:hover::after {
|
|
175
|
+
opacity: 1;
|
|
170
176
|
}
|
|
171
177
|
}
|
|
172
178
|
}
|
|
173
179
|
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
&.purpur-table-row--selected .purpur-table-row-cell:first-of-type {
|
|
181
|
+
transform: translateZ(0);
|
|
182
|
+
|
|
183
|
+
&::after {
|
|
176
184
|
content: "";
|
|
177
185
|
position: absolute;
|
|
178
186
|
left: calc(-1 * var(--purpur-border-width-xs));
|
|
@@ -180,6 +188,8 @@
|
|
|
180
188
|
bottom: 0;
|
|
181
189
|
width: var(--purpur-border-width-md);
|
|
182
190
|
background-color: var(--purpur-color-border-interactive-primary);
|
|
191
|
+
opacity: 1;
|
|
192
|
+
pointer-events: none;
|
|
183
193
|
}
|
|
184
194
|
}
|
|
185
195
|
}
|
package/src/table.tsx
CHANGED
|
@@ -286,7 +286,7 @@ export const Table = <TData extends RowData>({
|
|
|
286
286
|
|
|
287
287
|
const showBorder = (index: number) => {
|
|
288
288
|
// Only show the border for sticky columns when the table is scrolled
|
|
289
|
-
return isScrolled && getStickyColumn(index);
|
|
289
|
+
return isScrolled && stickyFirstColumn && getStickyColumn(index);
|
|
290
290
|
};
|
|
291
291
|
|
|
292
292
|
const tableRows = tanstackTable.getRowModel().rows;
|