@salesforce/design-system-react 0.10.44 → 0.10.47

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 (81) hide show
  1. package/components/button/__tests__/button.browser-test.jsx +0 -1
  2. package/components/combobox/combobox.d.ts +3 -0
  3. package/components/combobox/combobox.jsx +4 -1
  4. package/components/component-docs.json +6 -3
  5. package/components/data-table/cell.jsx +2 -2
  6. package/components/data-table/index.jsx +134 -85
  7. package/components/data-table/private/context-helper.js +26 -14
  8. package/components/data-table/private/head.jsx +269 -260
  9. package/components/data-table/private/header-cell.jsx +204 -230
  10. package/components/data-table/private/row.jsx +140 -105
  11. package/components/data-table/row-actions.jsx +2 -2
  12. package/components/pill-container/__docs__/__snapshots__/storybook-stories.storyshot +15 -15
  13. package/components/pill-container/private/selected-listbox.jsx +1 -0
  14. package/components/popover/__tests__/popover.browser-test.jsx +28 -0
  15. package/components/progress-indicator.d.ts +29 -8
  16. package/components/slider.d.ts +10 -4
  17. package/components/utilities/truncate/index.jsx +1 -1
  18. package/design-system-react-components.js +62406 -0
  19. package/design-system-react-components.js.map +1 -0
  20. package/design-system-react-components.min.js +3 -0
  21. package/design-system-react-components.min.js.LICENSE.txt +83 -0
  22. package/design-system-react-components.min.js.map +1 -0
  23. package/design-system-react.js +73800 -0
  24. package/design-system-react.js.map +1 -0
  25. package/design-system-react.min.js +3 -0
  26. package/design-system-react.min.js.LICENSE.txt +83 -0
  27. package/design-system-react.min.js.map +1 -0
  28. package/lib/components/button/__tests__/button.browser-test.jsx +0 -1
  29. package/lib/components/combobox/combobox.d.ts +3 -0
  30. package/lib/components/combobox/combobox.js +4 -1
  31. package/lib/components/component-docs.json +6 -3
  32. package/lib/components/data-table/cell.js +6 -6
  33. package/lib/components/data-table/index.js +131 -99
  34. package/lib/components/data-table/private/context-helper.js +13 -14
  35. package/lib/components/data-table/private/head.js +233 -252
  36. package/lib/components/data-table/private/header-cell.js +185 -221
  37. package/lib/components/data-table/private/row.js +97 -89
  38. package/lib/components/data-table/row-actions.js +6 -6
  39. package/lib/components/pill-container/__docs__/__snapshots__/storybook-stories.storyshot +15 -15
  40. package/lib/components/pill-container/private/selected-listbox.js +3 -0
  41. package/lib/components/popover/__tests__/popover.browser-test.jsx +28 -0
  42. package/lib/components/progress-indicator.d.ts +29 -8
  43. package/lib/components/slider.d.ts +10 -4
  44. package/lib/components/utilities/truncate/index.js +2 -2
  45. package/lib/design-system-react-components.min.js.LICENSE.txt +83 -0
  46. package/lib/design-system-react.min.js.LICENSE.txt +83 -0
  47. package/lib/package.json +5 -5
  48. package/lib/utilities/keyboard-navigable-dialog.js +6 -1
  49. package/module/components/button/__tests__/button.browser-test.js +0 -1
  50. package/module/components/button/__tests__/button.browser-test.js.map +1 -1
  51. package/module/components/combobox/combobox.d.ts +3 -0
  52. package/module/components/combobox/combobox.js +4 -1
  53. package/module/components/combobox/combobox.js.map +1 -1
  54. package/module/components/component-docs.json +6 -3
  55. package/module/components/data-table/cell.js +6 -6
  56. package/module/components/data-table/cell.js.map +1 -1
  57. package/module/components/data-table/index.js +124 -95
  58. package/module/components/data-table/index.js.map +1 -1
  59. package/module/components/data-table/private/context-helper.js +12 -12
  60. package/module/components/data-table/private/context-helper.js.map +1 -1
  61. package/module/components/data-table/private/head.js +230 -255
  62. package/module/components/data-table/private/head.js.map +1 -1
  63. package/module/components/data-table/private/header-cell.js +184 -225
  64. package/module/components/data-table/private/header-cell.js.map +1 -1
  65. package/module/components/data-table/private/row.js +95 -87
  66. package/module/components/data-table/private/row.js.map +1 -1
  67. package/module/components/data-table/row-actions.js +6 -6
  68. package/module/components/data-table/row-actions.js.map +1 -1
  69. package/module/components/pill-container/__docs__/__snapshots__/storybook-stories.storyshot +15 -15
  70. package/module/components/pill-container/private/selected-listbox.js +3 -0
  71. package/module/components/pill-container/private/selected-listbox.js.map +1 -1
  72. package/module/components/popover/__tests__/popover.browser-test.js +25 -0
  73. package/module/components/popover/__tests__/popover.browser-test.js.map +1 -1
  74. package/module/components/progress-indicator.d.ts +29 -8
  75. package/module/components/slider.d.ts +10 -4
  76. package/module/components/utilities/truncate/index.js +1 -1
  77. package/module/components/utilities/truncate/index.js.map +1 -1
  78. package/module/utilities/keyboard-navigable-dialog.js +4 -1
  79. package/module/utilities/keyboard-navigable-dialog.js.map +1 -1
  80. package/package.json +5 -5
  81. package/utilities/keyboard-navigable-dialog.js +3 -0
@@ -2,7 +2,7 @@
2
2
  /* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
3
3
 
4
4
  // ### React
5
- import React from 'react';
5
+ import React, { useContext, useEffect, useRef, useState } from 'react';
6
6
 
7
7
  import PropTypes from 'prop-types';
8
8
 
@@ -23,7 +23,7 @@ import Link from './link';
23
23
  import InteractiveLink from '../interactive-link';
24
24
  import CellContext from '../private/cell-context';
25
25
  import TableContext from '../private/table-context';
26
- import contextHelper from './context-helper';
26
+ import useContextHelper from './context-helper';
27
27
 
28
28
  // ## Constants
29
29
  import {
@@ -31,83 +31,85 @@ import {
31
31
  DATA_TABLE_COLUMN,
32
32
  } from '../../../utilities/constants';
33
33
 
34
+ // ### Prop Types
35
+ const propTypes = {
36
+ assistiveText: PropTypes.shape({
37
+ actionsHeader: PropTypes.string,
38
+ columnSort: PropTypes.string,
39
+ columnSortedAscending: PropTypes.string,
40
+ columnSortedDescending: PropTypes.string,
41
+ selectAllRows: PropTypes.string,
42
+ selectRow: PropTypes.string,
43
+ }),
44
+ cellRef: PropTypes.func,
45
+ fixedHeader: PropTypes.bool,
46
+ id: PropTypes.string.isRequired,
47
+ /**
48
+ * Some columns, such as "date last viewed" or "date recently updated," should sort descending first, since that is what the user probably wants. How often does one want to see their oldest files first in a table? If sortable and the `DataTable`'s parent has not defined the sort order, then ascending (A at the top to Z at the bottom) is the default sort order on first click.
49
+ */
50
+ isDefaultSortDescending: PropTypes.bool,
51
+ /**
52
+ * Indicates if column is sorted.
53
+ */
54
+ isSorted: PropTypes.bool,
55
+ /**
56
+ * The column label.
57
+ */
58
+ label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
59
+ /**
60
+ * The function to execute on sort.
61
+ */
62
+ onSort: PropTypes.func,
63
+ /**
64
+ * The property which corresponds to this column.
65
+ */
66
+ property: PropTypes.string,
67
+ /**
68
+ * Whether or not the column is sortable.
69
+ */
70
+ sortable: PropTypes.bool,
71
+ /**
72
+ * The current sort direction.
73
+ */
74
+ sortDirection: PropTypes.oneOf(['desc', 'asc']),
75
+ /**
76
+ * Width of column. This is required for advanced/fixed layout tables. Please provide units. (`rems` are recommended)
77
+ */
78
+ width: PropTypes.string,
79
+ };
80
+
34
81
  /**
35
82
  * Used internally, renders each individual column heading.
36
83
  */
37
- class DataTableHeaderCell extends React.Component {
38
- // ### Display Name
39
- // Always use the canonical component name as the React display name.
40
- static displayName = DATA_TABLE_HEADER_CELL;
41
-
42
- // ### Prop Types
43
- static propTypes = {
44
- assistiveText: PropTypes.shape({
45
- actionsHeader: PropTypes.string,
46
- columnSort: PropTypes.string,
47
- columnSortedAscending: PropTypes.string,
48
- columnSortedDescending: PropTypes.string,
49
- selectAllRows: PropTypes.string,
50
- selectRow: PropTypes.string,
51
- }),
52
- cellRef: PropTypes.func,
53
- fixedHeader: PropTypes.bool,
54
- id: PropTypes.string.isRequired,
55
- /**
56
- * Some columns, such as "date last viewed" or "date recently updated," should sort descending first, since that is what the user probably wants. How often does one want to see their oldest files first in a table? If sortable and the `DataTable`'s parent has not defined the sort order, then ascending (A at the top to Z at the bottom) is the default sort order on first click.
57
- */
58
- isDefaultSortDescending: PropTypes.bool,
59
- /**
60
- * Indicates if column is sorted.
61
- */
62
- isSorted: PropTypes.bool,
63
- /**
64
- * The column label.
65
- */
66
- label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
67
- /**
68
- * The function to execute on sort.
69
- */
70
- onSort: PropTypes.func,
71
- /**
72
- * The property which corresponds to this column.
73
- */
74
- property: PropTypes.string,
75
- /**
76
- * Whether or not the column is sortable.
77
- */
78
- sortable: PropTypes.bool,
79
- /**
80
- * The current sort direction.
81
- */
82
- sortDirection: PropTypes.oneOf(['desc', 'asc']),
83
- /**
84
- * Width of column. This is required for advanced/fixed layout tables. Please provide units. (`rems` are recommended)
85
- */
86
- width: PropTypes.string,
87
- };
84
+ const DataTableHeaderCell = (props) => {
85
+ const [sortDirection, setSortDirection] = useState(null);
86
+ const prevIsSorted = useRef(null);
87
+ const tableContext = useContext(TableContext);
88
+ const cellContext = useContext(CellContext);
89
+ const { tabIndex, hasFocus, handleFocus, handleKeyDown } = useContextHelper(
90
+ tableContext,
91
+ cellContext,
92
+ props.fixedLayout
93
+ );
88
94
 
89
- state = {
90
- sortDirection: null,
91
- };
95
+ useEffect(() => {
96
+ checkProps(DATA_TABLE_COLUMN, props);
97
+ // eslint-disable-next-line react-hooks/exhaustive-deps
98
+ }, []);
92
99
 
93
- componentDidMount() {
94
- checkProps(DATA_TABLE_COLUMN, this.props);
95
- }
96
-
97
- componentDidUpdate(prevProps) {
98
- // reset sort state when another column is sorted
99
- if (prevProps.isSorted === true && this.props.isSorted === false) {
100
- this.setState({ sortDirection: null }); // eslint-disable-line react/no-did-update-set-state
100
+ useEffect(() => {
101
+ if (prevIsSorted.current === true && props.isSorted === false) {
102
+ setSortDirection(null);
101
103
  }
102
- }
104
+ prevIsSorted.current = props.isSorted;
105
+ }, [props.isSorted]);
103
106
 
104
- handleSort = (e) => {
107
+ const handleSort = (e) => {
105
108
  e.preventDefault();
106
109
 
107
- const oldSortDirection =
108
- this.props.sortDirection || this.state.sortDirection;
110
+ const oldSortDirection = props.sortDirection || sortDirection;
109
111
  // UX pattern: If sortable, and the DataTable's parent has not defined the sort order, then ascending (that is A->Z) is the default sort order on first click. Some columns, such as "last viewed" or "recently updated," should sort descending first, since that is what the user probably wants. Who wants to see the oldest files first?
110
- const sortDirection = (function sortDirectionFunction(
112
+ const newSortDirection = (function sortDirectionFunction(
111
113
  direction,
112
114
  isDefaultSortDescending
113
115
  ) {
@@ -121,190 +123,162 @@ class DataTableHeaderCell extends React.Component {
121
123
  default:
122
124
  return 'asc';
123
125
  }
124
- })(oldSortDirection, this.props.isDefaultSortDescending);
126
+ })(oldSortDirection, props.isDefaultSortDescending);
125
127
  const data = {
126
- property: this.props.property,
127
- sortDirection,
128
+ property: props.property,
129
+ sortDirection: newSortDirection,
128
130
  };
129
131
 
130
- this.setState({
131
- sortDirection,
132
- });
132
+ setSortDirection(newSortDirection);
133
133
 
134
- if (isFunction(this.props.onSort)) {
135
- this.props.onSort(data, e);
134
+ if (isFunction(props.onSort)) {
135
+ props.onSort(data, e);
136
136
  }
137
137
  };
138
138
 
139
- // ### Render
140
- render() {
141
- const {
142
- fixedHeader,
143
- isSorted,
144
- label,
145
- sortable,
146
- width,
147
- property,
148
- } = this.props;
139
+ const { fixedHeader, isSorted, label, sortable, width, property } = props;
149
140
 
150
- const labelType = typeof label;
151
- // This decides which arrow to render--which is current sort order if the column is sorted OR the future sort order if the arrow is clicked in the future.
152
- const sortDirection =
153
- this.props.sortDirection ||
154
- this.state.sortDirection ||
155
- (this.props.isDefaultSortDescending && 'desc');
156
- const expandedSortDirection =
157
- sortDirection === 'desc' ? 'descending' : 'ascending';
158
- const ariaSort = isSorted ? expandedSortDirection : 'none';
141
+ const labelType = typeof label;
142
+ // This decides which arrow to render--which is current sort order if the column is sorted OR the future sort order if the arrow is clicked in the future.
143
+ const effectiveSortDirection =
144
+ props.sortDirection ||
145
+ sortDirection ||
146
+ (props.isDefaultSortDescending && 'desc');
147
+ const expandedSortDirection =
148
+ effectiveSortDirection === 'desc' ? 'descending' : 'ascending';
149
+ const ariaSort = isSorted ? expandedSortDirection : 'none';
159
150
 
160
- const getFixedLayoutSubRenders = (isHidden) => {
161
- if (sortable) {
162
- // Don't make the anchor interactable when it's hidden
163
- const SortLink = isHidden ? Link : InteractiveLink;
164
- return (
165
- <SortLink
166
- href="#"
167
- className="slds-th__action slds-text-link_reset"
168
- onClick={this.handleSort}
169
- role="button"
170
- >
171
- <span className="slds-assistive-text">
172
- {this.props.assistiveTextForColumnSort ||
173
- this.props.assistiveText.columnSort}{' '}
174
- </span>
175
- <span
176
- className="slds-truncate"
177
- title={labelType === 'string' ? label : undefined}
178
- >
179
- {label}
180
- </span>
181
- <Icon
182
- className="slds-is-sortable__icon"
183
- category="utility"
184
- name={sortDirection === 'desc' ? 'arrowdown' : 'arrowup'}
185
- size="x-small"
186
- />
187
- {sortDirection ? (
188
- <span className="slds-assistive-text" aria-atomic="true">
189
- {sortDirection === 'asc'
190
- ? this.props.assistiveTextForColumnSortedAscending ||
191
- this.props.assistiveText.columnSortedAscending
192
- : this.props.assistiveTextForColumnSortedDescending ||
193
- this.props.assistiveText.columnSortedDescending}
194
- </span>
195
- ) : null}
196
- </SortLink>
197
- );
198
- }
151
+ const getFixedLayoutSubRenders = (isHidden) => {
152
+ if (sortable) {
153
+ // Don't make the anchor interactable when it's hidden
154
+ const SortLink = isHidden ? Link : InteractiveLink;
199
155
  return (
200
- <span
201
- className="slds-p-horizontal_x-small slds-th__action"
202
- style={{ display: 'flex' }}
156
+ <SortLink
157
+ href="#"
158
+ className="slds-th__action slds-text-link_reset"
159
+ onClick={handleSort}
160
+ role="button"
203
161
  >
162
+ <span className="slds-assistive-text">
163
+ {props.assistiveTextForColumnSort || props.assistiveText.columnSort}{' '}
164
+ </span>
204
165
  <span
205
166
  className="slds-truncate"
206
167
  title={labelType === 'string' ? label : undefined}
207
168
  >
208
169
  {label}
209
170
  </span>
210
- </span>
171
+ <Icon
172
+ className="slds-is-sortable__icon"
173
+ category="utility"
174
+ name={effectiveSortDirection === 'desc' ? 'arrowdown' : 'arrowup'}
175
+ size="x-small"
176
+ />
177
+ {effectiveSortDirection ? (
178
+ <span className="slds-assistive-text" aria-atomic="true">
179
+ {effectiveSortDirection === 'asc'
180
+ ? props.assistiveTextForColumnSortedAscending ||
181
+ props.assistiveText.columnSortedAscending
182
+ : props.assistiveTextForColumnSortedDescending ||
183
+ props.assistiveText.columnSortedDescending}
184
+ </span>
185
+ ) : null}
186
+ </SortLink>
211
187
  );
212
- };
213
-
214
- const getHeaderCellContent = (isHidden) =>
215
- this.props.fixedLayout ? (
216
- getFixedLayoutSubRenders(isHidden)
217
- ) : (
218
- <div
188
+ }
189
+ return (
190
+ <span
191
+ className="slds-p-horizontal_x-small slds-th__action"
192
+ style={{ display: 'flex' }}
193
+ >
194
+ <span
219
195
  className="slds-truncate"
220
196
  title={labelType === 'string' ? label : undefined}
221
197
  >
222
198
  {label}
223
- </div>
224
- );
199
+ </span>
200
+ </span>
201
+ );
202
+ };
225
203
 
226
- return (
227
- <TableContext.Consumer>
228
- {(tableContext) => (
229
- <CellContext.Consumer>
230
- {(cellContext) => {
231
- const {
232
- tabIndex,
233
- hasFocus,
234
- handleFocus,
235
- handleKeyDown,
236
- } = contextHelper(
237
- tableContext,
238
- cellContext,
239
- this.props.fixedLayout
240
- );
241
- return (
242
- <th
243
- id={`${this.props.id}-${property}-th`}
244
- aria-label={labelType === 'string' ? label : undefined}
245
- aria-sort={ariaSort}
246
- className={classNames({
247
- 'slds-is-sortable': sortable,
248
- 'slds-is-sorted': isSorted,
249
- [`slds-is-sorted_${sortDirection}`]: sortDirection,
250
- 'slds-is-sorted_asc': isSorted && !sortDirection, // default for hover, up arrow is ascending which means A is at the top of the table, and Z is at the bottom. You have to think about row numbers abstracting, and not the visual order on the table.
251
- })}
252
- onFocus={handleFocus}
253
- onKeyDown={handleKeyDown}
254
- ref={(ref) => {
255
- if (this.props.cellRef) {
256
- this.props.cellRef(ref);
257
- if (ref && hasFocus) {
258
- ref.focus();
259
- }
260
- }
261
- }}
262
- scope="col"
263
- style={
264
- fixedHeader || width
265
- ? {
266
- height: fixedHeader ? 0 : null,
267
- lineHeight: fixedHeader ? 0 : null,
268
- width: width || null,
269
- }
270
- : null
271
- }
272
- tabIndex={tabIndex}
273
- >
274
- {fixedHeader
275
- ? React.cloneElement(getHeaderCellContent(true), {
276
- style: {
277
- display: 'flex',
278
- height: 0,
279
- overflow: 'hidden',
280
- paddingBottom: 0,
281
- paddingTop: 0,
282
- visibility: 'hidden',
283
- },
284
- })
285
- : getHeaderCellContent()}
286
- {fixedHeader ? (
287
- <CellFixed>
288
- {React.cloneElement(getHeaderCellContent(), {
289
- style: {
290
- alignItems: 'center',
291
- display: 'flex',
292
- flex: '1 1 auto',
293
- lineHeight: 1.25,
294
- width: '100%',
295
- },
296
- tabIndex: sortable ? 0 : null,
297
- })}
298
- </CellFixed>
299
- ) : null}
300
- </th>
301
- );
302
- }}
303
- </CellContext.Consumer>
304
- )}
305
- </TableContext.Consumer>
204
+ const getHeaderCellContent = (isHidden) =>
205
+ props.fixedLayout ? (
206
+ getFixedLayoutSubRenders(isHidden)
207
+ ) : (
208
+ <div
209
+ className="slds-truncate"
210
+ title={labelType === 'string' ? label : undefined}
211
+ >
212
+ {label}
213
+ </div>
306
214
  );
307
- }
308
- }
215
+
216
+ return (
217
+ <th
218
+ id={`${props.id}-${property}-th`}
219
+ aria-label={labelType === 'string' ? label : undefined}
220
+ aria-sort={ariaSort}
221
+ className={classNames({
222
+ 'slds-is-sortable': sortable,
223
+ 'slds-is-sorted': isSorted,
224
+ [`slds-is-sorted_${effectiveSortDirection}`]: effectiveSortDirection,
225
+ 'slds-is-sorted_asc': isSorted && !effectiveSortDirection, // default for hover, up arrow is ascending which means A is at the top of the table, and Z is at the bottom. You have to think about row numbers abstracting, and not the visual order on the table.
226
+ })}
227
+ onFocus={handleFocus}
228
+ onKeyDown={handleKeyDown}
229
+ ref={(ref) => {
230
+ if (props.cellRef) {
231
+ props.cellRef(ref);
232
+ if (ref && hasFocus) {
233
+ ref.focus();
234
+ }
235
+ }
236
+ }}
237
+ scope="col"
238
+ style={
239
+ fixedHeader || width
240
+ ? {
241
+ height: fixedHeader ? 0 : null,
242
+ lineHeight: fixedHeader ? 0 : null,
243
+ width: width || null,
244
+ }
245
+ : null
246
+ }
247
+ tabIndex={tabIndex}
248
+ >
249
+ {fixedHeader
250
+ ? React.cloneElement(getHeaderCellContent(true), {
251
+ style: {
252
+ display: 'flex',
253
+ height: 0,
254
+ overflow: 'hidden',
255
+ paddingBottom: 0,
256
+ paddingTop: 0,
257
+ visibility: 'hidden',
258
+ },
259
+ })
260
+ : getHeaderCellContent()}
261
+ {fixedHeader ? (
262
+ <CellFixed>
263
+ {React.cloneElement(getHeaderCellContent(), {
264
+ style: {
265
+ alignItems: 'center',
266
+ display: 'flex',
267
+ flex: '1 1 auto',
268
+ lineHeight: 1.25,
269
+ width: '100%',
270
+ },
271
+ tabIndex: sortable ? 0 : null,
272
+ })}
273
+ </CellFixed>
274
+ ) : null}
275
+ </th>
276
+ );
277
+ };
278
+
279
+ // ### Display Name
280
+ // Always use the canonical component name as the React display name.
281
+ DataTableHeaderCell.displayName = DATA_TABLE_HEADER_CELL;
282
+ DataTableHeaderCell.propTypes = propTypes;
309
283
 
310
284
  export default DataTableHeaderCell;