@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.
- package/components/button/__tests__/button.browser-test.jsx +0 -1
- package/components/data-table/cell.jsx +2 -2
- package/components/data-table/index.jsx +130 -85
- package/components/data-table/private/context-helper.js +26 -14
- package/components/data-table/private/head.jsx +269 -260
- package/components/data-table/private/header-cell.jsx +204 -230
- package/components/data-table/private/row.jsx +140 -105
- package/components/data-table/row-actions.jsx +2 -2
- package/components/utilities/truncate/index.jsx +1 -1
- package/lib/components/button/__tests__/button.browser-test.jsx +0 -1
- package/lib/components/data-table/cell.js +6 -6
- package/lib/components/data-table/index.js +127 -99
- package/lib/components/data-table/private/context-helper.js +13 -14
- package/lib/components/data-table/private/head.js +233 -252
- package/lib/components/data-table/private/header-cell.js +185 -221
- package/lib/components/data-table/private/row.js +97 -89
- package/lib/components/data-table/row-actions.js +6 -6
- package/lib/components/utilities/truncate/index.js +2 -2
- package/lib/package.json +4 -4
- package/module/components/button/__tests__/button.browser-test.js +0 -1
- package/module/components/button/__tests__/button.browser-test.js.map +1 -1
- package/module/components/data-table/cell.js +6 -6
- package/module/components/data-table/cell.js.map +1 -1
- package/module/components/data-table/index.js +120 -95
- package/module/components/data-table/index.js.map +1 -1
- package/module/components/data-table/private/context-helper.js +12 -12
- package/module/components/data-table/private/context-helper.js.map +1 -1
- package/module/components/data-table/private/head.js +230 -255
- package/module/components/data-table/private/head.js.map +1 -1
- package/module/components/data-table/private/header-cell.js +184 -225
- package/module/components/data-table/private/header-cell.js.map +1 -1
- package/module/components/data-table/private/row.js +95 -87
- package/module/components/data-table/private/row.js.map +1 -1
- package/module/components/data-table/row-actions.js +6 -6
- package/module/components/data-table/row-actions.js.map +1 -1
- package/module/components/utilities/truncate/index.js +1 -1
- package/module/components/utilities/truncate/index.js.map +1 -1
- 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, { useContext } from 'react';
|
|
5
|
+
import React, { useCallback, useContext, useMemo } from 'react';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
7
|
|
|
8
8
|
// ### classNames
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
import InteractiveElement from '../interactive-element';
|
|
26
26
|
import CellContext from '../private/cell-context';
|
|
27
27
|
import TableContext from '../private/table-context';
|
|
28
|
-
import
|
|
28
|
+
import useContextHelper from './context-helper';
|
|
29
29
|
|
|
30
30
|
const InteractiveCheckbox = InteractiveElement(Checkbox);
|
|
31
31
|
const InteractiveRadio = InteractiveElement(Radio);
|
|
@@ -67,25 +67,34 @@ const propTypes = {
|
|
|
67
67
|
*/
|
|
68
68
|
const DataTableRow = (props) => {
|
|
69
69
|
const tableContext = useContext(TableContext);
|
|
70
|
-
const selectRowCellContext =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const selectRowCellContext = useMemo(
|
|
71
|
+
() => ({
|
|
72
|
+
rowIndex: props.rowIndex,
|
|
73
|
+
columnIndex: 0,
|
|
74
|
+
}),
|
|
75
|
+
[props.rowIndex]
|
|
76
|
+
);
|
|
77
|
+
const { tabIndex, hasFocus, handleFocus, handleKeyDown } = useContextHelper(
|
|
75
78
|
tableContext,
|
|
76
79
|
selectRowCellContext,
|
|
77
80
|
props.fixedLayout
|
|
78
81
|
);
|
|
79
82
|
|
|
80
|
-
const
|
|
81
|
-
|
|
83
|
+
const { item, onToggle } = props;
|
|
84
|
+
const handleToggle = useCallback(
|
|
85
|
+
(e, { checked }) => onToggle(item, checked, e),
|
|
86
|
+
[item, onToggle]
|
|
87
|
+
);
|
|
82
88
|
|
|
83
|
-
const
|
|
84
|
-
const
|
|
89
|
+
const isSelected = !!find(props.selection, item);
|
|
90
|
+
const ariaProps = useMemo(() => {
|
|
91
|
+
const result = {};
|
|
85
92
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
if (props.canSelectRows) {
|
|
94
|
+
result['aria-selected'] = isSelected ? 'true' : 'false';
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}, [isSelected, props.canSelectRows]);
|
|
89
98
|
|
|
90
99
|
// i18n
|
|
91
100
|
return (
|
|
@@ -97,100 +106,126 @@ const DataTableRow = (props) => {
|
|
|
97
106
|
'slds-has-focus': hasFocus,
|
|
98
107
|
})}
|
|
99
108
|
>
|
|
100
|
-
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<CellContext.Provider value={selectRowCellContext}>
|
|
117
|
-
{props.canSelectRows === 'radio' ? (
|
|
118
|
-
<InteractiveRadio
|
|
119
|
-
assistiveText={{
|
|
120
|
-
label: `${props.assistiveText.selectRow} ${
|
|
121
|
-
Number(props.index) + 1
|
|
122
|
-
}`,
|
|
109
|
+
{useMemo(
|
|
110
|
+
() => (
|
|
111
|
+
<React.Fragment>
|
|
112
|
+
{props.canSelectRows ? (
|
|
113
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
114
|
+
<td
|
|
115
|
+
role={props.fixedLayout ? 'gridcell' : null}
|
|
116
|
+
className="slds-text-align_right"
|
|
117
|
+
data-label={props.stacked ? 'Select Row' : undefined}
|
|
118
|
+
style={{ width: '3.25rem' }}
|
|
119
|
+
onFocus={handleFocus}
|
|
120
|
+
onKeyDown={handleKeyDown}
|
|
121
|
+
ref={(ref) => {
|
|
122
|
+
if (ref && hasFocus) {
|
|
123
|
+
ref.focus();
|
|
124
|
+
}
|
|
123
125
|
}}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
126
|
+
tabIndex={tabIndex}
|
|
127
|
+
>
|
|
128
|
+
<CellContext.Provider value={selectRowCellContext}>
|
|
129
|
+
{props.canSelectRows === 'radio' ? (
|
|
130
|
+
<InteractiveRadio
|
|
131
|
+
assistiveText={{
|
|
132
|
+
label: `${props.assistiveText.selectRow} ${
|
|
133
|
+
Number(props.index) + 1
|
|
134
|
+
}`,
|
|
135
|
+
}}
|
|
136
|
+
aria-labelledby={`${props.id}-SelectRow-label ${props.tableId}-SLDSDataTableHead-column-group-header-row-select`}
|
|
137
|
+
checked={isSelected}
|
|
138
|
+
className="slds-m-right_x-small"
|
|
139
|
+
id={`${props.id}-SelectRow`}
|
|
140
|
+
labelId={`${props.id}-SelectRow-label`}
|
|
141
|
+
name={`${props.tableId}-SelectRow`}
|
|
142
|
+
onChange={handleToggle}
|
|
143
|
+
/>
|
|
144
|
+
) : (
|
|
145
|
+
<InteractiveCheckbox
|
|
146
|
+
assistiveText={{
|
|
147
|
+
label: `${props.assistiveText.selectRow} ${
|
|
148
|
+
Number(props.index) + 1
|
|
149
|
+
}`,
|
|
150
|
+
}}
|
|
151
|
+
aria-labelledby={`${props.id}-SelectRow-label ${props.tableId}-SLDSDataTableHead-column-group-header-row-select`}
|
|
152
|
+
checked={isSelected}
|
|
153
|
+
id={`${props.id}-SelectRow`}
|
|
154
|
+
labelId={`${props.id}-SelectRow-label`}
|
|
155
|
+
name={`SelectRow${props.index + 1}`}
|
|
156
|
+
onChange={handleToggle}
|
|
157
|
+
/>
|
|
158
|
+
)}
|
|
159
|
+
</CellContext.Provider>
|
|
160
|
+
</td>
|
|
161
|
+
) : null}
|
|
162
|
+
{props.columns.map((column, index) => {
|
|
163
|
+
const { Cell } = column;
|
|
164
|
+
const cellId = `${props.id}-${DATA_TABLE_CELL}-${column.props.property}`;
|
|
153
165
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
166
|
+
return (
|
|
167
|
+
<CellContext.Provider
|
|
168
|
+
key={cellId}
|
|
169
|
+
value={{
|
|
170
|
+
columnIndex: props.canSelectRows ? index + 1 : index,
|
|
171
|
+
rowIndex: props.rowIndex,
|
|
172
|
+
}}
|
|
173
|
+
>
|
|
174
|
+
<Cell
|
|
175
|
+
{...column.props}
|
|
176
|
+
className={column.props.truncate ? 'slds-truncate' : null}
|
|
177
|
+
fixedLayout={props.fixedLayout}
|
|
178
|
+
rowHeader={column.props.primaryColumn}
|
|
179
|
+
id={cellId}
|
|
180
|
+
item={item}
|
|
181
|
+
width={column.props.width}
|
|
182
|
+
headerId={item.headerId}
|
|
183
|
+
columns={props.columns}
|
|
184
|
+
>
|
|
185
|
+
{item[column.props.property]}
|
|
186
|
+
</Cell>
|
|
187
|
+
</CellContext.Provider>
|
|
188
|
+
);
|
|
189
|
+
})}
|
|
190
|
+
<CellContext.Provider
|
|
191
|
+
value={{
|
|
192
|
+
columnIndex: props.canSelectRows
|
|
193
|
+
? props.columns.length + 1
|
|
194
|
+
: props.columns.length,
|
|
195
|
+
rowIndex: props.rowIndex,
|
|
196
|
+
}}
|
|
172
197
|
>
|
|
173
|
-
{props.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
198
|
+
{props.rowActions
|
|
199
|
+
? React.cloneElement(props.rowActions, {
|
|
200
|
+
id: `${props.id}-${DATA_TABLE_ROW_ACTIONS}`,
|
|
201
|
+
item,
|
|
202
|
+
fixedLayout: props.fixedLayout,
|
|
203
|
+
})
|
|
204
|
+
: null}
|
|
205
|
+
</CellContext.Provider>
|
|
206
|
+
</React.Fragment>
|
|
207
|
+
),
|
|
208
|
+
[
|
|
209
|
+
handleFocus,
|
|
210
|
+
handleKeyDown,
|
|
211
|
+
handleToggle,
|
|
212
|
+
hasFocus,
|
|
213
|
+
isSelected,
|
|
214
|
+
item,
|
|
215
|
+
tabIndex,
|
|
216
|
+
props.assistiveText.selectRow,
|
|
217
|
+
props.canSelectRows,
|
|
218
|
+
props.columns,
|
|
219
|
+
props.fixedLayout,
|
|
220
|
+
props.id,
|
|
221
|
+
props.index,
|
|
222
|
+
props.rowActions,
|
|
223
|
+
props.rowIndex,
|
|
224
|
+
props.stacked,
|
|
225
|
+
props.tableId,
|
|
226
|
+
selectRowCellContext,
|
|
227
|
+
]
|
|
228
|
+
)}
|
|
194
229
|
</tr>
|
|
195
230
|
);
|
|
196
231
|
};
|
|
@@ -20,7 +20,7 @@ import EventUtil from '../../utilities/event';
|
|
|
20
20
|
import InteractiveElement from './interactive-element';
|
|
21
21
|
import CellContext from './private/cell-context';
|
|
22
22
|
import TableContext from './private/table-context';
|
|
23
|
-
import
|
|
23
|
+
import useContextHelper from './private/context-helper';
|
|
24
24
|
|
|
25
25
|
// ## Constants
|
|
26
26
|
import { DATA_TABLE_ROW_ACTIONS } from '../../utilities/constants';
|
|
@@ -75,7 +75,7 @@ const defaultProps = {
|
|
|
75
75
|
const DataTableRowActions = (props) => {
|
|
76
76
|
const tableContext = useContext(TableContext);
|
|
77
77
|
const cellContext = useContext(CellContext);
|
|
78
|
-
const { tabIndex, hasFocus, handleFocus, handleKeyDown } =
|
|
78
|
+
const { tabIndex, hasFocus, handleFocus, handleKeyDown } = useContextHelper(
|
|
79
79
|
tableContext,
|
|
80
80
|
cellContext,
|
|
81
81
|
props.fixedLayout
|
|
@@ -17,7 +17,7 @@ var _cellContext = _interopRequireDefault(require("./private/cell-context"));
|
|
|
17
17
|
|
|
18
18
|
var _tableContext = _interopRequireDefault(require("./private/table-context"));
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _contextHelper = _interopRequireDefault(require("./private/context-helper"));
|
|
21
21
|
|
|
22
22
|
var _constants = require("../../utilities/constants");
|
|
23
23
|
|
|
@@ -41,11 +41,11 @@ var DataTableCell = function DataTableCell(props) {
|
|
|
41
41
|
var tableContext = (0, _react.useContext)(_tableContext.default);
|
|
42
42
|
var cellContext = (0, _react.useContext)(_cellContext.default);
|
|
43
43
|
|
|
44
|
-
var
|
|
45
|
-
tabIndex =
|
|
46
|
-
hasFocus =
|
|
47
|
-
handleFocus =
|
|
48
|
-
handleKeyDown =
|
|
44
|
+
var _useContextHelper = (0, _contextHelper.default)(tableContext, cellContext, props.fixedLayout),
|
|
45
|
+
tabIndex = _useContextHelper.tabIndex,
|
|
46
|
+
hasFocus = _useContextHelper.hasFocus,
|
|
47
|
+
handleFocus = _useContextHelper.handleFocus,
|
|
48
|
+
handleKeyDown = _useContextHelper.handleKeyDown;
|
|
49
49
|
|
|
50
50
|
var childText = /*#__PURE__*/_react.default.isValidElement(props.children) ? props.children.props.children : props.children;
|
|
51
51
|
|
|
@@ -17,7 +17,11 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
17
17
|
|
|
18
18
|
var _lodash = _interopRequireDefault(require("lodash.assign"));
|
|
19
19
|
|
|
20
|
-
var _lodash2 = _interopRequireDefault(require("lodash.
|
|
20
|
+
var _lodash2 = _interopRequireDefault(require("lodash.isequal"));
|
|
21
|
+
|
|
22
|
+
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
23
|
+
|
|
24
|
+
var _lodash3 = _interopRequireDefault(require("lodash.reject"));
|
|
21
25
|
|
|
22
26
|
var _columnResizer = _interopRequireDefault(require("column-resizer"));
|
|
23
27
|
|
|
@@ -57,10 +61,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
57
61
|
|
|
58
62
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
59
63
|
|
|
60
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
61
|
-
|
|
62
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
63
|
-
|
|
64
64
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
65
65
|
|
|
66
66
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -69,10 +69,6 @@ function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "und
|
|
|
69
69
|
|
|
70
70
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
71
71
|
|
|
72
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
73
|
-
|
|
74
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
75
|
-
|
|
76
72
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
77
73
|
|
|
78
74
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -105,6 +101,14 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
105
101
|
|
|
106
102
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
107
103
|
|
|
104
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
105
|
+
|
|
106
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
107
|
+
|
|
108
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
109
|
+
|
|
110
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
111
|
+
|
|
108
112
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
109
113
|
|
|
110
114
|
// Safely get the length of an array, returning 0 for invalid input.
|
|
@@ -132,6 +136,84 @@ var defaultProps = {
|
|
|
132
136
|
draggingClass: 'slds-table-column-resizer'
|
|
133
137
|
}
|
|
134
138
|
};
|
|
139
|
+
var getAssistiveText = (0, _memoizeOne.default)(function (assistiveText, actionsHeaderText, columnSortText, columnSortedAscendingText, columnSortedDescendingText, selectAllRowsText, selectRowText) {
|
|
140
|
+
var result = _objectSpread(_objectSpread({}, defaultProps.assistiveText), assistiveText);
|
|
141
|
+
|
|
142
|
+
if (actionsHeaderText) {
|
|
143
|
+
result.actionsHeader = actionsHeaderText;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (selectAllRowsText) {
|
|
147
|
+
result.selectAllRows = selectAllRowsText;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (columnSortedAscendingText) {
|
|
151
|
+
result.columnSortedAscending = columnSortedAscendingText;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (columnSortedDescendingText) {
|
|
155
|
+
result.columnSortedDescending = columnSortedDescendingText;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (columnSortText) {
|
|
159
|
+
result.columnSort = columnSortText;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (selectRowText) {
|
|
163
|
+
result.selectRow = selectRowText;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return result;
|
|
167
|
+
}, _lodash2.default);
|
|
168
|
+
var getColumnsAndRowActions = (0, _memoizeOne.default)(function (children, id, fixedHeader, fixedLayout, search) {
|
|
169
|
+
var columns = [];
|
|
170
|
+
var RowActions = null;
|
|
171
|
+
|
|
172
|
+
_react.default.Children.forEach(children, function (child) {
|
|
173
|
+
if (child && child.type.displayName === _column.default.displayName) {
|
|
174
|
+
var _child$props = child.props,
|
|
175
|
+
columnChildren = _child$props.children,
|
|
176
|
+
columnProps = _objectWithoutProperties(_child$props, ["children"]);
|
|
177
|
+
|
|
178
|
+
var props = _objectSpread({
|
|
179
|
+
fixedLayout: fixedLayout,
|
|
180
|
+
search: search,
|
|
181
|
+
id: id
|
|
182
|
+
}, columnProps);
|
|
183
|
+
|
|
184
|
+
var Cell;
|
|
185
|
+
|
|
186
|
+
if (columnChildren && columnChildren.type.displayName === _constants.DATA_TABLE_CELL) {
|
|
187
|
+
Cell = columnChildren.type;
|
|
188
|
+
(0, _lodash.default)(props, columnChildren.props);
|
|
189
|
+
} else {
|
|
190
|
+
Cell = _cell.default;
|
|
191
|
+
} // eslint-disable-next-line fp/no-mutating-methods
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
columns.push({
|
|
195
|
+
Cell: Cell,
|
|
196
|
+
props: props
|
|
197
|
+
});
|
|
198
|
+
} else if (child && child.type.displayName === _rowActions.default.displayName) {
|
|
199
|
+
var dropdown = child.props.dropdown;
|
|
200
|
+
var dropdownPropOverrides = {};
|
|
201
|
+
|
|
202
|
+
if (fixedHeader) {
|
|
203
|
+
dropdownPropOverrides.menuPosition = 'overflowBoundaryElement';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
RowActions = /*#__PURE__*/_react.default.cloneElement(child, {
|
|
207
|
+
dropdown: dropdown ? /*#__PURE__*/_react.default.cloneElement(dropdown, dropdownPropOverrides) : null
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
columns: columns,
|
|
214
|
+
RowActions: RowActions
|
|
215
|
+
};
|
|
216
|
+
}, _lodash2.default);
|
|
135
217
|
/**
|
|
136
218
|
* DataTables support the display of structured data in rows and columns with an HTML table. To sort, filter or paginate the table, simply update the data passed in the items to the table and it will re-render itself appropriately. The table will throw a sort event as needed, and helper components for paging and filtering are coming soon.
|
|
137
219
|
*
|
|
@@ -153,6 +235,27 @@ var DataTable = /*#__PURE__*/function (_React$Component) {
|
|
|
153
235
|
|
|
154
236
|
_this = _super.call(this, props);
|
|
155
237
|
|
|
238
|
+
_defineProperty(_assertThisInitialized(_this), "getTableContext", (0, _memoizeOne.default)(function (state, isKeyboardNavigation) {
|
|
239
|
+
return {
|
|
240
|
+
activeCell: state.activeCell,
|
|
241
|
+
activeElement: state.activeElement,
|
|
242
|
+
mode: state.mode,
|
|
243
|
+
tableHasFocus: state.tableHasFocus,
|
|
244
|
+
changeActiveCell: _this.changeActiveCell,
|
|
245
|
+
changeActiveElement: _this.changeActiveElement,
|
|
246
|
+
handleKeyDown: _this.handleKeyDown,
|
|
247
|
+
registerInteractiveElement: _this.registerInteractiveElement,
|
|
248
|
+
allowKeyboardNavigation: state.allowKeyboardNavigation,
|
|
249
|
+
setAllowKeyboardNavigation: function setAllowKeyboardNavigation(allowKeyboardNavigation) {
|
|
250
|
+
if (isKeyboardNavigation) {
|
|
251
|
+
_this.setState({
|
|
252
|
+
allowKeyboardNavigation: allowKeyboardNavigation
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
}));
|
|
258
|
+
|
|
156
259
|
_defineProperty(_assertThisInitialized(_this), "handleToggleAll", function (e, _ref) {
|
|
157
260
|
var checked = _ref.checked;
|
|
158
261
|
|
|
@@ -186,7 +289,7 @@ var DataTable = /*#__PURE__*/function (_React$Component) {
|
|
|
186
289
|
if (selected) {
|
|
187
290
|
selection = _this.props.selectRows === 'radio' ? [item] : [].concat(_toConsumableArray(_this.props.selection), [item]);
|
|
188
291
|
} else {
|
|
189
|
-
selection = (0,
|
|
292
|
+
selection = (0, _lodash3.default)(_this.props.selection, item);
|
|
190
293
|
}
|
|
191
294
|
|
|
192
295
|
_this.props.onChange(selection, e);
|
|
@@ -199,7 +302,7 @@ var DataTable = /*#__PURE__*/function (_React$Component) {
|
|
|
199
302
|
if (selected) {
|
|
200
303
|
_selection2 = _this.props.selectRows === 'radio' ? [item] : [].concat(_toConsumableArray(_this.props.selection), [item]);
|
|
201
304
|
} else {
|
|
202
|
-
_selection2 = (0,
|
|
305
|
+
_selection2 = (0, _lodash3.default)(_this.props.selection, item);
|
|
203
306
|
}
|
|
204
307
|
|
|
205
308
|
_this.props.onRowChange(e, {
|
|
@@ -356,10 +459,6 @@ var DataTable = /*#__PURE__*/function (_React$Component) {
|
|
|
356
459
|
this.loadMoreIfNeeded();
|
|
357
460
|
}
|
|
358
461
|
|
|
359
|
-
if (this.props.items !== prevProps.items) {
|
|
360
|
-
this.interactiveElements = {};
|
|
361
|
-
}
|
|
362
|
-
|
|
363
462
|
if (this.state.allowKeyboardNavigation && !prevState.allowKeyboardNavigation) {
|
|
364
463
|
// When re-enabling keyboard navigation (e.g. when a dropdown closes), mark that
|
|
365
464
|
// focus has returned to the table. This must wait until after `allowKeyboardNavigation`
|
|
@@ -436,6 +535,14 @@ var DataTable = /*#__PURE__*/function (_React$Component) {
|
|
|
436
535
|
|
|
437
536
|
return null;
|
|
438
537
|
}
|
|
538
|
+
}, {
|
|
539
|
+
key: "UNSAFE_componentWillUpdate",
|
|
540
|
+
value: // eslint-disable-next-line camelcase
|
|
541
|
+
function UNSAFE_componentWillUpdate(nextProps) {
|
|
542
|
+
if (this.props.items !== nextProps.items) {
|
|
543
|
+
this.interactiveElements = {};
|
|
544
|
+
}
|
|
545
|
+
}
|
|
439
546
|
}, {
|
|
440
547
|
key: "isResizable",
|
|
441
548
|
value: function isResizable() {
|
|
@@ -843,73 +950,12 @@ var DataTable = /*#__PURE__*/function (_React$Component) {
|
|
|
843
950
|
var canSelectRows = this.props.selectRows && numNonHeaderRows > 0 ? this.props.selectRows : false;
|
|
844
951
|
var allSelected = canSelectRows && numNonHeaderRows === numSelected;
|
|
845
952
|
var indeterminateSelected = canSelectRows && numNonHeaderRows !== numSelected && numSelected !== 0;
|
|
846
|
-
var columns = [];
|
|
847
|
-
var RowActions = null;
|
|
848
953
|
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
children = _child$props.children,
|
|
853
|
-
columnProps = _objectWithoutProperties(_child$props, ["children"]);
|
|
954
|
+
var _getColumnsAndRowActi = getColumnsAndRowActions(this.props.children, this.props.id, this.getFixedHeader(), this.props.fixedLayout, this.props.search),
|
|
955
|
+
columns = _getColumnsAndRowActi.columns,
|
|
956
|
+
RowActions = _getColumnsAndRowActi.RowActions;
|
|
854
957
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
delete props.children;
|
|
858
|
-
(0, _lodash.default)(props, columnProps);
|
|
859
|
-
var Cell;
|
|
860
|
-
|
|
861
|
-
if (children && children.type.displayName === _constants.DATA_TABLE_CELL) {
|
|
862
|
-
Cell = children.type;
|
|
863
|
-
(0, _lodash.default)(props, children.props);
|
|
864
|
-
} else {
|
|
865
|
-
Cell = _cell.default;
|
|
866
|
-
} // eslint-disable-next-line fp/no-mutating-methods
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
columns.push({
|
|
870
|
-
Cell: Cell,
|
|
871
|
-
props: props,
|
|
872
|
-
dataTableProps: _this4.props
|
|
873
|
-
});
|
|
874
|
-
} else if (child && child.type.displayName === _rowActions.default.displayName) {
|
|
875
|
-
var dropdown = child.props.dropdown;
|
|
876
|
-
var dropdownPropOverrides = {};
|
|
877
|
-
|
|
878
|
-
if (_this4.getFixedHeader()) {
|
|
879
|
-
dropdownPropOverrides.menuPosition = 'overflowBoundaryElement';
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
RowActions = /*#__PURE__*/_react.default.cloneElement(child, {
|
|
883
|
-
dropdown: dropdown ? /*#__PURE__*/_react.default.cloneElement(dropdown, dropdownPropOverrides) : null
|
|
884
|
-
});
|
|
885
|
-
}
|
|
886
|
-
});
|
|
887
|
-
|
|
888
|
-
var assistiveText = _objectSpread(_objectSpread({}, defaultProps.assistiveText), this.props.assistiveText);
|
|
889
|
-
|
|
890
|
-
if (this.props.assistiveTextForActionsHeader) {
|
|
891
|
-
assistiveText.actionsHeader = this.props.assistiveTextForActionsHeader;
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
if (this.props.assistiveTextForSelectAllRows) {
|
|
895
|
-
assistiveText.selectAllRows = this.props.assistiveTextForSelectAllRows;
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
if (this.props.assistiveTextForColumnSortedAscending) {
|
|
899
|
-
assistiveText.columnSortedAscending = this.props.assistiveTextForColumnSortedAscending;
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
if (this.props.assistiveTextForColumnSortedDescending) {
|
|
903
|
-
assistiveText.columnSortedDescending = this.props.assistiveTextForColumnSortedDescending;
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
if (this.props.assistiveTextForColumnSort) {
|
|
907
|
-
assistiveText.columnSort = this.props.assistiveTextForColumnSort;
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
if (this.props.assistiveTextForSelectRow) {
|
|
911
|
-
assistiveText.selectRow = this.props.assistiveTextForSelectRow;
|
|
912
|
-
}
|
|
958
|
+
var assistiveText = getAssistiveText(this.props.assistiveText, this.props.assistiveTextForActionsHeader, this.props.assistiveTextForSelectAllRows, this.props.assistiveTextForColumnSortedAscending, this.props.assistiveTextForColumnSortedDescending, this.props.assistiveTextForColumnSort, this.props.assistiveTextForSelectRow);
|
|
913
959
|
|
|
914
960
|
if (this.props.selectRows && this.props.selectRows !== 'radio') {
|
|
915
961
|
ariaProps['aria-multiselectable'] = 'true';
|
|
@@ -921,27 +967,9 @@ var DataTable = /*#__PURE__*/function (_React$Component) {
|
|
|
921
967
|
column: this.headerRefs.column.slice(0, columns.length),
|
|
922
968
|
select: canSelectRows ? this.headerRefs.select : []
|
|
923
969
|
};
|
|
924
|
-
var tableContext = {
|
|
925
|
-
activeCell: this.state.activeCell,
|
|
926
|
-
activeElement: this.state.activeElement,
|
|
927
|
-
mode: this.state.mode,
|
|
928
|
-
tableHasFocus: this.state.tableHasFocus,
|
|
929
|
-
changeActiveCell: this.changeActiveCell,
|
|
930
|
-
changeActiveElement: this.changeActiveElement,
|
|
931
|
-
handleKeyDown: this.handleKeyDown,
|
|
932
|
-
registerInteractiveElement: this.registerInteractiveElement,
|
|
933
|
-
allowKeyboardNavigation: this.state.allowKeyboardNavigation,
|
|
934
|
-
setAllowKeyboardNavigation: function setAllowKeyboardNavigation(allowKeyboardNavigation) {
|
|
935
|
-
if (_this4.getKeyboardNavigation()) {
|
|
936
|
-
_this4.setState({
|
|
937
|
-
allowKeyboardNavigation: allowKeyboardNavigation
|
|
938
|
-
});
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
};
|
|
942
970
|
|
|
943
971
|
var component = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_tableContext.default.Provider, {
|
|
944
|
-
value:
|
|
972
|
+
value: this.getTableContext(this.state, this.getKeyboardNavigation())
|
|
945
973
|
}, /*#__PURE__*/_react.default.createElement("table", _extends({}, ariaProps, {
|
|
946
974
|
className: (0, _classnames.default)('slds-table', {
|
|
947
975
|
'slds-table_fixed-layout': this.getFixedLayout(),
|