@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,19 @@
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 declare const pxToRem: (pxValue: number) => number;
12
+ /**
13
+ * Converts pixel values to rem strings with 'rem' unit appended
14
+ *
15
+ * @param pxValue The pixel value to convert to rem
16
+ * @returns A string with the rem value and 'rem' unit
17
+ */
18
+ export declare const pxToRemString: (pxValue: number) => string;
19
+ //# sourceMappingURL=unit-conversions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unit-conversions.d.ts","sourceRoot":"","sources":["../../src/utils/unit-conversions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,OAAO,YAAa,MAAM,KAAG,MASzC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,MAE/C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=unit-conversions.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unit-conversions.spec.d.ts","sourceRoot":"","sources":["../../src/utils/unit-conversions.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ import purpurCommon from "@purpurds/component-rig/eslint.config.mjs";
2
+ export default purpurCommon;
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@purpurds/table",
3
+ "version": "0.0.1",
4
+ "license": "AGPL-3.0-only",
5
+ "main": "./dist/table.cjs.js",
6
+ "types": "./dist/table.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "require": "./dist/table.cjs.js",
10
+ "types": "./dist/table.d.ts",
11
+ "default": "./dist/table.es.js"
12
+ },
13
+ "./styles": "./dist/styles.css",
14
+ "./metadata": "./dist/metadata.js"
15
+ },
16
+ "source": "src/table.tsx",
17
+ "dependencies": {
18
+ "@tanstack/react-table": "~8.21.2",
19
+ "classnames": "~2.5.0",
20
+ "@purpurds/button": "6.11.1",
21
+ "@purpurds/badge": "6.11.1",
22
+ "@purpurds/checkbox": "6.11.1",
23
+ "@purpurds/cta-link": "6.11.1",
24
+ "@purpurds/drawer": "6.11.1",
25
+ "@purpurds/icon": "6.11.1",
26
+ "@purpurds/heading": "6.11.1",
27
+ "@purpurds/select": "6.11.1",
28
+ "@purpurds/link": "6.11.1",
29
+ "@purpurds/paragraph": "6.11.1",
30
+ "@purpurds/skeleton": "6.11.1",
31
+ "@purpurds/text-field": "6.11.1",
32
+ "@purpurds/tooltip": "6.11.1",
33
+ "@purpurds/tokens": "6.11.1",
34
+ "@purpurds/toggle": "6.11.1",
35
+ "@purpurds/visually-hidden": "6.11.1"
36
+ },
37
+ "devDependencies": {
38
+ "@rushstack/eslint-patch": "~1.10.0",
39
+ "@storybook/blocks": "^8.6.4",
40
+ "@storybook/react": "^8.6.4",
41
+ "@testing-library/dom": "~10.4.0",
42
+ "@testing-library/jest-dom": "~6.4.0",
43
+ "@testing-library/react": "~16.2.0",
44
+ "@testing-library/user-event": "~14.5.1",
45
+ "@types/node": "20.12.12",
46
+ "@types/react": "^19.0.10",
47
+ "@types/react-dom": "^19.0.4",
48
+ "eslint": "9.24.0",
49
+ "jsdom": "~22.1.0",
50
+ "lint-staged": "15.5.0",
51
+ "prettier": "~2.8.8",
52
+ "react": "^19.0.0",
53
+ "react-dom": "^19.0.0",
54
+ "storybook": "^8.6.4",
55
+ "typescript": "^5.6.3",
56
+ "vite": "^6.2.1",
57
+ "vitest": "^3.1.2",
58
+ "vitest-axe": "~0.1.0",
59
+ "vitest-canvas-mock": "~0.3.3",
60
+ "@purpurds/grid": "6.11.1",
61
+ "@purpurds/component-rig": "1.0.0",
62
+ "@purpurds/autocomplete": "6.11.1",
63
+ "@purpurds/label": "6.11.1",
64
+ "@purpurds/illustrative-icon": "6.11.1",
65
+ "@purpurds/listbox": "6.11.1",
66
+ "@purpurds/pagination": "6.11.1"
67
+ },
68
+ "scripts": {
69
+ "build:dev": "vite",
70
+ "build:watch": "vite build --watch",
71
+ "build": "vite build",
72
+ "ci:build": "rushx build",
73
+ "coverage": "vitest run --coverage",
74
+ "lint:fix": "eslint . --fix",
75
+ "lint": "lint-staged --no-stash 2>&1",
76
+ "sbdev": "rush sbdev",
77
+ "test:unit": "vitest run --passWithNoTests",
78
+ "test:watch": "vitest --watch",
79
+ "test": "rushx test:unit",
80
+ "typecheck": "tsc -p ./tsconfig.json"
81
+ }
82
+ }
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import { Badge, BadgeProps } from "@purpurds/badge";
3
+ import { Cell, RowData } from "@tanstack/react-table";
4
+
5
+ import { EmptyCell } from "./empty-cell";
6
+
7
+ export type BadgeCellProps<TData> = {
8
+ cell: Cell<TData, unknown>;
9
+ };
10
+
11
+ export const BadgeCell = <TData extends RowData>({ cell }: BadgeCellProps<TData>) => {
12
+ const value = cell.getValue<BadgeProps>();
13
+
14
+ if (!value) {
15
+ return <EmptyCell />;
16
+ }
17
+
18
+ const { variant, children, ...props } = value;
19
+
20
+ return (
21
+ <Badge variant={variant} {...props}>
22
+ {children}
23
+ </Badge>
24
+ );
25
+ };
@@ -0,0 +1,54 @@
1
+ import React from "react";
2
+ import { Paragraph } from "@purpurds/paragraph";
3
+ import { Tooltip } from "@purpurds/tooltip";
4
+ import { Cell, RowData } from "@tanstack/react-table";
5
+ import c from "classnames/bind";
6
+
7
+ import styles from "../table.module.scss";
8
+ import useTruncatedTooltip from "../use-truncated-hook";
9
+ import { pxToRemString } from "../utils/unit-conversions";
10
+ import { EmptyCell } from "./empty-cell";
11
+ const cx = c.bind(styles);
12
+
13
+ export type BodyTextCellProps<TData> = {
14
+ cell: Cell<TData, unknown>;
15
+ };
16
+
17
+ export const BodyTextCell = <TData extends RowData>({ cell }: BodyTextCellProps<TData>) => {
18
+ const value = cell.getValue<string>();
19
+ const { divRef, showPopover, onMouseLeave, onMouseEnter } = useTruncatedTooltip(cell);
20
+
21
+ if (!value) {
22
+ return <EmptyCell />;
23
+ }
24
+
25
+ const widthInRemString = pxToRemString(cell.column.getSize());
26
+
27
+ const content = (
28
+ <div
29
+ ref={divRef}
30
+ className={cx("purpur-table-row-cell__truncate")}
31
+ style={{
32
+ maxWidth: widthInRemString,
33
+ minWidth: widthInRemString,
34
+ }}
35
+ onMouseEnter={onMouseEnter}
36
+ onMouseLeave={onMouseLeave}
37
+ >
38
+ <Paragraph>{value}</Paragraph>
39
+ </div>
40
+ );
41
+
42
+ return (
43
+ <Tooltip
44
+ position="top"
45
+ align="center"
46
+ triggerElement={content}
47
+ // @ts-expect-error open does not exist on tooltip but gets passed down to radix tooltip with ...props
48
+ open={showPopover}
49
+ contentClassName={cx("purpur-table-row-cell___tooltip-content")}
50
+ >
51
+ {value}
52
+ </Tooltip>
53
+ );
54
+ };
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+ import { Button, ButtonProps } from "@purpurds/button";
3
+ import { Cell, RowData } from "@tanstack/react-table";
4
+
5
+ import { EmptyCell } from "./empty-cell";
6
+
7
+ export type ButtonCellProps<TData> = {
8
+ cell: Cell<TData, unknown>;
9
+ };
10
+
11
+ export const ButtonCell = <TData extends RowData>({ cell }: ButtonCellProps<TData>) => {
12
+ const buttonProps = (cell.row.original as Record<string, ButtonProps>)[cell.column.id];
13
+
14
+ if (buttonProps === undefined || buttonProps === null) {
15
+ return <EmptyCell />;
16
+ }
17
+ const metaOnClick = cell.column.columnDef.meta?.onClick;
18
+
19
+ const { children, ...restButtonProps } = buttonProps;
20
+
21
+ return (
22
+ <Button type="button" onClick={() => metaOnClick?.(cell)} size="sm" {...restButtonProps}>
23
+ {children}
24
+ </Button>
25
+ );
26
+ };
@@ -0,0 +1,54 @@
1
+ import React, { ReactElement } from "react";
2
+ import { Button, ButtonVariant } from "@purpurds/button";
3
+ import { IconProps } from "@purpurds/icon";
4
+ import { Cell, RowData } from "@tanstack/react-table";
5
+ import c from "classnames/bind";
6
+
7
+ import styles from "../table.module.scss";
8
+ import { EmptyCell } from "./empty-cell";
9
+ const cx = c.bind(styles);
10
+
11
+ export type ButtonGroupButtonProp = {
12
+ id: string;
13
+ ariaLabel: string;
14
+ variant: ButtonVariant;
15
+ icon: ReactElement<IconProps>;
16
+ };
17
+
18
+ export type ButtonGroupCellProps<TData> = {
19
+ cell: Cell<TData, unknown>;
20
+ };
21
+
22
+ export const ButtonGroupCell = <TData extends RowData>({ cell }: ButtonGroupCellProps<TData>) => {
23
+ const buttons = (cell.row.original as Record<string, ButtonGroupButtonProp[]>)[cell.column.id];
24
+
25
+ if (!buttons || !Array.isArray(buttons) || buttons.length === 0) {
26
+ return <EmptyCell />;
27
+ }
28
+
29
+ return (
30
+ <div className={cx("purpur-table-row-cell__button-group")}>
31
+ {buttons.map((props, index) => {
32
+ const { icon, ariaLabel, variant, ...restProps } = props;
33
+ return (
34
+ <Button
35
+ key={props.id || `button-${index}`}
36
+ iconOnly
37
+ aria-label={ariaLabel}
38
+ variant={variant}
39
+ type="button"
40
+ onClick={() => {
41
+ cell.column.columnDef.meta?.onClick?.({
42
+ ...cell,
43
+ buttonId: `${cell.id}_${props.id}`,
44
+ });
45
+ }}
46
+ {...restProps}
47
+ >
48
+ {icon}
49
+ </Button>
50
+ );
51
+ })}
52
+ </div>
53
+ );
54
+ };
@@ -0,0 +1,25 @@
1
+ import React from "react";
2
+ import { CtaLink, CtaLinkProps } from "@purpurds/cta-link";
3
+ import { Cell, RowData } from "@tanstack/react-table";
4
+
5
+ import { EmptyCell } from "./empty-cell";
6
+
7
+ export type CtaLinkCellProps<TData> = {
8
+ cell: Cell<TData, unknown>;
9
+ };
10
+
11
+ export const CtaLinkCell = <TData extends RowData>({ cell }: CtaLinkCellProps<TData>) => {
12
+ const value = cell.getValue<CtaLinkProps>();
13
+
14
+ if (!value) {
15
+ return <EmptyCell />;
16
+ }
17
+
18
+ const { variant, children, ...props } = value;
19
+
20
+ return (
21
+ <CtaLink variant={variant} {...props}>
22
+ {children}
23
+ </CtaLink>
24
+ );
25
+ };
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+ import { Paragraph } from "@purpurds/paragraph";
3
+ import { Cell, RowData } from "@tanstack/react-table";
4
+ import c from "classnames/bind";
5
+
6
+ import styles from "../table.module.scss";
7
+ import { EmptyCell } from "./empty-cell";
8
+ const cx = c.bind(styles);
9
+
10
+ export type DateCellProps<TData> = {
11
+ cell: Cell<TData, unknown>;
12
+ };
13
+
14
+ export const DateCell = <TData extends RowData>({ cell }: DateCellProps<TData>) => {
15
+ const dateString = cell.getValue<string>();
16
+
17
+ if (!dateString) {
18
+ return <EmptyCell />;
19
+ }
20
+
21
+ const showTime = cell.column.columnDef.meta?.showTime || true;
22
+
23
+ const dateObj = new Date(dateString);
24
+ const date = dateObj.toLocaleDateString("sv-SE");
25
+ const time = dateObj.toLocaleTimeString("sv-SE", { hour: "2-digit", minute: "2-digit" });
26
+
27
+ return (
28
+ <Paragraph className={cx("purpur-table-row-cell__date")}>
29
+ {date}
30
+ <span>{showTime ? ` ${time}` : null}</span>
31
+ </Paragraph>
32
+ );
33
+ };
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ import { Paragraph } from "@purpurds/paragraph";
3
+
4
+ export const EmptyCell = () => {
5
+ return <Paragraph>-</Paragraph>;
6
+ };
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import { IconError } from "@purpurds/icon/error";
3
+ import { Paragraph } from "@purpurds/paragraph";
4
+ import { Cell, RowData } from "@tanstack/react-table";
5
+ import c from "classnames/bind";
6
+
7
+ import styles from "../table.module.scss";
8
+ import { EmptyCell } from "./empty-cell";
9
+ const cx = c.bind(styles);
10
+
11
+ export type ErrorAlertMessageProps<TData> = {
12
+ cell: Cell<TData, unknown>;
13
+ };
14
+
15
+ export const ErrorAlertMessageCell = <TData extends RowData>({
16
+ cell,
17
+ }: ErrorAlertMessageProps<TData>) => {
18
+ const message = cell.getValue<string>();
19
+
20
+ if (!message) {
21
+ return <EmptyCell />;
22
+ }
23
+
24
+ return (
25
+ <div className={cx("purpur-table-row-cell__error-message")}>
26
+ <IconError data-testid="error-icon" />
27
+ <Paragraph>{message}</Paragraph>
28
+ </div>
29
+ );
30
+ };
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import { Cell, RowData } from "@tanstack/react-table";
3
+ import c from "classnames/bind";
4
+
5
+ import styles from "../table.module.scss";
6
+ import { EmptyCell } from "./empty-cell";
7
+ const cx = c.bind(styles);
8
+
9
+ export type IconTextCellProps<TData> = {
10
+ cell: Cell<TData, unknown>;
11
+ };
12
+
13
+ type CellValue = { icon: React.ReactNode; text?: string };
14
+
15
+ export const IconTextCell = <TData extends RowData>({ cell }: IconTextCellProps<TData>) => {
16
+ const value = cell.getValue<CellValue>();
17
+
18
+ if (!value) {
19
+ return <EmptyCell />;
20
+ }
21
+
22
+ const { icon, text } = value;
23
+
24
+ return (
25
+ <div className={cx("purpur-table-row-cell__icon-text")}>
26
+ {icon}
27
+ {text && text}
28
+ </div>
29
+ );
30
+ };
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { Paragraph } from "@purpurds/paragraph";
3
+ import { Cell, RowData } from "@tanstack/react-table";
4
+
5
+ import { EmptyCell } from "./empty-cell";
6
+
7
+ export type LeadTextCellProps<TData> = {
8
+ cell: Cell<TData, unknown>;
9
+ };
10
+
11
+ export const LeadTextCell = <TData extends RowData>({ cell }: LeadTextCellProps<TData>) => {
12
+ const value = cell.getValue<string>();
13
+
14
+ if (!value) {
15
+ return <EmptyCell />;
16
+ }
17
+
18
+ return <Paragraph variant="paragraph-100-bold">{value}</Paragraph>;
19
+ };
@@ -0,0 +1,58 @@
1
+ import React from "react";
2
+ import { Link, LinkProps } from "@purpurds/link";
3
+ import { Tooltip } from "@purpurds/tooltip";
4
+ import { Cell, RowData } from "@tanstack/react-table";
5
+ import c from "classnames/bind";
6
+
7
+ import styles from "../table.module.scss";
8
+ import useTruncatedTooltip from "../use-truncated-hook";
9
+ import { pxToRemString } from "../utils/unit-conversions";
10
+ import { EmptyCell } from "./empty-cell";
11
+ const cx = c.bind(styles);
12
+
13
+ export type LinkCellProps<TData> = {
14
+ cell: Cell<TData, unknown>;
15
+ };
16
+
17
+ export const LinkCell = <TData extends RowData>({ cell }: LinkCellProps<TData>) => {
18
+ const value = cell.getValue<LinkProps>();
19
+ const { divRef, showPopover, onMouseLeave, onMouseEnter } = useTruncatedTooltip(cell);
20
+
21
+ if (!value) {
22
+ return <EmptyCell />;
23
+ }
24
+
25
+ const { children, href, variant, ...props } = value;
26
+
27
+ const widthInRemString = pxToRemString(cell.column.getSize());
28
+
29
+ const content = (
30
+ <div
31
+ ref={divRef}
32
+ className={cx("purpur-table-row-cell__truncate")}
33
+ style={{
34
+ minWidth: widthInRemString,
35
+ maxWidth: widthInRemString,
36
+ }}
37
+ onMouseEnter={onMouseEnter}
38
+ onMouseLeave={onMouseLeave}
39
+ >
40
+ <Link variant={variant} href={href} {...props}>
41
+ {children}
42
+ </Link>
43
+ </div>
44
+ );
45
+
46
+ return (
47
+ <Tooltip
48
+ position="top"
49
+ align="center"
50
+ triggerElement={content}
51
+ // @ts-expect-error open does not exist on tooltip but gets passed down to radix tooltip with ...props
52
+ open={showPopover}
53
+ contentClassName={cx("purpur-table-row-cell__tooltip-content")}
54
+ >
55
+ {children}
56
+ </Tooltip>
57
+ );
58
+ };
@@ -0,0 +1,27 @@
1
+ import React from "react";
2
+ import { Paragraph } from "@purpurds/paragraph";
3
+ import { Cell, RowData } from "@tanstack/react-table";
4
+ import c from "classnames/bind";
5
+
6
+ import styles from "../table.module.scss";
7
+ import { EmptyCell } from "./empty-cell";
8
+ const cx = c.bind(styles);
9
+
10
+ export type NumberCellProps<TData> = {
11
+ cell: Cell<TData, unknown>;
12
+ };
13
+
14
+ export const NumberCell = <TData extends RowData>({ cell }: NumberCellProps<TData>) => {
15
+ const text = cell.getValue<string>();
16
+ const rightAlignCell = cell.column.columnDef.meta?.numberCellAlignment === "right";
17
+
18
+ if (!text) {
19
+ return <EmptyCell />;
20
+ }
21
+
22
+ return (
23
+ <Paragraph className={cx({ "purpur-table-row-cell__right-align": rightAlignCell })}>
24
+ {text}
25
+ </Paragraph>
26
+ );
27
+ };
@@ -0,0 +1,22 @@
1
+ import React from "react";
2
+ import { Checkbox } from "@purpurds/checkbox";
3
+ import { Cell, RowData } from "@tanstack/react-table";
4
+ import c from "classnames/bind";
5
+
6
+ import styles from "../table.module.scss";
7
+ const cx = c.bind(styles);
8
+
9
+ export type RowSelectionCellProps<TData extends RowData> = {
10
+ cell: Cell<TData, unknown>;
11
+ };
12
+
13
+ export const RowSelectionCell = <TData extends RowData>({ cell }: RowSelectionCellProps<TData>) => (
14
+ <Checkbox
15
+ id={cell.id}
16
+ className={cx("purpur-table-row-cell__row-selection")}
17
+ onChange={cell.row.getToggleSelectedHandler()}
18
+ checked={cell.row.getIsSelected()}
19
+ disabled={!cell.row.getCanSelect()}
20
+ aria-label={cell.column.columnDef.meta?.rowSelectionAriaLabels?.row}
21
+ />
22
+ );
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ import { Cell, RowData } from "@tanstack/react-table";
3
+ import c from "classnames/bind";
4
+
5
+ import styles from "../table.module.scss";
6
+ const cx = c.bind(styles);
7
+
8
+ export type RowToggleCellProps<TData extends RowData> = {
9
+ cell: Cell<TData, unknown>;
10
+ };
11
+
12
+ export const RowToggleCell = <TData extends RowData>({ cell }: RowToggleCellProps<TData>) => (
13
+ <input
14
+ id={cell.id}
15
+ className={cx("purpur-table-row-cell__row-toggle")}
16
+ type="radio"
17
+ onChange={cell.row.getToggleSelectedHandler()}
18
+ checked={cell.row.getIsSelected()}
19
+ aria-checked={cell.row.getIsSelected()}
20
+ disabled={!cell.row.getCanSelect()}
21
+ aria-label={cell.column.columnDef.meta?.rowSelectionAriaLabels?.row}
22
+ />
23
+ );
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { Toggle, ToggleProps } from "@purpurds/toggle";
3
+ import { Cell, RowData } from "@tanstack/react-table";
4
+
5
+ import { EmptyCell } from "./empty-cell";
6
+
7
+ export type ToggleCellProps<TData> = {
8
+ cell: Cell<TData, unknown>;
9
+ };
10
+
11
+ export const ToggleCell = <TData extends RowData>({ cell }: ToggleCellProps<TData>) => {
12
+ const toggleProps = cell.getValue<ToggleProps>();
13
+
14
+ if (!toggleProps) {
15
+ return <EmptyCell />;
16
+ }
17
+
18
+ return <Toggle {...toggleProps} />;
19
+ };
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+ import { IconAlert } from "@purpurds/icon/alert";
3
+ import { Paragraph } from "@purpurds/paragraph";
4
+ import { Cell, RowData } from "@tanstack/react-table";
5
+ import c from "classnames/bind";
6
+
7
+ import styles from "../table.module.scss";
8
+ import { EmptyCell } from "./empty-cell";
9
+ const cx = c.bind(styles);
10
+
11
+ export type WarningAlertMessageProps<TData> = {
12
+ cell: Cell<TData, unknown>;
13
+ };
14
+
15
+ export const WarningAlertMessageCell = <TData extends RowData>({
16
+ cell,
17
+ }: WarningAlertMessageProps<TData>) => {
18
+ const message = cell.getValue<string>();
19
+
20
+ if (!message) {
21
+ return <EmptyCell />;
22
+ }
23
+
24
+ return (
25
+ <div className={cx("purpur-table-row-cell__warning-message")}>
26
+ <IconAlert data-testid="alert-icon" />
27
+ <Paragraph>{message}</Paragraph>
28
+ </div>
29
+ );
30
+ };
@@ -0,0 +1,4 @@
1
+ declare module "*.scss" {
2
+ const styles: { [className: string]: string };
3
+ export default styles;
4
+ }