@pingux/astro 1.27.0-alpha.14 → 1.27.0-alpha.16
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/lib/cjs/components/DataTable/DataTable.js +477 -0
- package/lib/cjs/components/DataTable/DataTable.stories.js +310 -0
- package/lib/cjs/components/DataTable/DataTable.styles.js +156 -0
- package/lib/cjs/components/DataTable/DataTable.test.js +1307 -0
- package/lib/cjs/components/DataTable/DataTableChip.js +63 -0
- package/lib/cjs/components/DataTable/DataTableChip.test.js +38 -0
- package/lib/cjs/components/DataTable/DataTableMenu.js +51 -0
- package/lib/cjs/components/DataTable/DataTableMenu.test.js +20 -0
- package/lib/cjs/components/DataTable/DataTableMultiLine.js +75 -0
- package/lib/cjs/components/DataTable/DataTableMultiLine.test.js +30 -0
- package/lib/cjs/components/DataTable/DataTableVirtualizer.js +188 -0
- package/lib/cjs/components/DataTable/index.js +54 -0
- package/lib/cjs/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.js +8 -2
- package/lib/cjs/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.test.js +35 -0
- package/lib/cjs/components/PageHeader/PageHeader.js +7 -1
- package/lib/cjs/context/DataTableContext/index.js +31 -0
- package/lib/cjs/index.js +67 -2
- package/lib/cjs/recipes/FlippableCaretMenuButton.stories.js +38 -30
- package/lib/cjs/recipes/ListAndPanel.stories.js +102 -87
- package/lib/cjs/recipes/MaskedValue.stories.js +8 -5
- package/lib/cjs/recipes/NeutralInput.stories.js +6 -3
- package/lib/cjs/recipes/OneWayToBidirectionalArrow.stories.js +38 -33
- package/lib/cjs/recipes/PageHeader.stories.js +73 -0
- package/lib/cjs/recipes/RowLineChart.stories.js +58 -70
- package/lib/cjs/recipes/SelectedFieldOverlay.story.js +25 -21
- package/lib/cjs/recipes/TrialExperienceStatusBar.stories.js +81 -72
- package/lib/cjs/styles/variants/variants.js +4 -1
- package/lib/components/DataTable/DataTable.js +431 -0
- package/lib/components/DataTable/DataTable.stories.js +273 -0
- package/lib/components/DataTable/DataTable.styles.js +137 -0
- package/lib/components/DataTable/DataTable.test.js +1256 -0
- package/lib/components/DataTable/DataTableChip.js +33 -0
- package/lib/components/DataTable/DataTableChip.test.js +31 -0
- package/lib/components/DataTable/DataTableMenu.js +24 -0
- package/lib/components/DataTable/DataTableMenu.test.js +13 -0
- package/lib/components/DataTable/DataTableMultiLine.js +46 -0
- package/lib/components/DataTable/DataTableMultiLine.test.js +22 -0
- package/lib/components/DataTable/DataTableVirtualizer.js +157 -0
- package/lib/components/DataTable/index.js +5 -0
- package/lib/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.js +7 -2
- package/lib/components/EnvironmentBreadcrumb/EnvironmentBreadcrumb.test.js +25 -0
- package/lib/components/PageHeader/PageHeader.js +8 -1
- package/lib/context/DataTableContext/index.js +5 -0
- package/lib/index.js +4 -1
- package/lib/recipes/FlippableCaretMenuButton.stories.js +38 -30
- package/lib/recipes/ListAndPanel.stories.js +102 -87
- package/lib/recipes/MaskedValue.stories.js +8 -5
- package/lib/recipes/NeutralInput.stories.js +6 -3
- package/lib/recipes/OneWayToBidirectionalArrow.stories.js +38 -33
- package/lib/recipes/PageHeader.stories.js +53 -0
- package/lib/recipes/RowLineChart.stories.js +58 -70
- package/lib/recipes/SelectedFieldOverlay.story.js +25 -21
- package/lib/recipes/TrialExperienceStatusBar.stories.js +81 -72
- package/lib/styles/variants/variants.js +3 -1
- package/package.json +55 -50
@@ -0,0 +1,431 @@
|
|
1
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
3
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
4
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
5
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
6
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
7
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
8
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
9
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
10
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
11
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
12
|
+
var _excluded = ["children"],
|
13
|
+
_excluded2 = ["children"],
|
14
|
+
_excluded3 = ["item", "children", "hasActions"];
|
15
|
+
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
17
|
+
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
19
|
+
|
20
|
+
import React, { forwardRef, useCallback, useMemo, useRef } from 'react';
|
21
|
+
import { mergeProps } from '@react-aria/utils';
|
22
|
+
import { FocusRing, useFocusRing } from '@react-aria/focus';
|
23
|
+
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
24
|
+
import { layoutInfoToStyle, VirtualizerItem } from '@react-aria/virtualizer';
|
25
|
+
import { useTableColumnResizeState, useTableState } from '@react-stately/table';
|
26
|
+
import { useStyleProps } from '@react-spectrum/utils';
|
27
|
+
import { TableLayout } from '@react-stately/layout';
|
28
|
+
import { useTable, useTableCell, useTableColumnHeader, useTableHeaderRow, useTableRow, useTableRowGroup } from '@react-aria/table';
|
29
|
+
import PropTypes from 'prop-types';
|
30
|
+
import MenuDownIcon from 'mdi-react/MenuDownIcon';
|
31
|
+
import MenuUpIcon from 'mdi-react/MenuUpIcon';
|
32
|
+
import { DataTableContext, useDataTableContext } from '../../context/DataTableContext';
|
33
|
+
import DataTableVirtualizer from './DataTableVirtualizer';
|
34
|
+
import { useStatusClasses } from '../../hooks';
|
35
|
+
import { Box, Icon, Loader } from '../../index';
|
36
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
37
|
+
var DEFAULT_HEADER_HEIGHT = {
|
38
|
+
medium: 34,
|
39
|
+
large: 37.5
|
40
|
+
};
|
41
|
+
var ROW_HEIGHTS = {
|
42
|
+
compact: {
|
43
|
+
medium: 32,
|
44
|
+
large: 40
|
45
|
+
},
|
46
|
+
regular: {
|
47
|
+
medium: 40,
|
48
|
+
large: 50
|
49
|
+
},
|
50
|
+
spacious: {
|
51
|
+
medium: 48,
|
52
|
+
large: 75
|
53
|
+
}
|
54
|
+
};
|
55
|
+
/**
|
56
|
+
* DataTable component using react aria Spectrum TableView
|
57
|
+
* Primarily utilizes [TableView](https://react-spectrum.adobe.com/react-spectrum/TableView.html)
|
58
|
+
* Cross platform state management react hook for DataTable
|
59
|
+
* Primarily utilizes [useTableState](https://react-spectrum.adobe.com/react-stately/useTableState.html)
|
60
|
+
*/
|
61
|
+
|
62
|
+
var DataTable = /*#__PURE__*/forwardRef(function (props, ref) {
|
63
|
+
var onAction = props.onAction;
|
64
|
+
|
65
|
+
var _useStyleProps = useStyleProps(props),
|
66
|
+
styleProps = _useStyleProps.styleProps;
|
67
|
+
|
68
|
+
var direction = 'ltr'; // useLocale override
|
69
|
+
|
70
|
+
var scale = 'large'; // useProvider override
|
71
|
+
|
72
|
+
var getDefaultWidth = useCallback();
|
73
|
+
var state = useTableState(_objectSpread({}, props));
|
74
|
+
var columnState = useTableColumnResizeState(_objectSpread(_objectSpread({}, props), {}, {
|
75
|
+
getDefaultWidth: getDefaultWidth
|
76
|
+
}), state.collection);
|
77
|
+
var domRef = useRef(ref);
|
78
|
+
var bodyRef = useRef();
|
79
|
+
var density = props.density || 'regular';
|
80
|
+
var layout = useMemo(function () {
|
81
|
+
return new TableLayout({
|
82
|
+
// If props.rowHeight is auto, then use estimated heights based on scale,
|
83
|
+
// otherwise use fixed heights.
|
84
|
+
rowHeight: props.overflowMode === 'wrap' ? null : ROW_HEIGHTS[density][scale],
|
85
|
+
estimatedRowHeight: props.overflowMode === 'wrap' ? ROW_HEIGHTS[density][scale] : null,
|
86
|
+
headingHeight: props.overflowMode === 'wrap' ? null : DEFAULT_HEADER_HEIGHT[scale],
|
87
|
+
estimatedHeadingHeight: props.overflowMode === 'wrap' ? DEFAULT_HEADER_HEIGHT[scale] : null
|
88
|
+
});
|
89
|
+
}, [props.overflowMode, scale, density]);
|
90
|
+
layout.collection = state.collection;
|
91
|
+
layout.getColumnWidth = columnState.getColumnWidth;
|
92
|
+
|
93
|
+
var _useTable = useTable(_objectSpread(_objectSpread({}, props), {}, {
|
94
|
+
isVirtualized: true,
|
95
|
+
layout: layout,
|
96
|
+
onRowAction: onAction
|
97
|
+
}), state, domRef),
|
98
|
+
gridProps = _useTable.gridProps; // This overrides collection view's renderWrapper to support DOM hierarchy.
|
99
|
+
|
100
|
+
|
101
|
+
var renderWrapper = function renderWrapper(parent, reusableView, children, renderChildren) {
|
102
|
+
var style = layoutInfoToStyle(reusableView.layoutInfo, direction, parent && parent.layoutInfo);
|
103
|
+
|
104
|
+
if (style.overflow === 'hidden') {
|
105
|
+
style.overflow = 'visible'; // needed to support position: sticky
|
106
|
+
}
|
107
|
+
|
108
|
+
if (reusableView.viewType === 'rowgroup') {
|
109
|
+
return ___EmotionJSX(TableRowGroup, {
|
110
|
+
key: reusableView.key,
|
111
|
+
style: style
|
112
|
+
}, renderChildren(children));
|
113
|
+
}
|
114
|
+
|
115
|
+
if (reusableView.viewType === 'header') {
|
116
|
+
return ___EmotionJSX(TableHeader, {
|
117
|
+
key: reusableView.key,
|
118
|
+
style: style
|
119
|
+
}, renderChildren(children));
|
120
|
+
}
|
121
|
+
|
122
|
+
if (reusableView.viewType === 'row') {
|
123
|
+
return ___EmotionJSX(TableRow, {
|
124
|
+
key: reusableView.key,
|
125
|
+
item: reusableView.content,
|
126
|
+
style: style,
|
127
|
+
hasActions: onAction
|
128
|
+
}, renderChildren(children));
|
129
|
+
}
|
130
|
+
|
131
|
+
if (reusableView.viewType === 'headerrow') {
|
132
|
+
return ___EmotionJSX(TableHeaderRow, {
|
133
|
+
key: reusableView.key,
|
134
|
+
style: style,
|
135
|
+
item: reusableView.content
|
136
|
+
}, renderChildren(children));
|
137
|
+
}
|
138
|
+
|
139
|
+
return ___EmotionJSX(VirtualizerItem, {
|
140
|
+
key: reusableView.key,
|
141
|
+
reusableView: reusableView,
|
142
|
+
parent: parent
|
143
|
+
});
|
144
|
+
};
|
145
|
+
|
146
|
+
var renderView = function renderView(type, item) {
|
147
|
+
switch (type) {
|
148
|
+
case 'header':
|
149
|
+
case 'rowgroup':
|
150
|
+
case 'row':
|
151
|
+
case 'headerrow':
|
152
|
+
return null;
|
153
|
+
|
154
|
+
case 'cell':
|
155
|
+
{
|
156
|
+
return ___EmotionJSX(TableCell, {
|
157
|
+
cell: item
|
158
|
+
});
|
159
|
+
}
|
160
|
+
|
161
|
+
case 'column':
|
162
|
+
return ___EmotionJSX(TableColumnHeader, {
|
163
|
+
column: item
|
164
|
+
});
|
165
|
+
|
166
|
+
case 'loader':
|
167
|
+
return ___EmotionJSX(CenteredWrapper, null, ___EmotionJSX(Loader, {
|
168
|
+
color: "accent.70",
|
169
|
+
"aria-label": state.collection.size > 0 ? 'loadingMore' : 'loading'
|
170
|
+
}));
|
171
|
+
|
172
|
+
default:
|
173
|
+
return null;
|
174
|
+
}
|
175
|
+
};
|
176
|
+
|
177
|
+
var viewport = useRef({
|
178
|
+
x: 0,
|
179
|
+
y: 0,
|
180
|
+
width: 0,
|
181
|
+
height: 0
|
182
|
+
});
|
183
|
+
var onVisibleRectChange = useCallback(function (e) {
|
184
|
+
if (viewport.current.width === e.width && viewport.current.height === e.height) {
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
|
188
|
+
viewport.current = e;
|
189
|
+
}, []);
|
190
|
+
return ___EmotionJSX(DataTableContext.Provider, {
|
191
|
+
value: {
|
192
|
+
state: state,
|
193
|
+
layout: layout,
|
194
|
+
columnState: columnState
|
195
|
+
}
|
196
|
+
}, ___EmotionJSX(DataTableVirtualizer, _extends({
|
197
|
+
style: {
|
198
|
+
whiteSpace: props.overflowMode === 'wrap' ? 'normal' : 'initial'
|
199
|
+
}
|
200
|
+
}, gridProps, styleProps, {
|
201
|
+
layout: layout,
|
202
|
+
collection: state.collection,
|
203
|
+
focusedKey: state.selectionManager.focusedKey,
|
204
|
+
renderView: renderView,
|
205
|
+
renderWrapper: renderWrapper,
|
206
|
+
setTableWidth: columnState.setTableWidth,
|
207
|
+
onVisibleRectChange: onVisibleRectChange,
|
208
|
+
domRef: domRef,
|
209
|
+
bodyRef: bodyRef,
|
210
|
+
getColumnWidth: columnState.getColumnWidth
|
211
|
+
})));
|
212
|
+
});
|
213
|
+
|
214
|
+
function TableHeader(_ref) {
|
215
|
+
var children = _ref.children,
|
216
|
+
otherProps = _objectWithoutProperties(_ref, _excluded);
|
217
|
+
|
218
|
+
var _useTableRowGroup = useTableRowGroup(),
|
219
|
+
rowGroupProps = _useTableRowGroup.rowGroupProps;
|
220
|
+
|
221
|
+
return ___EmotionJSX(Box, _extends({}, rowGroupProps, otherProps), children);
|
222
|
+
}
|
223
|
+
|
224
|
+
function TableColumnHeader(props) {
|
225
|
+
var _state$sortDescriptor, _state$sortDescriptor2;
|
226
|
+
|
227
|
+
var column = props.column;
|
228
|
+
var ref = useRef(null);
|
229
|
+
|
230
|
+
var _useDataTableContext = useDataTableContext(),
|
231
|
+
state = _useDataTableContext.state;
|
232
|
+
|
233
|
+
var _useTableColumnHeader = useTableColumnHeader({
|
234
|
+
node: column,
|
235
|
+
isVirtualized: true
|
236
|
+
}, state, ref),
|
237
|
+
columnHeaderProps = _useTableColumnHeader.columnHeaderProps;
|
238
|
+
|
239
|
+
var columnProps = column.props;
|
240
|
+
var arrowIcon = ((_state$sortDescriptor = state.sortDescriptor) === null || _state$sortDescriptor === void 0 ? void 0 : _state$sortDescriptor.direction) === 'ascending' && column.key === ((_state$sortDescriptor2 = state.sortDescriptor) === null || _state$sortDescriptor2 === void 0 ? void 0 : _state$sortDescriptor2.column) ? ___EmotionJSX(Icon, {
|
241
|
+
icon: MenuUpIcon
|
242
|
+
}) : ___EmotionJSX(Icon, {
|
243
|
+
icon: MenuDownIcon,
|
244
|
+
color: "active"
|
245
|
+
});
|
246
|
+
var allProps = [columnHeaderProps];
|
247
|
+
|
248
|
+
var _useStatusClasses = useStatusClasses(_defineProperty({
|
249
|
+
'is-column-sortable': columnProps.allowsSorting
|
250
|
+
}, "is-align-".concat(columnProps.align), columnProps.align)),
|
251
|
+
classNames = _useStatusClasses.classNames;
|
252
|
+
|
253
|
+
return ___EmotionJSX(FocusRing, {
|
254
|
+
focusRingClass: "is-key-focused",
|
255
|
+
focusClass: "is-click-focused"
|
256
|
+
}, ___EmotionJSX(Box, _extends({}, mergeProps.apply(void 0, allProps), {
|
257
|
+
ref: ref,
|
258
|
+
variant: "dataTable.tableHeadCell",
|
259
|
+
className: classNames
|
260
|
+
}), columnProps.hideHeader ? ___EmotionJSX(VisuallyHidden, null, column.rendered) : ___EmotionJSX(Box, null, column.rendered), columnProps.allowsSorting && ___EmotionJSX(Box, null, arrowIcon)));
|
261
|
+
}
|
262
|
+
|
263
|
+
function TableRowGroup(_ref2) {
|
264
|
+
var children = _ref2.children,
|
265
|
+
otherProps = _objectWithoutProperties(_ref2, _excluded2);
|
266
|
+
|
267
|
+
var _useTableRowGroup2 = useTableRowGroup(),
|
268
|
+
rowGroupProps = _useTableRowGroup2.rowGroupProps;
|
269
|
+
|
270
|
+
return ___EmotionJSX(Box, _extends({}, rowGroupProps, otherProps), children);
|
271
|
+
}
|
272
|
+
|
273
|
+
function TableRow(_ref3) {
|
274
|
+
var item = _ref3.item,
|
275
|
+
children = _ref3.children,
|
276
|
+
hasActions = _ref3.hasActions,
|
277
|
+
otherProps = _objectWithoutProperties(_ref3, _excluded3);
|
278
|
+
|
279
|
+
var ref = useRef();
|
280
|
+
|
281
|
+
var _useDataTableContext2 = useDataTableContext(),
|
282
|
+
state = _useDataTableContext2.state;
|
283
|
+
|
284
|
+
var _useTableRow = useTableRow({
|
285
|
+
node: item,
|
286
|
+
isVirtualized: true
|
287
|
+
}, state, ref),
|
288
|
+
rowProps = _useTableRow.rowProps;
|
289
|
+
|
290
|
+
var _useFocusRing = useFocusRing({
|
291
|
+
within: true
|
292
|
+
}),
|
293
|
+
isFocusVisibleWithin = _useFocusRing.isFocusVisible,
|
294
|
+
focusWithinProps = _useFocusRing.focusProps;
|
295
|
+
|
296
|
+
var _useFocusRing2 = useFocusRing(),
|
297
|
+
isFocusVisible = _useFocusRing2.isFocusVisible,
|
298
|
+
focusProps = _useFocusRing2.focusProps;
|
299
|
+
|
300
|
+
var props = mergeProps(rowProps, otherProps, focusWithinProps, focusProps);
|
301
|
+
|
302
|
+
var _useStatusClasses3 = useStatusClasses({
|
303
|
+
'is-row-focus-visible': isFocusVisible || isFocusVisibleWithin
|
304
|
+
}),
|
305
|
+
classNames = _useStatusClasses3.classNames;
|
306
|
+
|
307
|
+
return ___EmotionJSX(Box, _extends({}, props, {
|
308
|
+
ref: ref,
|
309
|
+
variant: "dataTable.tableRow",
|
310
|
+
className: classNames
|
311
|
+
}), children);
|
312
|
+
}
|
313
|
+
|
314
|
+
function TableHeaderRow(_ref4) {
|
315
|
+
var item = _ref4.item,
|
316
|
+
children = _ref4.children,
|
317
|
+
style = _ref4.style;
|
318
|
+
|
319
|
+
var _useDataTableContext3 = useDataTableContext(),
|
320
|
+
state = _useDataTableContext3.state;
|
321
|
+
|
322
|
+
var ref = useRef();
|
323
|
+
|
324
|
+
var _useTableHeaderRow = useTableHeaderRow({
|
325
|
+
node: item,
|
326
|
+
isVirtualized: true
|
327
|
+
}, state, ref),
|
328
|
+
rowProps = _useTableHeaderRow.rowProps;
|
329
|
+
|
330
|
+
return ___EmotionJSX(Box, _extends({}, rowProps, {
|
331
|
+
ref: ref,
|
332
|
+
style: style
|
333
|
+
}), children);
|
334
|
+
}
|
335
|
+
|
336
|
+
function TableCell(_ref5) {
|
337
|
+
var cell = _ref5.cell;
|
338
|
+
|
339
|
+
var _useDataTableContext4 = useDataTableContext(),
|
340
|
+
state = _useDataTableContext4.state;
|
341
|
+
|
342
|
+
var ref = useRef();
|
343
|
+
var columnProps = cell.column.props;
|
344
|
+
|
345
|
+
var _useTableCell = useTableCell({
|
346
|
+
node: cell,
|
347
|
+
isVirtualized: true
|
348
|
+
}, state, ref),
|
349
|
+
gridCellProps = _useTableCell.gridCellProps;
|
350
|
+
|
351
|
+
var _useStatusClasses4 = useStatusClasses(_defineProperty({}, "is-align-".concat(columnProps.align), columnProps.align)),
|
352
|
+
classNames = _useStatusClasses4.classNames;
|
353
|
+
|
354
|
+
return ___EmotionJSX(FocusRing, {
|
355
|
+
focusRingClass: "is-key-focused"
|
356
|
+
}, ___EmotionJSX(Box, _extends({}, gridCellProps, {
|
357
|
+
ref: ref,
|
358
|
+
variant: "dataTable.tableCell",
|
359
|
+
className: classNames
|
360
|
+
}), ___EmotionJSX(Box, {
|
361
|
+
variant: "dataTable.tableCellContents"
|
362
|
+
}, cell.rendered)));
|
363
|
+
}
|
364
|
+
|
365
|
+
function CenteredWrapper(_ref6) {
|
366
|
+
var children = _ref6.children;
|
367
|
+
|
368
|
+
var _useDataTableContext5 = useDataTableContext(),
|
369
|
+
state = _useDataTableContext5.state;
|
370
|
+
|
371
|
+
return ___EmotionJSX(Box, {
|
372
|
+
role: "row",
|
373
|
+
"aria-rowindex": state.collection.headerRows.length + state.collection.size + 1,
|
374
|
+
variant: "dataTable.tableCenteredWrapper"
|
375
|
+
}, ___EmotionJSX(Box, {
|
376
|
+
role: "rowheader",
|
377
|
+
"aria-colspan": state.collection.columns.length
|
378
|
+
}, children));
|
379
|
+
}
|
380
|
+
|
381
|
+
DataTable.propTypes = {
|
382
|
+
/**
|
383
|
+
* Sets the amount of vertical padding within each cell.
|
384
|
+
* density: 'compact' | 'regular' | 'spacious'
|
385
|
+
* @default 'regular'
|
386
|
+
*/
|
387
|
+
density: PropTypes.string,
|
388
|
+
|
389
|
+
/**
|
390
|
+
* Sets the overflow behavior for the cell contents.
|
391
|
+
* overflowMode: 'wrap' | 'truncate'
|
392
|
+
* @default 'truncate'
|
393
|
+
*/
|
394
|
+
overflowMode: PropTypes.string,
|
395
|
+
|
396
|
+
/** Handler that is called when a user performs an action on a row. */
|
397
|
+
onAction: PropTypes.func
|
398
|
+
};
|
399
|
+
TableCell.propTypes = {
|
400
|
+
cell: PropTypes.shape({
|
401
|
+
column: PropTypes.shape({
|
402
|
+
props: PropTypes.shape({
|
403
|
+
align: PropTypes.string
|
404
|
+
})
|
405
|
+
}),
|
406
|
+
parentKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
407
|
+
rendered: PropTypes.node
|
408
|
+
})
|
409
|
+
};
|
410
|
+
TableHeaderRow.propTypes = {
|
411
|
+
children: PropTypes.node,
|
412
|
+
item: PropTypes.shape({}),
|
413
|
+
style: PropTypes.shape({})
|
414
|
+
};
|
415
|
+
TableRow.propTypes = {
|
416
|
+
children: PropTypes.node,
|
417
|
+
hasActions: PropTypes.func,
|
418
|
+
item: PropTypes.shape({})
|
419
|
+
};
|
420
|
+
TableColumnHeader.propTypes = {
|
421
|
+
column: PropTypes.shape({
|
422
|
+
key: PropTypes.string,
|
423
|
+
props: PropTypes.shape({
|
424
|
+
align: PropTypes.string,
|
425
|
+
allowsSorting: PropTypes.bool,
|
426
|
+
hideHeader: PropTypes.bool
|
427
|
+
}),
|
428
|
+
rendered: PropTypes.node
|
429
|
+
})
|
430
|
+
};
|
431
|
+
export default DataTable;
|
@@ -0,0 +1,273 @@
|
|
1
|
+
import _parseInt from "@babel/runtime-corejs3/core-js-stable/parse-int";
|
2
|
+
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
3
|
+
import _sortInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/sort";
|
4
|
+
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
5
|
+
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
6
|
+
import _keysInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/keys";
|
7
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
8
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
9
|
+
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
10
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
11
|
+
import React from 'react';
|
12
|
+
import { useAsyncList } from '@react-stately/data';
|
13
|
+
import ApplicationIcon from 'mdi-react/ApplicationIcon';
|
14
|
+
import { action } from '@storybook/addon-actions';
|
15
|
+
import { faker } from '@faker-js/faker';
|
16
|
+
import isChromatic from 'chromatic/isChromatic';
|
17
|
+
import { DataTable, DataTableBody, DataTableCell, DataTableColumn, DataTableHeader, DataTableRow, DataTableChip, DataTableMenu, DataTableMultiLine } from '../../index';
|
18
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
19
|
+
export default {
|
20
|
+
title: 'DataTable',
|
21
|
+
component: DataTable,
|
22
|
+
parameters: {
|
23
|
+
docs: {
|
24
|
+
source: {
|
25
|
+
type: 'code'
|
26
|
+
}
|
27
|
+
}
|
28
|
+
},
|
29
|
+
argTypes: {
|
30
|
+
density: {
|
31
|
+
control: {
|
32
|
+
type: 'radio',
|
33
|
+
options: ['compact', 'regular', 'spacious']
|
34
|
+
},
|
35
|
+
defaultValue: 'spacious'
|
36
|
+
},
|
37
|
+
overflowMode: {
|
38
|
+
control: {
|
39
|
+
type: 'radio',
|
40
|
+
options: ['truncate', 'wrap']
|
41
|
+
},
|
42
|
+
defaultValue: 'truncate'
|
43
|
+
},
|
44
|
+
width: {
|
45
|
+
defaultValue: '100%',
|
46
|
+
control: {
|
47
|
+
type: 'text'
|
48
|
+
}
|
49
|
+
},
|
50
|
+
height: {
|
51
|
+
defaultValue: 565,
|
52
|
+
control: {
|
53
|
+
type: 'number'
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
};
|
58
|
+
export var Default = function Default(args) {
|
59
|
+
var columns = [{
|
60
|
+
name: 'Country',
|
61
|
+
key: 'country'
|
62
|
+
}, {
|
63
|
+
name: 'Population',
|
64
|
+
key: 'population'
|
65
|
+
}, {
|
66
|
+
name: 'Continent',
|
67
|
+
key: 'continent'
|
68
|
+
}];
|
69
|
+
var rows = [{
|
70
|
+
id: 1,
|
71
|
+
country: 'USA',
|
72
|
+
population: '320,000,000',
|
73
|
+
continent: 'North America'
|
74
|
+
}, {
|
75
|
+
id: 2,
|
76
|
+
country: 'Canada',
|
77
|
+
population: '37,000,000',
|
78
|
+
continent: 'North America'
|
79
|
+
}, {
|
80
|
+
id: 3,
|
81
|
+
country: 'China',
|
82
|
+
population: '1,398,000,000',
|
83
|
+
continent: 'Asia'
|
84
|
+
}, {
|
85
|
+
id: 4,
|
86
|
+
country: 'France',
|
87
|
+
population: '67,000,000',
|
88
|
+
continent: 'Europe'
|
89
|
+
}];
|
90
|
+
return ___EmotionJSX(DataTable, _extends({}, args, {
|
91
|
+
"aria-label": "Static table"
|
92
|
+
}), ___EmotionJSX(DataTableHeader, {
|
93
|
+
columns: columns
|
94
|
+
}, function (column) {
|
95
|
+
return ___EmotionJSX(DataTableColumn, {
|
96
|
+
align: "center"
|
97
|
+
}, column.name);
|
98
|
+
}), ___EmotionJSX(DataTableBody, {
|
99
|
+
items: rows
|
100
|
+
}, function (item) {
|
101
|
+
return ___EmotionJSX(DataTableRow, null, function (columnKey) {
|
102
|
+
return ___EmotionJSX(DataTableCell, null, item[columnKey]);
|
103
|
+
});
|
104
|
+
}));
|
105
|
+
};
|
106
|
+
export var CustomContent = function CustomContent(args) {
|
107
|
+
/**
|
108
|
+
* isChromatic checks if the code is running in Chromatic environment
|
109
|
+
* @returns {Boolean}
|
110
|
+
* Source: https://www.chromatic.com/docs/ischromatic
|
111
|
+
* */
|
112
|
+
var chromatic = isChromatic();
|
113
|
+
var columns = [{
|
114
|
+
name: 'Name/ID',
|
115
|
+
key: 'name_id',
|
116
|
+
isSortable: true
|
117
|
+
}, {
|
118
|
+
name: 'Status',
|
119
|
+
key: 'status',
|
120
|
+
isSortable: false
|
121
|
+
}, {
|
122
|
+
name: 'Category',
|
123
|
+
key: 'category',
|
124
|
+
isSortable: false
|
125
|
+
}, {
|
126
|
+
name: 'Date Submitted',
|
127
|
+
key: 'date',
|
128
|
+
isSortable: true
|
129
|
+
}, {
|
130
|
+
name: 'Submitted By',
|
131
|
+
key: 'submitted_by',
|
132
|
+
isSortable: true
|
133
|
+
}, {
|
134
|
+
name: 'Menu',
|
135
|
+
key: 'menu',
|
136
|
+
isSortable: false
|
137
|
+
}];
|
138
|
+
var list = useAsyncList({
|
139
|
+
load: function load(_ref) {
|
140
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
141
|
+
var _context, _context2, _context3;
|
142
|
+
|
143
|
+
var signal, cursor, res, json, random, fakeData, tableData;
|
144
|
+
return _regeneratorRuntime.wrap(function _callee$(_context5) {
|
145
|
+
while (1) {
|
146
|
+
switch (_context5.prev = _context5.next) {
|
147
|
+
case 0:
|
148
|
+
signal = _ref.signal, cursor = _ref.cursor;
|
149
|
+
|
150
|
+
if (cursor) {
|
151
|
+
// eslint-disable-next-line no-param-reassign
|
152
|
+
cursor = cursor.replace(/^http:\/\//i, 'https://');
|
153
|
+
}
|
154
|
+
|
155
|
+
_context5.next = 4;
|
156
|
+
return fetch(cursor || 'https://pokeapi.co/api/v2/pokemon', {
|
157
|
+
signal: signal
|
158
|
+
});
|
159
|
+
|
160
|
+
case 4:
|
161
|
+
res = _context5.sent;
|
162
|
+
_context5.next = 7;
|
163
|
+
return res.json();
|
164
|
+
|
165
|
+
case 7:
|
166
|
+
json = _context5.sent;
|
167
|
+
|
168
|
+
random = function random(items) {
|
169
|
+
return items[Math.floor(Math.random() * items.length)];
|
170
|
+
};
|
171
|
+
|
172
|
+
fakeData = _mapInstanceProperty(_context = _concatInstanceProperty(_context2 = []).call(_context2, _keysInstanceProperty(_context3 = Array(json.results.length)).call(_context3))).call(_context, function (key) {
|
173
|
+
var _context4;
|
174
|
+
|
175
|
+
return {
|
176
|
+
id: key,
|
177
|
+
date: chromatic ? '2022-12-25' : "".concat(faker.date.past().toLocaleDateString('fr-CA')),
|
178
|
+
category: chromatic ? 'Other' : "".concat(random(['App Catalog', 'Delete Environment', 'Other'])),
|
179
|
+
status: ___EmotionJSX(DataTableChip, {
|
180
|
+
cell: chromatic ? 'Pending' : "".concat(random(['Pending', 'Rejected', 'Approved', 'Failed']))
|
181
|
+
}),
|
182
|
+
submitted_by: chromatic ? 'John Doe' : _concatInstanceProperty(_context4 = "".concat(faker.name.firstName(), " ")).call(_context4, faker.name.lastName()),
|
183
|
+
name_id: ___EmotionJSX(DataTableMultiLine, {
|
184
|
+
cell: [{
|
185
|
+
name: chromatic ? 'ACME' : "".concat(faker.company.name()),
|
186
|
+
icon: ApplicationIcon,
|
187
|
+
accountId: chromatic ? '123456789' : "".concat(faker.finance.routingNumber())
|
188
|
+
}]
|
189
|
+
}),
|
190
|
+
menu: ___EmotionJSX(DataTableMenu, null)
|
191
|
+
};
|
192
|
+
});
|
193
|
+
tableData = _mapInstanceProperty(fakeData).call(fakeData, function (item, i) {
|
194
|
+
return _Object$assign({}, item, json.results[i]);
|
195
|
+
});
|
196
|
+
return _context5.abrupt("return", {
|
197
|
+
items: tableData,
|
198
|
+
cursor: json.next
|
199
|
+
});
|
200
|
+
|
201
|
+
case 12:
|
202
|
+
case "end":
|
203
|
+
return _context5.stop();
|
204
|
+
}
|
205
|
+
}
|
206
|
+
}, _callee);
|
207
|
+
}))();
|
208
|
+
},
|
209
|
+
sort: function sort(_ref2) {
|
210
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
211
|
+
var items, sortDescriptor, cmp;
|
212
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context7) {
|
213
|
+
while (1) {
|
214
|
+
switch (_context7.prev = _context7.next) {
|
215
|
+
case 0:
|
216
|
+
items = _ref2.items, sortDescriptor = _ref2.sortDescriptor;
|
217
|
+
return _context7.abrupt("return", {
|
218
|
+
items: _sortInstanceProperty(items).call(items, function (a, b) {
|
219
|
+
var _context6;
|
220
|
+
|
221
|
+
var first = sortDescriptor.column !== 'name_id' ? a[sortDescriptor.column] : a[sortDescriptor.column].props.cell[0].name;
|
222
|
+
var second = sortDescriptor.column !== 'name_id' ? b[sortDescriptor.column] : b[sortDescriptor.column].props.cell[0].name;
|
223
|
+
|
224
|
+
if (_includesInstanceProperty(_context6 = sortDescriptor.column).call(_context6, 'date')) {
|
225
|
+
cmp = new Date(first) < new Date(second) ? -1 : 1;
|
226
|
+
} else {
|
227
|
+
cmp = (_parseInt(first, 10) || first) < (_parseInt(second, 10) || second) ? -1 : 1;
|
228
|
+
}
|
229
|
+
|
230
|
+
if (sortDescriptor.direction === 'descending') {
|
231
|
+
cmp *= -1;
|
232
|
+
}
|
233
|
+
|
234
|
+
return cmp;
|
235
|
+
})
|
236
|
+
});
|
237
|
+
|
238
|
+
case 2:
|
239
|
+
case "end":
|
240
|
+
return _context7.stop();
|
241
|
+
}
|
242
|
+
}
|
243
|
+
}, _callee2);
|
244
|
+
}))();
|
245
|
+
}
|
246
|
+
});
|
247
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(DataTable, _extends({}, args, {
|
248
|
+
sortDescriptor: list.sortDescriptor,
|
249
|
+
onSortChange: _sortInstanceProperty(list),
|
250
|
+
"aria-label": "Custom content table",
|
251
|
+
onAction: action('onAction')
|
252
|
+
}), ___EmotionJSX(DataTableHeader, {
|
253
|
+
columns: columns
|
254
|
+
}, function (column) {
|
255
|
+
return ___EmotionJSX(DataTableColumn, {
|
256
|
+
width: // eslint-disable-next-line no-nested-ternary
|
257
|
+
column.key === 'name_id' ? '26.5%' : column.key === 'menu' ? '5%' : '16%',
|
258
|
+
align: column.key !== 'menu' ? 'start' : 'center',
|
259
|
+
allowsSorting: column.isSortable,
|
260
|
+
hideHeader: column.key === 'menu'
|
261
|
+
}, column.name);
|
262
|
+
}), ___EmotionJSX(DataTableBody, {
|
263
|
+
items: list.items,
|
264
|
+
loadingState: list.loadingState,
|
265
|
+
onLoadMore: list.loadMore
|
266
|
+
}, function (item) {
|
267
|
+
return ___EmotionJSX(DataTableRow, {
|
268
|
+
key: item.name
|
269
|
+
}, function (columnKey) {
|
270
|
+
return ___EmotionJSX(DataTableCell, null, item[columnKey]);
|
271
|
+
});
|
272
|
+
})));
|
273
|
+
};
|