@tcn/ui-table 2.3.4 → 2.3.6

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 (44) hide show
  1. package/dist/cell.css +1 -1
  2. package/dist/components/cells/data_cell.d.ts.map +1 -1
  3. package/dist/components/cells/data_cell.js +4 -3
  4. package/dist/components/cells/data_cell.js.map +1 -1
  5. package/dist/components/cells/footer_cell.d.ts.map +1 -1
  6. package/dist/components/cells/footer_cell.js +5 -4
  7. package/dist/components/cells/footer_cell.js.map +1 -1
  8. package/dist/components/cells/header_cell.d.ts +3 -5
  9. package/dist/components/cells/header_cell.d.ts.map +1 -1
  10. package/dist/components/cells/header_cell.js +49 -37
  11. package/dist/components/cells/header_cell.js.map +1 -1
  12. package/dist/components/cells/sort_control.d.ts +8 -0
  13. package/dist/components/cells/sort_control.d.ts.map +1 -0
  14. package/dist/components/cells/sort_control.js +27 -0
  15. package/dist/components/cells/sort_control.js.map +1 -0
  16. package/dist/components/cells/sticky_row_data_cell.d.ts.map +1 -1
  17. package/dist/components/cells/sticky_row_data_cell.js +14 -13
  18. package/dist/components/cells/sticky_row_data_cell.js.map +1 -1
  19. package/dist/components/cells/sticky_row_fill_cell.d.ts.map +1 -1
  20. package/dist/components/cells/sticky_row_fill_cell.js +4 -3
  21. package/dist/components/cells/sticky_row_fill_cell.js.map +1 -1
  22. package/dist/components/table/table.d.ts.map +1 -1
  23. package/dist/components/table/table.js +66 -64
  24. package/dist/components/table/table.js.map +1 -1
  25. package/dist/components/table_filter_panel/field_filters/string_field_filter.d.ts.map +1 -1
  26. package/dist/components/table_filter_panel/field_filters/string_field_filter.js +21 -20
  27. package/dist/components/table_filter_panel/field_filters/string_field_filter.js.map +1 -1
  28. package/dist/components/table_pager.d.ts.map +1 -1
  29. package/dist/components/table_pager.js +34 -16
  30. package/dist/components/table_pager.js.map +1 -1
  31. package/dist/table.css +1 -1
  32. package/package.json +4 -4
  33. package/src/__stories__/table.stories.tsx +232 -195
  34. package/src/components/cells/cell.module.css +7 -45
  35. package/src/components/cells/data_cell.tsx +3 -2
  36. package/src/components/cells/footer_cell.tsx +3 -2
  37. package/src/components/cells/header_cell.tsx +19 -28
  38. package/src/components/cells/sort_control.tsx +44 -0
  39. package/src/components/cells/sticky_row_data_cell.tsx +3 -2
  40. package/src/components/cells/sticky_row_fill_cell.tsx +3 -2
  41. package/src/components/table/table.module.css +24 -212
  42. package/src/components/table/table.tsx +35 -24
  43. package/src/components/table_filter_panel/field_filters/string_field_filter.tsx +1 -0
  44. package/src/components/table_pager.tsx +12 -2
@@ -2,22 +2,17 @@ import React, { useCallback } from 'react';
2
2
 
3
3
  import { Box, HStack } from '@tcn/ui/stacks';
4
4
 
5
- import { TwoClassSortDownIcon } from '@tcn/icons/two_class_sort_down_icon.js';
6
- import { TwoClassSortFilledIcon } from '@tcn/icons/two_class_sort_filled_icon.js';
7
- import { TwoClassSortUpIcon } from '@tcn/icons/two_class_sort_up_icon.js';
8
- import { Button } from '@tcn/ui/actions';
9
5
  import cellStyles from './cell.module.css';
6
+ import { SortControl, type SortControlProps } from './sort_control.js';
7
+ import { TH } from '@tcn/ui/layouts';
10
8
 
11
- export type HeaderCellProps = {
9
+ export interface HeaderCellProps extends SortControlProps {
12
10
  heading: React.ReactNode;
13
11
  index: number;
14
12
  sticky?: 'start' | 'end';
15
13
  onResize?: (width: number) => void;
16
14
  width?: number;
17
- sortMode?: 'none' | 'asc' | 'desc';
18
- onSortModeChange?: () => void;
19
- canSort?: boolean;
20
- };
15
+ }
21
16
 
22
17
  export function HeaderCell({
23
18
  heading,
@@ -38,40 +33,36 @@ export function HeaderCell({
38
33
  );
39
34
 
40
35
  return (
41
- <th
36
+ <TH
42
37
  className={cellStyles['table-cell']}
43
38
  data-stick-to={sticky}
44
39
  style={{ width: `${width}px`, zIndex }}
45
40
  >
46
41
  <Box
47
- padding="4px 6px"
42
+ padding="0px 8px" // FIXME: should be on theme ideally.
48
43
  overflow="hidden"
49
- minWidth="20px"
44
+ minWidth="24px"
50
45
  enableResizeOnEnd
51
46
  onWidthResize={handleResize}
52
47
  style={{ width: `${width}px`, minWidth: '20px' }}
53
48
  onClick={e => e.stopPropagation()}
54
- height="30px"
55
49
  >
56
50
  <HStack>
57
- <Box className="ellipsis" style={{ alignItems: 'center', display: 'flex' }}>
51
+ <Box
52
+ minWidth="24px"
53
+ className="ellipsis"
54
+ style={{ alignItems: 'center', display: 'flex' }}
55
+ >
58
56
  {heading}
59
57
  </Box>
60
- <Box width="auto" height="auto">
61
- {canSort && (
62
- <Button onClick={() => onSortModeChange?.()} hierarchy="tertiary">
63
- {sortMode === 'asc' ? (
64
- <TwoClassSortDownIcon />
65
- ) : sortMode === 'desc' ? (
66
- <TwoClassSortUpIcon />
67
- ) : (
68
- <TwoClassSortFilledIcon />
69
- )}
70
- </Button>
71
- )}
72
- </Box>
58
+
59
+ <SortControl
60
+ canSort={canSort}
61
+ onSortModeChange={onSortModeChange}
62
+ sortMode={sortMode}
63
+ />
73
64
  </HStack>
74
65
  </Box>
75
- </th>
66
+ </TH>
76
67
  );
77
68
  }
@@ -0,0 +1,44 @@
1
+ import React, { useCallback } from 'react';
2
+
3
+ import { Box } from '@tcn/ui/stacks';
4
+
5
+ import { TwoClassSortDownIcon } from '@tcn/icons/two_class_sort_down_icon.js';
6
+ import { TwoClassSortFilledIcon } from '@tcn/icons/two_class_sort_filled_icon.js';
7
+ import { TwoClassSortUpIcon } from '@tcn/icons/two_class_sort_up_icon.js';
8
+ import { Button } from '@tcn/ui/actions';
9
+
10
+ export type SortMode = 'asc' | 'desc' | 'none';
11
+
12
+ export interface SortControlProps {
13
+ canSort?: boolean;
14
+ onSortModeChange?: () => void;
15
+ sortMode?: SortMode;
16
+ }
17
+
18
+ const sortIconMap: Record<SortMode, React.ComponentType<any>> = {
19
+ asc: TwoClassSortDownIcon,
20
+ desc: TwoClassSortUpIcon,
21
+ none: TwoClassSortFilledIcon,
22
+ };
23
+
24
+ export const SortControl = ({
25
+ canSort,
26
+ onSortModeChange,
27
+ sortMode = 'none',
28
+ }: SortControlProps) => {
29
+ const handleSortModeChange = useCallback(() => {
30
+ onSortModeChange?.();
31
+ }, [onSortModeChange]);
32
+
33
+ if (!canSort) return null;
34
+
35
+ const SortIcon = sortIconMap[sortMode];
36
+
37
+ return (
38
+ <Box width="auto" height="auto">
39
+ <Button utility onClick={handleSortModeChange} hierarchy="tertiary">
40
+ <SortIcon />
41
+ </Button>
42
+ </Box>
43
+ );
44
+ };
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import cellStyles from './cell.module.css';
3
+ import { TD } from '@tcn/ui/layouts';
3
4
 
4
5
  export type StickyRowDataCellProps = {
5
6
  content: React.ReactNode;
@@ -15,7 +16,7 @@ export function StickyRowDataCell({
15
16
  top,
16
17
  }: StickyRowDataCellProps) {
17
18
  return (
18
- <td
19
+ <TD
19
20
  className={cellStyles['sticky-row-table-cell']}
20
21
  data-stick-to={sticky}
21
22
  style={{
@@ -26,6 +27,6 @@ export function StickyRowDataCell({
26
27
  }}
27
28
  >
28
29
  <div>{content}</div>
29
- </td>
30
+ </TD>
30
31
  );
31
32
  }
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import cellStyles from './cell.module.css';
3
+ import { TD } from '@tcn/ui/layouts';
3
4
 
4
5
  export type StyckyRowFillCellProps = {
5
6
  top?: number;
@@ -7,10 +8,10 @@ export type StyckyRowFillCellProps = {
7
8
 
8
9
  export function StickyRowFillCell({ top }: StyckyRowFillCellProps) {
9
10
  return (
10
- <td
11
+ <TD
11
12
  className={cellStyles['sticky-row-table-cell']}
12
13
  data-stick-to="start"
13
14
  style={{ top: `${top}px` }}
14
- ></td>
15
+ ></TD>
15
16
  );
16
17
  }
@@ -1,38 +1,36 @@
1
- .table-body-wrapper {
2
- box-shadow: var(--table-box-shadow, inset 0px 1px 2px 0px rgba(0, 0, 0, 0.5));
3
- font-family:
4
- -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell,
5
- "Open Sans", "Helvetica Neue", sans-serif;
6
- color: #333;
7
- }
8
-
9
1
  .table-body {
10
2
  border-spacing: 0;
11
3
  width: auto;
12
4
  min-width: 100%;
13
5
  height: auto;
14
6
  min-height: 100%;
15
- font-size: 12px;
16
7
  table-layout: fixed;
17
- background-color: #ebebeb;
18
- }
19
-
20
- :global(.dark-mode) .table-body {
21
- background-color: #333;
22
- color: rgba(255, 255, 255, 0.9);
23
- }
24
-
25
- td {
26
- text-align: start;
27
- overflow: hidden;
28
- white-space: nowrap;
29
- text-overflow: ellipsis;
30
- background-color: inherit;
8
+ display: table;
31
9
  }
32
10
 
33
- .table-body tr {
34
- font-size: 12px;
35
- }
11
+ /* FIXME: These styles should be handled at the theme level
12
+ but tcn ui does not handle resizing or sticky logic. */
13
+ /* Reset padding for header - due to resize logic */
14
+ .table-body thead {
15
+ th,
16
+ td {
17
+ padding: 0;
18
+ }
19
+ }
20
+
21
+ .table-body thead tr,
22
+ .table-body tbody tr {
23
+ th[data-stick-to="start"],
24
+ td[data-stick-to="start"] {
25
+ border-inline-end: 1px solid #ccc;
26
+ }
27
+ th[data-stick-to="end"],
28
+ td[data-stick-to="end"] {
29
+ border-inline-start: 1px solid #ccc;
30
+ }
31
+ }
32
+ /* ^^^^ */
33
+ /* This needs a better solution w/ theming system */
36
34
 
37
35
  .table-body tr[data-clickable="true"] {
38
36
  cursor: pointer;
@@ -61,109 +59,15 @@ td {
61
59
  z-index: 2;
62
60
  }
63
61
 
64
- .table-body th {
65
- --accent-color: #0077aa;
66
- --accent-surface-light: color-mix(in srgb, var(--accent-color) 8%, white);
67
- background-color: var(--accent-surface-light);
68
- color: #000; /* Black text color */
69
- font-weight: normal;
70
- text-align: start;
71
- }
72
-
73
62
  .table-body th > div {
74
- border-inline-start: 1px solid #ccc;
75
- border-bottom: 1px solid #ccc;
76
63
  display: flex;
77
64
  align-items: center;
78
65
  }
79
66
 
80
- .table-body th:first-child > div {
81
- border-inline-start: none;
82
- }
83
-
84
- .table-body th:last-child > div {
85
- border-inline: 1px solid #ccc;
86
- }
87
-
88
- :global(.dark-mode) .table-body th:last-child {
89
- border-inline: 1px solid #202020;
90
- }
91
-
92
- .table-body td:last-child > div {
93
- border-inline: 1px solid #ccc;
94
- }
95
-
96
- :global(.dark-mode) .table-body td:last-child > div {
97
- border-inline: 1px solid #202020;
98
- }
99
-
100
- :global(.dark-mode) .table-body th {
101
- color: rgba(255, 255, 255, 0.9);
102
- border-bottom: 1px solid #202020;
103
- border-inline-start: 1px solid #202020;
104
- background-color: #333;
105
- }
106
-
107
67
  .table-body td > div {
108
68
  height: 100%;
109
69
  display: flex;
110
70
  align-items: center;
111
- border-bottom: 1px solid #e0e0e0; /* Lighter border for cells */
112
- }
113
-
114
- :global(.dark-mode) .table-body td > div {
115
- border-bottom: 1px solid #202020; /* Lighter border for cells */
116
- }
117
-
118
- .table-body tr:nth-child(odd) {
119
- background-color: #f1f1f1;
120
- }
121
-
122
- .table-body tr:nth-child(even) {
123
- background-color: rgba(255, 255, 255);
124
- }
125
-
126
- :global(.dark-mode) .table-body tr:nth-child(odd) {
127
- background-color: #3b3b3b; /* Zebra striping for rows */
128
- }
129
-
130
- :global(.dark-mode) .table-body tr:nth-child(even) {
131
- background-color: #2e2e2e;
132
- }
133
-
134
- /* Hover effect for rows */
135
- .table-body tr:hover {
136
- background-color: #dedede;
137
- }
138
-
139
- :global(.dark-mode) .table-body tr:hover {
140
- background-color: rgba(30, 30, 30, 1);
141
- }
142
-
143
- /* Styling for the table's header row to mimic macOS window styling */
144
- .table-body thead {
145
- box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); /* Subtle shadow for depth */
146
- }
147
-
148
- /* Footer styling, if applicable */
149
- .table-body tfoot td {
150
- background-color: #f0f0f0;
151
- font-weight: bold;
152
- }
153
-
154
- .table-body tr:global(.fill) {
155
- height: auto;
156
- }
157
-
158
- .table-body tr td:global(.fill) {
159
- width: auto;
160
- min-width: none;
161
- background-color: inherit;
162
- }
163
-
164
- .table-body tr th:global(.fill) {
165
- width: auto;
166
- background-color: inherit;
167
71
  }
168
72
 
169
73
  .table-body tfoot {
@@ -171,103 +75,11 @@ td {
171
75
  bottom: 0px;
172
76
  }
173
77
 
174
- .table-body tr[data-selected="true"] {
175
- background-color: var(--accent-color, #549aff);
176
- color: #fff;
177
- }
178
-
179
- :global(.dark-mode) .table-body tr[data-selected="true"] {
180
- background-color: var(--accent-color, #549aff);
181
- color: #fff;
182
- }
183
-
184
78
  .table-body td,
185
79
  .table-body th {
186
- /* padding: 4px 0; */
187
- max-height: 30px;
188
- height: 30px;
189
- font-size: 12px;
190
80
  vertical-align: middle;
191
81
  }
192
82
 
193
- .table-body td:first-child > div {
194
- padding-inline-start: var(--surface-inset, 6px);
195
- }
196
-
197
- .table-body td:last-child > div {
198
- padding-inline-end: var(--surface-inset, 6px);
199
- }
200
-
201
- :global(.small-text) .table-body td,
202
- :global(.small-text) .table-body th {
203
- /* padding: 2px 4px; */
204
- max-height: 20px;
205
- height: 20px;
206
- font-size: 10px;
207
- }
208
-
209
- :global(.medium-small-text) .table-body td,
210
- :global(.medium-small-text) .table-body th {
211
- /* padding: 4px 6px; */
212
- max-height: 22px;
213
- height: 22px;
214
- font-size: 12px;
215
- }
216
-
217
- :global(.medium-text) .table-body td,
218
- :global(.medium-text) .table-body th {
219
- /* padding: 6px 8px; */
220
- max-height: 24px;
221
- height: 24px;
222
- font-size: 14px;
223
- }
224
-
225
- :global(.medium-large-text) .table-body td,
226
- :global(.medium-large-text) .table-body th {
227
- /* padding: 8px 10px; */
228
- max-height: 26px;
229
- height: 26px;
230
- font-size: 16px;
231
- }
232
-
233
- :global(.large-text) .table-body td,
234
- :global(.large-text) .table-body th {
235
- /* padding: 10px 12px; */
236
- height: 28px;
237
- max-height: 28px;
238
- font-size: 18px;
239
- }
240
-
241
- .table-body th {
242
- padding: 0 !important;
243
- }
244
-
245
- .table-body tr th:global(.spacer) {
246
- background-color: #f1f1f1;
247
- }
248
-
249
- :global(.dark-mode) .table-body tr th:global(.spacer) {
250
- background-color: #333;
251
- }
252
-
253
- .table-body tr th:global(.fill) {
254
- background-color: #f1f1f1;
255
- }
256
-
257
- :global(.dark-mode) .table-body tr th:global(.fill) {
258
- background-color: #333;
259
- }
260
-
261
- /* sticky stuff */
262
-
263
- .table-body tr[data-sticky-row] td {
264
- background-color: rgb(204, 204, 204);
265
- }
266
-
267
- :global(.dark-mode) .table-body tr[data-sticky-row] td {
268
- background-color: rgb(47, 47, 47);
269
- }
270
-
271
83
  .table-body[data-is-clickable="true"] td {
272
84
  cursor: pointer;
273
85
  }
@@ -12,7 +12,15 @@ import { StickyRowFillCell } from '../cells/sticky_row_fill_cell.js';
12
12
  import styles from './table.module.css';
13
13
  import { TableColumn, TableColumnProps } from './table_column.js';
14
14
  import { TablePresenter } from './table_presenter.js';
15
-
15
+ import {
16
+ TTable as PrimitiveTable,
17
+ TBody,
18
+ TD,
19
+ TFoot,
20
+ TH,
21
+ THead,
22
+ TR,
23
+ } from '@tcn/ui/layouts';
16
24
  export type TableProps<T> = BoxProps & {
17
25
  dataSource: DataSource<T>;
18
26
  children: ReactElement<TableColumnProps<T>>[];
@@ -21,7 +29,9 @@ export type TableProps<T> = BoxProps & {
21
29
  stickyItems?: T[];
22
30
  };
23
31
 
24
- const HEADER_ROW_HEIGHT = 30;
32
+ // FIXME: Ideally should be on theme - even if its a required theme variable.
33
+ const HEADER_ROW_HEIGHT = 32;
34
+ const BODY_ROW_HEIGHT = 24;
25
35
 
26
36
  // @TODO: Props for loading and error states
27
37
 
@@ -84,13 +94,13 @@ export function Table<T>({
84
94
  style={{ overflow: 'auto' }}
85
95
  {...props}
86
96
  >
87
- <table
97
+ <PrimitiveTable
88
98
  className={styles['table-body']}
89
99
  data-is-clickable={isClickable}
90
100
  style={{ width, height }}
91
101
  >
92
- <thead>
93
- <tr>
102
+ <THead>
103
+ <TR>
94
104
  {columnInfo.map((column, index) => (
95
105
  <HeaderCell
96
106
  key={`h-${index}`}
@@ -104,12 +114,12 @@ export function Table<T>({
104
114
  canSort={column.canSort}
105
115
  />
106
116
  ))}
107
- <th key="fill" className="fill"></th>
108
- </tr>
109
- </thead>
110
- <tbody>
117
+ <TH key="fill" fill className="fill"></TH>
118
+ </TR>
119
+ </THead>
120
+ <TBody>
111
121
  {stickyItems?.map((item, index) => (
112
- <tr key={`sticky-${index}`} data-sticky-row>
122
+ <TR key={`sticky-${index}`} data-sticky-row>
113
123
  {columnInfo.map((col, colIndex) => {
114
124
  const fieldName = col.fieldName;
115
125
  const render = col.render;
@@ -124,18 +134,19 @@ export function Table<T>({
124
134
  content={content}
125
135
  sticky={col.sticky}
126
136
  width={col.width}
127
- top={HEADER_ROW_HEIGHT * (index + 1)}
137
+ top={HEADER_ROW_HEIGHT + BODY_ROW_HEIGHT * index}
128
138
  />
129
139
  );
130
140
  })}
131
- <StickyRowFillCell top={HEADER_ROW_HEIGHT * (index + 1) + 1} />
132
- </tr>
141
+ <StickyRowFillCell top={HEADER_ROW_HEIGHT + BODY_ROW_HEIGHT * index} />
142
+ </TR>
133
143
  ))}
134
144
  {itemsStatus === Status.SUCCESS &&
135
145
  rows.map((item, rowIndex) => (
136
- <tr
146
+ <TR
137
147
  key={`${page}-${rowIndex}`}
138
148
  data-selected={isRowHighlighted?.(item, rowIndex)}
149
+ isSelected={isRowHighlighted?.(item, rowIndex)}
139
150
  onClick={() => onRowClick?.(item, rowIndex)}
140
151
  >
141
152
  {columnInfo.map((col, colIndex) => {
@@ -155,16 +166,16 @@ export function Table<T>({
155
166
  />
156
167
  );
157
168
  })}
158
- <td key="fill" className="fill"></td>
159
- </tr>
169
+ <TD key="fill" fill className="fill"></TD>
170
+ </TR>
160
171
  ))}
161
172
  {itemsStatus === Status.PENDING && 'Loading...'}
162
173
  {itemsStatus === Status.ERROR && 'Error loading data'}
163
- <tr key="fill" className="fill"></tr>
164
- </tbody>
174
+ <TR key="fill" className="fill"></TR>
175
+ </TBody>
165
176
  {showFooter && (
166
- <tfoot>
167
- <tr>
177
+ <TFoot>
178
+ <TR>
168
179
  {columnInfo.map((col, colIndex) => (
169
180
  <FooterCell
170
181
  key={`footer-${colIndex}`}
@@ -173,11 +184,11 @@ export function Table<T>({
173
184
  width={col.width}
174
185
  />
175
186
  ))}
176
- <td key="footer-fill" className="fill"></td>
177
- </tr>
178
- </tfoot>
187
+ <TD key="footer-fill" fill className="fill"></TD>
188
+ </TR>
189
+ </TFoot>
179
190
  )}
180
- </table>
191
+ </PrimitiveTable>
181
192
  </Box>
182
193
  );
183
194
  }
@@ -60,6 +60,7 @@ export function StringFieldFilter({ fieldName, label, operators }: FieldFilterPr
60
60
  <Button
61
61
  onClick={() => presenter.setValue(null)}
62
62
  hierarchy="tertiary"
63
+ utility
63
64
  disabled={value == null}
64
65
  >
65
66
  <CrossCircleIcon />
@@ -28,10 +28,20 @@ export function TablePager<T>({ dataSource, ...props }: TablePagerProps<T>) {
28
28
  <BodyText>Page:</BodyText>
29
29
  <BodyText className={styles['page-count']}>{pageIndex + 1}</BodyText>
30
30
  </HStack>
31
- <Button onClick={() => dataSource.previousPage()} disabled={pageIndex === 0}>
31
+ <Button
32
+ utility
33
+ hierarchy="tertiary"
34
+ onClick={() => dataSource.previousPage()}
35
+ disabled={pageIndex === 0}
36
+ >
32
37
  <ChevronLeftIcon flipOnRtl />
33
38
  </Button>
34
- <Button onClick={() => dataSource.nextPage()} disabled={!hasNextPage}>
39
+ <Button
40
+ utility
41
+ hierarchy="tertiary"
42
+ onClick={() => dataSource.nextPage()}
43
+ disabled={!hasNextPage}
44
+ >
35
45
  <ChevronRightIcon flipOnRtl />
36
46
  </Button>
37
47
  </HStack>