@patternfly/react-table 4.112.42 → 4.113.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 (37) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/components/Table/base/provider.d.ts +2 -2
  3. package/components/Table/base/types.d.ts +2 -2
  4. package/components/TableComposable/Td.d.ts +5 -1
  5. package/components/TableComposable/Td.d.ts.map +1 -1
  6. package/components/TableComposable/Td.js +3 -3
  7. package/components/TableComposable/Td.js.map +1 -1
  8. package/components/TableComposable/Th.d.ts +5 -1
  9. package/components/TableComposable/Th.d.ts.map +1 -1
  10. package/components/TableComposable/Th.js +3 -3
  11. package/components/TableComposable/Th.js.map +1 -1
  12. package/dist/esm/components/Table/base/provider.d.ts +2 -2
  13. package/dist/esm/components/Table/base/types.d.ts +2 -2
  14. package/dist/esm/components/TableComposable/Td.d.ts +5 -1
  15. package/dist/esm/components/TableComposable/Td.d.ts.map +1 -1
  16. package/dist/esm/components/TableComposable/Td.js +3 -3
  17. package/dist/esm/components/TableComposable/Td.js.map +1 -1
  18. package/dist/esm/components/TableComposable/Th.d.ts +5 -1
  19. package/dist/esm/components/TableComposable/Th.d.ts.map +1 -1
  20. package/dist/esm/components/TableComposable/Th.js +3 -3
  21. package/dist/esm/components/TableComposable/Th.js.map +1 -1
  22. package/dist/js/components/Table/base/provider.d.ts +2 -2
  23. package/dist/js/components/Table/base/types.d.ts +2 -2
  24. package/dist/js/components/TableComposable/Td.d.ts +5 -1
  25. package/dist/js/components/TableComposable/Td.d.ts.map +1 -1
  26. package/dist/js/components/TableComposable/Td.js +3 -3
  27. package/dist/js/components/TableComposable/Td.js.map +1 -1
  28. package/dist/js/components/TableComposable/Th.d.ts +5 -1
  29. package/dist/js/components/TableComposable/Th.d.ts.map +1 -1
  30. package/dist/js/components/TableComposable/Th.js +3 -3
  31. package/dist/js/components/TableComposable/Th.js.map +1 -1
  32. package/dist/umd/react-table.min.js +1 -1
  33. package/package.json +4 -4
  34. package/src/components/TableComposable/Td.tsx +8 -0
  35. package/src/components/TableComposable/Th.tsx +8 -0
  36. package/src/components/TableComposable/examples/ComposableTable.md +23 -2
  37. package/src/components/TableComposable/examples/ComposableTableRightStickyColumn.tsx +153 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-table",
3
- "version": "4.112.42",
3
+ "version": "4.113.1",
4
4
  "description": "This library provides a set of React table components for use with the PatternFly 4",
5
5
  "main": "dist/js/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -39,9 +39,9 @@
39
39
  "subpaths": "node scripts/copySubpaths.js"
40
40
  },
41
41
  "dependencies": {
42
- "@patternfly/react-core": "^4.276.8",
42
+ "@patternfly/react-core": "^4.276.9",
43
43
  "@patternfly/react-icons": "^4.93.6",
44
- "@patternfly/react-styles": "^4.92.6",
44
+ "@patternfly/react-styles": "^4.92.7",
45
45
  "@patternfly/react-tokens": "^4.94.6",
46
46
  "lodash": "^4.17.19",
47
47
  "tslib": "^2.0.0"
@@ -54,5 +54,5 @@
54
54
  "react": "^16.8 || ^17 || ^18",
55
55
  "react-dom": "^16.8 || ^17 || ^18"
56
56
  },
57
- "gitHead": "8e892ec941ec177d7424f5c6a74694b3c7e53941"
57
+ "gitHead": "fe114d6d5b6d072d2dcfc595bdf8a5836668f924"
58
58
  }
@@ -62,10 +62,14 @@ export interface TdProps extends BaseCellProps, Omit<React.HTMLProps<HTMLTableDa
62
62
  isStickyColumn?: boolean;
63
63
  /** Adds a border to the right side of the cell */
64
64
  hasRightBorder?: boolean;
65
+ /** Adds a border to the left side of the cell */
66
+ hasLeftBorder?: boolean;
65
67
  /** Minimum width for a sticky column */
66
68
  stickyMinWidth?: string;
67
69
  /** Left offset of a sticky column. This will typically be equal to the combined value set by stickyMinWidth of any sticky columns that precede the current sticky column. */
68
70
  stickyLeftOffset?: string;
71
+ /** Right offset of a sticky column. This will typically be equal to the combined value set by stickyMinWidth of any sticky columns that come after the current sticky column. */
72
+ stickyRightOffset?: string;
69
73
  }
70
74
 
71
75
  const TdBase: React.FunctionComponent<TdProps> = ({
@@ -91,8 +95,10 @@ const TdBase: React.FunctionComponent<TdProps> = ({
91
95
  onMouseEnter: onMouseEnterProp = () => {},
92
96
  isStickyColumn = false,
93
97
  hasRightBorder = false,
98
+ hasLeftBorder = false,
94
99
  stickyMinWidth = '120px',
95
100
  stickyLeftOffset,
101
+ stickyRightOffset,
96
102
  ...props
97
103
  }: TdProps) => {
98
104
  const [showTooltip, setShowTooltip] = React.useState(false);
@@ -255,6 +261,7 @@ const TdBase: React.FunctionComponent<TdProps> = ({
255
261
  noPadding && styles.modifiers.noPadding,
256
262
  isStickyColumn && scrollStyles.tableStickyColumn,
257
263
  hasRightBorder && scrollStyles.modifiers.borderRight,
264
+ hasLeftBorder && scrollStyles.modifiers.borderLeft,
258
265
  styles.modifiers[modifier as 'breakWord' | 'fitContent' | 'nowrap' | 'truncate' | 'wrap' | undefined],
259
266
  draggableParams && styles.tableDraggable,
260
267
  mergedClassName
@@ -266,6 +273,7 @@ const TdBase: React.FunctionComponent<TdProps> = ({
266
273
  style: {
267
274
  '--pf-c-table__sticky-column--MinWidth': stickyMinWidth ? stickyMinWidth : undefined,
268
275
  '--pf-c-table__sticky-column--Left': stickyLeftOffset ? stickyLeftOffset : undefined,
276
+ right: stickyRightOffset ? stickyRightOffset : 0,
269
277
  ...props.style
270
278
  } as React.CSSProperties
271
279
  })}
@@ -46,10 +46,14 @@ export interface ThProps
46
46
  isStickyColumn?: boolean;
47
47
  /** Adds a border to the right side of the cell */
48
48
  hasRightBorder?: boolean;
49
+ /** Adds a border to the left side of the cell */
50
+ hasLeftBorder?: boolean;
49
51
  /** Minimum width for a sticky column */
50
52
  stickyMinWidth?: string;
51
53
  /** Left offset of a sticky column. This will typically be equal to the combined value set by stickyMinWidth of any sticky columns that precede the current sticky column. */
52
54
  stickyLeftOffset?: string;
55
+ /** Right offset of a sticky column. This will typically be equal to the combined value set by stickyMinWidth of any sticky columns that come after the current sticky column. */
56
+ stickyRightOffset?: string;
53
57
  /** Indicates the <th> is part of a subheader of a nested header */
54
58
  isSubheader?: boolean;
55
59
  }
@@ -73,8 +77,10 @@ const ThBase: React.FunctionComponent<ThProps> = ({
73
77
  info: infoProps,
74
78
  isStickyColumn = false,
75
79
  hasRightBorder = false,
80
+ hasLeftBorder = false,
76
81
  stickyMinWidth = '120px',
77
82
  stickyLeftOffset,
83
+ stickyRightOffset,
78
84
  isSubheader = false,
79
85
  ...props
80
86
  }: ThProps) => {
@@ -171,6 +177,7 @@ const ThBase: React.FunctionComponent<ThProps> = ({
171
177
  isSubheader && styles.tableSubhead,
172
178
  isStickyColumn && scrollStyles.tableStickyColumn,
173
179
  hasRightBorder && scrollStyles.modifiers.borderRight,
180
+ hasLeftBorder && scrollStyles.modifiers.borderLeft,
174
181
  modifier && styles.modifiers[modifier as 'breakWord' | 'fitContent' | 'nowrap' | 'truncate' | 'wrap'],
175
182
  mergedClassName
176
183
  )}
@@ -180,6 +187,7 @@ const ThBase: React.FunctionComponent<ThProps> = ({
180
187
  style: {
181
188
  '--pf-c-table__sticky-column--MinWidth': stickyMinWidth ? stickyMinWidth : undefined,
182
189
  '--pf-c-table__sticky-column--Left': stickyLeftOffset ? stickyLeftOffset : undefined,
190
+ right: stickyRightOffset ? stickyRightOffset : 0,
183
191
  ...props.style
184
192
  } as React.CSSProperties
185
193
  })}
@@ -333,13 +333,34 @@ To make a column sticky, wrap `TableComposable` with `InnerScrollContainer` and
333
333
  ```ts file="ComposableTableStickyColumn.tsx"
334
334
  ```
335
335
 
336
- ### Composable: Multiple sticky columns
336
+ ### Composable: Multiple left-aligned sticky columns
337
337
 
338
- To make multiple columns sticky, wrap `TableComposable` with `InnerScrollContainer` and add `isStickyColumn` to all columns that should be sticky. The rightmost column should also have the `hasRightBorder` property, and each sticky column after the first must define a `stickyLeftOffset` property that equals the combined width of the previous sticky columns - set by `stickyMinWidth`. To prevent the default text wrapping behavior and allow horizontal scrolling, all `Th` or `Td` cells should also have the `modifier="nowrap"` property.
338
+ To make multiple left-aligned columns sticky:
339
+
340
+ - wrap `TableComposable` with `InnerScrollContainer`
341
+ - add `isStickyColumn` to all columns that should be sticky
342
+ - add `hasRightBorder` to the rightmost sticky column
343
+ - add `stickyLeftOffset` to each sticky column after the first, with a value that equals the combined width - set by `stickyMindWidth` - of the previous sticky columns
344
+
345
+ To prevent the default text wrapping behavior and allow horizontal scrolling, all `Th` or `Td` cells should also have the `modifier="nowrap"` property.
339
346
 
340
347
  ```ts file="ComposableTableMultipleStickyColumns.tsx"
341
348
  ```
342
349
 
350
+ ### Composable: Multiple right-aligned sticky columns
351
+
352
+ To make multiple right-aligned columns sticky:
353
+
354
+ - wrap `TableComposable` with `InnerScrollContainer`
355
+ - add `isStickyColumn` to all columns that should be sticky
356
+ - add `hasLeftBorder` to the leftmost sticky column
357
+ - add `stickyRightOffset` to each sticky column preceding the last, with a value that equals the combined width - set by `stickyMindWidth` - of the next sticky columns
358
+
359
+ To prevent the default text wrapping behavior and allow horizontal scrolling, all `Th` or `Td` cells should also have the `modifier="nowrap"` property.
360
+
361
+ ```ts file="ComposableTableRightStickyColumn.tsx"
362
+ ```
363
+
343
364
  ### Composable: Sticky columns and header
344
365
 
345
366
  To maintain proper sticky behavior across sticky columns and header, `TableComposable` must be wrapped with `OuterScrollContainer` and `InnerScrollContainer`.
@@ -0,0 +1,153 @@
1
+ import React from 'react';
2
+ import { TableComposable, Thead, Tr, Th, Tbody, Td, InnerScrollContainer, ThProps } from '@patternfly/react-table';
3
+
4
+ interface Fact {
5
+ name: string;
6
+ state: string;
7
+ detail1: string;
8
+ detail2: string;
9
+ detail3: string;
10
+ detail4: string;
11
+ detail5: string;
12
+ detail6: string;
13
+ detail7: string;
14
+ }
15
+
16
+ export const ComposableTableRightStickyColumn: React.FunctionComponent = () => {
17
+ // In real usage, this data would come from some external source like an API via props.
18
+ const facts: Fact[] = Array.from({ length: 9 }, (_, index) => ({
19
+ name: `Fact ${index + 1}`,
20
+ state: `State ${index + 1}`,
21
+ detail1: `Test cell ${index + 1}-3`,
22
+ detail2: `Test cell ${index + 1}-4`,
23
+ detail3: `Test cell ${index + 1}-5`,
24
+ detail4: `Test cell ${index + 1}-6`,
25
+ detail5: `Test cell ${index + 1}-7`,
26
+ detail6: `Test cell ${index + 1}-8`,
27
+ detail7: `Test cell ${index + 1}-9`
28
+ }));
29
+
30
+ const columnNames = {
31
+ name: 'Fact',
32
+ state: 'State',
33
+ header3: 'Header 3',
34
+ header4: 'Header 4',
35
+ header5: 'Header 5',
36
+ header6: 'Header 6',
37
+ header7: 'Header 7',
38
+ header8: 'Header 8',
39
+ header9: 'Header 9'
40
+ };
41
+
42
+ // Index of the currently sorted column
43
+ // Note: if you intend to make columns reorderable, you may instead want to use a non-numeric key
44
+ // as the identifier of the sorted column. See the "Compound expandable" example.
45
+ const [activeSortIndex, setActiveSortIndex] = React.useState<number | null>(null);
46
+
47
+ // Sort direction of the currently sorted column
48
+ const [activeSortDirection, setActiveSortDirection] = React.useState<'asc' | 'desc' | null>(null);
49
+
50
+ // Since OnSort specifies sorted columns by index, we need sortable values for our object by column index.
51
+ // This example is trivial since our data objects just contain strings, but if the data was more complex
52
+ // this would be a place to return simplified string or number versions of each column to sort by.
53
+ const getSortableRowValues = (fact: Fact): (string | number)[] => {
54
+ const { name, state, detail1, detail2, detail3, detail4, detail5, detail6, detail7 } = fact;
55
+ return [name, state, detail1, detail2, detail3, detail4, detail5, detail6, detail7];
56
+ };
57
+
58
+ // Note that we perform the sort as part of the component's render logic and not in onSort.
59
+ // We shouldn't store the list of data in state because we don't want to have to sync that with props.
60
+ let sortedFacts = facts;
61
+ if (activeSortIndex !== null) {
62
+ sortedFacts = facts.sort((a, b) => {
63
+ const aValue = getSortableRowValues(a)[activeSortIndex];
64
+ const bValue = getSortableRowValues(b)[activeSortIndex];
65
+ if (aValue === bValue) {
66
+ return 0;
67
+ }
68
+ if (activeSortDirection === 'asc') {
69
+ return aValue > bValue ? 1 : -1;
70
+ } else {
71
+ return bValue > aValue ? 1 : -1;
72
+ }
73
+ });
74
+ }
75
+
76
+ const getSortParams = (columnIndex: number): ThProps['sort'] => ({
77
+ sortBy: {
78
+ index: activeSortIndex,
79
+ direction: activeSortDirection
80
+ },
81
+ onSort: (_event, index, direction) => {
82
+ setActiveSortIndex(index);
83
+ setActiveSortDirection(direction);
84
+ },
85
+ columnIndex
86
+ });
87
+
88
+ return (
89
+ <InnerScrollContainer>
90
+ <TableComposable aria-label="Sticky column table" gridBreakPoint="">
91
+ <Thead>
92
+ <Tr>
93
+ <Th modifier="truncate" sort={getSortParams(0)}>
94
+ {columnNames.name}
95
+ </Th>
96
+ <Th modifier="truncate" sort={getSortParams(1)}>
97
+ {columnNames.state}
98
+ </Th>
99
+ <Th modifier="truncate">{columnNames.header3}</Th>
100
+ <Th modifier="truncate">{columnNames.header4}</Th>
101
+ <Th modifier="truncate">{columnNames.header5}</Th>
102
+ <Th modifier="truncate">{columnNames.header6}</Th>
103
+ <Th modifier="truncate">{columnNames.header7}</Th>
104
+ <Th isStickyColumn hasLeftBorder stickyMinWidth="130px" stickyRightOffset="130px" modifier="truncate">
105
+ {columnNames.header8}
106
+ </Th>
107
+ <Th isStickyColumn stickyMinWidth="130px" modifier="truncate">
108
+ {columnNames.header9}
109
+ </Th>
110
+ </Tr>
111
+ </Thead>
112
+ <Tbody>
113
+ {sortedFacts.map(fact => (
114
+ <Tr key={fact.name}>
115
+ <Th modifier="nowrap">{fact.name}</Th>
116
+ <Td modifier="nowrap" dataLabel={columnNames.state}>
117
+ {fact.state}
118
+ </Td>
119
+ <Td modifier="nowrap" dataLabel={columnNames.header3}>
120
+ {fact.detail1}
121
+ </Td>
122
+ <Td modifier="nowrap" dataLabel={columnNames.header4}>
123
+ {fact.detail2}
124
+ </Td>
125
+ <Td modifier="nowrap" dataLabel={columnNames.header5}>
126
+ {fact.detail3}
127
+ </Td>
128
+ <Td modifier="nowrap" dataLabel={columnNames.header6}>
129
+ {fact.detail4}
130
+ </Td>
131
+ <Td modifier="nowrap" dataLabel={columnNames.header7}>
132
+ {fact.detail5}
133
+ </Td>
134
+ <Td
135
+ isStickyColumn
136
+ hasLeftBorder
137
+ stickyMinWidth="130px"
138
+ stickyRightOffset="130px"
139
+ modifier="nowrap"
140
+ dataLabel={columnNames.header8}
141
+ >
142
+ {fact.detail6}
143
+ </Td>
144
+ <Td isStickyColumn stickyMinWidth="130px" modifier="nowrap" dataLabel={columnNames.header9}>
145
+ {fact.detail7}
146
+ </Td>
147
+ </Tr>
148
+ ))}
149
+ </Tbody>
150
+ </TableComposable>
151
+ </InnerScrollContainer>
152
+ );
153
+ };