@purpurds/table 0.0.1
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 +213 -0
- package/dist/cell-types/badge-cell.d.ts +8 -0
- package/dist/cell-types/badge-cell.d.ts.map +1 -0
- package/dist/cell-types/body-text-cell.d.ts +8 -0
- package/dist/cell-types/body-text-cell.d.ts.map +1 -0
- package/dist/cell-types/button-cell.d.ts +8 -0
- package/dist/cell-types/button-cell.d.ts.map +1 -0
- package/dist/cell-types/button-group-cell.d.ts +16 -0
- package/dist/cell-types/button-group-cell.d.ts.map +1 -0
- package/dist/cell-types/cta-link-cell.d.ts +8 -0
- package/dist/cell-types/cta-link-cell.d.ts.map +1 -0
- package/dist/cell-types/date-cell.d.ts +8 -0
- package/dist/cell-types/date-cell.d.ts.map +1 -0
- package/dist/cell-types/empty-cell.d.ts +4 -0
- package/dist/cell-types/empty-cell.d.ts.map +1 -0
- package/dist/cell-types/error-message-cell.d.ts +8 -0
- package/dist/cell-types/error-message-cell.d.ts.map +1 -0
- package/dist/cell-types/icon-text-cell.d.ts +8 -0
- package/dist/cell-types/icon-text-cell.d.ts.map +1 -0
- package/dist/cell-types/lead-text-cell.d.ts +8 -0
- package/dist/cell-types/lead-text-cell.d.ts.map +1 -0
- package/dist/cell-types/link-cell.d.ts +8 -0
- package/dist/cell-types/link-cell.d.ts.map +1 -0
- package/dist/cell-types/number-cell.d.ts +8 -0
- package/dist/cell-types/number-cell.d.ts.map +1 -0
- package/dist/cell-types/row-selection-cell.d.ts +8 -0
- package/dist/cell-types/row-selection-cell.d.ts.map +1 -0
- package/dist/cell-types/row-toggle-cell.d.ts +8 -0
- package/dist/cell-types/row-toggle-cell.d.ts.map +1 -0
- package/dist/cell-types/toggle-cell.d.ts +8 -0
- package/dist/cell-types/toggle-cell.d.ts.map +1 -0
- package/dist/cell-types/warning-message-cell.d.ts +8 -0
- package/dist/cell-types/warning-message-cell.d.ts.map +1 -0
- package/dist/metadata.js +17 -0
- package/dist/story-utils/column-def.d.ts +5 -0
- package/dist/story-utils/column-def.d.ts.map +1 -0
- package/dist/story-utils/table-data.d.ts +35 -0
- package/dist/story-utils/table-data.d.ts.map +1 -0
- package/dist/story-utils/use-fetch-table-data-hook.d.ts +11 -0
- package/dist/story-utils/use-fetch-table-data-hook.d.ts.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/table-action-bar.d.ts +26 -0
- package/dist/table-action-bar.d.ts.map +1 -0
- package/dist/table-body.d.ts +10 -0
- package/dist/table-body.d.ts.map +1 -0
- package/dist/table-column-header-cell.d.ts +28 -0
- package/dist/table-column-header-cell.d.ts.map +1 -0
- package/dist/table-export-drawer.d.ts +17 -0
- package/dist/table-export-drawer.d.ts.map +1 -0
- package/dist/table-header.d.ts +11 -0
- package/dist/table-header.d.ts.map +1 -0
- package/dist/table-row-cell-skeleton.d.ts +14 -0
- package/dist/table-row-cell-skeleton.d.ts.map +1 -0
- package/dist/table-row-cell.d.ts +25 -0
- package/dist/table-row-cell.d.ts.map +1 -0
- package/dist/table-row.d.ts +11 -0
- package/dist/table-row.d.ts.map +1 -0
- package/dist/table-settings-drawer.d.ts +41 -0
- package/dist/table-settings-drawer.d.ts.map +1 -0
- package/dist/table-toolbar.d.ts +37 -0
- package/dist/table-toolbar.d.ts.map +1 -0
- package/dist/table.cjs.js +259 -0
- package/dist/table.cjs.js.map +1 -0
- package/dist/table.d.ts +20 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.es.js +13585 -0
- package/dist/table.es.js.map +1 -0
- package/dist/test-utils/column-def.d.ts +6 -0
- package/dist/test-utils/column-def.d.ts.map +1 -0
- package/dist/test-utils/helpers.d.ts +138 -0
- package/dist/test-utils/helpers.d.ts.map +1 -0
- package/dist/test-utils/table-data.d.ts +33 -0
- package/dist/test-utils/table-data.d.ts.map +1 -0
- package/dist/types.d.ts +420 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/use-screen-size.hook.d.ts +7 -0
- package/dist/use-screen-size.hook.d.ts.map +1 -0
- package/dist/use-truncated-hook.d.ts +10 -0
- package/dist/use-truncated-hook.d.ts.map +1 -0
- package/dist/utils/custom-functions.d.ts +9 -0
- package/dist/utils/custom-functions.d.ts.map +1 -0
- package/dist/utils/unit-conversions.d.ts +19 -0
- package/dist/utils/unit-conversions.d.ts.map +1 -0
- package/dist/utils/unit-conversions.spec.d.ts +2 -0
- package/dist/utils/unit-conversions.spec.d.ts.map +1 -0
- package/eslint.config.mjs +2 -0
- package/package.json +82 -0
- package/src/cell-types/badge-cell.tsx +25 -0
- package/src/cell-types/body-text-cell.tsx +54 -0
- package/src/cell-types/button-cell.tsx +26 -0
- package/src/cell-types/button-group-cell.tsx +54 -0
- package/src/cell-types/cta-link-cell.tsx +25 -0
- package/src/cell-types/date-cell.tsx +33 -0
- package/src/cell-types/empty-cell.tsx +6 -0
- package/src/cell-types/error-message-cell.tsx +30 -0
- package/src/cell-types/icon-text-cell.tsx +30 -0
- package/src/cell-types/lead-text-cell.tsx +19 -0
- package/src/cell-types/link-cell.tsx +58 -0
- package/src/cell-types/number-cell.tsx +27 -0
- package/src/cell-types/row-selection-cell.tsx +22 -0
- package/src/cell-types/row-toggle-cell.tsx +23 -0
- package/src/cell-types/toggle-cell.tsx +19 -0
- package/src/cell-types/warning-message-cell.tsx +30 -0
- package/src/global.d.ts +4 -0
- package/src/story-utils/column-def.ts +148 -0
- package/src/story-utils/table-data.tsx +262 -0
- package/src/story-utils/use-fetch-table-data-hook.tsx +30 -0
- package/src/table-action-bar.module.scss +106 -0
- package/src/table-action-bar.test.tsx +111 -0
- package/src/table-action-bar.tsx +104 -0
- package/src/table-body.tsx +25 -0
- package/src/table-column-header-cell.tsx +305 -0
- package/src/table-export-drawer.module.scss +9 -0
- package/src/table-export-drawer.test.tsx +75 -0
- package/src/table-export-drawer.tsx +59 -0
- package/src/table-header.tsx +35 -0
- package/src/table-kitchen-sink.test.tsx +1196 -0
- package/src/table-row-cell-skeleton.tsx +61 -0
- package/src/table-row-cell.test.tsx +360 -0
- package/src/table-row-cell.tsx +188 -0
- package/src/table-row.tsx +30 -0
- package/src/table-settings-drawer.module.scss +25 -0
- package/src/table-settings-drawer.test.tsx +350 -0
- package/src/table-settings-drawer.tsx +254 -0
- package/src/table-toolbar.module.scss +17 -0
- package/src/table-toolbar.test.tsx +95 -0
- package/src/table-toolbar.tsx +136 -0
- package/src/table.module.scss +367 -0
- package/src/table.stories.tsx +1246 -0
- package/src/table.story.css +11 -0
- package/src/table.test.tsx +318 -0
- package/src/table.tsx +501 -0
- package/src/test-utils/column-def.ts +152 -0
- package/src/test-utils/helpers.ts +234 -0
- package/src/test-utils/table-data.tsx +318 -0
- package/src/types.ts +496 -0
- package/src/use-screen-size.hook.ts +23 -0
- package/src/use-truncated-hook.tsx +74 -0
- package/src/utils/custom-functions.ts +52 -0
- package/src/utils/unit-conversions.spec.ts +92 -0
- package/src/utils/unit-conversions.ts +30 -0
- package/vitest.setup.ts +60 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { pxToRem, pxToRemString } from "./unit-conversions";
|
|
4
|
+
|
|
5
|
+
describe("unit-conversions", () => {
|
|
6
|
+
// Store the original getComputedStyle
|
|
7
|
+
const originalGetComputedStyle = window.getComputedStyle;
|
|
8
|
+
|
|
9
|
+
// Mock for getComputedStyle
|
|
10
|
+
let mockGetPropertyValue: ReturnType<typeof vi.fn>;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
// Setup the mock for getComputedStyle
|
|
14
|
+
mockGetPropertyValue = vi.fn().mockImplementation((prop) => {
|
|
15
|
+
// Default mock behavior - return empty string for unknown properties
|
|
16
|
+
if (prop === "--purpur-rescale") {
|
|
17
|
+
return "1"; // Default to 1 for 16px rem base
|
|
18
|
+
}
|
|
19
|
+
return "";
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
window.getComputedStyle = vi.fn().mockImplementation(
|
|
23
|
+
() =>
|
|
24
|
+
({
|
|
25
|
+
getPropertyValue: mockGetPropertyValue,
|
|
26
|
+
} as unknown as CSSStyleDeclaration)
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
// Restore original getComputedStyle
|
|
32
|
+
window.getComputedStyle = originalGetComputedStyle;
|
|
33
|
+
vi.resetAllMocks();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("pxToRem", () => {
|
|
37
|
+
it("should convert px to rem with rescale factor 1 (16px base)", () => {
|
|
38
|
+
// Mock 16px base (--purpur-rescale: 1)
|
|
39
|
+
mockGetPropertyValue.mockImplementation((prop) => (prop === "--purpur-rescale" ? "1" : ""));
|
|
40
|
+
|
|
41
|
+
expect(pxToRem(16)).toBe(1);
|
|
42
|
+
expect(pxToRem(32)).toBe(2);
|
|
43
|
+
expect(pxToRem(8)).toBe(0.5);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should convert px to rem with rescale factor 1.6 (10px base)", () => {
|
|
47
|
+
// Mock 10px base (--purpur-rescale: 1.6)
|
|
48
|
+
mockGetPropertyValue.mockImplementation((prop) => (prop === "--purpur-rescale" ? "1.6" : ""));
|
|
49
|
+
|
|
50
|
+
expect(pxToRem(16)).toBeCloseTo(1.6);
|
|
51
|
+
expect(pxToRem(10)).toBeCloseTo(1);
|
|
52
|
+
expect(pxToRem(20)).toBeCloseTo(2);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should handle empty CSS variable value and default to 1", () => {
|
|
56
|
+
// Mock missing CSS variable
|
|
57
|
+
mockGetPropertyValue.mockImplementation(() => "");
|
|
58
|
+
|
|
59
|
+
expect(pxToRem(16)).toBe(1);
|
|
60
|
+
expect(pxToRem(32)).toBe(2);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should handle non-numeric CSS variable value and default to 1", () => {
|
|
64
|
+
// Mock invalid CSS variable value
|
|
65
|
+
mockGetPropertyValue.mockImplementation((prop) =>
|
|
66
|
+
prop === "--purpur-rescale" ? "invalid" : ""
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
expect(pxToRem(16)).toBe(1);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("pxToRemString", () => {
|
|
74
|
+
it("should return a string with 'rem' unit for rescale factor 1", () => {
|
|
75
|
+
// Mock 16px base (--purpur-rescale: 1)
|
|
76
|
+
mockGetPropertyValue.mockImplementation((prop) => (prop === "--purpur-rescale" ? "1" : ""));
|
|
77
|
+
|
|
78
|
+
expect(pxToRemString(16)).toBe("1rem");
|
|
79
|
+
expect(pxToRemString(32)).toBe("2rem");
|
|
80
|
+
expect(pxToRemString(8)).toBe("0.5rem");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should return a string with 'rem' unit for rescale factor 1.6", () => {
|
|
84
|
+
// Mock 10px base (--purpur-rescale: 1.6)
|
|
85
|
+
mockGetPropertyValue.mockImplementation((prop) => (prop === "--purpur-rescale" ? "1.6" : ""));
|
|
86
|
+
|
|
87
|
+
// For 10px base, 16px should be 1.6rem
|
|
88
|
+
expect(pxToRemString(16)).toBe("1.6rem");
|
|
89
|
+
expect(pxToRemString(10)).toBe("1rem");
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts pixel values to rem values accounting for the Purpur rescale factor
|
|
3
|
+
*
|
|
4
|
+
* In the Purpur design system:
|
|
5
|
+
* - For 16px rem base: --purpur-rescale = 1
|
|
6
|
+
* - For 10px rem base: --purpur-rescale = 1.6
|
|
7
|
+
*
|
|
8
|
+
* @param pxValue The pixel value to convert to rem
|
|
9
|
+
* @returns The value in rem units
|
|
10
|
+
*/
|
|
11
|
+
export const pxToRem = (pxValue: number): number => {
|
|
12
|
+
const purpurRescale = Number(
|
|
13
|
+
getComputedStyle(document.documentElement).getPropertyValue("--purpur-rescale") || "1"
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// For 16px base (rescale=1): divide by 16
|
|
17
|
+
// For 10px base (rescale=1.6): divide by 16 and then multiply by 1.6 = divide by 10
|
|
18
|
+
const conversionFactor = 16 / (purpurRescale || 1);
|
|
19
|
+
return pxValue / conversionFactor;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Converts pixel values to rem strings with 'rem' unit appended
|
|
24
|
+
*
|
|
25
|
+
* @param pxValue The pixel value to convert to rem
|
|
26
|
+
* @returns A string with the rem value and 'rem' unit
|
|
27
|
+
*/
|
|
28
|
+
export const pxToRemString = (pxValue: number): string => {
|
|
29
|
+
return `${pxToRem(pxValue)}rem`;
|
|
30
|
+
};
|
package/vitest.setup.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as matchers from "@testing-library/jest-dom/matchers";
|
|
3
|
+
import { cleanup } from "@testing-library/react";
|
|
4
|
+
import { afterEach, expect, vi } from "vitest";
|
|
5
|
+
import * as axeMatchers from "vitest-axe/matchers";
|
|
6
|
+
|
|
7
|
+
import "vitest-axe/extend-expect";
|
|
8
|
+
import "vitest-canvas-mock";
|
|
9
|
+
|
|
10
|
+
process.env.TZ = "CET";
|
|
11
|
+
|
|
12
|
+
expect.extend(matchers);
|
|
13
|
+
expect.extend(axeMatchers);
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
cleanup();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Mock TableRowCellSkeleton to fix "unsupported style property" warning
|
|
20
|
+
vi.mock("./src/table-row-cell-skeleton.tsx", () => ({
|
|
21
|
+
default: () => {
|
|
22
|
+
return React.createElement(
|
|
23
|
+
"td",
|
|
24
|
+
{ className: "mocked-skeleton-cell", style: { padding: "1rem" } },
|
|
25
|
+
[
|
|
26
|
+
// Add a div with the correct test ID that the test is looking for
|
|
27
|
+
React.createElement("div", {
|
|
28
|
+
"data-testid": "purpur-table-cell-skeleton",
|
|
29
|
+
key: "skeleton",
|
|
30
|
+
}),
|
|
31
|
+
]
|
|
32
|
+
);
|
|
33
|
+
},
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
const ResizeObserverMock = vi.fn(() => ({
|
|
37
|
+
disconnect: vi.fn(),
|
|
38
|
+
observe: vi.fn(),
|
|
39
|
+
takeRecords: vi.fn(),
|
|
40
|
+
unobserve: vi.fn(),
|
|
41
|
+
}));
|
|
42
|
+
vi.stubGlobal("ResizeObserver", ResizeObserverMock);
|
|
43
|
+
|
|
44
|
+
const IntersectionObserverMock = vi.fn(() => ({
|
|
45
|
+
disconnect: vi.fn(),
|
|
46
|
+
observe: vi.fn(),
|
|
47
|
+
takeRecords: vi.fn(),
|
|
48
|
+
unobserve: vi.fn(),
|
|
49
|
+
}));
|
|
50
|
+
vi.stubGlobal("IntersectionObserver", IntersectionObserverMock);
|
|
51
|
+
|
|
52
|
+
const matchMedia = vi.fn((query) => ({
|
|
53
|
+
matches: true,
|
|
54
|
+
media: query,
|
|
55
|
+
onchange: null,
|
|
56
|
+
addEventListener: vi.fn(),
|
|
57
|
+
removeEventListener: vi.fn(),
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
vi.stubGlobal("matchMedia", matchMedia);
|