@salesforce/design-system-react 0.10.44 → 0.10.45

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 (38) hide show
  1. package/components/button/__tests__/button.browser-test.jsx +0 -1
  2. package/components/data-table/cell.jsx +2 -2
  3. package/components/data-table/index.jsx +130 -85
  4. package/components/data-table/private/context-helper.js +26 -14
  5. package/components/data-table/private/head.jsx +269 -260
  6. package/components/data-table/private/header-cell.jsx +204 -230
  7. package/components/data-table/private/row.jsx +140 -105
  8. package/components/data-table/row-actions.jsx +2 -2
  9. package/components/utilities/truncate/index.jsx +1 -1
  10. package/lib/components/button/__tests__/button.browser-test.jsx +0 -1
  11. package/lib/components/data-table/cell.js +6 -6
  12. package/lib/components/data-table/index.js +127 -99
  13. package/lib/components/data-table/private/context-helper.js +13 -14
  14. package/lib/components/data-table/private/head.js +233 -252
  15. package/lib/components/data-table/private/header-cell.js +185 -221
  16. package/lib/components/data-table/private/row.js +97 -89
  17. package/lib/components/data-table/row-actions.js +6 -6
  18. package/lib/components/utilities/truncate/index.js +2 -2
  19. package/lib/package.json +4 -4
  20. package/module/components/button/__tests__/button.browser-test.js +0 -1
  21. package/module/components/button/__tests__/button.browser-test.js.map +1 -1
  22. package/module/components/data-table/cell.js +6 -6
  23. package/module/components/data-table/cell.js.map +1 -1
  24. package/module/components/data-table/index.js +120 -95
  25. package/module/components/data-table/index.js.map +1 -1
  26. package/module/components/data-table/private/context-helper.js +12 -12
  27. package/module/components/data-table/private/context-helper.js.map +1 -1
  28. package/module/components/data-table/private/head.js +230 -255
  29. package/module/components/data-table/private/head.js.map +1 -1
  30. package/module/components/data-table/private/header-cell.js +184 -225
  31. package/module/components/data-table/private/header-cell.js.map +1 -1
  32. package/module/components/data-table/private/row.js +95 -87
  33. package/module/components/data-table/private/row.js.map +1 -1
  34. package/module/components/data-table/row-actions.js +6 -6
  35. package/module/components/data-table/row-actions.js.map +1 -1
  36. package/module/components/utilities/truncate/index.js +1 -1
  37. package/module/components/utilities/truncate/index.js.map +1 -1
  38. package/package.json +4 -4
@@ -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 } from 'react';
6
6
  import PropTypes from 'prop-types';
7
7
  import classNames from 'classnames';
8
8
 
@@ -13,295 +13,304 @@ import HeaderCell from './header-cell';
13
13
  import InteractiveElement from '../interactive-element';
14
14
  import CellContext from '../private/cell-context';
15
15
  import TableContext from '../private/table-context';
16
- import contextHelper from './context-helper';
16
+ import useContextHelper from './context-helper';
17
17
 
18
18
  // ## Constants
19
19
  import { DATA_TABLE_HEAD } from '../../../utilities/constants';
20
20
 
21
21
  const InteractiveCheckbox = InteractiveElement(Checkbox);
22
22
 
23
- /**
24
- * Used internally, provides header row rendering to the DataTable.
25
- */
26
- class DataTableHead extends React.Component {
27
- // ### Display Name
28
- // Always use the canonical component name as the React display name.
29
- static displayName = DATA_TABLE_HEAD;
23
+ // ### Prop Types
24
+ const propTypes = {
25
+ assistiveText: PropTypes.shape({
26
+ actionsHeader: PropTypes.string,
27
+ columnSort: PropTypes.string,
28
+ columnSortedAscending: PropTypes.string,
29
+ columnSortedDescending: PropTypes.string,
30
+ selectAllRows: PropTypes.string,
31
+ selectRow: PropTypes.string,
32
+ }),
33
+ allSelected: PropTypes.bool,
34
+ headerRefs: PropTypes.func,
35
+ isHidden: PropTypes.bool,
36
+ indeterminateSelected: PropTypes.bool,
37
+ canSelectRows: PropTypes.oneOfType([
38
+ PropTypes.bool,
39
+ PropTypes.oneOf(['checkbox', 'radio']),
40
+ ]),
41
+ columns: PropTypes.arrayOf(
42
+ PropTypes.shape({
43
+ Cell: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
44
+ props: PropTypes.object,
45
+ })
46
+ ),
47
+ fixedHeader: PropTypes.bool,
48
+ id: PropTypes.string,
49
+ onToggleAll: PropTypes.func,
50
+ onSort: PropTypes.func,
51
+ showRowActions: PropTypes.bool,
52
+ };
53
+
54
+ const ActionsHeader = (props) => {
55
+ const tableContext = useContext(TableContext);
56
+ const cellContext = { columnIndex: props.columnIndex, rowIndex: 0 };
57
+ const { tabIndex, hasFocus, handleFocus, handleKeyDown } = useContextHelper(
58
+ tableContext,
59
+ cellContext,
60
+ props.fixedLayout
61
+ );
62
+ const { fixedHeader } = props;
63
+ const getContent = (style) => (
64
+ <div className="slds-th__action" style={style}>
65
+ <span className="slds-assistive-text">{props.assistiveText}</span>
66
+ </div>
67
+ );
30
68
 
31
- // ### Prop Types
32
- static propTypes = {
33
- assistiveText: PropTypes.shape({
34
- actionsHeader: PropTypes.string,
35
- columnSort: PropTypes.string,
36
- columnSortedAscending: PropTypes.string,
37
- columnSortedDescending: PropTypes.string,
38
- selectAllRows: PropTypes.string,
39
- selectRow: PropTypes.string,
40
- }),
41
- allSelected: PropTypes.bool,
42
- headerRefs: PropTypes.func,
43
- isHidden: PropTypes.bool,
44
- indeterminateSelected: PropTypes.bool,
45
- canSelectRows: PropTypes.oneOfType([
46
- PropTypes.bool,
47
- PropTypes.oneOf(['checkbox', 'radio']),
48
- ]),
49
- columns: PropTypes.arrayOf(
50
- PropTypes.shape({
51
- Cell: PropTypes.func,
52
- props: PropTypes.object,
53
- })
54
- ),
55
- fixedHeader: PropTypes.bool,
56
- id: PropTypes.string,
57
- onToggleAll: PropTypes.func,
58
- onSort: PropTypes.func,
59
- showRowActions: PropTypes.bool,
69
+ return (
70
+ <th
71
+ className={classNames({ 'slds-has-focus': hasFocus })}
72
+ ref={(ref) => {
73
+ if (props.headerRefs) {
74
+ props.headerRefs(ref, 'action');
75
+ }
76
+ if (ref && hasFocus) {
77
+ ref.focus();
78
+ }
79
+ }}
80
+ scope="col"
81
+ style={{
82
+ height: fixedHeader ? 0 : null,
83
+ lineHeight: fixedHeader ? 0 : null,
84
+ width: '3.25rem',
85
+ }}
86
+ onFocus={handleFocus}
87
+ onKeyDown={handleKeyDown}
88
+ tabIndex={tabIndex}
89
+ >
90
+ {getContent(
91
+ fixedHeader
92
+ ? {
93
+ height: 0,
94
+ overflow: 'hidden',
95
+ paddingBottom: 0,
96
+ paddingTop: 0,
97
+ visibility: 'hidden',
98
+ }
99
+ : null
100
+ )}
101
+ {fixedHeader ? (
102
+ <CellFixed>
103
+ {getContent({
104
+ lineHeight: 1,
105
+ width: '100%',
106
+ })}
107
+ </CellFixed>
108
+ ) : null}
109
+ </th>
110
+ );
111
+ };
112
+
113
+ const SelectHeader = (props) => {
114
+ const tableContext = useContext(TableContext);
115
+ const cellContext = { columnIndex: 0, rowIndex: 0 };
116
+ const { tabIndex, hasFocus, handleFocus, handleKeyDown } = useContextHelper(
117
+ tableContext,
118
+ cellContext,
119
+ props.fixedLayout
120
+ );
121
+ const { fixedHeader, canSelectRows } = props;
122
+ const getContent = (idSuffix, style, ariaHidden) => {
123
+ let render = null;
124
+
125
+ if (canSelectRows === 'radio') {
126
+ render = !ariaHidden ? (
127
+ <div
128
+ className="slds-truncate slds-assistive-text"
129
+ id={`${props.id}-column-group-header-row-select`}
130
+ title={props.assistiveText.selectRowGroup}
131
+ >
132
+ {props.assistiveText.selectRowGroup}
133
+ </div>
134
+ ) : null;
135
+ } else if (canSelectRows === true || canSelectRows === 'checkbox') {
136
+ render = (
137
+ <div
138
+ className="slds-th__action slds-th__action_form"
139
+ aria-hidden={ariaHidden && true}
140
+ style={style}
141
+ >
142
+ {!ariaHidden ? (
143
+ <span
144
+ id={`${props.id}-column-group-header-row-select`}
145
+ className="slds-assistive-text"
146
+ >
147
+ {props.assistiveText.selectAllRows}
148
+ </span>
149
+ ) : null}
150
+ <InteractiveCheckbox
151
+ assistiveText={{
152
+ label: props.assistiveText.selectAllRows,
153
+ }}
154
+ checked={props.allSelected}
155
+ indeterminate={props.indeterminateSelected}
156
+ id={`${props.id}-${idSuffix}`}
157
+ // There is a checkbox for user interaction and a checkbox for positioning. ariaHidden is for the checkbox for positioning and it should be removed from the accessibility tree.
158
+ name={!ariaHidden ? 'SelectAll' : undefined}
159
+ onChange={props.onToggleAll}
160
+ />
161
+ </div>
162
+ );
163
+ }
164
+
165
+ return render;
60
166
  };
167
+ return (
168
+ <th
169
+ className={classNames('slds-text-align_right', {
170
+ 'slds-has-focus': hasFocus,
171
+ })}
172
+ ref={(ref) => {
173
+ if (props.headerRefs) {
174
+ props.headerRefs(ref, 'select');
175
+ }
176
+ if (ref && hasFocus) {
177
+ ref.focus();
178
+ }
179
+ }}
180
+ scope="col"
181
+ style={{
182
+ height: fixedHeader ? 0 : null,
183
+ lineHeight: fixedHeader ? 0 : null,
184
+ width: '3.25rem',
185
+ }}
186
+ onFocus={handleFocus}
187
+ onKeyDown={handleKeyDown}
188
+ tabIndex={tabIndex}
189
+ >
190
+ <CellContext.Provider value={cellContext}>
191
+ {getContent(
192
+ 'SelectAll-fixed-header',
193
+ fixedHeader
194
+ ? {
195
+ display: 'flex',
196
+ height: 0,
197
+ overflow: 'hidden',
198
+ paddingBottom: 0,
199
+ paddingTop: 0,
200
+ visibility: 'hidden',
201
+ }
202
+ : null,
203
+ fixedHeader && 'ariaHidden'
204
+ )}
205
+ {fixedHeader ? (
206
+ <CellFixed>
207
+ {getContent('SelectAll', {
208
+ display: 'flex',
209
+ justifyContent: 'flex-end',
210
+ lineHeight: 1,
211
+ width: '100%',
212
+ })}
213
+ </CellFixed>
214
+ ) : null}
215
+ </CellContext.Provider>
216
+ </th>
217
+ );
218
+ };
61
219
 
62
- getActionsHeader = () => {
63
- const { fixedHeader } = this.props;
64
- const getContent = (style) => (
65
- <div className="slds-th__action" style={style}>
66
- <span className="slds-assistive-text">
67
- {this.props.assistiveText.actionsHeader}
68
- </span>
69
- </div>
70
- );
220
+ /**
221
+ * Used internally, provides header row rendering to the DataTable.
222
+ */
223
+ const DataTableHead = (props) => {
224
+ const getActionsHeader = () => {
71
225
  let actionsHeader = null;
72
226
 
73
- if (this.props.showRowActions) {
227
+ if (props.showRowActions) {
74
228
  actionsHeader = (
75
- <TableContext.Consumer>
76
- {(tableContext) => {
77
- const columnIndex = this.props.canSelectRows
78
- ? this.props.columns.length + 1
79
- : this.props.columns.length;
80
- const cellContext = { columnIndex, rowIndex: 0 };
81
- const {
82
- tabIndex,
83
- hasFocus,
84
- handleFocus,
85
- handleKeyDown,
86
- } = contextHelper(
87
- tableContext,
88
- cellContext,
89
- this.props.fixedLayout
90
- );
91
- return (
92
- <th
93
- className={classNames({ 'slds-has-focus': hasFocus })}
94
- ref={(ref) => {
95
- if (this.props.headerRefs) {
96
- this.props.headerRefs(ref, 'action');
97
- }
98
- if (ref && hasFocus) {
99
- ref.focus();
100
- }
101
- }}
102
- scope="col"
103
- style={{
104
- height: fixedHeader ? 0 : null,
105
- lineHeight: fixedHeader ? 0 : null,
106
- width: '3.25rem',
107
- }}
108
- onFocus={handleFocus}
109
- onKeyDown={handleKeyDown}
110
- tabIndex={tabIndex}
111
- >
112
- {getContent(
113
- fixedHeader
114
- ? {
115
- height: 0,
116
- overflow: 'hidden',
117
- paddingBottom: 0,
118
- paddingTop: 0,
119
- visibility: 'hidden',
120
- }
121
- : null
122
- )}
123
- {fixedHeader ? (
124
- <CellFixed>
125
- {getContent({
126
- lineHeight: 1,
127
- width: '100%',
128
- })}
129
- </CellFixed>
130
- ) : null}
131
- </th>
132
- );
133
- }}
134
- </TableContext.Consumer>
229
+ <ActionsHeader
230
+ assistiveText={props.assistiveText.actionsHeader}
231
+ columnIndex={
232
+ props.canSelectRows
233
+ ? props.columns.length + 1
234
+ : props.columns.length
235
+ }
236
+ fixedLayout={props.fixedLayout}
237
+ fixedHeader={props.fixedHeader}
238
+ headerRefs={props.headerRefs}
239
+ />
135
240
  );
136
241
  }
137
242
 
138
243
  return actionsHeader;
139
244
  };
140
245
 
141
- getSelectHeader = () => {
142
- const { canSelectRows, fixedHeader } = this.props;
143
- const getContent = (idSuffix, style, ariaHidden) => {
144
- let render = null;
145
-
146
- if (canSelectRows === 'radio') {
147
- render = !ariaHidden ? (
148
- <div
149
- className="slds-truncate slds-assistive-text"
150
- id={`${this.props.id}-column-group-header-row-select`}
151
- title={this.props.assistiveText.selectRowGroup}
152
- >
153
- {this.props.assistiveText.selectRowGroup}
154
- </div>
155
- ) : null;
156
- } else if (canSelectRows === true || canSelectRows === 'checkbox') {
157
- render = (
158
- <div
159
- className="slds-th__action slds-th__action_form"
160
- aria-hidden={ariaHidden && true}
161
- style={style}
162
- >
163
- {!ariaHidden ? (
164
- <span
165
- id={`${this.props.id}-column-group-header-row-select`}
166
- className="slds-assistive-text"
167
- >
168
- {this.props.assistiveText.selectAllRows}
169
- </span>
170
- ) : null}
171
- <InteractiveCheckbox
172
- assistiveText={{
173
- label: this.props.assistiveText.selectAllRows,
174
- }}
175
- checked={this.props.allSelected}
176
- indeterminate={this.props.indeterminateSelected}
177
- id={`${this.props.id}-${idSuffix}`}
178
- // There is a checkbox for user interaction and a checkbox for positioning. ariaHidden is for the checkbox for positioning and it should be removed from the accessibility tree.
179
- name={!ariaHidden ? 'SelectAll' : undefined}
180
- onChange={this.props.onToggleAll}
181
- />
182
- </div>
183
- );
184
- }
185
-
186
- return render;
187
- };
188
-
246
+ const getSelectHeader = () => {
247
+ const { canSelectRows } = props;
189
248
  let selectHeader = null;
190
249
 
191
250
  if (canSelectRows) {
192
251
  selectHeader = (
193
- <TableContext.Consumer>
194
- {(tableContext) => {
195
- const cellContext = { columnIndex: 0, rowIndex: 0 };
196
- const {
197
- tabIndex,
198
- hasFocus,
199
- handleFocus,
200
- handleKeyDown,
201
- } = contextHelper(
202
- tableContext,
203
- cellContext,
204
- this.props.fixedLayout
205
- );
206
- return (
207
- <th
208
- className={classNames('slds-text-align_right', {
209
- 'slds-has-focus': hasFocus,
210
- })}
211
- ref={(ref) => {
212
- if (this.props.headerRefs) {
213
- this.props.headerRefs(ref, 'select');
214
- }
215
- if (ref && hasFocus) {
216
- ref.focus();
217
- }
218
- }}
219
- scope="col"
220
- style={{
221
- height: fixedHeader ? 0 : null,
222
- lineHeight: fixedHeader ? 0 : null,
223
- width: '3.25rem',
224
- }}
225
- onFocus={handleFocus}
226
- onKeyDown={handleKeyDown}
227
- tabIndex={tabIndex}
228
- >
229
- <CellContext.Provider value={cellContext}>
230
- {getContent(
231
- 'SelectAll-fixed-header',
232
- fixedHeader
233
- ? {
234
- display: 'flex',
235
- height: 0,
236
- overflow: 'hidden',
237
- paddingBottom: 0,
238
- paddingTop: 0,
239
- visibility: 'hidden',
240
- }
241
- : null,
242
- fixedHeader && 'ariaHidden'
243
- )}
244
- {fixedHeader ? (
245
- <CellFixed>
246
- {getContent('SelectAll', {
247
- display: 'flex',
248
- justifyContent: 'flex-end',
249
- lineHeight: 1,
250
- width: '100%',
251
- })}
252
- </CellFixed>
253
- ) : null}
254
- </CellContext.Provider>
255
- </th>
256
- );
252
+ <SelectHeader
253
+ allSelected={props.allSelected}
254
+ assistiveText={{
255
+ selectAllRows: props.assistiveText.selectAllRows,
256
+ selectRowGroup: props.assistiveText.selectRowGroup,
257
257
  }}
258
- </TableContext.Consumer>
258
+ canSelectRows={canSelectRows}
259
+ fixedHeader={props.fixedHeader}
260
+ fixedLayout={props.fixedLayout}
261
+ headerRefs={props.headerRefs}
262
+ id={props.id}
263
+ indeterminateSelected={props.indeterminateSelected}
264
+ onToggleAll={props.onToggleAll}
265
+ />
259
266
  );
260
267
  }
261
268
 
262
269
  return selectHeader;
263
270
  };
264
271
 
265
- // ### Render
266
- render() {
267
- const actionsHeader = this.getActionsHeader();
268
- const selectHeader = this.getSelectHeader();
272
+ const actionsHeader = getActionsHeader();
273
+ const selectHeader = getSelectHeader();
269
274
 
270
- return (
271
- <thead
272
- className={classNames({
273
- 'slds-assistive-text': this.props.isHidden,
274
- })}
275
- >
276
- <tr className="slds-line-height_reset">
277
- {selectHeader}
278
- {this.props.columns.map((column, index) => (
279
- <CellContext.Provider
280
- key={`${this.props.id}-${column.props.property}`}
281
- value={{
282
- columnIndex: this.props.canSelectRows ? index + 1 : index,
283
- rowIndex: 0,
275
+ return (
276
+ <thead
277
+ className={classNames({
278
+ 'slds-assistive-text': props.isHidden,
279
+ })}
280
+ >
281
+ <tr className="slds-line-height_reset">
282
+ {selectHeader}
283
+ {props.columns.map((column, index) => (
284
+ <CellContext.Provider
285
+ key={`${props.id}-${column.props.property}`}
286
+ value={{
287
+ columnIndex: props.canSelectRows ? index + 1 : index,
288
+ rowIndex: 0,
289
+ }}
290
+ >
291
+ <HeaderCell
292
+ assistiveText={props.assistiveText}
293
+ cellRef={(ref) => {
294
+ if (props.headerRefs) {
295
+ props.headerRefs(ref, index);
296
+ }
284
297
  }}
285
- >
286
- <HeaderCell
287
- assistiveText={this.props.assistiveText}
288
- cellRef={(ref) => {
289
- if (this.props.headerRefs) {
290
- this.props.headerRefs(ref, index);
291
- }
292
- }}
293
- fixedHeader={this.props.fixedHeader}
294
- id={`${this.props.id}-${column.props.property}`}
295
- onSort={this.props.onSort}
296
- {...column.props}
297
- />
298
- </CellContext.Provider>
299
- ))}
300
- {actionsHeader}
301
- </tr>
302
- </thead>
303
- );
304
- }
305
- }
298
+ fixedHeader={props.fixedHeader}
299
+ id={`${props.id}-${column.props.property}`}
300
+ onSort={props.onSort}
301
+ {...column.props}
302
+ />
303
+ </CellContext.Provider>
304
+ ))}
305
+ {actionsHeader}
306
+ </tr>
307
+ </thead>
308
+ );
309
+ };
310
+
311
+ // ### Display Name
312
+ // Always use the canonical component name as the React display name.
313
+ DataTableHead.displayName = DATA_TABLE_HEAD;
314
+ DataTableHead.propTypes = propTypes;
306
315
 
307
316
  export default DataTableHead;