Skip to content

Commit a4dbf21

Browse files
committed
feat(DataTable): implement TanStack Table (#2055)
- use tanstack as basis for table implementation - add in relevant stories for styles - add in snapshots for tests
1 parent 269ba31 commit a4dbf21

File tree

11 files changed

+5753
-543
lines changed

11 files changed

+5753
-543
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"dependencies": {
9191
"@headlessui/react": "^1.7.19",
9292
"@popperjs/core": "^2.11.8",
93+
"@tanstack/react-table": "^8.20.5",
9394
"@tippyjs/react": "^4.2.6",
9495
"chalk": "^4.1.2",
9596
"clsx": "^2.1.1",

src/components/DataTable/DataTable.module.css

+134-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
# DATA TABLE
33
\*------------------------------------*/
44

5-
/**
6-
* DataTable
7-
*/
8-
95
/* Visible table caption */
6+
/* TODO-AH: make it so that we have the search bar and actions wrap together instead of separately */
107
.data-table__caption-container {
118
display: flex;
129
align-items: flex-end;
@@ -15,7 +12,7 @@
1512
gap: calc(var(--eds-size-3) / 16 * 1rem) calc(var(--eds-size-6) / 16 * 1rem);
1613

1714
text-align: start;
18-
margin: 0 calc(var(--eds-size-3) / 16 * 1rem) calc(var(--eds-size-4) / 16 * 1rem);
15+
margin: 0 calc(var(--eds-size-3) / 16 * 1rem) calc(var(--eds-size-4) / 16 * 1rem);
1916
}
2017

2118
.data-table__caption-text {
@@ -37,9 +34,15 @@
3734
}
3835

3936
.data-table__table {
40-
border: 1px solid;
37+
table-layout: fixed;
4138
width: 100%;
4239

40+
/* add class instead of tag for styles? */
41+
th, td {
42+
padding: 0;
43+
vertical-align: top;
44+
}
45+
4346
.data-table__caption + &,
4447
.data-table__subcaption + & {
4548
margin-top: calc(var(--eds-size-4) / 16 * 1rem);
@@ -50,11 +53,116 @@
5053
width: calc(var(--eds-size-34) / 16 * 1rem);
5154
}
5255

56+
.data-table--tableStyle-border {
57+
border: calc(var(--eds-border-width-sm) * 1px) solid;
58+
}
59+
60+
.data-table__cell-text {
61+
text-align: start;
62+
63+
.data-table__cell--alignment-leading & {
64+
text-align: start;
65+
}
66+
67+
.data-table__cell--alignment-trailing & {
68+
text-align: end;
69+
}
70+
}
71+
72+
.data-table__cell--alignment-leading {
73+
justify-content: flex-start;
74+
}
75+
76+
.data-table__cell--alignment-trailing {
77+
justify-content: flex-end;
78+
}
79+
80+
.data-table__cell-sublabel {
81+
display: block;
82+
font: var(--eds-theme-typography-body-sm);
83+
}
84+
85+
.data-table__header-cell {
86+
display: flex;
87+
gap: calc(var(--eds-size-1) / 16 * 1rem);
88+
align-items: flex-start;
89+
font: var(--eds-theme-typography-title-md);
90+
91+
.data-table--size-sm & {
92+
font: var(--eds-theme-typography-title-sm);
93+
/* TODO(bug): we want to use top-/bottom-padding of 5px (instead of 4px) to give overall height divisible by 8 (32px) */
94+
padding: calc(var(--eds-size-half) / 16 * 1rem) calc(var(--eds-size-1) / 16 * 1rem);
95+
}
96+
97+
.data-table--size-md & {
98+
padding: calc(var(--eds-size-2) / 16 * 1rem) calc(var(--eds-size-3) / 16 * 1rem);
99+
}
100+
101+
.data-cell__cell--icon {
102+
margin-top: calc(var(--eds-size-1) / 16 * 1rem);
103+
flex-shrink: 0;
104+
105+
.data-table--size-sm & {
106+
margin-top: calc(var(--eds-size-half) / 16 * 1rem);
107+
}
108+
}
109+
}
110+
111+
.data-table__cell {
112+
display: flex;
113+
gap: calc(var(--eds-size-1) / 16 * 1rem);
114+
align-items: flex-start;
115+
font: var(--eds-theme-typography-body-md);
116+
117+
.data-table--size-sm & {
118+
font: var(--eds-theme-typography-body-sm);
119+
padding: calc(var(--eds-size-half) / 16 * 1rem) calc(var(--eds-size-1) / 16 * 1rem);
120+
}
121+
122+
.data-table--size-md & {
123+
padding: calc(var(--eds-size-2) / 16 * 1rem) calc(var(--eds-size-3) / 16 * 1rem);
124+
}
125+
126+
.data-cell__cell--icon {
127+
margin-top: calc(var(--eds-size-half) / 16 * 1rem);
128+
flex-shrink: 0;
129+
}
130+
}
131+
132+
.data-table__row {
133+
.data-table--rowStyle-lined & {
134+
border-bottom: calc(var(--eds-border-width-sm) * 1px) solid;
135+
}
136+
137+
.data-table--rowStyle-striped &:nth-child(even) {
138+
background-color: var(--eds-theme-color-background-table-row-stripe-2);
139+
}
140+
141+
.data-table--rowStyle-striped &:nth-child(odd) {
142+
background-color: var(--eds-theme-color-background-table-row-stripe-1);
143+
}
144+
}
145+
146+
.data-table__header-row {
147+
border-bottom: calc(var(--eds-border-width-sm) * 1px) solid;
148+
position: sticky;
149+
top: 0;
150+
}
151+
53152
/**
54153
* Color Tokens
55154
*/
56155
.data-table {
57156
display: block;
157+
position: relative;
158+
159+
.data-table__table {
160+
background-color: var(--eds-theme-color-background-utility-base-1);
161+
162+
th {
163+
background-color: var(--eds-theme-color-background-utility-base-1);
164+
}
165+
}
58166

59167
.data-table__caption {
60168
color: var(--eds-theme-color-text-utility-default-primary);
@@ -63,4 +171,24 @@
63171
.data-table__subcaption {
64172
color: var(--eds-theme-color-text-utility-default-secondary);
65173
}
174+
175+
.data-table--tableStyle-border, .data-table__header-row {
176+
border-color: var(--eds-theme-color-border-utility-default-low-emphasis);
177+
}
178+
179+
.data-table__header-cell {
180+
color: var(--eds-theme-color-text-utility-default-primary);
181+
}
182+
183+
.data-table__cell {
184+
color: var(--eds-theme-color-text-utility-default-primary);
185+
}
186+
187+
.data-table--rowStyle-lined {
188+
color: var(--eds-theme-color-border-utility-default-low-emphasis);
189+
}
190+
191+
.data-table__cell-sublabel, .data-table__header-cell-sublabel {
192+
color: var(--eds-theme-color-text-utility-default-secondary);
193+
}
66194
}

0 commit comments

Comments
 (0)