@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.
Files changed (142) hide show
  1. package/dist/LICENSE.txt +213 -0
  2. package/dist/cell-types/badge-cell.d.ts +8 -0
  3. package/dist/cell-types/badge-cell.d.ts.map +1 -0
  4. package/dist/cell-types/body-text-cell.d.ts +8 -0
  5. package/dist/cell-types/body-text-cell.d.ts.map +1 -0
  6. package/dist/cell-types/button-cell.d.ts +8 -0
  7. package/dist/cell-types/button-cell.d.ts.map +1 -0
  8. package/dist/cell-types/button-group-cell.d.ts +16 -0
  9. package/dist/cell-types/button-group-cell.d.ts.map +1 -0
  10. package/dist/cell-types/cta-link-cell.d.ts +8 -0
  11. package/dist/cell-types/cta-link-cell.d.ts.map +1 -0
  12. package/dist/cell-types/date-cell.d.ts +8 -0
  13. package/dist/cell-types/date-cell.d.ts.map +1 -0
  14. package/dist/cell-types/empty-cell.d.ts +4 -0
  15. package/dist/cell-types/empty-cell.d.ts.map +1 -0
  16. package/dist/cell-types/error-message-cell.d.ts +8 -0
  17. package/dist/cell-types/error-message-cell.d.ts.map +1 -0
  18. package/dist/cell-types/icon-text-cell.d.ts +8 -0
  19. package/dist/cell-types/icon-text-cell.d.ts.map +1 -0
  20. package/dist/cell-types/lead-text-cell.d.ts +8 -0
  21. package/dist/cell-types/lead-text-cell.d.ts.map +1 -0
  22. package/dist/cell-types/link-cell.d.ts +8 -0
  23. package/dist/cell-types/link-cell.d.ts.map +1 -0
  24. package/dist/cell-types/number-cell.d.ts +8 -0
  25. package/dist/cell-types/number-cell.d.ts.map +1 -0
  26. package/dist/cell-types/row-selection-cell.d.ts +8 -0
  27. package/dist/cell-types/row-selection-cell.d.ts.map +1 -0
  28. package/dist/cell-types/row-toggle-cell.d.ts +8 -0
  29. package/dist/cell-types/row-toggle-cell.d.ts.map +1 -0
  30. package/dist/cell-types/toggle-cell.d.ts +8 -0
  31. package/dist/cell-types/toggle-cell.d.ts.map +1 -0
  32. package/dist/cell-types/warning-message-cell.d.ts +8 -0
  33. package/dist/cell-types/warning-message-cell.d.ts.map +1 -0
  34. package/dist/metadata.js +17 -0
  35. package/dist/story-utils/column-def.d.ts +5 -0
  36. package/dist/story-utils/column-def.d.ts.map +1 -0
  37. package/dist/story-utils/table-data.d.ts +35 -0
  38. package/dist/story-utils/table-data.d.ts.map +1 -0
  39. package/dist/story-utils/use-fetch-table-data-hook.d.ts +11 -0
  40. package/dist/story-utils/use-fetch-table-data-hook.d.ts.map +1 -0
  41. package/dist/styles.css +1 -0
  42. package/dist/table-action-bar.d.ts +26 -0
  43. package/dist/table-action-bar.d.ts.map +1 -0
  44. package/dist/table-body.d.ts +10 -0
  45. package/dist/table-body.d.ts.map +1 -0
  46. package/dist/table-column-header-cell.d.ts +28 -0
  47. package/dist/table-column-header-cell.d.ts.map +1 -0
  48. package/dist/table-export-drawer.d.ts +17 -0
  49. package/dist/table-export-drawer.d.ts.map +1 -0
  50. package/dist/table-header.d.ts +11 -0
  51. package/dist/table-header.d.ts.map +1 -0
  52. package/dist/table-row-cell-skeleton.d.ts +14 -0
  53. package/dist/table-row-cell-skeleton.d.ts.map +1 -0
  54. package/dist/table-row-cell.d.ts +25 -0
  55. package/dist/table-row-cell.d.ts.map +1 -0
  56. package/dist/table-row.d.ts +11 -0
  57. package/dist/table-row.d.ts.map +1 -0
  58. package/dist/table-settings-drawer.d.ts +41 -0
  59. package/dist/table-settings-drawer.d.ts.map +1 -0
  60. package/dist/table-toolbar.d.ts +37 -0
  61. package/dist/table-toolbar.d.ts.map +1 -0
  62. package/dist/table.cjs.js +259 -0
  63. package/dist/table.cjs.js.map +1 -0
  64. package/dist/table.d.ts +20 -0
  65. package/dist/table.d.ts.map +1 -0
  66. package/dist/table.es.js +13585 -0
  67. package/dist/table.es.js.map +1 -0
  68. package/dist/test-utils/column-def.d.ts +6 -0
  69. package/dist/test-utils/column-def.d.ts.map +1 -0
  70. package/dist/test-utils/helpers.d.ts +138 -0
  71. package/dist/test-utils/helpers.d.ts.map +1 -0
  72. package/dist/test-utils/table-data.d.ts +33 -0
  73. package/dist/test-utils/table-data.d.ts.map +1 -0
  74. package/dist/types.d.ts +420 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/use-screen-size.hook.d.ts +7 -0
  77. package/dist/use-screen-size.hook.d.ts.map +1 -0
  78. package/dist/use-truncated-hook.d.ts +10 -0
  79. package/dist/use-truncated-hook.d.ts.map +1 -0
  80. package/dist/utils/custom-functions.d.ts +9 -0
  81. package/dist/utils/custom-functions.d.ts.map +1 -0
  82. package/dist/utils/unit-conversions.d.ts +19 -0
  83. package/dist/utils/unit-conversions.d.ts.map +1 -0
  84. package/dist/utils/unit-conversions.spec.d.ts +2 -0
  85. package/dist/utils/unit-conversions.spec.d.ts.map +1 -0
  86. package/eslint.config.mjs +2 -0
  87. package/package.json +82 -0
  88. package/src/cell-types/badge-cell.tsx +25 -0
  89. package/src/cell-types/body-text-cell.tsx +54 -0
  90. package/src/cell-types/button-cell.tsx +26 -0
  91. package/src/cell-types/button-group-cell.tsx +54 -0
  92. package/src/cell-types/cta-link-cell.tsx +25 -0
  93. package/src/cell-types/date-cell.tsx +33 -0
  94. package/src/cell-types/empty-cell.tsx +6 -0
  95. package/src/cell-types/error-message-cell.tsx +30 -0
  96. package/src/cell-types/icon-text-cell.tsx +30 -0
  97. package/src/cell-types/lead-text-cell.tsx +19 -0
  98. package/src/cell-types/link-cell.tsx +58 -0
  99. package/src/cell-types/number-cell.tsx +27 -0
  100. package/src/cell-types/row-selection-cell.tsx +22 -0
  101. package/src/cell-types/row-toggle-cell.tsx +23 -0
  102. package/src/cell-types/toggle-cell.tsx +19 -0
  103. package/src/cell-types/warning-message-cell.tsx +30 -0
  104. package/src/global.d.ts +4 -0
  105. package/src/story-utils/column-def.ts +148 -0
  106. package/src/story-utils/table-data.tsx +262 -0
  107. package/src/story-utils/use-fetch-table-data-hook.tsx +30 -0
  108. package/src/table-action-bar.module.scss +106 -0
  109. package/src/table-action-bar.test.tsx +111 -0
  110. package/src/table-action-bar.tsx +104 -0
  111. package/src/table-body.tsx +25 -0
  112. package/src/table-column-header-cell.tsx +305 -0
  113. package/src/table-export-drawer.module.scss +9 -0
  114. package/src/table-export-drawer.test.tsx +75 -0
  115. package/src/table-export-drawer.tsx +59 -0
  116. package/src/table-header.tsx +35 -0
  117. package/src/table-kitchen-sink.test.tsx +1196 -0
  118. package/src/table-row-cell-skeleton.tsx +61 -0
  119. package/src/table-row-cell.test.tsx +360 -0
  120. package/src/table-row-cell.tsx +188 -0
  121. package/src/table-row.tsx +30 -0
  122. package/src/table-settings-drawer.module.scss +25 -0
  123. package/src/table-settings-drawer.test.tsx +350 -0
  124. package/src/table-settings-drawer.tsx +254 -0
  125. package/src/table-toolbar.module.scss +17 -0
  126. package/src/table-toolbar.test.tsx +95 -0
  127. package/src/table-toolbar.tsx +136 -0
  128. package/src/table.module.scss +367 -0
  129. package/src/table.stories.tsx +1246 -0
  130. package/src/table.story.css +11 -0
  131. package/src/table.test.tsx +318 -0
  132. package/src/table.tsx +501 -0
  133. package/src/test-utils/column-def.ts +152 -0
  134. package/src/test-utils/helpers.ts +234 -0
  135. package/src/test-utils/table-data.tsx +318 -0
  136. package/src/types.ts +496 -0
  137. package/src/use-screen-size.hook.ts +23 -0
  138. package/src/use-truncated-hook.tsx +74 -0
  139. package/src/utils/custom-functions.ts +52 -0
  140. package/src/utils/unit-conversions.spec.ts +92 -0
  141. package/src/utils/unit-conversions.ts +30 -0
  142. 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
+ };
@@ -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);