@commercetools-uikit/data-table 20.4.0 → 20.6.0
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.
|
@@ -22,14 +22,12 @@ var _styled = require('@emotion/styled/base');
|
|
|
22
22
|
var react = require('@emotion/react');
|
|
23
23
|
var designSystem = require('@commercetools-uikit/design-system');
|
|
24
24
|
var AccessibleButton = require('@commercetools-uikit/accessible-button');
|
|
25
|
-
var _taggedTemplateLiteral = require('@babel/runtime-corejs3/helpers/taggedTemplateLiteral');
|
|
26
25
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
27
26
|
var icons = require('@commercetools-uikit/icons');
|
|
28
27
|
var _Number$isNaN = require('@babel/runtime-corejs3/core-js-stable/number/is-nan');
|
|
29
28
|
var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
|
|
30
29
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
31
30
|
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
32
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
33
31
|
var dataTableManagerProvider = require('@commercetools-uikit/data-table-manager/data-table-manager-provider');
|
|
34
32
|
|
|
35
33
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
@@ -50,7 +48,6 @@ var AccessibleButton__default = /*#__PURE__*/_interopDefault(AccessibleButton);
|
|
|
50
48
|
var _Number$isNaN__default = /*#__PURE__*/_interopDefault(_Number$isNaN);
|
|
51
49
|
var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
|
|
52
50
|
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
53
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
54
51
|
|
|
55
52
|
const getPaddingStyle = props => {
|
|
56
53
|
if (props.isCondensed) return /*#__PURE__*/react.css("padding:", designSystem.designTokens.spacing20, " ", designSystem.designTokens.spacing40, ";" + ("" ), "" );
|
|
@@ -141,7 +138,7 @@ var _ref2 = {
|
|
|
141
138
|
} ;
|
|
142
139
|
const BaseCell = /*#__PURE__*/_styled__default["default"]("td", {
|
|
143
140
|
target: "e10u1n7e2"
|
|
144
|
-
} )("position:relative;display:flex;background-color:", designSystem.designTokens.colorSurface, ";border-bottom:", props => props.shouldRenderBottomBorder ?
|
|
141
|
+
} )("position:relative;display:flex;background-color:", designSystem.designTokens.colorSurface, ";border-bottom:", props => props.shouldRenderBottomBorder ? `1px solid ${designSystem.designTokens.colorNeutral95};` : 'none', ";font-size:", designSystem.designTokens.fontSize20, ";", props => props.shouldClipContent ? _ref2 : '', " ", props => props.shouldIgnoreRowClick ? _ref$1 : '', ";" + ("" ));
|
|
145
142
|
/*#__PURE__*/_styled__default["default"]("td", {
|
|
146
143
|
target: "e10u1n7e1"
|
|
147
144
|
} )("position:", props => props.disableFooterStickiness ? 'relative' : 'sticky', ";left:0;bottom:0;grid-column:1/", props => props.numberOfColumns, ";background-color:", designSystem.designTokens.colorSurface, ";border-bottom:1px solid ", designSystem.designTokens.colorNeutral90, ";border-top:1px solid ", designSystem.designTokens.colorNeutral90, ";margin-top:-1px;" + ("" ));
|
|
@@ -149,7 +146,6 @@ const RowExpandCollapseButton = /*#__PURE__*/_styled__default["default"](Accessi
|
|
|
149
146
|
target: "e10u1n7e0"
|
|
150
147
|
} )("cursor:", props => props.isRowCollapsed ? /*#__PURE__*/react.css("" , "" ) : /*#__PURE__*/react.css("" , "" ), ";position:absolute;height:16px;width:16px;bottom:0;right:0;opacity:0;display:flex;justify-content:flex-end;align-items:flex-end;" + ("" ));
|
|
151
148
|
|
|
152
|
-
var _templateObject, _templateObject2, _templateObject3;
|
|
153
149
|
const getButtonStyle = () => /*#__PURE__*/react.css("cursor:pointer;border:none;background:none;text-decoration:none;color:inherit;font:inherit;font-size:", designSystem.designTokens.fontSize10, ";font-family:inherit;" + ("" ), "" );
|
|
154
150
|
|
|
155
151
|
/* When a sortable header is deselected,
|
|
@@ -160,19 +156,38 @@ const getButtonStyle = () => /*#__PURE__*/react.css("cursor:pointer;border:none;
|
|
|
160
156
|
* is not the active sorted column, the icon for
|
|
161
157
|
* the current sort direction is animated with fadeIn
|
|
162
158
|
*/
|
|
163
|
-
const fadeIn = react.keyframes
|
|
159
|
+
const fadeIn = react.keyframes`
|
|
160
|
+
from {
|
|
161
|
+
opacity: 0;
|
|
162
|
+
}
|
|
163
|
+
to {
|
|
164
|
+
opacity: 1;
|
|
165
|
+
}
|
|
166
|
+
`;
|
|
164
167
|
|
|
165
168
|
/* When a sortable header is activated/selected,
|
|
166
169
|
* and the sort direction is 'desc', the ArrowDown
|
|
167
170
|
* icon is animated with rotateClockwise
|
|
168
171
|
*/
|
|
169
|
-
const rotateClockwise = react.keyframes
|
|
172
|
+
const rotateClockwise = react.keyframes`
|
|
173
|
+
from {
|
|
174
|
+
transform: rotate(-180deg);
|
|
175
|
+
} to {
|
|
176
|
+
transform: rotate(0deg);
|
|
177
|
+
}
|
|
178
|
+
`;
|
|
170
179
|
|
|
171
180
|
/* When a sortable header is activated/selected,
|
|
172
181
|
* and the sort direction is 'asc', the ArrowUp
|
|
173
182
|
* icon is animated with rotateCounterClockwise
|
|
174
183
|
*/
|
|
175
|
-
const rotateCounterClockwise = react.keyframes
|
|
184
|
+
const rotateCounterClockwise = react.keyframes`
|
|
185
|
+
from {
|
|
186
|
+
transform: rotate(180deg);
|
|
187
|
+
} to {
|
|
188
|
+
transform: rotate(0deg);
|
|
189
|
+
}
|
|
190
|
+
`;
|
|
176
191
|
|
|
177
192
|
/* A sortable header has the two arrow svg icons
|
|
178
193
|
* GIVEN column is sortable and is not focused
|
|
@@ -204,7 +219,7 @@ const HeaderIconWrapper = /*#__PURE__*/_styled__default["default"]("div", {
|
|
|
204
219
|
target: "e1ipt8n20"
|
|
205
220
|
} )("display:inline-flex;align-items:center;justify-content:center;margin-left:", designSystem.designTokens.spacing20, ";vertical-align:middle;" + ("" ));
|
|
206
221
|
|
|
207
|
-
const convertNumericDimensionToPixelValue = dimensionValue => typeof dimensionValue === 'number' ?
|
|
222
|
+
const convertNumericDimensionToPixelValue = dimensionValue => typeof dimensionValue === 'number' ? `${dimensionValue}px` : dimensionValue;
|
|
208
223
|
var convertNumericDimensionToPixelValue$1 = convertNumericDimensionToPixelValue;
|
|
209
224
|
|
|
210
225
|
const getClickableRowStyle = props => {
|
|
@@ -227,7 +242,10 @@ const TableContainer = /*#__PURE__*/_styled__default["default"]("div", {
|
|
|
227
242
|
target: "epk01s24"
|
|
228
243
|
} )("position:relative;z-index:0;box-shadow:", designSystem.designTokens.shadow17, ";border:1px solid ", designSystem.designTokens.colorNeutral95, ";border-radius:", designSystem.designTokens.borderRadius4, ";", props =>
|
|
229
244
|
// this is needed in order to have a sticky header
|
|
230
|
-
props.maxHeight ?
|
|
245
|
+
props.maxHeight ? `overflow-x: auto;` : '', " ", props => props.maxWidth && !props.disableSelfContainment ? `max-width: ${convertNumericDimensionToPixelValue$1(props.maxWidth)};` : '', " ", props => props.isBeingResized && `
|
|
246
|
+
* {
|
|
247
|
+
user-select: none;
|
|
248
|
+
}`, " ", getDisabledSelfContainmentStyles, ";" + ("" ));
|
|
231
249
|
const TableGrid = /*#__PURE__*/_styled__default["default"]("table", {
|
|
232
250
|
target: "epk01s23"
|
|
233
251
|
} )("display:grid;grid-template-columns:", props => {
|
|
@@ -235,7 +253,7 @@ const TableGrid = /*#__PURE__*/_styled__default["default"]("table", {
|
|
|
235
253
|
return props.columns && _mapInstanceProperty__default["default"](_context = props.columns).call(_context, column => column.width || 'auto').join(' ');
|
|
236
254
|
}, ";", props =>
|
|
237
255
|
// this is needed in order to have a sticky header
|
|
238
|
-
props.maxHeight ?
|
|
256
|
+
props.maxHeight ? `overflow-y: auto;` : '', " ", props => props.maxHeight && !props.disableSelfContainment ? `max-height: ${convertNumericDimensionToPixelValue$1(props.maxHeight)};` : '', " ", props => props.resizedTotalWidth ? `max-width: ${props.resizedTotalWidth}px;` : '', " ", getDisabledSelfContainmentStyles, ";" + ("" ));
|
|
239
257
|
const TableHeader = /*#__PURE__*/_styled__default["default"]("thead", {
|
|
240
258
|
target: "epk01s22"
|
|
241
259
|
} )("display:contents;:hover{", BaseHeaderCell, ":before{content:'';position:absolute;border-right:1px solid ", designSystem.designTokens.colorNeutral, ";top:", designSystem.designTokens.spacing20, ";right:0;bottom:", designSystem.designTokens.spacing20, ";}", BaseHeaderCell, ":last-child:before{display:none;}}" + ("" ));
|
|
@@ -254,7 +272,7 @@ function ownKeys$4(e, r) { var t = _Object$keys__default["default"](e); if (_Obj
|
|
|
254
272
|
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$4(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$4(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
255
273
|
const FooterEl = /*#__PURE__*/_styled__default["default"]("div", {
|
|
256
274
|
target: "e2ce7vj0"
|
|
257
|
-
} )("box-sizing:border-box;display:block;", getPaddingStyle, " ", getHorizontalAlignmentStyle, " background-color:", designSystem.designTokens.colorSurface, ";border-top:1px solid ", designSystem.designTokens.colorNeutral90, ";border-bottom:1px solid ", designSystem.designTokens.colorNeutral90, ";width:100%;", props => props.resizedTotalWidth ?
|
|
275
|
+
} )("box-sizing:border-box;display:block;", getPaddingStyle, " ", getHorizontalAlignmentStyle, " background-color:", designSystem.designTokens.colorSurface, ";border-top:1px solid ", designSystem.designTokens.colorNeutral90, ";border-bottom:1px solid ", designSystem.designTokens.colorNeutral90, ";width:100%;", props => props.resizedTotalWidth ? `max-width: ${props.resizedTotalWidth}px;` : '', ";" + ("" ));
|
|
258
276
|
const Footer = _ref => {
|
|
259
277
|
let _ref$horizontalCellAl = _ref.horizontalCellAlignment,
|
|
260
278
|
horizontalCellAlignment = _ref$horizontalCellAl === void 0 ? 'left' : _ref$horizontalCellAl,
|
|
@@ -294,18 +312,14 @@ const _excluded$3 = ["sortDirection", "disableHeaderStickiness", "horizontalCell
|
|
|
294
312
|
function ownKeys$3(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
295
313
|
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$3(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$3(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
296
314
|
const HeaderCellWrapper = props => {
|
|
297
|
-
var _headerRef$current2;
|
|
298
315
|
const columnResizingReducer = react$1.useContext(ColumnResizingContext);
|
|
299
316
|
const headerRef = react$1.useRef(null);
|
|
300
317
|
const onStartResizing = event => {
|
|
301
|
-
if (headerRef
|
|
318
|
+
if (headerRef?.current) {
|
|
302
319
|
columnResizingReducer.startResizing(headerRef, event);
|
|
303
320
|
}
|
|
304
321
|
};
|
|
305
|
-
const onDrag = event =>
|
|
306
|
-
var _headerRef$current;
|
|
307
|
-
return columnResizingReducer.onDragResizing(event, (_headerRef$current = headerRef.current) === null || _headerRef$current === void 0 ? void 0 : _headerRef$current.cellIndex);
|
|
308
|
-
};
|
|
322
|
+
const onDrag = event => columnResizingReducer.onDragResizing(event, headerRef.current?.cellIndex);
|
|
309
323
|
const onDragEnd = () => {
|
|
310
324
|
const finalSizes = columnResizingReducer.finishResizing();
|
|
311
325
|
if (props.onColumnResized) {
|
|
@@ -314,7 +328,7 @@ const HeaderCellWrapper = props => {
|
|
|
314
328
|
window.removeEventListener('mousemove', onDrag);
|
|
315
329
|
window.removeEventListener('mouseup', onDragEnd);
|
|
316
330
|
};
|
|
317
|
-
if (columnResizingReducer.getIsColumnBeingResized(
|
|
331
|
+
if (columnResizingReducer.getIsColumnBeingResized(headerRef.current?.cellIndex)) {
|
|
318
332
|
window.addEventListener('mousemove', onDrag);
|
|
319
333
|
window.addEventListener('mouseup', onDragEnd);
|
|
320
334
|
}
|
|
@@ -326,7 +340,7 @@ const HeaderCellWrapper = props => {
|
|
|
326
340
|
const shouldClipContent = props.columnWidth && isFixedWidthValue$1(props.columnWidth) || columnResizingReducer.getHasTableBeenResized() || columnResizingReducer.getIsAnyColumnBeingResized();
|
|
327
341
|
return jsxRuntime.jsxs(BaseHeaderCell, {
|
|
328
342
|
ref: headerRef,
|
|
329
|
-
"data-testid":
|
|
343
|
+
"data-testid": `header-${props.columnKey}`,
|
|
330
344
|
"data-id": props.columnKey,
|
|
331
345
|
shouldClipContent: shouldClipContent,
|
|
332
346
|
disableHeaderStickiness: props.disableHeaderStickiness,
|
|
@@ -477,27 +491,21 @@ const DataRow = _ref => {
|
|
|
477
491
|
const shouldRenderCollapseButton = (totalColumnsLength, currentColumnIndex) => rowHasTruncatedColumn && totalColumnsLength - 1 === currentColumnIndex;
|
|
478
492
|
return jsxRuntime.jsx(TableRow, {
|
|
479
493
|
isRowClickable: Boolean(props.onRowClick),
|
|
480
|
-
children: _mapInstanceProperty__default["default"](_context2 = props.columns).call(_context2, (column, columnIndex) => {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
} : undefined,
|
|
496
|
-
shouldRenderBottomBorder: shouldRenderBottomBorder,
|
|
497
|
-
shouldRenderResizingIndicator: getIsColumnBeingResized(columnIndex),
|
|
498
|
-
children: column.renderItem ? column.renderItem(props.row, isRowCollapsed) : itemRenderer(props.row, column, isRowCollapsed)
|
|
499
|
-
}, _concatInstanceProperty__default["default"](_context3 = "".concat(props.row.id, "-")).call(_context3, column.key));
|
|
500
|
-
})
|
|
494
|
+
children: _mapInstanceProperty__default["default"](_context2 = props.columns).call(_context2, (column, columnIndex) => jsxRuntime.jsx(DataCell$1, {
|
|
495
|
+
"data-testid": `cell-${props.rowIndex}-${column.key}`,
|
|
496
|
+
isTruncated: column.isTruncated && isRowCollapsed,
|
|
497
|
+
isCondensed: isCondensed,
|
|
498
|
+
isRowCollapsed: isRowCollapsed,
|
|
499
|
+
verticalCellAlignment: verticalCellAlignment,
|
|
500
|
+
horizontalCellAlignment: column.align ? column.align : horizontalCellAlignment,
|
|
501
|
+
shouldIgnoreRowClick: column.shouldIgnoreRowClick,
|
|
502
|
+
handleRowCollapseClick: handleRowCollapseClick,
|
|
503
|
+
shouldRenderCollapseButton: shouldRenderCollapseButton(props.columns.length, columnIndex),
|
|
504
|
+
onCellClick: props.onRowClick && !column.shouldIgnoreRowClick ? () => props.onRowClick?.(props.row, props.rowIndex, column.key) : undefined,
|
|
505
|
+
shouldRenderBottomBorder: shouldRenderBottomBorder,
|
|
506
|
+
shouldRenderResizingIndicator: getIsColumnBeingResized(columnIndex),
|
|
507
|
+
children: column.renderItem ? column.renderItem(props.row, isRowCollapsed) : itemRenderer(props.row, column, isRowCollapsed)
|
|
508
|
+
}, `${props.row.id}-${column.key}`))
|
|
501
509
|
});
|
|
502
510
|
};
|
|
503
511
|
DataRow.displayName = 'DataRow';
|
|
@@ -528,7 +536,7 @@ const setColumnWidth = function () {
|
|
|
528
536
|
});
|
|
529
537
|
return columns;
|
|
530
538
|
};
|
|
531
|
-
const getGridTemplateColumnsStyle = columns =>
|
|
539
|
+
const getGridTemplateColumnsStyle = columns => `${_mapInstanceProperty__default["default"](columns).call(columns, width => `${width || 0}px`).join(' ')}`;
|
|
532
540
|
const initialState = tableRef => ({
|
|
533
541
|
initialColWidth: undefined,
|
|
534
542
|
initialMousePosition: undefined,
|
|
@@ -575,14 +583,13 @@ const useManualResizingReducer = tableRef => {
|
|
|
575
583
|
return [manualResizingState, dispatch];
|
|
576
584
|
};
|
|
577
585
|
const useManualColumnResizing = tableRef => {
|
|
578
|
-
var _state$tableRef;
|
|
579
586
|
const _useManualResizingRed = useManualResizingReducer(tableRef),
|
|
580
587
|
_useManualResizingRed2 = _slicedToArray(_useManualResizingRed, 2),
|
|
581
588
|
state = _useManualResizingRed2[0],
|
|
582
589
|
dispatch = _useManualResizingRed2[1];
|
|
583
590
|
|
|
584
591
|
// if the table element has been rendered and we haven't yet measured the columns
|
|
585
|
-
if (
|
|
592
|
+
if (state.tableRef?.current && !state.sizes) {
|
|
586
593
|
var _context;
|
|
587
594
|
const renderedColumnMeasurements = [];
|
|
588
595
|
_forEachInstanceProperty__default["default"](_context = state.tableRef.current.querySelectorAll(':scope > thead > tr > th')).call(_context, header => {
|
|
@@ -611,10 +618,9 @@ const useManualColumnResizing = tableRef => {
|
|
|
611
618
|
const onDragResizing = (event, columnIndex) => {
|
|
612
619
|
// throttle and sync resizing update rate with screen refresh rate
|
|
613
620
|
requestAnimationFrame(() => {
|
|
614
|
-
var _state$tableRef2;
|
|
615
621
|
const width = calculateNewSize(state.initialColWidth, state.initialMousePosition, event.clientX);
|
|
616
622
|
const newColumnsSizes = setColumnWidth(state.sizes, columnIndex, width);
|
|
617
|
-
if (!
|
|
623
|
+
if (!state.tableRef?.current) return;
|
|
618
624
|
state.tableRef.current.style.gridTemplateColumns = getGridTemplateColumnsStyle(_mapInstanceProperty__default["default"](newColumnsSizes).call(newColumnsSizes, newColumnsSize => newColumnsSize.width.toString()));
|
|
619
625
|
});
|
|
620
626
|
};
|
|
@@ -635,8 +641,7 @@ const useManualColumnResizing = tableRef => {
|
|
|
635
641
|
return _reduceInstanceProperty__default["default"](_context2 = state.sizes).call(_context2, (a, b) => a + b.width, 0);
|
|
636
642
|
};
|
|
637
643
|
const reset = () => {
|
|
638
|
-
|
|
639
|
-
if (!((_state$tableRef3 = state.tableRef) !== null && _state$tableRef3 !== void 0 && _state$tableRef3.current)) return;
|
|
644
|
+
if (!state.tableRef?.current) return;
|
|
640
645
|
state.tableRef.current.style.gridTemplateColumns = '';
|
|
641
646
|
return dispatch({
|
|
642
647
|
type: 'reset'
|
|
@@ -787,7 +792,7 @@ DataTable.displayName = 'DataTable';
|
|
|
787
792
|
var DataTable$1 = DataTable;
|
|
788
793
|
|
|
789
794
|
// NOTE: This string will be replaced on build time with the package version.
|
|
790
|
-
var version = "20.
|
|
795
|
+
var version = "20.6.0";
|
|
791
796
|
|
|
792
797
|
Object.defineProperty(exports, 'useRowSelection', {
|
|
793
798
|
enumerable: true,
|