@commercetools-uikit/data-table 19.11.0 → 19.12.1

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 icons = require('@commercetools-uikit/icons');
27
26
  var jsxRuntime = require('@emotion/react/jsx-runtime');
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 ? "1px solid ".concat(designSystem.designTokens.colorNeutral95, ";") : 'none', ";font-size:", designSystem.designTokens.fontSize20, ";", props => props.shouldClipContent ? _ref2 : '', " ", props => props.shouldIgnoreRowClick ? _ref$1 : '', ";" + ("" ));
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(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n from {\n opacity: 0;\n }\n to {\n opacity: 1;\n }\n"])));
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(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n from {\n transform: rotate(-180deg);\n } to {\n transform: rotate(0deg);\n }\n"])));
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(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n from {\n transform: rotate(180deg);\n } to {\n transform: rotate(0deg);\n }\n"])));
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' ? "".concat(dimensionValue, "px") : dimensionValue;
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 ? "overflow-x: auto;" : '', " ", props => props.maxWidth && !props.disableSelfContainment ? "max-width: ".concat(convertNumericDimensionToPixelValue$1(props.maxWidth), ";") : '', " ", props => props.isBeingResized && "\n * {\n user-select: none;\n }", " ", getDisabledSelfContainmentStyles, ";" + ("" ));
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 ? "overflow-y: auto;" : '', " ", props => props.maxHeight && !props.disableSelfContainment ? "max-height: ".concat(convertNumericDimensionToPixelValue$1(props.maxHeight), ";") : '', " ", props => props.resizedTotalWidth ? "max-width: ".concat(props.resizedTotalWidth, "px;") : '', " ", getDisabledSelfContainmentStyles, ";" + ("" ));
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 @@ const defaultProps$4 = {
254
272
  };
255
273
  const Footer = /*#__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, ";", props => props.resizedTotalWidth ? "max-width: ".concat(props.resizedTotalWidth, "px;") : '', ";" + ("" ));
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, ";", props => props.resizedTotalWidth ? `max-width: ${props.resizedTotalWidth}px;` : '', ";" + ("" ));
258
276
  Footer.displayName = 'Footer';
259
277
  Footer.defaultProps = defaultProps$4;
260
278
  var Footer$1 = Footer;
@@ -287,16 +305,12 @@ var isFixedWidthValue$1 = isFixedWidthValue;
287
305
  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; }
288
306
  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; }
289
307
  const HeaderCellWrapper = props => {
290
- var _headerRef$current2;
291
308
  const columnResizingReducer = react$1.useContext(ColumnResizingContext);
292
309
  const headerRef = react$1.useRef(null);
293
310
  const onStartResizing = event => {
294
311
  columnResizingReducer.startResizing(headerRef, event);
295
312
  };
296
- const onDrag = event => {
297
- var _headerRef$current;
298
- return columnResizingReducer.onDragResizing(event, (_headerRef$current = headerRef.current) === null || _headerRef$current === void 0 ? void 0 : _headerRef$current.cellIndex);
299
- };
313
+ const onDrag = event => columnResizingReducer.onDragResizing(event, headerRef.current?.cellIndex);
300
314
  const onDragEnd = () => {
301
315
  const finalSizes = columnResizingReducer.finishResizing();
302
316
  if (props.onColumnResized) {
@@ -305,7 +319,7 @@ const HeaderCellWrapper = props => {
305
319
  window.removeEventListener('mousemove', onDrag);
306
320
  window.removeEventListener('mouseup', onDragEnd);
307
321
  };
308
- if (columnResizingReducer.getIsColumnBeingResized((_headerRef$current2 = headerRef.current) === null || _headerRef$current2 === void 0 ? void 0 : _headerRef$current2.cellIndex)) {
322
+ if (columnResizingReducer.getIsColumnBeingResized(headerRef.current?.cellIndex)) {
309
323
  window.addEventListener('mousemove', onDrag);
310
324
  window.addEventListener('mouseup', onDragEnd);
311
325
  }
@@ -317,7 +331,7 @@ const HeaderCellWrapper = props => {
317
331
  const shouldClipContent = props.columnWidth && isFixedWidthValue$1(props.columnWidth) || columnResizingReducer.getHasTableBeenResized() || columnResizingReducer.getIsAnyColumnBeingResized();
318
332
  return jsxRuntime.jsxs(BaseHeaderCell, {
319
333
  ref: headerRef,
320
- "data-testid": "header-".concat(props.columnKey),
334
+ "data-testid": `header-${props.columnKey}`,
321
335
  "data-id": props.columnKey,
322
336
  shouldClipContent: shouldClipContent,
323
337
  disableHeaderStickiness: props.disableHeaderStickiness,
@@ -362,7 +376,7 @@ const HeaderCell = props => {
362
376
  children: [jsxRuntime.jsx(HeaderLabelTextWrapper, {
363
377
  children: props.children
364
378
  }), props.iconComponent && jsxRuntime.jsx(HeaderIconWrapper, {
365
- children: props.iconComponent
379
+ children: typeof props.iconComponent === 'function' ? props.iconComponent() : props.iconComponent
366
380
  })]
367
381
  }), props.isSortable && jsxRuntime.jsxs(jsxRuntime.Fragment, {
368
382
  children: [jsxRuntime.jsx(icons.AngleUpDownIcon, {
@@ -460,27 +474,21 @@ const DataRow = props => {
460
474
  const shouldRenderCollapseButton = (totalColumnsLength, currentColumnIndex) => rowHasTruncatedColumn && totalColumnsLength - 1 === currentColumnIndex;
461
475
  return jsxRuntime.jsx(TableRow, {
462
476
  isRowClickable: Boolean(props.onRowClick),
463
- children: _mapInstanceProperty__default["default"](_context2 = props.columns).call(_context2, (column, columnIndex) => {
464
- var _context3, _context4;
465
- return jsxRuntime.jsx(DataCell$1, {
466
- "data-testid": _concatInstanceProperty__default["default"](_context4 = "cell-".concat(props.rowIndex, "-")).call(_context4, column.key),
467
- isTruncated: column.isTruncated && isRowCollapsed,
468
- isCondensed: props.isCondensed,
469
- isRowCollapsed: isRowCollapsed,
470
- verticalCellAlignment: props.verticalCellAlignment,
471
- horizontalCellAlignment: column.align ? column.align : props.horizontalCellAlignment,
472
- shouldIgnoreRowClick: column.shouldIgnoreRowClick,
473
- handleRowCollapseClick: handleRowCollapseClick,
474
- shouldRenderCollapseButton: shouldRenderCollapseButton(props.columns.length, columnIndex),
475
- onCellClick: props.onRowClick && !column.shouldIgnoreRowClick ? () => {
476
- var _props$onRowClick;
477
- return (_props$onRowClick = props.onRowClick) === null || _props$onRowClick === void 0 ? void 0 : _props$onRowClick.call(props, props.row, props.rowIndex, column.key);
478
- } : undefined,
479
- shouldRenderBottomBorder: props.shouldRenderBottomBorder,
480
- shouldRenderResizingIndicator: getIsColumnBeingResized(columnIndex),
481
- children: column.renderItem ? column.renderItem(props.row, isRowCollapsed) : props.itemRenderer(props.row, column, isRowCollapsed)
482
- }, _concatInstanceProperty__default["default"](_context3 = "".concat(props.row.id, "-")).call(_context3, column.key));
483
- })
477
+ children: _mapInstanceProperty__default["default"](_context2 = props.columns).call(_context2, (column, columnIndex) => jsxRuntime.jsx(DataCell$1, {
478
+ "data-testid": `cell-${props.rowIndex}-${column.key}`,
479
+ isTruncated: column.isTruncated && isRowCollapsed,
480
+ isCondensed: props.isCondensed,
481
+ isRowCollapsed: isRowCollapsed,
482
+ verticalCellAlignment: props.verticalCellAlignment,
483
+ horizontalCellAlignment: column.align ? column.align : props.horizontalCellAlignment,
484
+ shouldIgnoreRowClick: column.shouldIgnoreRowClick,
485
+ handleRowCollapseClick: handleRowCollapseClick,
486
+ shouldRenderCollapseButton: shouldRenderCollapseButton(props.columns.length, columnIndex),
487
+ onCellClick: props.onRowClick && !column.shouldIgnoreRowClick ? () => props.onRowClick?.(props.row, props.rowIndex, column.key) : undefined,
488
+ shouldRenderBottomBorder: props.shouldRenderBottomBorder,
489
+ shouldRenderResizingIndicator: getIsColumnBeingResized(columnIndex),
490
+ children: column.renderItem ? column.renderItem(props.row, isRowCollapsed) : props.itemRenderer(props.row, column, isRowCollapsed)
491
+ }, `${props.row.id}-${column.key}`))
484
492
  });
485
493
  };
486
494
  DataRow.propTypes = {};
@@ -513,7 +521,7 @@ const setColumnWidth = function () {
513
521
  });
514
522
  return columns;
515
523
  };
516
- const getGridTemplateColumnsStyle = columns => "".concat(_mapInstanceProperty__default["default"](columns).call(columns, width => "".concat(width || 0, "px")).join(' '));
524
+ const getGridTemplateColumnsStyle = columns => `${_mapInstanceProperty__default["default"](columns).call(columns, width => `${width || 0}px`).join(' ')}`;
517
525
  const initialState = tableRef => ({
518
526
  initialColWidth: undefined,
519
527
  initialMousePosition: undefined,
@@ -560,14 +568,13 @@ const useManualResizingReducer = tableRef => {
560
568
  return [manualResizingState, dispatch];
561
569
  };
562
570
  const useManualColumnResizing = tableRef => {
563
- var _state$tableRef;
564
571
  const _useManualResizingRed = useManualResizingReducer(tableRef),
565
572
  _useManualResizingRed2 = _slicedToArray(_useManualResizingRed, 2),
566
573
  state = _useManualResizingRed2[0],
567
574
  dispatch = _useManualResizingRed2[1];
568
575
 
569
576
  // if the table element has been rendered and we haven't yet measured the columns
570
- if ((_state$tableRef = state.tableRef) !== null && _state$tableRef !== void 0 && _state$tableRef.current && !state.sizes) {
577
+ if (state.tableRef?.current && !state.sizes) {
571
578
  var _context;
572
579
  const renderedColumnMeasurements = [];
573
580
  _forEachInstanceProperty__default["default"](_context = state.tableRef.current.querySelectorAll(':scope > thead > tr > th')).call(_context, header => {
@@ -596,10 +603,9 @@ const useManualColumnResizing = tableRef => {
596
603
  const onDragResizing = (event, columnIndex) => {
597
604
  // throttle and sync resizing update rate with screen refresh rate
598
605
  requestAnimationFrame(() => {
599
- var _state$tableRef2;
600
606
  const width = calculateNewSize(state.initialColWidth, state.initialMousePosition, event.clientX);
601
607
  const newColumnsSizes = setColumnWidth(state.sizes, columnIndex, width);
602
- if (!((_state$tableRef2 = state.tableRef) !== null && _state$tableRef2 !== void 0 && _state$tableRef2.current)) return;
608
+ if (!state.tableRef?.current) return;
603
609
  state.tableRef.current.style.gridTemplateColumns = getGridTemplateColumnsStyle(_mapInstanceProperty__default["default"](newColumnsSizes).call(newColumnsSizes, newColumnsSize => newColumnsSize.width.toString()));
604
610
  });
605
611
  };
@@ -620,8 +626,7 @@ const useManualColumnResizing = tableRef => {
620
626
  return _reduceInstanceProperty__default["default"](_context2 = state.sizes).call(_context2, (a, b) => a + b.width, 0);
621
627
  };
622
628
  const reset = () => {
623
- var _state$tableRef3;
624
- if (!((_state$tableRef3 = state.tableRef) !== null && _state$tableRef3 !== void 0 && _state$tableRef3.current)) return;
629
+ if (!state.tableRef?.current) return;
625
630
  state.tableRef.current.style.gridTemplateColumns = '';
626
631
  return dispatch({
627
632
  type: 'reset'
@@ -759,7 +764,7 @@ DataTable.displayName = 'DataTable';
759
764
  var DataTable$1 = DataTable;
760
765
 
761
766
  // NOTE: This string will be replaced on build time with the package version.
762
- var version = "19.11.0";
767
+ var version = "19.12.1";
763
768
 
764
769
  Object.defineProperty(exports, 'useRowSelection', {
765
770
  enumerable: true,