@salesforce/design-system-react 0.10.41 → 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/brand-band/__docs__/__snapshots__/storybook-stories.storyshot +47 -157
- package/components/brand-band/__docs__/storybook-stories.jsx +4 -2
- package/components/brand-band/__examples__/{lightning-blue-theme.jsx → group-image.jsx} +1 -11
- package/components/brand-band/__examples__/no-image.jsx +1 -2
- package/{lib/components/brand-band/__examples__/lightning-blue-theme.jsx → components/brand-band/__examples__/user-image.jsx} +1 -11
- package/components/brand-band/check-props.js +18 -0
- package/components/brand-band/component.json +8 -4
- package/components/brand-band/index.jsx +23 -66
- package/components/brand-band.d.ts +1 -26
- package/components/button/__tests__/button.browser-test.jsx +0 -1
- package/components/combobox/__tests__/combobox.browser-test.jsx +18 -0
- package/components/combobox/combobox.jsx +4 -1
- package/components/component-docs.json +13 -38
- 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/icon/__docs__/__snapshots__/storybook-stories.storyshot +49 -2
- package/components/icon/__docs__/storybook-stories.jsx +2 -0
- package/components/icon/__examples__/color-success.jsx +24 -0
- package/components/icon/__examples__/colors.jsx +10 -2
- package/components/icon/index.jsx +2 -0
- package/components/icon.d.ts +1 -1
- package/components/site-stories.js +8 -4
- package/components/utilities/truncate/index.jsx +1 -1
- package/lib/components/brand-band/__docs__/__snapshots__/storybook-stories.storyshot +47 -157
- package/lib/components/brand-band/__docs__/storybook-stories.jsx +4 -2
- package/lib/components/brand-band/__examples__/group-image.jsx +12 -0
- package/lib/components/brand-band/__examples__/no-image.jsx +1 -2
- package/lib/components/brand-band/__examples__/user-image.jsx +12 -0
- package/lib/components/brand-band/check-props.js +29 -0
- package/lib/components/brand-band/component.json +8 -4
- package/lib/components/brand-band/index.js +9 -50
- package/lib/components/brand-band.d.ts +1 -26
- package/lib/components/button/__tests__/button.browser-test.jsx +0 -1
- package/lib/components/combobox/__tests__/combobox.browser-test.jsx +18 -0
- package/lib/components/combobox/combobox.js +6 -2
- package/lib/components/component-docs.json +13 -38
- 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/icon/__docs__/__snapshots__/storybook-stories.storyshot +49 -2
- package/lib/components/icon/__docs__/storybook-stories.jsx +2 -0
- package/lib/components/icon/__examples__/color-success.jsx +24 -0
- package/lib/components/icon/__examples__/colors.jsx +10 -2
- package/lib/components/icon/index.js +2 -1
- package/lib/components/icon.d.ts +1 -1
- package/lib/components/site-stories.js +6 -3
- package/lib/components/utilities/truncate/index.js +2 -2
- package/lib/package.json +13 -9
- package/module/components/brand-band/__docs__/__snapshots__/storybook-stories.storyshot +47 -157
- package/module/components/brand-band/__docs__/storybook-stories.js +6 -3
- package/module/components/brand-band/__docs__/storybook-stories.js.map +1 -1
- package/module/components/brand-band/__examples__/{lightning-blue-theme.js → group-image.js} +4 -9
- package/module/components/brand-band/__examples__/group-image.js.map +1 -0
- package/module/components/brand-band/__examples__/no-image.js +2 -4
- package/module/components/brand-band/__examples__/no-image.js.map +1 -1
- package/module/components/brand-band/__examples__/user-image.js +52 -0
- package/module/components/brand-band/__examples__/user-image.js.map +1 -0
- package/module/components/brand-band/check-props.js +20 -0
- package/module/components/brand-band/check-props.js.map +1 -0
- package/module/components/brand-band/component.json +8 -4
- package/module/components/brand-band/index.js +10 -51
- package/module/components/brand-band/index.js.map +1 -1
- package/module/components/brand-band.d.ts +1 -26
- 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/combobox/__tests__/combobox.browser-test.js +22 -0
- package/module/components/combobox/__tests__/combobox.browser-test.js.map +1 -1
- package/module/components/combobox/combobox.js +6 -2
- package/module/components/combobox/combobox.js.map +1 -1
- package/module/components/component-docs.json +13 -38
- 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/icon/__docs__/__snapshots__/storybook-stories.storyshot +49 -2
- package/module/components/icon/__docs__/storybook-stories.js +3 -0
- package/module/components/icon/__docs__/storybook-stories.js.map +1 -1
- package/module/components/icon/__examples__/color-success.js +64 -0
- package/module/components/icon/__examples__/color-success.js.map +1 -0
- package/module/components/icon/__examples__/colors.js +11 -2
- package/module/components/icon/__examples__/colors.js.map +1 -1
- package/module/components/icon/index.js +2 -1
- package/module/components/icon/index.js.map +1 -1
- package/module/components/icon.d.ts +1 -1
- package/module/components/site-stories.js +6 -3
- package/module/components/site-stories.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 +13 -9
- package/module/components/brand-band/__examples__/lightning-blue-theme.js.map +0 -1
|
@@ -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
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
checkProps(DATA_TABLE_COLUMN, props);
|
|
97
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
98
|
+
}, []);
|
|
92
99
|
|
|
93
|
-
|
|
94
|
-
|
|
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
|
|
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,
|
|
126
|
+
})(oldSortDirection, props.isDefaultSortDescending);
|
|
125
127
|
const data = {
|
|
126
|
-
property:
|
|
127
|
-
sortDirection,
|
|
128
|
+
property: props.property,
|
|
129
|
+
sortDirection: newSortDirection,
|
|
128
130
|
};
|
|
129
131
|
|
|
130
|
-
|
|
131
|
-
sortDirection,
|
|
132
|
-
});
|
|
132
|
+
setSortDirection(newSortDirection);
|
|
133
133
|
|
|
134
|
-
if (isFunction(
|
|
135
|
-
|
|
134
|
+
if (isFunction(props.onSort)) {
|
|
135
|
+
props.onSort(data, e);
|
|
136
136
|
}
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
<
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
<
|
|
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
|
-
</
|
|
224
|
-
|
|
199
|
+
</span>
|
|
200
|
+
</span>
|
|
201
|
+
);
|
|
202
|
+
};
|
|
225
203
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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;
|