@patternfly/react-table 6.0.0-alpha.5 → 6.0.0-alpha.7

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 (67) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/components/package.json +1 -1
  3. package/deprecated/package.json +1 -1
  4. package/dist/dynamic/components/Table/package.json +1 -1
  5. package/dist/dynamic/components/Table/utils/decorators/package.json +1 -1
  6. package/dist/dynamic/components/Table/utils/package.json +1 -1
  7. package/dist/dynamic/deprecated/components/Table/base/package.json +1 -1
  8. package/dist/dynamic/deprecated/components/Table/package.json +1 -1
  9. package/dist/dynamic/deprecated/components/package.json +1 -1
  10. package/dist/esm/components/Table/SelectColumn.d.ts +5 -0
  11. package/dist/esm/components/Table/SelectColumn.d.ts.map +1 -1
  12. package/dist/esm/components/Table/SelectColumn.js +6 -3
  13. package/dist/esm/components/Table/SelectColumn.js.map +1 -1
  14. package/dist/esm/components/Table/SortColumn.d.ts +4 -0
  15. package/dist/esm/components/Table/SortColumn.d.ts.map +1 -1
  16. package/dist/esm/components/Table/SortColumn.js +2 -2
  17. package/dist/esm/components/Table/SortColumn.js.map +1 -1
  18. package/dist/esm/components/Table/TableText.d.ts +3 -1
  19. package/dist/esm/components/Table/TableText.d.ts.map +1 -1
  20. package/dist/esm/components/Table/TableText.js +12 -10
  21. package/dist/esm/components/Table/TableText.js.map +1 -1
  22. package/dist/esm/components/Table/TableTypes.d.ts +3 -0
  23. package/dist/esm/components/Table/TableTypes.d.ts.map +1 -1
  24. package/dist/esm/components/Table/Th.d.ts +3 -0
  25. package/dist/esm/components/Table/Th.d.ts.map +1 -1
  26. package/dist/esm/components/Table/Th.js +14 -7
  27. package/dist/esm/components/Table/Th.js.map +1 -1
  28. package/dist/esm/components/Table/utils/decorators/selectable.d.ts.map +1 -1
  29. package/dist/esm/components/Table/utils/decorators/selectable.js +2 -2
  30. package/dist/esm/components/Table/utils/decorators/selectable.js.map +1 -1
  31. package/dist/esm/components/Table/utils/decorators/sortable.d.ts.map +1 -1
  32. package/dist/esm/components/Table/utils/decorators/sortable.js +6 -3
  33. package/dist/esm/components/Table/utils/decorators/sortable.js.map +1 -1
  34. package/dist/js/components/Table/SelectColumn.d.ts +5 -0
  35. package/dist/js/components/Table/SelectColumn.d.ts.map +1 -1
  36. package/dist/js/components/Table/SelectColumn.js +6 -3
  37. package/dist/js/components/Table/SelectColumn.js.map +1 -1
  38. package/dist/js/components/Table/SortColumn.d.ts +4 -0
  39. package/dist/js/components/Table/SortColumn.d.ts.map +1 -1
  40. package/dist/js/components/Table/SortColumn.js +3 -2
  41. package/dist/js/components/Table/SortColumn.js.map +1 -1
  42. package/dist/js/components/Table/TableText.d.ts +3 -1
  43. package/dist/js/components/Table/TableText.d.ts.map +1 -1
  44. package/dist/js/components/Table/TableText.js +12 -10
  45. package/dist/js/components/Table/TableText.js.map +1 -1
  46. package/dist/js/components/Table/TableTypes.d.ts +3 -0
  47. package/dist/js/components/Table/TableTypes.d.ts.map +1 -1
  48. package/dist/js/components/Table/Th.d.ts +3 -0
  49. package/dist/js/components/Table/Th.d.ts.map +1 -1
  50. package/dist/js/components/Table/Th.js +14 -7
  51. package/dist/js/components/Table/Th.js.map +1 -1
  52. package/dist/js/components/Table/utils/decorators/selectable.d.ts.map +1 -1
  53. package/dist/js/components/Table/utils/decorators/selectable.js +2 -2
  54. package/dist/js/components/Table/utils/decorators/selectable.js.map +1 -1
  55. package/dist/js/components/Table/utils/decorators/sortable.d.ts.map +1 -1
  56. package/dist/js/components/Table/utils/decorators/sortable.js +6 -3
  57. package/dist/js/components/Table/utils/decorators/sortable.js.map +1 -1
  58. package/dist/umd/react-table.min.js +3 -3
  59. package/package.json +6 -6
  60. package/src/components/Table/SelectColumn.tsx +27 -8
  61. package/src/components/Table/SortColumn.tsx +15 -1
  62. package/src/components/Table/TableText.tsx +19 -9
  63. package/src/components/Table/TableTypes.tsx +3 -0
  64. package/src/components/Table/Th.tsx +16 -5
  65. package/src/components/Table/utils/decorators/selectable.tsx +2 -1
  66. package/src/components/Table/utils/decorators/sortable.tsx +8 -2
  67. package/src/demos/examples/TableSortableResponsive.tsx +3 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-table",
3
- "version": "6.0.0-alpha.5",
3
+ "version": "6.0.0-alpha.7",
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",
@@ -40,10 +40,10 @@
40
40
  "subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json"
41
41
  },
42
42
  "dependencies": {
43
- "@patternfly/react-core": "^6.0.0-alpha.5",
44
- "@patternfly/react-icons": "^6.0.0-alpha.4",
45
- "@patternfly/react-styles": "^6.0.0-alpha.4",
46
- "@patternfly/react-tokens": "^6.0.0-alpha.4",
43
+ "@patternfly/react-core": "^6.0.0-alpha.7",
44
+ "@patternfly/react-icons": "^6.0.0-alpha.5",
45
+ "@patternfly/react-styles": "^6.0.0-alpha.5",
46
+ "@patternfly/react-tokens": "^6.0.0-alpha.5",
47
47
  "lodash": "^4.17.19",
48
48
  "tslib": "^2.5.0"
49
49
  },
@@ -55,5 +55,5 @@
55
55
  "react": "^17 || ^18",
56
56
  "react-dom": "^17 || ^18"
57
57
  },
58
- "gitHead": "0213323de9e62364f8cd3f401bec86f1f34ee4fe"
58
+ "gitHead": "e9117354af65f496fe3166e6faea7b8721f08b62"
59
59
  }
@@ -1,4 +1,5 @@
1
1
  import * as React from 'react';
2
+ import { Tooltip, TooltipProps } from '@patternfly/react-core/dist/esm/components/Tooltip';
2
3
 
3
4
  export enum RowSelectVariant {
4
5
  radio = 'radio',
@@ -11,6 +12,10 @@ export interface SelectColumnProps {
11
12
  className?: string;
12
13
  onSelect?: (event: React.FormEvent<HTMLInputElement>) => void;
13
14
  selectVariant?: RowSelectVariant;
15
+ /** text to display on the tooltip */
16
+ tooltip?: React.ReactNode;
17
+ /** other props to pass to the tooltip */
18
+ tooltipProps?: Omit<TooltipProps, 'content'>;
14
19
  }
15
20
 
16
21
  export const SelectColumn: React.FunctionComponent<SelectColumnProps> = ({
@@ -19,13 +24,27 @@ export const SelectColumn: React.FunctionComponent<SelectColumnProps> = ({
19
24
  className,
20
25
  onSelect = null as (event: React.FormEvent<HTMLInputElement>) => void,
21
26
  selectVariant,
27
+ tooltip,
28
+ tooltipProps,
22
29
  ...props
23
- }: SelectColumnProps) => (
24
- <React.Fragment>
25
- <label>
26
- <input {...props} type={selectVariant} onChange={onSelect} />
27
- </label>
28
- {children}
29
- </React.Fragment>
30
- );
30
+ }: SelectColumnProps) => {
31
+ const inputRef = React.createRef<HTMLInputElement>();
32
+
33
+ const content = (
34
+ <React.Fragment>
35
+ <label>
36
+ <input {...props} ref={inputRef} type={selectVariant} onChange={onSelect} />
37
+ </label>
38
+ {children}
39
+ </React.Fragment>
40
+ );
41
+
42
+ return tooltip ? (
43
+ <Tooltip triggerRef={inputRef} content={tooltip} {...tooltipProps}>
44
+ {content}
45
+ </Tooltip>
46
+ ) : (
47
+ content
48
+ );
49
+ };
31
50
  SelectColumn.displayName = 'SelectColumn';
@@ -5,6 +5,7 @@ import ArrowsAltVIcon from '@patternfly/react-icons/dist/esm/icons/arrows-alt-v-
5
5
  import { css } from '@patternfly/react-styles';
6
6
  import styles from '@patternfly/react-styles/css/components/Table/table';
7
7
  import { TableText } from './TableText';
8
+ import { TooltipProps } from '@patternfly/react-core/dist/esm/components/Tooltip';
8
9
 
9
10
  export enum SortByDirection {
10
11
  asc = 'asc',
@@ -17,6 +18,9 @@ export interface SortColumnProps extends React.ButtonHTMLAttributes<HTMLButtonEl
17
18
  isSortedBy?: boolean;
18
19
  onSort?: Function;
19
20
  sortDirection?: string;
21
+ tooltip?: React.ReactNode;
22
+ tooltipProps?: Omit<TooltipProps, 'content'>;
23
+ tooltipHasDefaultBehavior?: boolean;
20
24
  }
21
25
 
22
26
  export const SortColumn: React.FunctionComponent<SortColumnProps> = ({
@@ -26,6 +30,9 @@ export const SortColumn: React.FunctionComponent<SortColumnProps> = ({
26
30
  onSort = null,
27
31
  sortDirection = '',
28
32
  type = 'button',
33
+ tooltip,
34
+ tooltipProps,
35
+ tooltipHasDefaultBehavior,
29
36
  ...props
30
37
  }: SortColumnProps) => {
31
38
  let SortedByIcon;
@@ -45,7 +52,14 @@ export const SortColumn: React.FunctionComponent<SortColumnProps> = ({
45
52
  onBlur={() => setFocused(false)}
46
53
  >
47
54
  <div className={css(className, styles.tableButtonContent)}>
48
- <TableText focused={focused}>{children}</TableText>
55
+ <TableText
56
+ tooltip={tooltip}
57
+ tooltipProps={tooltipProps}
58
+ tooltipHasDefaultBehavior={tooltipHasDefaultBehavior}
59
+ focused={focused}
60
+ >
61
+ {children}
62
+ </TableText>
49
63
  <span className={css(styles.tableSortIndicator)}>
50
64
  <SortedByIcon />
51
65
  </span>
@@ -26,13 +26,15 @@ export interface TableTextProps extends React.HTMLProps<HTMLDivElement> {
26
26
  /** Determines which wrapping modifier to apply to the table text */
27
27
  wrapModifier?: WrapModifier | 'wrap' | 'nowrap' | 'truncate' | 'breakWord' | 'fitContent';
28
28
  /** text to display on the tooltip */
29
- tooltip?: string;
29
+ tooltip?: React.ReactNode;
30
30
  /** other props to pass to the tooltip */
31
31
  tooltipProps?: Omit<TooltipProps, 'content'>;
32
32
  /** callback used to create the tooltip if text is truncated */
33
33
  onMouseEnter?: (event: any) => void;
34
34
  /** Determines if the TableText is focused by parent component */
35
35
  focused?: boolean;
36
+ /** Determines if tooltip should have normal visbility behavior. If false, the tooltip will only be shown when children is not entirely visible */
37
+ tooltipHasDefaultBehavior?: boolean;
36
38
  }
37
39
 
38
40
  export const TableText: React.FunctionComponent<TableTextProps> = ({
@@ -44,12 +46,13 @@ export const TableText: React.FunctionComponent<TableTextProps> = ({
44
46
  tooltipProps = {},
45
47
  onMouseEnter: onMouseEnterProp = () => {},
46
48
  focused = false,
49
+ tooltipHasDefaultBehavior = false,
47
50
  ...props
48
51
  }: TableTextProps) => {
49
52
  const Component: TableTextVariant | 'span' | 'div' = variant;
50
53
  const textRef = React.createRef<HTMLElement>();
51
54
 
52
- const [tooltip, setTooltip] = React.useState('');
55
+ const [tooltip, setTooltip] = React.useState(tooltipProp);
53
56
  const onMouseEnter = (event: any) => {
54
57
  if (event.target.offsetWidth < event.target.scrollWidth) {
55
58
  setTooltip(tooltipProp || event.target.innerText);
@@ -70,7 +73,7 @@ export const TableText: React.FunctionComponent<TableTextProps> = ({
70
73
  const text = (
71
74
  <Component
72
75
  ref={textRef as React.Ref<HTMLDivElement>}
73
- onMouseEnter={onMouseEnter}
76
+ onMouseEnter={!tooltipHasDefaultBehavior ? onMouseEnter : undefined}
74
77
  className={css(className, wrapModifier && styles.modifiers[wrapModifier], styles.tableText)}
75
78
  {...props}
76
79
  >
@@ -79,15 +82,22 @@ export const TableText: React.FunctionComponent<TableTextProps> = ({
79
82
  );
80
83
 
81
84
  React.useEffect(() => {
82
- if (focused) {
83
- onFocus(textRef.current);
84
- } else {
85
- setTooltip('');
85
+ if (!tooltipHasDefaultBehavior) {
86
+ if (focused) {
87
+ onFocus(textRef.current);
88
+ } else {
89
+ setTooltip('');
90
+ }
86
91
  }
87
- }, [focused]);
92
+ }, [focused, tooltipHasDefaultBehavior]);
88
93
 
89
94
  return tooltip !== '' ? (
90
- <Tooltip triggerRef={textRef} content={tooltip} isVisible {...tooltipProps}>
95
+ <Tooltip
96
+ triggerRef={textRef}
97
+ content={tooltip}
98
+ {...(!tooltipHasDefaultBehavior && { isVisible: true })}
99
+ {...tooltipProps}
100
+ >
91
101
  {text}
92
102
  </Tooltip>
93
103
  ) : (
@@ -132,6 +132,9 @@ export interface IExtra extends IExtraData {
132
132
  rowData?: IRowData;
133
133
  className?: string;
134
134
  ariaLabel?: string;
135
+ tooltip?: React.ReactNode;
136
+ tooltipProps?: Omit<TooltipProps, 'content'>;
137
+ tooltipHasDefaultBehavior?: boolean;
135
138
  }
136
139
 
137
140
  export type IFormatterValueType = formatterValueType & {
@@ -6,7 +6,7 @@ import { info, sortable, sortableFavorites, selectable, collapsible, cellWidth,
6
6
  import { ThInfoType, ThSelectType, ThExpandType, ThSortType, formatterValueType } from './base/types';
7
7
  import { mergeProps } from './base/merge-props';
8
8
  import { IVisibility } from './utils/decorators/classNames';
9
- import { Tooltip } from '@patternfly/react-core/dist/esm/components/Tooltip/Tooltip';
9
+ import { Tooltip, TooltipProps } from '@patternfly/react-core/dist/esm/components/Tooltip';
10
10
  import { BaseCellProps } from './Table';
11
11
  import { IFormatterValueType, IColumn } from './TableTypes';
12
12
  import cssStickyCellMinWidth from '@patternfly/react-tokens/dist/esm/c_table__sticky_cell_MinWidth';
@@ -34,6 +34,8 @@ export interface ThProps
34
34
  * To disable it completely you can set it to null.
35
35
  */
36
36
  tooltip?: React.ReactNode;
37
+ /** other props to pass to the tooltip */
38
+ tooltipProps?: Omit<TooltipProps, 'content'>;
37
39
  /** Callback on mouse enter */
38
40
  onMouseEnter?: (event: any) => void;
39
41
  /** Adds tooltip/popover info button */
@@ -68,6 +70,7 @@ const ThBase: React.FunctionComponent<ThProps> = ({
68
70
  select = null,
69
71
  expand: collapse = null,
70
72
  tooltip = '',
73
+ tooltipProps,
71
74
  onMouseEnter: onMouseEnterProp = () => {},
72
75
  width,
73
76
  visibility,
@@ -99,7 +102,9 @@ const ThBase: React.FunctionComponent<ThProps> = ({
99
102
  sortParams = sortableFavorites({
100
103
  onSort: sort?.onSort,
101
104
  columnIndex: sort.columnIndex,
102
- sortBy: sort.sortBy
105
+ sortBy: sort.sortBy,
106
+ tooltip: tooltip as string,
107
+ tooltipProps
103
108
  })();
104
109
  } else {
105
110
  sortParams = sortable(children as IFormatterValueType, {
@@ -109,7 +114,9 @@ const ThBase: React.FunctionComponent<ThProps> = ({
109
114
  sortBy: sort.sortBy,
110
115
  onSort: sort?.onSort
111
116
  }
112
- } as IColumn
117
+ } as IColumn,
118
+ tooltip: tooltip as string,
119
+ tooltipProps
113
120
  });
114
121
  }
115
122
  }
@@ -127,7 +134,9 @@ const ThBase: React.FunctionComponent<ThProps> = ({
127
134
  allRowsSelected: select.isSelected,
128
135
  isHeaderSelectDisabled: !!select.isHeaderSelectDisabled
129
136
  }
130
- }
137
+ },
138
+ tooltip: tooltip as string,
139
+ tooltipProps
131
140
  })
132
141
  : null;
133
142
  const collapseParams = collapse
@@ -208,13 +217,15 @@ const ThBase: React.FunctionComponent<ThProps> = ({
208
217
  );
209
218
 
210
219
  const canMakeDefaultTooltip = tooltip === '' ? typeof transformedChildren === 'string' : true;
211
- return tooltip !== null && canMakeDefaultTooltip && showTooltip ? (
220
+ const childControlsTooltip = sortParams || selectParams;
221
+ return tooltip !== null && canMakeDefaultTooltip && !childControlsTooltip && showTooltip ? (
212
222
  <>
213
223
  {cell}
214
224
  <Tooltip
215
225
  triggerRef={cellRef as React.RefObject<any>}
216
226
  content={tooltip || (tooltip === '' && children)}
217
227
  isVisible
228
+ {...tooltipProps}
218
229
  />
219
230
  </>
220
231
  ) : (
@@ -7,7 +7,7 @@ import checkStyles from '@patternfly/react-styles/css/components/Check/check';
7
7
 
8
8
  export const selectable: ITransform = (
9
9
  label: IFormatterValueType,
10
- { rowIndex, columnIndex, rowData, column, property }: IExtra
10
+ { rowIndex, columnIndex, rowData, column, property, tooltip }: IExtra
11
11
  ) => {
12
12
  const {
13
13
  extraParams: { onSelect, selectVariant, allRowsSelected, isHeaderSelectDisabled }
@@ -69,6 +69,7 @@ export const selectable: ITransform = (
69
69
  selectVariant={selectVariant as RowSelectVariant}
70
70
  onSelect={selectClick}
71
71
  name={selectName}
72
+ tooltip={tooltip}
72
73
  >
73
74
  {label as React.ReactNode}
74
75
  </SelectColumn>
@@ -15,12 +15,15 @@ export const sortableFavorites = (sort: any) => () =>
15
15
  sortBy: sort.sortBy,
16
16
  onSort: sort?.onSort
17
17
  }
18
- }
18
+ },
19
+ tooltip: sort.tooltip,
20
+ tooltipProps: sort.tooltipProps,
21
+ tooltipHasDefaultBehavior: true
19
22
  });
20
23
 
21
24
  export const sortable: ITransform = (
22
25
  label: IFormatterValueType,
23
- { columnIndex, column, property, className, ariaLabel }: IExtra
26
+ { columnIndex, column, property, className, ariaLabel, tooltip, tooltipProps, tooltipHasDefaultBehavior }: IExtra
24
27
  ) => {
25
28
  const {
26
29
  extraParams: { sortBy, onSort }
@@ -56,6 +59,9 @@ export const sortable: ITransform = (
56
59
  sortDirection={isSortedBy ? sortBy.direction : ''}
57
60
  onSort={sortClicked}
58
61
  aria-label={ariaLabel}
62
+ tooltip={tooltip}
63
+ tooltipProps={tooltipProps}
64
+ tooltipHasDefaultBehavior={tooltipHasDefaultBehavior}
59
65
  >
60
66
  {label as React.ReactNode}
61
67
  </SortColumn>
@@ -28,7 +28,8 @@ import {
28
28
  OverflowMenuContent,
29
29
  OverflowMenuControl,
30
30
  OverflowMenuGroup,
31
- OverflowMenuItem
31
+ OverflowMenuItem,
32
+ PageSectionVariants
32
33
  } from '@patternfly/react-core';
33
34
  import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table';
34
35
  import CloneIcon from '@patternfly/react-icons/dist/esm/icons/clone-icon';
@@ -232,7 +233,7 @@ export const TableSortableResponsive: React.FunctionComponent = () => {
232
233
  return (
233
234
  <React.Fragment>
234
235
  <DashboardWrapper>
235
- <PageSection isWidthLimited>
236
+ <PageSection isWidthLimited variant={PageSectionVariants.light}>
236
237
  <TextContent>
237
238
  <Text component="h1">Table demos</Text>
238
239
  <Text component="p">