- Moon Design System
-
-
+
+
Moon Design System
+
+
+
Server components
+
+ {Object.entries(server).map(([key, _value]) => (
+ -
+ {key}
+
+ ))}
+
+
+
+
+
Client components
+
+ {Object.entries(client).map(([key, _value]) => (
+ -
+ {key}
+
+ ))}
+
+
)
}
diff --git a/docs/package.json b/docs/package.json
index 44b0ba0de5..9ae89d4bf0 100644
--- a/docs/package.json
+++ b/docs/package.json
@@ -14,8 +14,8 @@
"@heathmont/moon-base-tw": "workspace:^10.10.1",
"@heathmont/moon-cmdk-tw": "workspace:^10.10.1",
"@heathmont/moon-core-tw": "workspace:^10.10.1",
- "@heathmont/moon-themes-tw": "workspace:^10.10.1",
"@heathmont/moon-icons-tw": "9.28.6",
+ "@heathmont/moon-themes-tw": "workspace:^10.10.1",
"@types/node": "20.4.9",
"@types/react": "18.2.19",
"@types/react-dom": "18.2.7",
diff --git a/package.json b/package.json
index 725b4a5ce9..77edd6d861 100644
--- a/package.json
+++ b/package.json
@@ -129,6 +129,7 @@
}
},
"dependencies": {
- "@tanstack/react-table": "8.9.3"
+ "@tanstack/react-table": "8.9.3",
+ "ts-node": "^10.9.1"
}
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8c3d204b8c..4454f70883 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -35,6 +35,9 @@ importers:
'@tanstack/react-table':
specifier: 8.9.3
version: 8.9.3(react-dom@18.2.0)(react@18.2.0)
+ ts-node:
+ specifier: ^10.9.1
+ version: 10.9.1(@types/node@20.4.9)(typescript@5.1.6)
devDependencies:
'@babel/cli':
specifier: 7.22.10
@@ -125,7 +128,7 @@ importers:
version: 3.1.0
jest:
specifier: 28.1.3
- version: 28.1.3
+ version: 28.1.3(@types/node@20.4.9)(ts-node@10.9.1)
jest-styled-components:
specifier: 7.1.1
version: 7.1.1(styled-components@5.3.11)
@@ -158,7 +161,7 @@ importers:
version: 5.1.6
typescript-plugin-css-modules:
specifier: 5.0.1
- version: 5.0.1(typescript@5.1.6)
+ version: 5.0.1(ts-node@10.9.1)(typescript@5.1.6)
docs:
dependencies:
@@ -326,7 +329,7 @@ importers:
version: 3.0.0
jest:
specifier: 27.5.1
- version: 27.5.1
+ version: 27.5.1(ts-node@10.9.1)
jest-environment-jsdom:
specifier: 27.5.1
version: 27.5.1
@@ -673,7 +676,7 @@ importers:
version: 18.2.0
react-dnd:
specifier: 14.0.3
- version: 14.0.3(@types/react@18.2.19)(react@18.2.0)
+ version: 14.0.3(@types/node@20.4.9)(@types/react@18.2.19)(react@18.2.0)
react-dnd-html5-backend:
specifier: 14.0.1
version: 14.0.1
@@ -2773,7 +2776,6 @@ packages:
engines: {node: '>=12'}
dependencies:
'@jridgewell/trace-mapping': 0.3.9
- dev: false
/@emotion/babel-plugin@11.10.6:
resolution: {integrity: sha512-p2dAqtVrkhSa7xz1u/m9eHYdLi+en8NowrmXeF/dKtJpU8lCWli8RUAati7NcSl0afsBott48pdnANuD0wh9QQ==}
@@ -3056,7 +3058,7 @@ packages:
slash: 3.0.0
dev: true
- /@jest/core@27.5.1:
+ /@jest/core@27.5.1(ts-node@10.9.1):
resolution: {integrity: sha512-AK6/UTrvQD0Cd24NSqmIA6rKsu0tKIxfiCducZvqxYdmMisOYAsdItspT+fQDQYARPf8XgjAFZi0ogW2agH5nQ==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
peerDependencies:
@@ -3077,7 +3079,7 @@ packages:
exit: 0.1.2
graceful-fs: 4.2.11
jest-changed-files: 27.5.1
- jest-config: 27.5.1
+ jest-config: 27.5.1(ts-node@10.9.1)
jest-haste-map: 27.5.1
jest-message-util: 27.5.1
jest-regex-util: 27.5.1
@@ -3100,7 +3102,7 @@ packages:
- ts-node
- utf-8-validate
- /@jest/core@28.1.3:
+ /@jest/core@28.1.3(ts-node@10.9.1):
resolution: {integrity: sha512-CIKBrlaKOzA7YG19BEqCw3SLIsEwjZkeJzf5bdooVnW4bH5cktqe3JX+G2YV1aK5vP8N9na1IGWFzYaTp6k6NA==}
engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
peerDependencies:
@@ -3121,7 +3123,7 @@ packages:
exit: 0.1.2
graceful-fs: 4.2.11
jest-changed-files: 28.1.3
- jest-config: 28.1.3(@types/node@20.4.9)
+ jest-config: 28.1.3(@types/node@20.4.9)(ts-node@10.9.1)
jest-haste-map: 28.1.3
jest-message-util: 28.1.3
jest-regex-util: 28.0.2
@@ -3506,7 +3508,6 @@ packages:
dependencies:
'@jridgewell/resolve-uri': 3.1.0
'@jridgewell/sourcemap-codec': 1.4.15
- dev: false
/@manypkg/find-root@1.1.0:
resolution: {integrity: sha512-mki5uBvhHzO8kYYix/WRy2WX8S3B5wdVSc9D6KcU5lQNglP2yt58/VfLuAK49glRXChosY8ap2oJ1qgma3GUVA==}
@@ -4833,19 +4834,15 @@ packages:
/@tsconfig/node10@1.0.9:
resolution: {integrity: sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA==}
- dev: false
/@tsconfig/node12@1.0.11:
resolution: {integrity: sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==}
- dev: false
/@tsconfig/node14@1.0.3:
resolution: {integrity: sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==}
- dev: false
/@tsconfig/node16@1.0.4:
resolution: {integrity: sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==}
- dev: false
/@types/acorn@4.0.6:
resolution: {integrity: sha512-veQTnWP+1D/xbxVrPC3zHnCZRjSrKfhbMUlEA43iMZLu7EsnTtkJklIuwrCPbOi8YkvDQAiW05VQQFvvz9oieQ==}
@@ -5423,7 +5420,6 @@ packages:
/acorn-walk@8.2.0:
resolution: {integrity: sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==}
engines: {node: '>=0.4.0'}
- dev: false
/acorn@7.4.1:
resolution: {integrity: sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==}
@@ -9100,7 +9096,7 @@ packages:
- supports-color
dev: true
- /jest-cli@27.5.1:
+ /jest-cli@27.5.1(ts-node@10.9.1):
resolution: {integrity: sha512-Hc6HOOwYq4/74/c62dEE3r5elx8wjYqxY0r0G/nFrLDPMFRu6RA/u8qINOIkvhxG7mMQ5EJsOGfRpI8L6eFUVw==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
hasBin: true
@@ -9110,14 +9106,14 @@ packages:
node-notifier:
optional: true
dependencies:
- '@jest/core': 27.5.1
+ '@jest/core': 27.5.1(ts-node@10.9.1)
'@jest/test-result': 27.5.1
'@jest/types': 27.5.1
chalk: 4.1.2
exit: 0.1.2
graceful-fs: 4.2.11
import-local: 3.1.0
- jest-config: 27.5.1
+ jest-config: 27.5.1(ts-node@10.9.1)
jest-util: 27.5.1
jest-validate: 27.5.1
prompts: 2.4.2
@@ -9129,7 +9125,7 @@ packages:
- ts-node
- utf-8-validate
- /jest-cli@28.1.3:
+ /jest-cli@28.1.3(@types/node@20.4.9)(ts-node@10.9.1):
resolution: {integrity: sha512-roY3kvrv57Azn1yPgdTebPAXvdR2xfezaKKYzVxZ6It/5NCxzJym6tUI5P1zkdWhfUYkxEI9uZWcQdaFLo8mJQ==}
engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
hasBin: true
@@ -9139,14 +9135,14 @@ packages:
node-notifier:
optional: true
dependencies:
- '@jest/core': 28.1.3
+ '@jest/core': 28.1.3(ts-node@10.9.1)
'@jest/test-result': 28.1.3
'@jest/types': 28.1.3
chalk: 4.1.2
exit: 0.1.2
graceful-fs: 4.2.11
import-local: 3.1.0
- jest-config: 28.1.3(@types/node@20.4.9)
+ jest-config: 28.1.3(@types/node@20.4.9)(ts-node@10.9.1)
jest-util: 28.1.3
jest-validate: 28.1.3
prompts: 2.4.2
@@ -9157,7 +9153,7 @@ packages:
- ts-node
dev: true
- /jest-config@27.5.1:
+ /jest-config@27.5.1(ts-node@10.9.1):
resolution: {integrity: sha512-5sAsjm6tGdsVbW9ahcChPAFCk4IlkQUknH5AvKjuLTSlcO/wCZKyFdn7Rg0EkC+OGgWODEy2hDpWB1PgzH0JNA==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
peerDependencies:
@@ -9190,13 +9186,14 @@ packages:
pretty-format: 27.5.1
slash: 3.0.0
strip-json-comments: 3.1.1
+ ts-node: 10.9.1(@types/node@20.4.9)(typescript@5.1.6)
transitivePeerDependencies:
- bufferutil
- canvas
- supports-color
- utf-8-validate
- /jest-config@28.1.3(@types/node@20.4.9):
+ /jest-config@28.1.3(@types/node@20.4.9)(ts-node@10.9.1):
resolution: {integrity: sha512-MG3INjByJ0J4AsNBm7T3hsuxKQqFIiRo/AUqb1q9LRKI5UU6Aar9JHbr9Ivn1TVwfUD9KirRoM/T6u8XlcQPHQ==}
engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
peerDependencies:
@@ -9231,6 +9228,7 @@ packages:
pretty-format: 28.1.3
slash: 3.0.0
strip-json-comments: 3.1.1
+ ts-node: 10.9.1(@types/node@20.4.9)(typescript@5.1.6)
transitivePeerDependencies:
- supports-color
dev: true
@@ -9953,7 +9951,7 @@ packages:
supports-color: 8.1.1
dev: true
- /jest@27.5.1:
+ /jest@27.5.1(ts-node@10.9.1):
resolution: {integrity: sha512-Yn0mADZB89zTtjkPJEXwrac3LHudkQMR+Paqa8uxJHCBr9agxztUifWCyiYrjhMPBoUVBjyny0I7XH6ozDr7QQ==}
engines: {node: ^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0}
hasBin: true
@@ -9963,9 +9961,9 @@ packages:
node-notifier:
optional: true
dependencies:
- '@jest/core': 27.5.1
+ '@jest/core': 27.5.1(ts-node@10.9.1)
import-local: 3.1.0
- jest-cli: 27.5.1
+ jest-cli: 27.5.1(ts-node@10.9.1)
transitivePeerDependencies:
- bufferutil
- canvas
@@ -9973,7 +9971,7 @@ packages:
- ts-node
- utf-8-validate
- /jest@28.1.3:
+ /jest@28.1.3(@types/node@20.4.9)(ts-node@10.9.1):
resolution: {integrity: sha512-N4GT5on8UkZgH0O5LUavMRV1EDEhNTL0KEfRmDIeZHSV7p2XgLoY9t9VDUgL6o+yfdgYHVxuz81G8oB9VG5uyA==}
engines: {node: ^12.13.0 || ^14.15.0 || ^16.10.0 || >=17.0.0}
hasBin: true
@@ -9983,10 +9981,10 @@ packages:
node-notifier:
optional: true
dependencies:
- '@jest/core': 28.1.3
+ '@jest/core': 28.1.3(ts-node@10.9.1)
'@jest/types': 28.1.3
import-local: 3.1.0
- jest-cli: 28.1.3
+ jest-cli: 28.1.3(@types/node@20.4.9)(ts-node@10.9.1)
transitivePeerDependencies:
- '@types/node'
- supports-color
@@ -11731,7 +11729,7 @@ packages:
postcss: 8.4.27
dev: false
- /postcss-load-config@3.1.4(postcss@8.4.27):
+ /postcss-load-config@3.1.4(postcss@8.4.27)(ts-node@10.9.1):
resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==}
engines: {node: '>= 10'}
peerDependencies:
@@ -11745,6 +11743,7 @@ packages:
dependencies:
lilconfig: 2.1.0
postcss: 8.4.27
+ ts-node: 10.9.1(@types/node@20.4.9)(typescript@5.1.6)
yaml: 1.10.2
dev: true
@@ -12044,7 +12043,7 @@ packages:
dnd-core: 14.0.0
dev: false
- /react-dnd@14.0.3(@types/react@18.2.19)(react@18.2.0):
+ /react-dnd@14.0.3(@types/node@20.4.9)(@types/react@18.2.19)(react@18.2.0):
resolution: {integrity: sha512-i73Hx5SKfDRdwXe30+CjF/DidiRdt/gwpPN14ajkPR20t/0osnNKFNHg3DLV6RZym+DJ0pO9H5APeMsBWGU3+Q==}
peerDependencies:
'@types/hoist-non-react-statics': '>= 3.3.1'
@@ -12061,6 +12060,7 @@ packages:
dependencies:
'@react-dnd/invariant': 2.0.0
'@react-dnd/shallowequal': 2.0.0
+ '@types/node': 20.4.9
'@types/react': 18.2.19
dnd-core: 14.0.0
fast-deep-equal: 3.1.3
@@ -12988,7 +12988,7 @@ packages:
peerDependencies:
jest: '>=16'
dependencies:
- jest: 27.5.1
+ jest: 27.5.1(ts-node@10.9.1)
jest-diff: 29.6.2
jest-snapshot: 29.6.2
pretty-format: 29.6.2
@@ -13788,7 +13788,6 @@ packages:
typescript: 5.1.6
v8-compile-cache-lib: 3.0.1
yn: 3.1.1
- dev: false
/ts-node@9.1.1(typescript@5.1.6):
resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==}
@@ -13929,7 +13928,7 @@ packages:
dependencies:
is-typedarray: 1.0.0
- /typescript-plugin-css-modules@5.0.1(typescript@5.1.6):
+ /typescript-plugin-css-modules@5.0.1(ts-node@10.9.1)(typescript@5.1.6):
resolution: {integrity: sha512-hKXObfwfjx2/myRq4JeQ8D3xIWYTFqusi0hS/Aka7RFX1xQEoEkdOGDWyXNb8LmObawsUzbI30gQnZvqYXCrkA==}
peerDependencies:
typescript: '>=4.0.0'
@@ -13941,7 +13940,7 @@ packages:
less: 4.1.3
lodash.camelcase: 4.3.0
postcss: 8.4.27
- postcss-load-config: 3.1.4(postcss@8.4.27)
+ postcss-load-config: 3.1.4(postcss@8.4.27)(ts-node@10.9.1)
postcss-modules-extract-imports: 3.0.0(postcss@8.4.27)
postcss-modules-local-by-default: 4.0.3(postcss@8.4.27)
postcss-modules-scope: 3.0.0(postcss@8.4.27)
@@ -14173,7 +14172,6 @@ packages:
/v8-compile-cache-lib@3.0.1:
resolution: {integrity: sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==}
- dev: false
/v8-compile-cache@2.3.0:
resolution: {integrity: sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==}
From 6968938984f53f876a3df83d0bffb1a10bbcb1e3 Mon Sep 17 00:00:00 2001
From: Karl Kallavus <232199+karl-kallavus@users.noreply.github.com>
Date: Wed, 18 Oct 2023 16:09:45 +0200
Subject: [PATCH 2/7] MDS-738 Table & Checkbox Integration (#2434)
* feat: a new table with expanded selectable rows and checkboxes has been created
* fix: table control structure
* fix: row and branch selection and highlighting
* fix: row and branch selection and highlighting
* fix: burst selection/deselection
* fix: burst select/deselect
* feat: the Expandable table with Checkboxes
* fix: rows are being selected via checkbox only
* fix: some code improvements in the examples
* fmt
* fix: code improvement by the remarks
* fix: code improvement after the remarks
* fix: another code correction
* fix: type of the variable has been removed
* fix: a tiny fix at the Table component
* fmt
---
next-docs/pages/components/table.tsx | 8 +-
.../examples/table/ExpandableCheckboxes.tsx | 317 +
.../examples/table/ExpandedWithModals.tsx | 6 +-
next-docs/public/examples/table/LongData.tsx | 2 -
.../examples/table/SelectableCheckboxes.tsx | 60 +-
.../__snapshots__/index.test.tsx.snap | 24708 +++++++++++-----
.../examples/table/__tests__/index.test.tsx | 9 +
workspaces/tables/src/components/BodyTR.tsx | 2 +-
workspaces/tables/src/components/TH.tsx | 2 +
workspaces/tables/src/components/Table.tsx | 215 +-
.../src/private/types/RenderRowsProps.ts | 3 +-
.../tables/src/private/types/THProps.ts | 1 +
.../tables/src/private/utils/renderRows.tsx | 67 +-
13 files changed, 17178 insertions(+), 8222 deletions(-)
create mode 100644 next-docs/public/examples/table/ExpandableCheckboxes.tsx
diff --git a/next-docs/pages/components/table.tsx b/next-docs/pages/components/table.tsx
index d6a219a53f..441b1b324e 100644
--- a/next-docs/pages/components/table.tsx
+++ b/next-docs/pages/components/table.tsx
@@ -13,6 +13,7 @@ import CustomContent from '../../public/examples/table/CustomContent';
import DeepTable from '../../public/examples/table/DeepTable';
import Default from '../../public/examples/table/Default';
import Editable from '../../public/examples/table/Editable';
+import ExpandableCheckboxes from '../../public/examples/table/ExpandableCheckboxes';
import ExpandedRows from '../../public/examples/table/ExpandedRows';
import ExpandedWithModals from '../../public/examples/table/ExpandedWithModals';
import LongData from '../../public/examples/table/LongData';
@@ -108,10 +109,15 @@ const PageTable = () => {
code={examples ? examples.DeepTable : 'Loading'}
/>
}
code={examples ? examples.ExpandedWithModals : 'Loading'}
/>
+
}
+ code={examples ? examples.ExpandableCheckboxes : 'Loading'}
+ />
}
diff --git a/next-docs/public/examples/table/ExpandableCheckboxes.tsx b/next-docs/public/examples/table/ExpandableCheckboxes.tsx
new file mode 100644
index 0000000000..02427dba2c
--- /dev/null
+++ b/next-docs/public/examples/table/ExpandableCheckboxes.tsx
@@ -0,0 +1,317 @@
+import { Checkbox, Chip, Tooltip, mergeClassnames } from "@heathmont/moon-core-tw";
+import { OtherFrame } from "@heathmont/moon-icons-tw";
+import { Table } from "@heathmont/moon-table-tw";
+import React, { useState } from "react";
+
+interface HeaderProps {
+ rows: [];
+ rowsById: { [key: string]: boolean };
+ isAllRowsExpanded: boolean;
+ getToggleAllRowsExpandedProps: () => React.HTMLAttributes
;
+}
+
+const Example = () => {
+ /**
+ * The PREFIX is necessary if you use several different tables with checkboxes on the same page.
+ * Each table should have its own unique PREFIX to avoid assigning identical indexes to elements.
+ * When using only one table, the PREFIX can be omitted.
+ */
+ const PREFIX = "any__unique__string__for__each__table";
+
+ const [selected, setSelected] = useState<{ [key: string]: boolean }>({});
+
+ const columnShift = (depth: number) => {
+ const shiftMap: { [key: number]: string } = [
+ 'ps-0',
+ 'ps-6',
+ 'ps-12',
+ ];
+
+ return shiftMap[depth];
+ }
+
+ const checkIfSelected = (id: string, canExpand: boolean, rowsById: { [key: string]: boolean }) => {
+ return canExpand
+ ? Object.keys(rowsById)
+ .filter((rowId) => rowId.indexOf(id) === 0 && rowId !== id)
+ .every((rowId) => selected[rowId] === true)
+ : selected[id] === true;
+ }
+
+ const checkIfIndeterminate = (id: string, rowsById: { [key: string]: boolean }) => {
+ const matches = Object.keys(rowsById)
+ .filter((rowId) => rowId.indexOf(id) === 0 && rowId !== id);
+ return !matches.every((rowId) => selected[rowId] === true) && matches.some((rowId) => selected[rowId] === true);
+ }
+
+ const columnsInitial = [
+ {
+ 'Header': 'Expand/Select',
+ 'sticky': 'left',
+ columns: [
+ {
+ 'id': 'any_unique_string_required',
+ Header: ({
+ rows,
+ rowsById,
+ getToggleAllRowsExpandedProps,
+ isAllRowsExpanded,
+ }: HeaderProps) => (
+
+
+ { e.stopPropagation() }}
+ />
+
+ {
+ {isAllRowsExpanded ? '👇' : '👉'}
+ }
+
+ ),
+ Cell: ({ row, rowsById }: any) => (
+ {
+ if ((e.target as unknown as HTMLElement).tagName === 'SPAN') e.stopPropagation();
+ }}
+ >
+
+ e.stopPropagation()}
+ />
+
+ {row.canExpand ? (
+
+ {row.isExpanded ? '👇' : '👉'}
+
+ ) : null}
+
+ )
+ },
+ ],
+ },
+ {
+ Header: 'Name',
+ sticky: 'left',
+ columns: [
+ {
+ Header: 'First Name',
+ accessor: 'firstName',
+ },
+ ],
+ },
+ {
+ Header: 'Info',
+ columns: [
+ {
+ Header: 'Age',
+ accessor: 'age',
+ width: 50,
+ },
+ {
+ Header: 'Visits',
+ accessor: 'visits',
+ },
+ {
+ Header: 'Activity',
+ accessor: 'activity',
+ },
+ {
+ Header: 'Status',
+ width: 60,
+ accessor: 'status',
+ },
+ {
+ Header: 'Profile Progress',
+ Footer: 'Profile Progress',
+ accessor: 'progress',
+ },
+ ],
+ },
+ {
+ Header: 'Actions',
+ sticky: 'right',
+ columns: [
+ {
+ Header: 'Actions',
+ accessor: 'actions',
+ Footer: '',
+ },
+ ],
+ },
+ ];
+
+ const tooltip = () => (
+
+
+ }
+ />
+
+
+ Round details
+
+
+
+ );
+
+ const makeData = () => [
+ {
+ firstName: 'Test lvl1',
+ age: 36,
+ visits: 50,
+ progress: 20,
+ status: 19,
+ activity: 54,
+ actions: tooltip(),
+ subRows: [
+ {
+ firstName: 'Sub test lvl2',
+ age: 96,
+ visits: 8,
+ progress: 2,
+ status: 97,
+ activity: 23,
+ actions: tooltip(),
+ subRows: [
+ {
+ firstName: 'Sub test lvl3',
+ age: 63,
+ visits: 82,
+ progress: 59,
+ status: 52,
+ activity: 46,
+ actions: tooltip(),
+ },
+ {
+ firstName: 'Sub test lvl3',
+ age: 64,
+ visits: 35,
+ progress: 78,
+ status: 65,
+ activity: 5,
+ actions: tooltip(),
+ },
+ {
+ firstName: 'Sub test lvl3',
+ age: 12,
+ visits: 4,
+ progress: 44,
+ status: 98,
+ activity: 5,
+ actions: tooltip(),
+ },
+ ],
+ },
+ {
+ firstName: 'Sub test lvl2',
+ age: 74,
+ visits: 5,
+ progress: 1,
+ status: 86,
+ activity: 2,
+ actions: tooltip(),
+ subRows: [
+ {
+ firstName: 'Sub test lvl3',
+ age: 89,
+ visits: 98,
+ progress: 54,
+ status: 24,
+ activity: 43,
+ actions: tooltip(),
+ },
+ {
+ firstName: 'Sub test lvl3',
+ age: 52,
+ visits: 25,
+ progress: 25,
+ status: 97,
+ activity: 35,
+ actions: tooltip(),
+ },
+ {
+ firstName: 'Sub test lvl3',
+ age: 55,
+ visits: 54,
+ progress: 24,
+ status: 56,
+ activity: 33,
+ actions: tooltip(),
+ },
+ ],
+ },
+ {
+ firstName: 'Sub test lvl2',
+ age: 53,
+ visits: 63,
+ progress: 24,
+ status: 48,
+ activity: 3,
+ actions: tooltip(),
+ subRows: [
+ {
+ firstName: 'Sub test lvl3',
+ age: 4,
+ visits: 653,
+ progress: 36,
+ status: 44,
+ activity: 43,
+ actions: tooltip(),
+ },
+ {
+ firstName: 'Sub test lvl3',
+ age: 49,
+ visits: 45,
+ progress: 454,
+ status: 35,
+ activity: 4,
+ actions: tooltip(),
+ },
+ ],
+ },
+ ],
+ }
+ ];
+
+ const columns = React.useMemo(() => columnsInitial, [selected]);
+ const data = React.useMemo(() => makeData(), []);
+
+ const defaultColumn = React.useMemo(
+ () => ({
+ minWidth: 100,
+ width: 150,
+ maxWidth: 400,
+ }), []);
+
+ return (
+ (rows) => {
+ setSelected(rows.reduce((acc: { [key: string]: boolean }, item) => {
+ acc[item.id] = true;
+ return acc;
+ }, {})
+ );
+ }}
+ />
+ );
+}
+
+export default Example;
diff --git a/next-docs/public/examples/table/ExpandedWithModals.tsx b/next-docs/public/examples/table/ExpandedWithModals.tsx
index df812f44a7..3ab8d4fb19 100644
--- a/next-docs/public/examples/table/ExpandedWithModals.tsx
+++ b/next-docs/public/examples/table/ExpandedWithModals.tsx
@@ -2,7 +2,6 @@ import React, { ReactNode, useState } from 'react';
import { Table } from '@heathmont/moon-table-tw';
import { Button, Chip, Modal, Tooltip } from '@heathmont/moon-core-tw';
import { OtherFrame } from '@heathmont/moon-icons-tw';
-import { number } from 'zod';
interface HeaderProps {
isAllRowsExpanded: boolean;
@@ -107,7 +106,8 @@ const Example = () => {
onClick={() => {
setTitle(modal.title);
setPanel(modal.panel);
- openModal(); }}
+ openModal();
+ }}
/>
@@ -128,7 +128,7 @@ const Example = () => {
Activity: {Math.floor(index * 100)}
Actions: {Math.floor(index * 100)}
- )
+ )
};
}
diff --git a/next-docs/public/examples/table/LongData.tsx b/next-docs/public/examples/table/LongData.tsx
index 60a5ea9d6a..0f511192f1 100644
--- a/next-docs/public/examples/table/LongData.tsx
+++ b/next-docs/public/examples/table/LongData.tsx
@@ -48,8 +48,6 @@ const Example = () => {
'Header': 'Currency',
'accessor': 'currency',
'Footer': '',
- /*'maxWidth': Number.MAX_SAFE_INTEGER,
- 'width': 80 */
},
],
},
diff --git a/next-docs/public/examples/table/SelectableCheckboxes.tsx b/next-docs/public/examples/table/SelectableCheckboxes.tsx
index 2dfd060dd2..fa9844a9e6 100644
--- a/next-docs/public/examples/table/SelectableCheckboxes.tsx
+++ b/next-docs/public/examples/table/SelectableCheckboxes.tsx
@@ -1,8 +1,56 @@
-import React from 'react';
+import React, { useState } from 'react';
import { Table } from '@heathmont/moon-table-tw';
+import { Checkbox } from '@heathmont/moon-core-tw';
+
+interface HeaderProps {
+ rows: [];
+ rowsById: { [key: string]: boolean };
+}
const Example = () => {
+ /**
+ * The PREFIX is necessary if you use several different tables with checkboxes on the same page.
+ * Each table should have its own unique PREFIX to avoid assigning identical indexes to elements.
+ * When using only one table, the PREFIX can be omitted.
+ */
+ const PREFIX = "any_unique_string_for_each_table";
+
+ const [selected, setSelected] = useState<{ [key: string]: boolean }>({});
+
const columnsInitial = [
+ {
+ 'Header': 'Select',
+ 'sticky': 'left',
+ 'Footer': '',
+ columns: [
+ {
+ 'id': '_any_unique_string_required',
+ Header: ({
+ rows,
+ rowsById,
+ }: HeaderProps) => (
+
+ { e.stopPropagation() }}
+ />
+
+ ),
+ Cell: ({ row, rowsById }: any) => (
+
+ e.stopPropagation()}
+ />
+
+ ),
+ Footer: '',
+ },
+ ],
+ },
{
Header: 'Name',
sticky: 'left',
@@ -72,7 +120,6 @@ const Example = () => {
progress: {Math.floor(index * 100)},
status: Math.floor(index * 100),
activity: Math.floor(index * 100),
- isSelected: index === 3,
};
});
};
@@ -86,7 +133,7 @@ const Example = () => {
[]
);
- const columns = React.useMemo(() => columnsInitial, []);
+ const columns = React.useMemo(() => columnsInitial, [selected]);
const data = React.useMemo(() => makeData(40), []);
return (
@@ -99,8 +146,13 @@ const Example = () => {
withFooter={true}
selectable={true}
useCheckbox={true}
- getOnRowSelect={() => (rows: any) => {
+ getOnRowSelect={() => (rows) => {
console.log(`IDs of selected rows - ${rows.map((row: any) => row.id)}`);
+ setSelected(rows.reduce((acc: {[key: string]: boolean}, item) => {
+ acc[item.id] = true;
+ return acc;
+ }, {})
+ );
}}
/>
);
diff --git a/next-docs/public/examples/table/__tests__/__snapshots__/index.test.tsx.snap b/next-docs/public/examples/table/__tests__/__snapshots__/index.test.tsx.snap
index f96be3f3c5..c3d385f921 100644
--- a/next-docs/public/examples/table/__tests__/__snapshots__/index.test.tsx.snap
+++ b/next-docs/public/examples/table/__tests__/__snapshots__/index.test.tsx.snap
@@ -33741,7 +33741,7 @@ Object {
}
`;
-exports[`Table in RTL renders ExpandedRows 1`] = `
+exports[`Table in RTL renders ExpandableCheckboxes 1`] = `
Object {
"asFragment": [Function],
"baseElement":
@@ -33760,7 +33760,7 @@ Object {
- Expand
+ Expand/Select
Info
- Progress
+ Actions
-
- 👉
-
+
+
+ 👇
+
+
+
- Profile Progress
+ Actions
+
-
- 👉
-
+
+
+ 👇
+
+
- Test
+ Test lvl1
- 0
+ 36
- 0
+ 50
- 0
-
-
- 0
-
-
-
- 0
-
-
-
-
-
-
- 👉
-
-
-
- Test
+ 54
-
- 30
-
+ 19
- 100
+ 20
-
- 100
-
-
- 100
-
-
- 👉
-
+
+
+ 👇
+
+
- Test
+ Sub test lvl2
- 60
+ 96
- 200
+ 8
- 200
-
-
- 200
-
-
-
- 200
-
-
-
-
-
-
- 👉
-
-
-
- Test
+ 23
-
- 90
-
+ 97
- 300
+ 2
-
- 300
-
-
- 300
-
- Test
+ Sub test lvl3
- 120
+ 63
- 400
+ 82
- 400
-
-
- 400
-
-
-
- 400
-
-
-
-
-
-
- 👉
-
-
-
- Test
+ 46
-
- 150
-
+ 52
- 500
+ 59
-
- 500
-
-
- 500
-
- Test
+ Sub test lvl3
- 180
+ 64
- 600
+ 35
- 600
-
-
- 600
-
-
-
- 600
-
-
-
-
-
-
- 👉
-
-
-
- Test
+ 5
-
- 210
-
+ 65
- 700
+ 78
-
- 700
-
-
- 700
-
- Test
+ Sub test lvl3
- 240
+ 12
- 800
+ 4
- 800
-
-
- 800
-
-
-
- 800
-
-
-
-
-
-
- 👉
-
-
-
- Test
+ 5
-
- 270
-
+ 98
- 900
+ 44
-
- 900
-
-
- 900
-
-
- 👉
-
+
+
+ 👇
+
+
- Test
+ Sub test lvl2
- 300
+ 74
- 1000
+ 5
- 1000
-
-
- 1000
-
-
-
- 1000
-
-
-
-
-
-
- 👉
-
-
-
- Test
+ 2
-
- 330
-
+ 86
- 1100
+ 1
-
- 1100
-
-
- 1100
-
- Test
+ Sub test lvl3
- 360
+ 89
- 1200
+ 98
- 1200
+ 43
- 1200
+ 24
+
+
+
+ 54
+
- Test
+ Sub test lvl3
- 390
+ 52
- 1300
+ 25
- 1300
+ 35
- 1300
+ 97
+
+
+
+ 25
+
- Test
+ Sub test lvl3
- 420
+ 55
- 1400
+ 54
- 1400
+ 33
- 1400
+ 56
+
+
+
+ 24
+
-
- 👉
-
+
+
+ 👇
+
+
- Test
+ Sub test lvl2
- 450
+ 53
- 1500
+ 63
- 1500
+ 3
- 1500
+ 48
+
+
+
+ 24
+
- Test
+ Sub test lvl3
- 480
+ 4
- 1600
+ 653
- 1600
+ 43
- 1600
+ 44
+
+
+
+ 36
+
- Test
+ Sub test lvl3
- 510
+ 49
- 1700
+ 45
- 1700
+ 4
- 1700
+ 35
- 1700
+ 454
-
-
+
+
+
+
+ ,
+ "container": ,
+ "debug": [Function],
+ "findAllByAltText": [Function],
+ "findAllByDisplayValue": [Function],
+ "findAllByLabelText": [Function],
+ "findAllByPlaceholderText": [Function],
+ "findAllByRole": [Function],
+ "findAllByTestId": [Function],
+ "findAllByText": [Function],
+ "findAllByTitle": [Function],
+ "findByAltText": [Function],
+ "findByDisplayValue": [Function],
+ "findByLabelText": [Function],
+ "findByPlaceholderText": [Function],
+ "findByRole": [Function],
+ "findByTestId": [Function],
+ "findByText": [Function],
+ "findByTitle": [Function],
+ "getAllByAltText": [Function],
+ "getAllByDisplayValue": [Function],
+ "getAllByLabelText": [Function],
+ "getAllByPlaceholderText": [Function],
+ "getAllByRole": [Function],
+ "getAllByTestId": [Function],
+ "getAllByText": [Function],
+ "getAllByTitle": [Function],
+ "getByAltText": [Function],
+ "getByDisplayValue": [Function],
+ "getByLabelText": [Function],
+ "getByPlaceholderText": [Function],
+ "getByRole": [Function],
+ "getByTestId": [Function],
+ "getByText": [Function],
+ "getByTitle": [Function],
+ "queryAllByAltText": [Function],
+ "queryAllByDisplayValue": [Function],
+ "queryAllByLabelText": [Function],
+ "queryAllByPlaceholderText": [Function],
+ "queryAllByRole": [Function],
+ "queryAllByTestId": [Function],
+ "queryAllByText": [Function],
+ "queryAllByTitle": [Function],
+ "queryByAltText": [Function],
+ "queryByDisplayValue": [Function],
+ "queryByLabelText": [Function],
+ "queryByPlaceholderText": [Function],
+ "queryByRole": [Function],
+ "queryByTestId": [Function],
+ "queryByText": [Function],
+ "queryByTitle": [Function],
+ "rerender": [Function],
+ "unmount": [Function],
+}
+`;
+
+exports[`Table in RTL renders ExpandedRows 1`] = `
+Object {
+ "asFragment": [Function],
+ "baseElement":
+