@commercetools-uikit/data-table 0.0.0-FCT-1500-adjust-legacy-css-reset-20250527090339
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/LICENSE +21 -0
- package/README.md +275 -0
- package/dist/commercetools-uikit-data-table.cjs.d.ts +3 -0
- package/dist/commercetools-uikit-data-table.cjs.dev.js +1010 -0
- package/dist/commercetools-uikit-data-table.cjs.js +7 -0
- package/dist/commercetools-uikit-data-table.cjs.prod.js +801 -0
- package/dist/commercetools-uikit-data-table.esm.js +978 -0
- package/dist/declarations/src/data-table.d.ts +190 -0
- package/dist/declarations/src/export-types.d.ts +1 -0
- package/dist/declarations/src/index.d.ts +4 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/package.json +53 -0
|
@@ -0,0 +1,801 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
6
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
7
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
8
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
9
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
10
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
11
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
12
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
13
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
14
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
15
|
+
require('prop-types');
|
|
16
|
+
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
17
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
18
|
+
var react$1 = require('react');
|
|
19
|
+
var isEqual = require('lodash/isEqual');
|
|
20
|
+
var utils = require('@commercetools-uikit/utils');
|
|
21
|
+
var hooks = require('@commercetools-uikit/hooks');
|
|
22
|
+
var _styled = require('@emotion/styled/base');
|
|
23
|
+
var react = require('@emotion/react');
|
|
24
|
+
var designSystem = require('@commercetools-uikit/design-system');
|
|
25
|
+
var AccessibleButton = require('@commercetools-uikit/accessible-button');
|
|
26
|
+
var icons = require('@commercetools-uikit/icons');
|
|
27
|
+
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
28
|
+
var _Number$isNaN = require('@babel/runtime-corejs3/core-js-stable/number/is-nan');
|
|
29
|
+
var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
|
|
30
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
31
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
32
|
+
var dataTableManagerProvider = require('@commercetools-uikit/data-table-manager/data-table-manager-provider');
|
|
33
|
+
|
|
34
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
35
|
+
|
|
36
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
37
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
38
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
39
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
40
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
41
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
42
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
43
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
44
|
+
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
45
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
46
|
+
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
47
|
+
var _styled__default = /*#__PURE__*/_interopDefault(_styled);
|
|
48
|
+
var AccessibleButton__default = /*#__PURE__*/_interopDefault(AccessibleButton);
|
|
49
|
+
var _Number$isNaN__default = /*#__PURE__*/_interopDefault(_Number$isNaN);
|
|
50
|
+
var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
|
|
51
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
52
|
+
|
|
53
|
+
const getPaddingStyle = props => {
|
|
54
|
+
if (props.isCondensed) return /*#__PURE__*/react.css("padding:", designSystem.designTokens.spacing20, " ", designSystem.designTokens.spacing40, ";" + ("" ), "" );
|
|
55
|
+
return /*#__PURE__*/react.css("padding:", designSystem.designTokens.spacing30, " ", designSystem.designTokens.spacing40, ";" + ("" ), "" );
|
|
56
|
+
};
|
|
57
|
+
var _ref8 = {
|
|
58
|
+
name: "9nkbgg",
|
|
59
|
+
styles: "text-align:left;justify-self:flex-start"
|
|
60
|
+
} ;
|
|
61
|
+
var _ref9 = {
|
|
62
|
+
name: "1p06wbt",
|
|
63
|
+
styles: "text-align:right;justify-self:flex-end"
|
|
64
|
+
} ;
|
|
65
|
+
var _ref10 = {
|
|
66
|
+
name: "weshh4",
|
|
67
|
+
styles: "text-align:center;justify-self:center"
|
|
68
|
+
} ;
|
|
69
|
+
const getHorizontalAlignmentStyle = props => {
|
|
70
|
+
if (props.horizontalCellAlignment === 'center') {
|
|
71
|
+
return _ref10;
|
|
72
|
+
}
|
|
73
|
+
if (props.horizontalCellAlignment === 'right') {
|
|
74
|
+
return _ref9;
|
|
75
|
+
}
|
|
76
|
+
return _ref8;
|
|
77
|
+
};
|
|
78
|
+
var _ref5 = {
|
|
79
|
+
name: "xyzkeb",
|
|
80
|
+
styles: "align-self:flex-start"
|
|
81
|
+
} ;
|
|
82
|
+
var _ref6 = {
|
|
83
|
+
name: "1duj7gx",
|
|
84
|
+
styles: "align-self:flex-end"
|
|
85
|
+
} ;
|
|
86
|
+
var _ref7 = {
|
|
87
|
+
name: "qbt5ty",
|
|
88
|
+
styles: "align-self:center"
|
|
89
|
+
} ;
|
|
90
|
+
const getVerticalAlignmentStyle = props => {
|
|
91
|
+
if (props.verticalCellAlignment === 'center') {
|
|
92
|
+
return _ref7;
|
|
93
|
+
}
|
|
94
|
+
if (props.verticalCellAlignment === 'bottom') {
|
|
95
|
+
return _ref6;
|
|
96
|
+
}
|
|
97
|
+
return _ref5;
|
|
98
|
+
};
|
|
99
|
+
var _ref4 = {
|
|
100
|
+
name: "ucb1au",
|
|
101
|
+
styles: "overflow:hidden;white-space:nowrap;text-overflow:ellipsis"
|
|
102
|
+
} ;
|
|
103
|
+
const getTruncatedStyle = props => {
|
|
104
|
+
if (props.isTruncated) {
|
|
105
|
+
return _ref4;
|
|
106
|
+
}
|
|
107
|
+
return '';
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/* the :focus-within state doesn't enable the outline styles,
|
|
111
|
+
so we have to set them manually. */
|
|
112
|
+
const outlineStyles = {
|
|
113
|
+
name: "18k0dc3",
|
|
114
|
+
styles: "outline-offset:-3px;:has(:focus-visible){outline-style:auto;outline-color:Highlight;outline-color:activeborder;outline-color:-moz-mac-focusring;outline-color:-webkit-focus-ring-color;}"
|
|
115
|
+
} ;
|
|
116
|
+
const getCellInnerStyles = props => {
|
|
117
|
+
return [getVerticalAlignmentStyle(props), getHorizontalAlignmentStyle(props), getTruncatedStyle(props), outlineStyles];
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* The `shouldClipContent` overflow rule should only be enabled upon manual column resizing,
|
|
122
|
+
* otherwise it will change the way css-grid automatically allocates space for the cells of the table,
|
|
123
|
+
* preferring to clip the cells instead and adding horizontal scrollbar to the table container
|
|
124
|
+
*/
|
|
125
|
+
var _ref3 = {
|
|
126
|
+
name: "d3v9zr",
|
|
127
|
+
styles: "overflow:hidden"
|
|
128
|
+
} ;
|
|
129
|
+
const CellInner = /*#__PURE__*/_styled__default["default"]("div", {
|
|
130
|
+
target: "e10u1n7e3"
|
|
131
|
+
} )("box-sizing:border-box;flex:1;", getPaddingStyle, " ", getCellInnerStyles, " ", props => props.shouldClipContent ? _ref3 : '', ";" + ("" ));
|
|
132
|
+
var _ref$1 = {
|
|
133
|
+
name: "1a5erbp",
|
|
134
|
+
styles: "cursor:auto"
|
|
135
|
+
} ;
|
|
136
|
+
var _ref2 = {
|
|
137
|
+
name: "d3v9zr",
|
|
138
|
+
styles: "overflow:hidden"
|
|
139
|
+
} ;
|
|
140
|
+
const BaseCell = /*#__PURE__*/_styled__default["default"]("td", {
|
|
141
|
+
target: "e10u1n7e2"
|
|
142
|
+
} )("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 : '', ";" + ("" ));
|
|
143
|
+
/*#__PURE__*/_styled__default["default"]("td", {
|
|
144
|
+
target: "e10u1n7e1"
|
|
145
|
+
} )("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;" + ("" ));
|
|
146
|
+
const RowExpandCollapseButton = /*#__PURE__*/_styled__default["default"](AccessibleButton__default["default"], {
|
|
147
|
+
target: "e10u1n7e0"
|
|
148
|
+
} )("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;" + ("" ));
|
|
149
|
+
|
|
150
|
+
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;" + ("" ), "" );
|
|
151
|
+
|
|
152
|
+
/* When a sortable header is deselected,
|
|
153
|
+
* (i.e. when another sortable header is selected)
|
|
154
|
+
* the AngleUpDown is animated with fadeIn
|
|
155
|
+
*
|
|
156
|
+
* When the user hovers over a sortable header that
|
|
157
|
+
* is not the active sorted column, the icon for
|
|
158
|
+
* the current sort direction is animated with fadeIn
|
|
159
|
+
*/
|
|
160
|
+
const fadeIn = react.keyframes`
|
|
161
|
+
from {
|
|
162
|
+
opacity: 0;
|
|
163
|
+
}
|
|
164
|
+
to {
|
|
165
|
+
opacity: 1;
|
|
166
|
+
}
|
|
167
|
+
`;
|
|
168
|
+
|
|
169
|
+
/* When a sortable header is activated/selected,
|
|
170
|
+
* and the sort direction is 'desc', the ArrowDown
|
|
171
|
+
* icon is animated with rotateClockwise
|
|
172
|
+
*/
|
|
173
|
+
const rotateClockwise = react.keyframes`
|
|
174
|
+
from {
|
|
175
|
+
transform: rotate(-180deg);
|
|
176
|
+
} to {
|
|
177
|
+
transform: rotate(0deg);
|
|
178
|
+
}
|
|
179
|
+
`;
|
|
180
|
+
|
|
181
|
+
/* When a sortable header is activated/selected,
|
|
182
|
+
* and the sort direction is 'asc', the ArrowUp
|
|
183
|
+
* icon is animated with rotateCounterClockwise
|
|
184
|
+
*/
|
|
185
|
+
const rotateCounterClockwise = react.keyframes`
|
|
186
|
+
from {
|
|
187
|
+
transform: rotate(180deg);
|
|
188
|
+
} to {
|
|
189
|
+
transform: rotate(0deg);
|
|
190
|
+
}
|
|
191
|
+
`;
|
|
192
|
+
|
|
193
|
+
/* A sortable header has the two arrow svg icons
|
|
194
|
+
* GIVEN column is sortable and is not focused
|
|
195
|
+
* THEN AngleUpDown icon is shown (default behaviour)
|
|
196
|
+
* AND ArrowUp or ArrowDown icon is not shown
|
|
197
|
+
*
|
|
198
|
+
* GIVEN column is sortable and foucsed or hovered
|
|
199
|
+
* THEN AngleUpDown icon is hidden
|
|
200
|
+
* AND ArrowUp or ArrowDown icon is shown
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
const getSortableHeaderStyles = props => /*#__PURE__*/react.css("width:100%;display:flex;align-items:center;svg[data-icon-state='inactive'],svg[data-icon-state='active']{margin-left:", designSystem.designTokens.spacing10, ";flex-shrink:0;}svg[data-icon-state='inactive']{display:", props.isActive ? 'none' : 'inline-block', ";animation:", fadeIn, " 150ms ease-in-out;}svg[data-icon-state='active']{display:", props.isActive ? 'inline-block' : 'none', ";animation:", props.isActive && /*#__PURE__*/react.css(props.label === 'asc' ? rotateCounterClockwise : rotateClockwise, " 150ms ease-in-out;" + ("" ), "" ), ";}>svg *{fill:", designSystem.designTokens.colorNeutral60, "!important;}:hover,:focus{svg[data-icon-state='inactive']{display:none;}svg[data-icon-state='active']{display:inline-block;animation:", !props.isActive && /*#__PURE__*/react.css(fadeIn, " 150ms ease-in-out;" + ("" ), "" ), ";}}" + ("" ), "" );
|
|
204
|
+
const HeaderCellInner = /*#__PURE__*/_styled__default["default"]("div", {
|
|
205
|
+
target: "e1ipt8n24"
|
|
206
|
+
} )("box-sizing:border-box;display:flex;justify-content:flex-start;padding:0 ", designSystem.designTokens.spacing40, ";", getCellInnerStyles, " ", props => props.isSortable ? getSortableHeaderStyles(props) : '', ";", props => props.as === 'button' ? getButtonStyle() : '', ";", props => props.shouldWrap ? '' : 'white-space: nowrap', ";" + ("" ));
|
|
207
|
+
const BaseHeaderCell = /*#__PURE__*/_styled__default["default"]("th", {
|
|
208
|
+
target: "e1ipt8n23"
|
|
209
|
+
} )("color:", designSystem.designTokens.colorNeutral40, ";background-color:", designSystem.designTokens.colorNeutral98, ";position:", props => props.disableHeaderStickiness ? 'relative' : 'sticky', ";top:0;z-index:1;line-height:", designSystem.designTokens.lineHeight40, ";padding:0;font-weight:", designSystem.designTokens.fontWeight500, ";font-size:", designSystem.designTokens.fontSize10, ";:after{content:'';position:absolute;z-index:-1;width:100%;height:", designSystem.designTokens.borderWidth1, ";bottom:0;left:0;background-color:", designSystem.designTokens.colorNeutral95, ";}:hover,:active{z-index:2;}", HeaderCellInner, "{", props => props.shouldClipContent ? 'overflow: hidden;' : '', ";}" + ("" ));
|
|
210
|
+
const HeaderLabelWrapper = /*#__PURE__*/_styled__default["default"]("div", {
|
|
211
|
+
target: "e1ipt8n22"
|
|
212
|
+
} )("display:inline-flex;min-height:1.4em;margin:", designSystem.designTokens.spacing20, " 0;flex:0 0 fit-content;" + ("" ));
|
|
213
|
+
const HeaderLabelTextWrapper = /*#__PURE__*/_styled__default["default"]("span", {
|
|
214
|
+
target: "e1ipt8n21"
|
|
215
|
+
} )({
|
|
216
|
+
name: "1onapuj",
|
|
217
|
+
styles: "display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere"
|
|
218
|
+
} );
|
|
219
|
+
const HeaderIconWrapper = /*#__PURE__*/_styled__default["default"]("div", {
|
|
220
|
+
target: "e1ipt8n20"
|
|
221
|
+
} )("display:inline-flex;align-items:center;justify-content:center;margin-left:", designSystem.designTokens.spacing20, ";vertical-align:middle;" + ("" ));
|
|
222
|
+
|
|
223
|
+
const convertNumericDimensionToPixelValue = dimensionValue => typeof dimensionValue === 'number' ? `${dimensionValue}px` : dimensionValue;
|
|
224
|
+
var convertNumericDimensionToPixelValue$1 = convertNumericDimensionToPixelValue;
|
|
225
|
+
|
|
226
|
+
const getClickableRowStyle = props => {
|
|
227
|
+
if (props.isRowClickable) {
|
|
228
|
+
return /*#__PURE__*/react.css("cursor:pointer;&:hover td{background:", designSystem.designTokens.backgroundColorForInputWhenHovered, ";}" + ("" ), "" );
|
|
229
|
+
}
|
|
230
|
+
return '';
|
|
231
|
+
};
|
|
232
|
+
var _ref = {
|
|
233
|
+
name: "1jff5cf",
|
|
234
|
+
styles: "position:unset;overflow-x:unset;overflow-y:unset"
|
|
235
|
+
} ;
|
|
236
|
+
const getDisabledSelfContainmentStyles = props => {
|
|
237
|
+
if (props.disableSelfContainment) {
|
|
238
|
+
return _ref;
|
|
239
|
+
}
|
|
240
|
+
return '';
|
|
241
|
+
};
|
|
242
|
+
const TableContainer = /*#__PURE__*/_styled__default["default"]("div", {
|
|
243
|
+
target: "epk01s24"
|
|
244
|
+
} )("position:relative;z-index:0;box-shadow:", designSystem.designTokens.shadow17, ";border:1px solid ", designSystem.designTokens.colorNeutral95, ";border-radius:", designSystem.designTokens.borderRadius4, ";", props =>
|
|
245
|
+
// this is needed in order to have a sticky header
|
|
246
|
+
props.maxHeight ? `overflow-x: auto;` : '', " ", props => props.maxWidth && !props.disableSelfContainment ? `max-width: ${convertNumericDimensionToPixelValue$1(props.maxWidth)};` : '', " ", props => props.isBeingResized && `
|
|
247
|
+
* {
|
|
248
|
+
user-select: none;
|
|
249
|
+
}`, " ", getDisabledSelfContainmentStyles, ";" + ("" ));
|
|
250
|
+
const TableGrid = /*#__PURE__*/_styled__default["default"]("table", {
|
|
251
|
+
target: "epk01s23"
|
|
252
|
+
} )("display:grid;grid-template-columns:", props => {
|
|
253
|
+
var _context;
|
|
254
|
+
return props.columns && _mapInstanceProperty__default["default"](_context = props.columns).call(_context, column => column.width || 'auto').join(' ');
|
|
255
|
+
}, ";", props =>
|
|
256
|
+
// this is needed in order to have a sticky header
|
|
257
|
+
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, ";" + ("" ));
|
|
258
|
+
const TableHeader = /*#__PURE__*/_styled__default["default"]("thead", {
|
|
259
|
+
target: "epk01s22"
|
|
260
|
+
} )("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;}}" + ("" ));
|
|
261
|
+
const TableBody = /*#__PURE__*/_styled__default["default"]("tbody", {
|
|
262
|
+
target: "epk01s21"
|
|
263
|
+
} )({
|
|
264
|
+
name: "49aokf",
|
|
265
|
+
styles: "display:contents"
|
|
266
|
+
} );
|
|
267
|
+
const TableRow = /*#__PURE__*/_styled__default["default"]("tr", {
|
|
268
|
+
target: "epk01s20"
|
|
269
|
+
} )("display:contents;", getClickableRowStyle, " :hover,:focus-within{", RowExpandCollapseButton, "{opacity:1;}}" + ("" ));
|
|
270
|
+
|
|
271
|
+
const defaultProps = {
|
|
272
|
+
horizontalCellAlignment: 'left'
|
|
273
|
+
};
|
|
274
|
+
const Footer = /*#__PURE__*/_styled__default["default"]("div", {
|
|
275
|
+
target: "e2ce7vj0"
|
|
276
|
+
} )("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;` : '', ";" + ("" ));
|
|
277
|
+
Footer.displayName = 'Footer';
|
|
278
|
+
Footer.defaultProps = defaultProps;
|
|
279
|
+
var Footer$1 = Footer;
|
|
280
|
+
|
|
281
|
+
const ResizerIndicator = /*#__PURE__*/_styled__default["default"]("div", {
|
|
282
|
+
target: "e1ccic7f1"
|
|
283
|
+
} )("height:100%;width:3px;background:", designSystem.designTokens.colorInfo, ";visibility:hidden;cursor:col-resize;", (props // extra 1px of height to appear above the bottom horizontal row border
|
|
284
|
+
) => props.isOnDataCell ? 'visibility: visible; height: calc(100% + 1px);' : '', ";" + ("" ));
|
|
285
|
+
const DraggableArea = /*#__PURE__*/_styled__default["default"]("div", {
|
|
286
|
+
target: "e1ccic7f0"
|
|
287
|
+
} )("display:flex;justify-content:flex-end;height:100%;position:absolute;top:0;right:0;width:6px;cursor:col-resize;user-select:none;&:hover ", ResizerIndicator, "{height:100%;visibility:visible;}&:active{width:20px;right:-10px;", ResizerIndicator, "{margin-right:10px;visibility:visible;}}" + ("" ));
|
|
288
|
+
const ColumnResizer = props => jsxRuntime.jsx(DraggableArea, {
|
|
289
|
+
role: "presentation",
|
|
290
|
+
onMouseDown: props.onMouseDown,
|
|
291
|
+
children: jsxRuntime.jsx(ResizerIndicator, {
|
|
292
|
+
isOnDataCell: props.isOnDataCell
|
|
293
|
+
})
|
|
294
|
+
});
|
|
295
|
+
ColumnResizer.propTypes = {};
|
|
296
|
+
ColumnResizer.displayName = 'ColumnResizer';
|
|
297
|
+
var Resizer = ColumnResizer;
|
|
298
|
+
|
|
299
|
+
var ColumnResizingContext = /*#__PURE__*/react$1.createContext({});
|
|
300
|
+
|
|
301
|
+
const isFixedWidthValue = value => {
|
|
302
|
+
return !_Number$isNaN__default["default"](_parseInt__default["default"](String(value), 10));
|
|
303
|
+
};
|
|
304
|
+
var isFixedWidthValue$1 = isFixedWidthValue;
|
|
305
|
+
|
|
306
|
+
const _excluded$3 = ["sortDirection", "disableHeaderStickiness", "horizontalCellAlignment"];
|
|
307
|
+
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; }
|
|
308
|
+
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; }
|
|
309
|
+
const HeaderCellWrapper = props => {
|
|
310
|
+
const columnResizingReducer = react$1.useContext(ColumnResizingContext);
|
|
311
|
+
const headerRef = react$1.useRef(null);
|
|
312
|
+
const onStartResizing = event => {
|
|
313
|
+
columnResizingReducer.startResizing(headerRef, event);
|
|
314
|
+
};
|
|
315
|
+
const onDrag = event => columnResizingReducer.onDragResizing(event, headerRef.current?.cellIndex);
|
|
316
|
+
const onDragEnd = () => {
|
|
317
|
+
const finalSizes = columnResizingReducer.finishResizing();
|
|
318
|
+
if (props.onColumnResized) {
|
|
319
|
+
props.onColumnResized(finalSizes);
|
|
320
|
+
}
|
|
321
|
+
window.removeEventListener('mousemove', onDrag);
|
|
322
|
+
window.removeEventListener('mouseup', onDragEnd);
|
|
323
|
+
};
|
|
324
|
+
if (columnResizingReducer.getIsColumnBeingResized(headerRef.current?.cellIndex)) {
|
|
325
|
+
window.addEventListener('mousemove', onDrag);
|
|
326
|
+
window.addEventListener('mouseup', onDragEnd);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* GIVEN that any table column is being OR has been resized
|
|
330
|
+
* OR the width of the current column is a fixed value
|
|
331
|
+
* THEN the header content should be clipped
|
|
332
|
+
*/
|
|
333
|
+
const shouldClipContent = props.columnWidth && isFixedWidthValue$1(props.columnWidth) || columnResizingReducer.getHasTableBeenResized() || columnResizingReducer.getIsAnyColumnBeingResized();
|
|
334
|
+
return jsxRuntime.jsxs(BaseHeaderCell, {
|
|
335
|
+
ref: headerRef,
|
|
336
|
+
"data-testid": `header-${props.columnKey}`,
|
|
337
|
+
"data-id": props.columnKey,
|
|
338
|
+
shouldClipContent: shouldClipContent,
|
|
339
|
+
disableHeaderStickiness: props.disableHeaderStickiness,
|
|
340
|
+
children: [props.children, !props.disableResizing && jsxRuntime.jsx(Resizer, {
|
|
341
|
+
onMouseDown: onStartResizing
|
|
342
|
+
})]
|
|
343
|
+
});
|
|
344
|
+
};
|
|
345
|
+
HeaderCellWrapper.displayName = 'HeaderCellWrapper';
|
|
346
|
+
const HeaderCell = _ref => {
|
|
347
|
+
let _ref$sortDirection = _ref.sortDirection,
|
|
348
|
+
sortDirection = _ref$sortDirection === void 0 ? 'desc' : _ref$sortDirection,
|
|
349
|
+
_ref$disableHeaderSti = _ref.disableHeaderStickiness,
|
|
350
|
+
disableHeaderStickiness = _ref$disableHeaderSti === void 0 ? false : _ref$disableHeaderSti,
|
|
351
|
+
_ref$horizontalCellAl = _ref.horizontalCellAlignment,
|
|
352
|
+
horizontalCellAlignment = _ref$horizontalCellAl === void 0 ? 'left' : _ref$horizontalCellAl,
|
|
353
|
+
props = _objectWithoutProperties(_ref, _excluded$3);
|
|
354
|
+
let sortableHeaderProps = {};
|
|
355
|
+
let SortingIcon;
|
|
356
|
+
if (props.isSortable) {
|
|
357
|
+
const isActive = props.sortedBy === props.columnKey;
|
|
358
|
+
const nextSortDirection = !isActive || sortDirection === 'desc' ? 'asc' : 'desc';
|
|
359
|
+
SortingIcon = sortDirection === 'desc' ? icons.ArrowDownIcon : icons.ArrowUpIcon;
|
|
360
|
+
sortableHeaderProps = {
|
|
361
|
+
as: 'button',
|
|
362
|
+
label: sortDirection,
|
|
363
|
+
onClick: () => props.onClick && props.onClick(props.columnKey, nextSortDirection),
|
|
364
|
+
isActive,
|
|
365
|
+
isSortable: true
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
return jsxRuntime.jsx(HeaderCellWrapper, {
|
|
369
|
+
columnWidth: props.columnWidth,
|
|
370
|
+
columnKey: props.columnKey,
|
|
371
|
+
onColumnResized: props.onColumnResized,
|
|
372
|
+
disableResizing: props.disableResizing,
|
|
373
|
+
disableHeaderStickiness: disableHeaderStickiness,
|
|
374
|
+
children: jsxRuntime.jsxs(HeaderCellInner, _objectSpread$3(_objectSpread$3({
|
|
375
|
+
shouldWrap: props.shouldWrap,
|
|
376
|
+
isCondensed: props.isCondensed,
|
|
377
|
+
horizontalCellAlignment: horizontalCellAlignment
|
|
378
|
+
}, sortableHeaderProps), {}, {
|
|
379
|
+
children: [jsxRuntime.jsxs(HeaderLabelWrapper, {
|
|
380
|
+
children: [jsxRuntime.jsx(HeaderLabelTextWrapper, {
|
|
381
|
+
children: props.children
|
|
382
|
+
}), props.iconComponent && jsxRuntime.jsx(HeaderIconWrapper, {
|
|
383
|
+
children: typeof props.iconComponent === 'function' ? props.iconComponent() : props.iconComponent
|
|
384
|
+
})]
|
|
385
|
+
}), props.isSortable && jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
386
|
+
children: [jsxRuntime.jsx(icons.AngleUpDownIcon, {
|
|
387
|
+
size: "medium",
|
|
388
|
+
color: "surface",
|
|
389
|
+
"data-icon-state": "inactive"
|
|
390
|
+
}), jsxRuntime.jsx(SortingIcon, {
|
|
391
|
+
size: "medium",
|
|
392
|
+
color: "surface",
|
|
393
|
+
"data-icon-state": "active"
|
|
394
|
+
})]
|
|
395
|
+
})]
|
|
396
|
+
}))
|
|
397
|
+
});
|
|
398
|
+
};
|
|
399
|
+
HeaderCell.propTypes = {};
|
|
400
|
+
HeaderCell.displayName = 'HeaderCell';
|
|
401
|
+
var HeaderCell$1 = HeaderCell;
|
|
402
|
+
|
|
403
|
+
const _excluded$2 = ["isTruncated", "shouldRenderBottomBorder"];
|
|
404
|
+
function ownKeys$2(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; }
|
|
405
|
+
function _objectSpread$2(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$2(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$2(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
406
|
+
const DataCell = _ref => {
|
|
407
|
+
let _ref$isTruncated = _ref.isTruncated,
|
|
408
|
+
isTruncated = _ref$isTruncated === void 0 ? false : _ref$isTruncated,
|
|
409
|
+
_ref$shouldRenderBott = _ref.shouldRenderBottomBorder,
|
|
410
|
+
shouldRenderBottomBorder = _ref$shouldRenderBott === void 0 ? true : _ref$shouldRenderBott,
|
|
411
|
+
props = _objectWithoutProperties(_ref, _excluded$2);
|
|
412
|
+
if (props.shouldRenderCollapseButton) ;
|
|
413
|
+
const Icon = props.isRowCollapsed ? icons.RightTriangleFilledIcon : icons.RightTriangleLinearIcon;
|
|
414
|
+
return jsxRuntime.jsxs(BaseCell, {
|
|
415
|
+
onClick: props.onCellClick,
|
|
416
|
+
shouldIgnoreRowClick: props.shouldIgnoreRowClick,
|
|
417
|
+
shouldClipContent: isTruncated && !props.shouldRenderResizingIndicator,
|
|
418
|
+
shouldRenderBottomBorder: shouldRenderBottomBorder,
|
|
419
|
+
children: [jsxRuntime.jsx(CellInner, _objectSpread$2(_objectSpread$2({
|
|
420
|
+
isCondensed: props.isCondensed,
|
|
421
|
+
isTruncated: isTruncated,
|
|
422
|
+
verticalCellAlignment: props.verticalCellAlignment,
|
|
423
|
+
horizontalCellAlignment: props.horizontalCellAlignment
|
|
424
|
+
}, utils.filterDataAttributes(_objectSpread$2({
|
|
425
|
+
isTruncated,
|
|
426
|
+
shouldRenderBottomBorder
|
|
427
|
+
}, props))), {}, {
|
|
428
|
+
children: props.children
|
|
429
|
+
})), props.shouldRenderCollapseButton && jsxRuntime.jsx(RowExpandCollapseButton, {
|
|
430
|
+
label: "Expand/Collapse Row",
|
|
431
|
+
onClick: event => {
|
|
432
|
+
if (props.handleRowCollapseClick) props.handleRowCollapseClick();
|
|
433
|
+
event.stopPropagation();
|
|
434
|
+
},
|
|
435
|
+
isRowCollapsed: props.isRowCollapsed,
|
|
436
|
+
children: jsxRuntime.jsx(Icon, {
|
|
437
|
+
size: "small"
|
|
438
|
+
})
|
|
439
|
+
}), props.shouldRenderResizingIndicator && jsxRuntime.jsx(Resizer, {
|
|
440
|
+
isOnDataCell: true
|
|
441
|
+
})]
|
|
442
|
+
});
|
|
443
|
+
};
|
|
444
|
+
DataCell.propTypes = {};
|
|
445
|
+
DataCell.displayName = 'DataCell';
|
|
446
|
+
var DataCell$1 = DataCell;
|
|
447
|
+
|
|
448
|
+
const _excluded$1 = ["isCondensed", "shouldClipContent", "verticalCellAlignment", "horizontalCellAlignment", "shouldRenderBottomBorder", "itemRenderer"];
|
|
449
|
+
const defaultItemRenderer = (row, column, _isRowCollapsed) => {
|
|
450
|
+
// @ts-ignore
|
|
451
|
+
return row[column.key];
|
|
452
|
+
};
|
|
453
|
+
const DataRow = _ref => {
|
|
454
|
+
var _context, _context2;
|
|
455
|
+
let _ref$isCondensed = _ref.isCondensed,
|
|
456
|
+
isCondensed = _ref$isCondensed === void 0 ? true : _ref$isCondensed;
|
|
457
|
+
_ref.shouldClipContent;
|
|
458
|
+
let _ref$verticalCellAlig = _ref.verticalCellAlignment,
|
|
459
|
+
verticalCellAlignment = _ref$verticalCellAlig === void 0 ? 'top' : _ref$verticalCellAlig,
|
|
460
|
+
_ref$horizontalCellAl = _ref.horizontalCellAlignment,
|
|
461
|
+
horizontalCellAlignment = _ref$horizontalCellAl === void 0 ? 'left' : _ref$horizontalCellAl,
|
|
462
|
+
_ref$shouldRenderBott = _ref.shouldRenderBottomBorder,
|
|
463
|
+
shouldRenderBottomBorder = _ref$shouldRenderBott === void 0 ? true : _ref$shouldRenderBott,
|
|
464
|
+
_ref$itemRenderer = _ref.itemRenderer,
|
|
465
|
+
itemRenderer = _ref$itemRenderer === void 0 ? defaultItemRenderer : _ref$itemRenderer,
|
|
466
|
+
props = _objectWithoutProperties(_ref, _excluded$1);
|
|
467
|
+
const _ref2 = react$1.useContext(ColumnResizingContext),
|
|
468
|
+
getIsColumnBeingResized = _ref2.getIsColumnBeingResized;
|
|
469
|
+
const rowHasTruncatedColumn = _someInstanceProperty__default["default"](_context = props.columns).call(_context, column => column.isTruncated);
|
|
470
|
+
const _useState = react$1.useState(rowHasTruncatedColumn),
|
|
471
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
472
|
+
isRowCollapsed = _useState2[0],
|
|
473
|
+
collapseRow = _useState2[1];
|
|
474
|
+
const handleRowCollapseClick = () => {
|
|
475
|
+
collapseRow(!isRowCollapsed);
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
// update the collapsed state if isTruncated options are changed for the whole row
|
|
479
|
+
react$1.useEffect(() => {
|
|
480
|
+
if (rowHasTruncatedColumn) {
|
|
481
|
+
collapseRow(true);
|
|
482
|
+
} else {
|
|
483
|
+
collapseRow(false);
|
|
484
|
+
}
|
|
485
|
+
}, [rowHasTruncatedColumn]);
|
|
486
|
+
const shouldRenderCollapseButton = (totalColumnsLength, currentColumnIndex) => rowHasTruncatedColumn && totalColumnsLength - 1 === currentColumnIndex;
|
|
487
|
+
return jsxRuntime.jsx(TableRow, {
|
|
488
|
+
isRowClickable: Boolean(props.onRowClick),
|
|
489
|
+
children: _mapInstanceProperty__default["default"](_context2 = props.columns).call(_context2, (column, columnIndex) => jsxRuntime.jsx(DataCell$1, {
|
|
490
|
+
"data-testid": `cell-${props.rowIndex}-${column.key}`,
|
|
491
|
+
isTruncated: column.isTruncated && isRowCollapsed,
|
|
492
|
+
isCondensed: isCondensed,
|
|
493
|
+
isRowCollapsed: isRowCollapsed,
|
|
494
|
+
verticalCellAlignment: verticalCellAlignment,
|
|
495
|
+
horizontalCellAlignment: column.align ? column.align : horizontalCellAlignment,
|
|
496
|
+
shouldIgnoreRowClick: column.shouldIgnoreRowClick,
|
|
497
|
+
handleRowCollapseClick: handleRowCollapseClick,
|
|
498
|
+
shouldRenderCollapseButton: shouldRenderCollapseButton(props.columns.length, columnIndex),
|
|
499
|
+
onCellClick: props.onRowClick && !column.shouldIgnoreRowClick ? () => props.onRowClick?.(props.row, props.rowIndex, column.key) : undefined,
|
|
500
|
+
shouldRenderBottomBorder: shouldRenderBottomBorder,
|
|
501
|
+
shouldRenderResizingIndicator: getIsColumnBeingResized(columnIndex),
|
|
502
|
+
children: column.renderItem ? column.renderItem(props.row, isRowCollapsed) : itemRenderer(props.row, column, isRowCollapsed)
|
|
503
|
+
}, `${props.row.id}-${column.key}`))
|
|
504
|
+
});
|
|
505
|
+
};
|
|
506
|
+
DataRow.propTypes = {};
|
|
507
|
+
DataRow.displayName = 'DataRow';
|
|
508
|
+
var DataRow$1 = DataRow;
|
|
509
|
+
|
|
510
|
+
function ownKeys$1(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; }
|
|
511
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys$1(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys$1(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
512
|
+
const MINIMUM_COLUMN_SIZE = 32;
|
|
513
|
+
|
|
514
|
+
// calculates size on mouse-drag and enforces a minimum size
|
|
515
|
+
const calculateNewSize = function () {
|
|
516
|
+
let initialSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
517
|
+
let initialMousePosition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
518
|
+
let newMousePosition = arguments.length > 2 ? arguments[2] : undefined;
|
|
519
|
+
let minSize = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : MINIMUM_COLUMN_SIZE;
|
|
520
|
+
const newSize = initialSize - (initialMousePosition - newMousePosition);
|
|
521
|
+
return minSize > newSize ? minSize : newSize;
|
|
522
|
+
};
|
|
523
|
+
const setColumnWidth = function () {
|
|
524
|
+
let columns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
525
|
+
let position = arguments.length > 1 ? arguments[1] : undefined;
|
|
526
|
+
let value = arguments.length > 2 ? arguments[2] : undefined;
|
|
527
|
+
// columns => comes from state.sizes which reflects component's state
|
|
528
|
+
// any update to the columns results in updating the state
|
|
529
|
+
|
|
530
|
+
columns[position] = _objectSpread$1(_objectSpread$1({}, columns[position]), {}, {
|
|
531
|
+
width: value
|
|
532
|
+
});
|
|
533
|
+
return columns;
|
|
534
|
+
};
|
|
535
|
+
const getGridTemplateColumnsStyle = columns => `${_mapInstanceProperty__default["default"](columns).call(columns, width => `${width || 0}px`).join(' ')}`;
|
|
536
|
+
const initialState = tableRef => ({
|
|
537
|
+
initialColWidth: undefined,
|
|
538
|
+
initialMousePosition: undefined,
|
|
539
|
+
columnBeingResized: undefined,
|
|
540
|
+
hasBeenResized: false,
|
|
541
|
+
sizes: undefined,
|
|
542
|
+
tableRef
|
|
543
|
+
});
|
|
544
|
+
function reducer(state, action) {
|
|
545
|
+
switch (action.type) {
|
|
546
|
+
case 'reset':
|
|
547
|
+
{
|
|
548
|
+
return _objectSpread$1({}, initialState(state.tableRef));
|
|
549
|
+
}
|
|
550
|
+
case 'registerColumnMeasurements':
|
|
551
|
+
{
|
|
552
|
+
return _objectSpread$1(_objectSpread$1({}, state), {}, {
|
|
553
|
+
sizes: action.payload.sizes
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
case 'startResizing':
|
|
557
|
+
return _objectSpread$1(_objectSpread$1({}, state), {}, {
|
|
558
|
+
initialColWidth: action.payload.initialColWidth,
|
|
559
|
+
initialMousePosition: action.payload.initialMousePosition,
|
|
560
|
+
columnBeingResized: action.payload.columnBeingResized
|
|
561
|
+
});
|
|
562
|
+
case 'finishResizing':
|
|
563
|
+
return _objectSpread$1(_objectSpread$1({}, state), {}, {
|
|
564
|
+
initialColWidth: undefined,
|
|
565
|
+
initialMousePosition: undefined,
|
|
566
|
+
columnBeingResized: undefined,
|
|
567
|
+
hasBeenResized: true
|
|
568
|
+
});
|
|
569
|
+
default:
|
|
570
|
+
return state;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
const useManualResizingReducer = tableRef => {
|
|
574
|
+
const _useReducer = react$1.useReducer(reducer, initialState(tableRef)),
|
|
575
|
+
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
576
|
+
manualResizingState = _useReducer2[0],
|
|
577
|
+
dispatch = _useReducer2[1];
|
|
578
|
+
react$1.useDebugValue(manualResizingState);
|
|
579
|
+
return [manualResizingState, dispatch];
|
|
580
|
+
};
|
|
581
|
+
const useManualColumnResizing = tableRef => {
|
|
582
|
+
const _useManualResizingRed = useManualResizingReducer(tableRef),
|
|
583
|
+
_useManualResizingRed2 = _slicedToArray(_useManualResizingRed, 2),
|
|
584
|
+
state = _useManualResizingRed2[0],
|
|
585
|
+
dispatch = _useManualResizingRed2[1];
|
|
586
|
+
|
|
587
|
+
// if the table element has been rendered and we haven't yet measured the columns
|
|
588
|
+
if (state.tableRef?.current && !state.sizes) {
|
|
589
|
+
var _context;
|
|
590
|
+
const renderedColumnMeasurements = [];
|
|
591
|
+
_forEachInstanceProperty__default["default"](_context = state.tableRef.current.querySelectorAll(':scope > thead > tr > th')).call(_context, header => {
|
|
592
|
+
renderedColumnMeasurements.push({
|
|
593
|
+
key: header.getAttribute('data-id'),
|
|
594
|
+
width: header.getBoundingClientRect().width
|
|
595
|
+
});
|
|
596
|
+
});
|
|
597
|
+
dispatch({
|
|
598
|
+
type: 'registerColumnMeasurements',
|
|
599
|
+
payload: {
|
|
600
|
+
sizes: renderedColumnMeasurements
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
const startResizing = (headerRef, mouseEvent) => {
|
|
605
|
+
dispatch({
|
|
606
|
+
type: 'startResizing',
|
|
607
|
+
payload: {
|
|
608
|
+
initialColWidth: headerRef.current.clientWidth,
|
|
609
|
+
initialMousePosition: mouseEvent.clientX,
|
|
610
|
+
columnBeingResized: headerRef.current.cellIndex
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
};
|
|
614
|
+
const onDragResizing = (event, columnIndex) => {
|
|
615
|
+
// throttle and sync resizing update rate with screen refresh rate
|
|
616
|
+
requestAnimationFrame(() => {
|
|
617
|
+
const width = calculateNewSize(state.initialColWidth, state.initialMousePosition, event.clientX);
|
|
618
|
+
const newColumnsSizes = setColumnWidth(state.sizes, columnIndex, width);
|
|
619
|
+
if (!state.tableRef?.current) return;
|
|
620
|
+
state.tableRef.current.style.gridTemplateColumns = getGridTemplateColumnsStyle(_mapInstanceProperty__default["default"](newColumnsSizes).call(newColumnsSizes, newColumnsSize => newColumnsSize.width.toString()));
|
|
621
|
+
});
|
|
622
|
+
};
|
|
623
|
+
const finishResizing = () => {
|
|
624
|
+
dispatch({
|
|
625
|
+
type: 'finishResizing'
|
|
626
|
+
});
|
|
627
|
+
return state.sizes;
|
|
628
|
+
};
|
|
629
|
+
const getIsColumnBeingResized = columnIndex => state.columnBeingResized !== undefined ? state.columnBeingResized === columnIndex : false;
|
|
630
|
+
const getIsAnyColumnBeingResized = () => state.columnBeingResized !== undefined;
|
|
631
|
+
const getHasTableBeenResized = () => state.hasBeenResized;
|
|
632
|
+
const getTotalResizedTableWidth = () => {
|
|
633
|
+
var _context2;
|
|
634
|
+
if (!state.hasBeenResized || !state.sizes) {
|
|
635
|
+
return -1;
|
|
636
|
+
}
|
|
637
|
+
return _reduceInstanceProperty__default["default"](_context2 = state.sizes).call(_context2, (a, b) => a + b.width, 0);
|
|
638
|
+
};
|
|
639
|
+
const reset = () => {
|
|
640
|
+
if (!state.tableRef?.current) return;
|
|
641
|
+
state.tableRef.current.style.gridTemplateColumns = '';
|
|
642
|
+
return dispatch({
|
|
643
|
+
type: 'reset'
|
|
644
|
+
});
|
|
645
|
+
};
|
|
646
|
+
const getSizes = () => state.sizes;
|
|
647
|
+
react$1.useDebugValue(state);
|
|
648
|
+
return {
|
|
649
|
+
reset,
|
|
650
|
+
getSizes,
|
|
651
|
+
startResizing,
|
|
652
|
+
onDragResizing,
|
|
653
|
+
finishResizing,
|
|
654
|
+
getHasTableBeenResized,
|
|
655
|
+
getIsColumnBeingResized,
|
|
656
|
+
getIsAnyColumnBeingResized,
|
|
657
|
+
getTotalResizedTableWidth
|
|
658
|
+
};
|
|
659
|
+
};
|
|
660
|
+
var useManualColumnResizing$1 = useManualColumnResizing;
|
|
661
|
+
|
|
662
|
+
const _excluded = ["columns", "isCondensed", "wrapHeaderLabels", "verticalCellAlignment", "horizontalCellAlignment", "disableSelfContainment", "itemRenderer"];
|
|
663
|
+
function ownKeys(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; }
|
|
664
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
665
|
+
const getColumnsLayoutInfo = columns => _reduceInstanceProperty__default["default"](columns).call(columns, (acc, currentValue) => [...acc, {
|
|
666
|
+
key: currentValue.key,
|
|
667
|
+
width: currentValue.width
|
|
668
|
+
}], []);
|
|
669
|
+
const shouldRenderRowBottomBorder = (rowIndex, rowCount, footer) => {
|
|
670
|
+
if (!footer) return true;
|
|
671
|
+
if (rowIndex + 1 < rowCount) return true;
|
|
672
|
+
return false;
|
|
673
|
+
};
|
|
674
|
+
const DataTable = _ref => {
|
|
675
|
+
var _context;
|
|
676
|
+
let _ref$columns = _ref.columns,
|
|
677
|
+
columns = _ref$columns === void 0 ? [] : _ref$columns,
|
|
678
|
+
_ref$isCondensed = _ref.isCondensed,
|
|
679
|
+
isCondensed = _ref$isCondensed === void 0 ? true : _ref$isCondensed,
|
|
680
|
+
_ref$wrapHeaderLabels = _ref.wrapHeaderLabels,
|
|
681
|
+
wrapHeaderLabels = _ref$wrapHeaderLabels === void 0 ? true : _ref$wrapHeaderLabels,
|
|
682
|
+
_ref$verticalCellAlig = _ref.verticalCellAlignment,
|
|
683
|
+
verticalCellAlignment = _ref$verticalCellAlig === void 0 ? 'top' : _ref$verticalCellAlig,
|
|
684
|
+
_ref$horizontalCellAl = _ref.horizontalCellAlignment,
|
|
685
|
+
horizontalCellAlignment = _ref$horizontalCellAl === void 0 ? 'left' : _ref$horizontalCellAl,
|
|
686
|
+
_ref$disableSelfConta = _ref.disableSelfContainment,
|
|
687
|
+
disableSelfContainment = _ref$disableSelfConta === void 0 ? false : _ref$disableSelfConta,
|
|
688
|
+
_ref$itemRenderer = _ref.itemRenderer,
|
|
689
|
+
itemRenderer = _ref$itemRenderer === void 0 ? (row, column) => row[column.key] : _ref$itemRenderer,
|
|
690
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
691
|
+
const _useDataTableManagerC = dataTableManagerProvider.useDataTableManagerContext(),
|
|
692
|
+
contextColumns = _useDataTableManagerC.columns,
|
|
693
|
+
contextIsCondensed = _useDataTableManagerC.isCondensed;
|
|
694
|
+
const isValueFromProvider = Boolean(contextColumns && contextColumns.length !== 0);
|
|
695
|
+
const columnsData = isValueFromProvider ? contextColumns : columns;
|
|
696
|
+
const condensedValue = isValueFromProvider && contextIsCondensed !== undefined ? contextIsCondensed : isCondensed;
|
|
697
|
+
const tableRef = react$1.useRef();
|
|
698
|
+
const columnResizingReducer = useManualColumnResizing$1(tableRef);
|
|
699
|
+
|
|
700
|
+
// if the table columns have been measured
|
|
701
|
+
// and if the list of columns, their width field, or the isCondensed prop has changed
|
|
702
|
+
// then we need to reset the resized column widths
|
|
703
|
+
const columnsInfo = getColumnsLayoutInfo(columnsData);
|
|
704
|
+
const prevLayout = hooks.usePrevious({
|
|
705
|
+
columns: columnsInfo,
|
|
706
|
+
isCondensed: condensedValue
|
|
707
|
+
});
|
|
708
|
+
const currentLayout = {
|
|
709
|
+
columns: columnsInfo,
|
|
710
|
+
isCondensed: condensedValue
|
|
711
|
+
};
|
|
712
|
+
const hasLayoutChanged = !isEqual__default["default"](prevLayout, currentLayout);
|
|
713
|
+
react$1.useLayoutEffect(() => {
|
|
714
|
+
if (hasLayoutChanged) {
|
|
715
|
+
columnResizingReducer.reset();
|
|
716
|
+
}
|
|
717
|
+
}, [columnResizingReducer, hasLayoutChanged]);
|
|
718
|
+
const hasTableBeenResized = columnResizingReducer.getHasTableBeenResized();
|
|
719
|
+
const resizedTotalWidth = hasTableBeenResized && tableRef.current ? columnResizingReducer.getTotalResizedTableWidth() + (
|
|
720
|
+
// if the table has a maxHeight, it might add a scrollbar which takes space inside the container
|
|
721
|
+
tableRef.current.offsetWidth - tableRef.current.clientWidth) : undefined;
|
|
722
|
+
return jsxRuntime.jsxs(TableContainer, {
|
|
723
|
+
maxWidth: props.maxWidth,
|
|
724
|
+
maxHeight: props.maxHeight,
|
|
725
|
+
isBeingResized: columnResizingReducer.getIsAnyColumnBeingResized(),
|
|
726
|
+
disableSelfContainment: !!disableSelfContainment,
|
|
727
|
+
children: [jsxRuntime.jsx(TableGrid, _objectSpread(_objectSpread({
|
|
728
|
+
ref: tableRef
|
|
729
|
+
}, utils.filterDataAttributes(_objectSpread({
|
|
730
|
+
isCondensed,
|
|
731
|
+
wrapHeaderLabels,
|
|
732
|
+
verticalCellAlignment,
|
|
733
|
+
horizontalCellAlignment,
|
|
734
|
+
disableSelfContainment
|
|
735
|
+
}, props))), {}, {
|
|
736
|
+
columns: columnsData,
|
|
737
|
+
maxHeight: props.maxHeight,
|
|
738
|
+
disableSelfContainment: !!disableSelfContainment,
|
|
739
|
+
resizedTotalWidth: resizedTotalWidth,
|
|
740
|
+
children: jsxRuntime.jsxs(ColumnResizingContext.Provider, {
|
|
741
|
+
value: columnResizingReducer,
|
|
742
|
+
children: [jsxRuntime.jsx(TableHeader, {
|
|
743
|
+
children: jsxRuntime.jsx(TableRow, {
|
|
744
|
+
isRowClickable: false,
|
|
745
|
+
children: _mapInstanceProperty__default["default"](columnsData).call(columnsData, column => jsxRuntime.jsx(HeaderCell$1, {
|
|
746
|
+
shouldWrap: wrapHeaderLabels,
|
|
747
|
+
isCondensed: condensedValue,
|
|
748
|
+
iconComponent: column.headerIcon,
|
|
749
|
+
onColumnResized: props.onColumnResized,
|
|
750
|
+
disableResizing: column.disableResizing,
|
|
751
|
+
horizontalCellAlignment: column.align ? column.align : horizontalCellAlignment,
|
|
752
|
+
disableHeaderStickiness: Boolean(props.disableHeaderStickiness),
|
|
753
|
+
columnWidth: column.width
|
|
754
|
+
/* Sorting Props */,
|
|
755
|
+
onClick: props.onSortChange && props.onSortChange,
|
|
756
|
+
sortedBy: props.sortedBy,
|
|
757
|
+
columnKey: column.key,
|
|
758
|
+
isSortable: column.isSortable,
|
|
759
|
+
sortDirection: props.sortDirection,
|
|
760
|
+
children: column.label
|
|
761
|
+
}, column.key))
|
|
762
|
+
})
|
|
763
|
+
}), jsxRuntime.jsx(TableBody, {
|
|
764
|
+
children: _mapInstanceProperty__default["default"](_context = props.rows).call(_context, (row, rowIndex) => react.createElement(DataRow$1, _objectSpread(_objectSpread({}, props), {}, {
|
|
765
|
+
itemRenderer: itemRenderer,
|
|
766
|
+
isCondensed: condensedValue,
|
|
767
|
+
columns: columnsData,
|
|
768
|
+
row: row,
|
|
769
|
+
key: row.id,
|
|
770
|
+
rowIndex: rowIndex,
|
|
771
|
+
shouldClipContent: columnResizingReducer.getIsAnyColumnBeingResized() || Boolean(hasTableBeenResized),
|
|
772
|
+
shouldRenderBottomBorder: shouldRenderRowBottomBorder(rowIndex, props.rows.length, props.footer)
|
|
773
|
+
})))
|
|
774
|
+
})]
|
|
775
|
+
})
|
|
776
|
+
})), props.footer && jsxRuntime.jsx(Footer$1, {
|
|
777
|
+
"data-testid": "footer",
|
|
778
|
+
isCondensed: condensedValue,
|
|
779
|
+
horizontalCellAlignment: horizontalCellAlignment,
|
|
780
|
+
resizedTotalWidth: resizedTotalWidth,
|
|
781
|
+
children: props.footer
|
|
782
|
+
})]
|
|
783
|
+
});
|
|
784
|
+
};
|
|
785
|
+
DataTable.propTypes = {};
|
|
786
|
+
DataTable.displayName = 'DataTable';
|
|
787
|
+
var DataTable$1 = DataTable;
|
|
788
|
+
|
|
789
|
+
// NOTE: This string will be replaced on build time with the package version.
|
|
790
|
+
var version = "19.25.1";
|
|
791
|
+
|
|
792
|
+
Object.defineProperty(exports, 'useRowSelection', {
|
|
793
|
+
enumerable: true,
|
|
794
|
+
get: function () { return hooks.useRowSelection; }
|
|
795
|
+
});
|
|
796
|
+
Object.defineProperty(exports, 'useSorting', {
|
|
797
|
+
enumerable: true,
|
|
798
|
+
get: function () { return hooks.useSorting; }
|
|
799
|
+
});
|
|
800
|
+
exports["default"] = DataTable$1;
|
|
801
|
+
exports.version = version;
|