@pingux/astro 2.214.0 → 2.216.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/components/OverlayPanel/OverlayPanel.js +6 -0
- package/lib/cjs/components/OverlayPanel/OverlayPanel.test.js +64 -0
- package/lib/cjs/components/Table/Table.mdx +2 -3
- package/lib/cjs/components/TableBase/Convenience/TableBaseEmptyState.stories.js +73 -0
- package/lib/cjs/components/TableBase/Customization/CustomEmptyState.stories.js +62 -0
- package/lib/cjs/components/TableBase/TableBase.js +179 -37
- package/lib/cjs/components/TableBase/TableBase.stories.js +217 -26
- package/lib/cjs/components/TableBase/TableBase.styles.d.ts +3 -0
- package/lib/cjs/components/TableBase/TableBase.styles.js +3 -0
- package/lib/cjs/components/TableBase/TableBase.test.js +557 -66
- package/lib/cjs/components/TableBase/TableBaseEmptyState.d.ts +4 -0
- package/lib/cjs/components/TableBase/TableBaseEmptyState.js +72 -0
- package/lib/cjs/components/TableBase/TableBaseEmptyState.test.js +54 -0
- package/lib/cjs/components/TableBase/index.d.ts +1 -0
- package/lib/cjs/components/TableBase/index.js +8 -1
- package/lib/cjs/components/TableBase/tableBaseAttributes.d.ts +21 -0
- package/lib/cjs/components/TableBase/tableBaseAttributes.js +24 -1
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +8 -0
- package/lib/cjs/types/tableBase.d.ts +16 -1
- package/lib/components/OverlayPanel/OverlayPanel.js +7 -1
- package/lib/components/OverlayPanel/OverlayPanel.test.js +64 -0
- package/lib/components/Table/Table.mdx +2 -3
- package/lib/components/TableBase/Convenience/TableBaseEmptyState.stories.js +65 -0
- package/lib/components/TableBase/Customization/CustomEmptyState.stories.js +54 -0
- package/lib/components/TableBase/TableBase.js +179 -35
- package/lib/components/TableBase/TableBase.stories.js +220 -28
- package/lib/components/TableBase/TableBase.styles.js +3 -0
- package/lib/components/TableBase/TableBase.test.js +557 -66
- package/lib/components/TableBase/TableBaseEmptyState.js +60 -0
- package/lib/components/TableBase/TableBaseEmptyState.test.js +51 -0
- package/lib/components/TableBase/index.js +2 -1
- package/lib/components/TableBase/tableBaseAttributes.js +23 -0
- package/lib/index.js +1 -0
- package/package.json +1 -1
|
@@ -6,17 +6,21 @@ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/inst
|
|
|
6
6
|
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
7
7
|
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
8
8
|
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
9
|
-
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
10
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
11
10
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
11
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
12
12
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
13
|
-
var _excluded = ["
|
|
14
|
-
_excluded2 = ["caption"],
|
|
15
|
-
_excluded3 = ["
|
|
16
|
-
|
|
17
|
-
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
|
13
|
+
var _excluded = ["children", "items", "renderEmptyState", "loadingState"],
|
|
14
|
+
_excluded2 = ["caption", "selectionMode", "selectionBehavior", "hasSelectionCheckboxes", "isStickyHeader", "className", "isLastColumnSticky", "loadingState", "renderEmptyState", "onResizeStart", "onResize", "onResizeEnd", "onRowAction"],
|
|
15
|
+
_excluded3 = ["caption"],
|
|
16
|
+
_excluded4 = ["type", "children", "className", "isSticky"];
|
|
18
17
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19
18
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context5, _context6; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context5 = ownKeys(Object(t), !0)).call(_context5, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context6 = ownKeys(Object(t))).call(_context6, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
19
|
+
import _Set from "@babel/runtime-corejs3/core-js-stable/set";
|
|
20
|
+
import _Map from "@babel/runtime-corejs3/core-js-stable/map";
|
|
21
|
+
import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
|
|
22
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
23
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
|
20
24
|
import React, { forwardRef, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
21
25
|
import { useFocusRing } from '@react-aria/focus';
|
|
22
26
|
import { useHover, usePress } from '@react-aria/interactions';
|
|
@@ -26,7 +30,54 @@ import { VisuallyHidden } from '@react-aria/visually-hidden';
|
|
|
26
30
|
import { useTableColumnResizeState, useTableState } from '@react-stately/table';
|
|
27
31
|
import { Box, CheckboxField, Icon, Loader, Text } from '../..';
|
|
28
32
|
import { useGetTheme, useLocalOrForwardRef, useStatusClasses } from '../../hooks';
|
|
33
|
+
import TableBaseEmptyState from './TableBaseEmptyState';
|
|
34
|
+
|
|
35
|
+
// Strips react-stately collection props that must not reach the DOM tbody element.
|
|
29
36
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
37
|
+
var omitTableBodyProps = function omitTableBodyProps(_ref) {
|
|
38
|
+
var children = _ref.children,
|
|
39
|
+
items = _ref.items,
|
|
40
|
+
renderEmptyState = _ref.renderEmptyState,
|
|
41
|
+
loadingState = _ref.loadingState,
|
|
42
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
43
|
+
return rest;
|
|
44
|
+
};
|
|
45
|
+
var LOADING_STATES = new _Set(['loading', 'sorting']);
|
|
46
|
+
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
var BoxCell = function BoxCell(props) {
|
|
49
|
+
return ___EmotionJSX(Box, _extends({
|
|
50
|
+
as: "td",
|
|
51
|
+
display: "table-cell"
|
|
52
|
+
}, props));
|
|
53
|
+
};
|
|
54
|
+
function LoadingOrEmptyState(_ref2) {
|
|
55
|
+
var _renderEmptyState;
|
|
56
|
+
var loadingState = _ref2.loadingState,
|
|
57
|
+
collectionSize = _ref2.collectionSize,
|
|
58
|
+
colSpan = _ref2.colSpan,
|
|
59
|
+
renderEmptyState = _ref2.renderEmptyState;
|
|
60
|
+
if (collectionSize > 0) return null;
|
|
61
|
+
if (loadingState && LOADING_STATES.has(loadingState)) {
|
|
62
|
+
return ___EmotionJSX(Box, {
|
|
63
|
+
as: "tr",
|
|
64
|
+
display: "table-row"
|
|
65
|
+
}, ___EmotionJSX(BoxCell, {
|
|
66
|
+
colSpan: colSpan
|
|
67
|
+
}, ___EmotionJSX(Loader, {
|
|
68
|
+
variant: "loader.withinDataTable"
|
|
69
|
+
})));
|
|
70
|
+
}
|
|
71
|
+
return ___EmotionJSX(Box, {
|
|
72
|
+
as: "tr",
|
|
73
|
+
display: "table-row"
|
|
74
|
+
}, ___EmotionJSX(BoxCell, {
|
|
75
|
+
colSpan: colSpan,
|
|
76
|
+
sx: {
|
|
77
|
+
textAlign: 'center'
|
|
78
|
+
}
|
|
79
|
+
}, (_renderEmptyState = renderEmptyState === null || renderEmptyState === void 0 ? void 0 : renderEmptyState()) !== null && _renderEmptyState !== void 0 ? _renderEmptyState : ___EmotionJSX(TableBaseEmptyState, null)));
|
|
80
|
+
}
|
|
30
81
|
var useHandleFocusRef = function useHandleFocusRef(ref) {
|
|
31
82
|
React.useEffect(function () {
|
|
32
83
|
var el = ref.current;
|
|
@@ -56,24 +107,96 @@ var TableBase = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
56
107
|
isStickyHeader = _props$isStickyHeader === void 0 ? false : _props$isStickyHeader,
|
|
57
108
|
className = props.className,
|
|
58
109
|
isLastColumnSticky = props.isLastColumnSticky,
|
|
110
|
+
loadingState = props.loadingState,
|
|
111
|
+
renderEmptyState = props.renderEmptyState,
|
|
59
112
|
onResizeStart = props.onResizeStart,
|
|
60
113
|
onResize = props.onResize,
|
|
61
114
|
onResizeEnd = props.onResizeEnd,
|
|
62
|
-
|
|
115
|
+
onRowAction = props.onRowAction,
|
|
116
|
+
others = _objectWithoutProperties(props, _excluded2);
|
|
63
117
|
var tableRef = useLocalOrForwardRef(ref);
|
|
64
118
|
var headerRef = useRef(null);
|
|
65
119
|
var scrollRef = useRef(null);
|
|
66
120
|
var bodyRef = useRef(null);
|
|
121
|
+
// Map of row key -> <tr> DOM element, used to focus the clicked row after onRowAction fires.
|
|
122
|
+
var rowRefMap = useRef(new _Map());
|
|
123
|
+
// Guard flag: set to true just before onRowAction fires so the subsequent blur
|
|
124
|
+
// event (caused by an OverlayPanel FocusScope stealing focus) does not clear
|
|
125
|
+
// activeRowKey prematurely. Resets to false after the blur handler runs.
|
|
126
|
+
var actionJustFired = useRef(false);
|
|
67
127
|
var _useState = useState(0),
|
|
68
128
|
_useState2 = _slicedToArray(_useState, 2),
|
|
69
129
|
tableWidth = _useState2[0],
|
|
70
130
|
setTableWidth = _useState2[1];
|
|
131
|
+
var _useState3 = useState(null),
|
|
132
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
133
|
+
activeRowKey = _useState4[0],
|
|
134
|
+
setActiveRowKey = _useState4[1];
|
|
135
|
+
var registerRowRef = useCallback(function (key, el) {
|
|
136
|
+
if (el) {
|
|
137
|
+
rowRefMap.current.set(key, el);
|
|
138
|
+
} else {
|
|
139
|
+
rowRefMap.current["delete"](key);
|
|
140
|
+
}
|
|
141
|
+
}, []);
|
|
142
|
+
var wrappedOnRowAction = useCallback(function (key) {
|
|
143
|
+
// Toggle off if clicking the already-active row
|
|
144
|
+
setActiveRowKey(function (prev) {
|
|
145
|
+
return prev === key ? null : key;
|
|
146
|
+
});
|
|
147
|
+
// Signal that a row action just fired so handleTableBlur skips the clear.
|
|
148
|
+
// This prevents OverlayPanel's FocusScope autoFocus from triggering a false
|
|
149
|
+
// positive blur that would remove the active-row highlight.
|
|
150
|
+
actionJustFired.current = true;
|
|
151
|
+
onRowAction === null || onRowAction === void 0 || onRowAction(key);
|
|
152
|
+
// Move DOM focus to the clicked row's <tr> so React Aria can handle arrow-key
|
|
153
|
+
// navigation from that row after a mouse click.
|
|
154
|
+
var rowEl = rowRefMap.current.get(key);
|
|
155
|
+
if (rowEl) {
|
|
156
|
+
rowEl.focus();
|
|
157
|
+
}
|
|
158
|
+
// Reset the guard after the current event loop tick so any FocusScope
|
|
159
|
+
// autoFocus steal (which fires synchronously) is absorbed, but subsequent
|
|
160
|
+
// genuine blur events (Tab away, click outside) are not.
|
|
161
|
+
_setTimeout(function () {
|
|
162
|
+
actionJustFired.current = false;
|
|
163
|
+
}, 0);
|
|
164
|
+
}, [onRowAction]);
|
|
165
|
+
|
|
166
|
+
// Called when any row receives focus. If the newly focused row is different
|
|
167
|
+
// from the active row (set by a click), clear activeRowKey so arrow-key
|
|
168
|
+
// navigation does not leave stale active-row highlights on multiple rows.
|
|
169
|
+
// Skip when actionJustFired is true — that focus event is the programmatic
|
|
170
|
+
// rowEl.focus() inside wrappedOnRowAction, not user navigation.
|
|
171
|
+
var handleRowFocus = useCallback(function (key) {
|
|
172
|
+
if (actionJustFired.current) return;
|
|
173
|
+
setActiveRowKey(function (prev) {
|
|
174
|
+
return prev !== null && prev !== key ? null : prev;
|
|
175
|
+
});
|
|
176
|
+
}, []);
|
|
177
|
+
|
|
178
|
+
// Clear activeRowKey when focus leaves the table entirely.
|
|
179
|
+
// Skip the clear if a row action just fired (e.g. OverlayPanel FocusScope
|
|
180
|
+
// autoFocus stealing focus) — that is not a genuine focus-out.
|
|
181
|
+
var handleTableBlur = useCallback(function (e) {
|
|
182
|
+
if (actionJustFired.current) {
|
|
183
|
+
actionJustFired.current = false;
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
var relatedTarget = e.relatedTarget;
|
|
187
|
+
var scrollEl = scrollRef.current;
|
|
188
|
+
var focusMovedOutside = !relatedTarget || !scrollEl || !scrollEl.contains(relatedTarget);
|
|
189
|
+
if (focusMovedOutside) {
|
|
190
|
+
setActiveRowKey(null);
|
|
191
|
+
}
|
|
192
|
+
}, []);
|
|
71
193
|
var state = useTableState(_objectSpread(_objectSpread({}, props), {}, {
|
|
72
194
|
showSelectionCheckboxes: hasSelectionCheckboxes || selectionMode === 'multiple' && selectionBehavior !== 'replace'
|
|
73
195
|
}));
|
|
74
196
|
var collection = state.collection;
|
|
75
197
|
var _useTable = useTable(_objectSpread(_objectSpread({}, props), {}, {
|
|
76
|
-
scrollRef: scrollRef
|
|
198
|
+
scrollRef: scrollRef,
|
|
199
|
+
onRowAction: onRowAction ? wrappedOnRowAction : undefined
|
|
77
200
|
}), state, tableRef),
|
|
78
201
|
gridProps = _useTable.gridProps;
|
|
79
202
|
var getDefaultWidth = useCallback(function (node) {
|
|
@@ -110,7 +233,8 @@ var TableBase = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
110
233
|
}),
|
|
111
234
|
classNames = _useStatusClasses.classNames;
|
|
112
235
|
return ___EmotionJSX(Box, {
|
|
113
|
-
ref: scrollRef
|
|
236
|
+
ref: scrollRef,
|
|
237
|
+
onBlur: handleTableBlur
|
|
114
238
|
}, ___EmotionJSX(Box, _extends({
|
|
115
239
|
as: "table",
|
|
116
240
|
display: "table",
|
|
@@ -148,24 +272,22 @@ var TableBase = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
148
272
|
})), ___EmotionJSX(TableRowGroup, _extends({
|
|
149
273
|
ref: bodyRef,
|
|
150
274
|
type: "tbody"
|
|
151
|
-
}, collection.body.props),
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
justifyContent: "center",
|
|
158
|
-
px: "lg",
|
|
159
|
-
py: "md"
|
|
160
|
-
}, ___EmotionJSX(Loader, {
|
|
161
|
-
variant: "loader.withinDataTable"
|
|
162
|
-
})), _mapInstanceProperty(_context3 = _Array$from(collection.body.childNodes)).call(_context3, function (row) {
|
|
275
|
+
}, omitTableBodyProps(collection.body.props)), ___EmotionJSX(LoadingOrEmptyState, {
|
|
276
|
+
loadingState: loadingState,
|
|
277
|
+
collectionSize: collection.size,
|
|
278
|
+
colSpan: collection.columns.length,
|
|
279
|
+
renderEmptyState: renderEmptyState
|
|
280
|
+
}), _mapInstanceProperty(_context3 = _Array$from(collection.body.childNodes)).call(_context3, function (row) {
|
|
163
281
|
var _context4, _collection$getChildr, _collection$getChildr2;
|
|
164
282
|
return ___EmotionJSX(TableRow, {
|
|
165
283
|
key: row.key,
|
|
166
284
|
item: row,
|
|
167
285
|
state: state,
|
|
168
|
-
hasSelectionCheckboxes: hasSelectionCheckboxes
|
|
286
|
+
hasSelectionCheckboxes: hasSelectionCheckboxes,
|
|
287
|
+
hasActions: !!onRowAction,
|
|
288
|
+
isActiveRow: row.key === activeRowKey,
|
|
289
|
+
registerRef: registerRowRef,
|
|
290
|
+
onRowFocus: handleRowFocus
|
|
169
291
|
}, _mapInstanceProperty(_context4 = _Array$from((_collection$getChildr = (_collection$getChildr2 = collection.getChildren) === null || _collection$getChildr2 === void 0 ? void 0 : _collection$getChildr2.call(collection, row.key)) !== null && _collection$getChildr !== void 0 ? _collection$getChildr : [])).call(_context4, function (cell) {
|
|
170
292
|
return cell.props.isSelectionCell ? ___EmotionJSX(TableCheckboxCell, {
|
|
171
293
|
key: cell.key,
|
|
@@ -176,14 +298,15 @@ var TableBase = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
176
298
|
key: cell.key,
|
|
177
299
|
cell: cell,
|
|
178
300
|
state: state,
|
|
179
|
-
layoutState: layoutState
|
|
301
|
+
layoutState: layoutState,
|
|
302
|
+
hasActions: !!onRowAction
|
|
180
303
|
});
|
|
181
304
|
}));
|
|
182
305
|
}))));
|
|
183
306
|
});
|
|
184
307
|
var TableCaption = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
185
308
|
var caption = props.caption,
|
|
186
|
-
others = _objectWithoutProperties(props,
|
|
309
|
+
others = _objectWithoutProperties(props, _excluded3);
|
|
187
310
|
if (!caption) {
|
|
188
311
|
return null;
|
|
189
312
|
}
|
|
@@ -200,7 +323,7 @@ var TableRowGroup = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
200
323
|
children = props.children,
|
|
201
324
|
className = props.className,
|
|
202
325
|
isSticky = props.isSticky,
|
|
203
|
-
others = _objectWithoutProperties(props,
|
|
326
|
+
others = _objectWithoutProperties(props, _excluded4);
|
|
204
327
|
var _useTableRowGroup = useTableRowGroup(),
|
|
205
328
|
rowGroupProps = _useTableRowGroup.rowGroupProps;
|
|
206
329
|
var _useStatusClasses2 = useStatusClasses(className, {
|
|
@@ -344,8 +467,18 @@ function TableRow(props) {
|
|
|
344
467
|
state = props.state,
|
|
345
468
|
children = props.children,
|
|
346
469
|
className = props.className,
|
|
347
|
-
hasSelectionCheckboxes = props.hasSelectionCheckboxes
|
|
470
|
+
hasSelectionCheckboxes = props.hasSelectionCheckboxes,
|
|
471
|
+
hasActions = props.hasActions,
|
|
472
|
+
isActiveRow = props.isActiveRow,
|
|
473
|
+
registerRef = props.registerRef,
|
|
474
|
+
onRowFocus = props.onRowFocus;
|
|
348
475
|
var ref = useRef(null);
|
|
476
|
+
|
|
477
|
+
// Register this row's DOM element so wrappedOnRowAction can focus it programmatically.
|
|
478
|
+
var setRef = useCallback(function (el) {
|
|
479
|
+
ref.current = el;
|
|
480
|
+
registerRef === null || registerRef === void 0 || registerRef(item.key, el);
|
|
481
|
+
}, [item.key, registerRef]);
|
|
349
482
|
var _useTableRow = useTableRow({
|
|
350
483
|
node: item
|
|
351
484
|
}, state, ref),
|
|
@@ -380,12 +513,18 @@ function TableRow(props) {
|
|
|
380
513
|
e.preventDefault();
|
|
381
514
|
state.selectionManager.toggleSelection(item.key);
|
|
382
515
|
}, [isDisabled, item.key, state.selectionManager]);
|
|
516
|
+
var rowFocusProps = useCallback(function (e) {
|
|
517
|
+
if (e.currentTarget === e.target) {
|
|
518
|
+
onRowFocus === null || onRowFocus === void 0 || onRowFocus(item.key);
|
|
519
|
+
}
|
|
520
|
+
}, [item.key, onRowFocus]);
|
|
383
521
|
var _useStatusClasses5 = useStatusClasses(className, {
|
|
384
522
|
isSelected: isSelected,
|
|
385
523
|
isHovered: isHovered,
|
|
386
524
|
isPressed: isPressed,
|
|
387
|
-
isFocused: isFocusVisible,
|
|
388
|
-
isDisabled: isDisabled
|
|
525
|
+
isFocused: isFocusVisible || !!isActiveRow,
|
|
526
|
+
isDisabled: isDisabled,
|
|
527
|
+
'has-actions': hasActions
|
|
389
528
|
}),
|
|
390
529
|
classNames = _useStatusClasses5.classNames;
|
|
391
530
|
return ___EmotionJSX(Box, _extends({
|
|
@@ -394,16 +533,18 @@ function TableRow(props) {
|
|
|
394
533
|
className: classNames,
|
|
395
534
|
variant: "tableBase.row"
|
|
396
535
|
}, mergeProps(rowProps, focusProps, hoverProps, pressProps, {
|
|
397
|
-
onKeyDown: enterKeyProps
|
|
536
|
+
onKeyDown: enterKeyProps,
|
|
537
|
+
onFocus: rowFocusProps
|
|
398
538
|
}), {
|
|
399
|
-
ref:
|
|
539
|
+
ref: setRef
|
|
400
540
|
}), children);
|
|
401
541
|
}
|
|
402
542
|
function TableCell(props) {
|
|
403
543
|
var cell = props.cell,
|
|
404
544
|
state = props.state,
|
|
405
545
|
className = props.className,
|
|
406
|
-
layoutState = props.layoutState
|
|
546
|
+
layoutState = props.layoutState,
|
|
547
|
+
hasActions = props.hasActions;
|
|
407
548
|
var ref = useRef(null);
|
|
408
549
|
var _useTableCell = useTableCell({
|
|
409
550
|
node: cell
|
|
@@ -419,9 +560,15 @@ function TableCell(props) {
|
|
|
419
560
|
useHandleFocusRef(ref);
|
|
420
561
|
|
|
421
562
|
// Prevents pointer events reaching the row's press handler, allowing native text-selection drags.
|
|
563
|
+
// Skipped when the table has row actions so that clicks on cells bubble up
|
|
564
|
+
// and trigger onRowAction.
|
|
422
565
|
var stopPointerPropagation = useCallback(function (e) {
|
|
423
566
|
e.stopPropagation();
|
|
424
567
|
}, []);
|
|
568
|
+
var pointerBlockers = hasActions ? {} : {
|
|
569
|
+
onPointerDown: stopPointerPropagation,
|
|
570
|
+
onMouseDown: stopPointerPropagation
|
|
571
|
+
};
|
|
425
572
|
return ___EmotionJSX(Box, _extends({
|
|
426
573
|
as: "td",
|
|
427
574
|
display: "table-cell",
|
|
@@ -431,10 +578,7 @@ function TableCell(props) {
|
|
|
431
578
|
sx: _objectSpread({
|
|
432
579
|
width: layoutState === null || layoutState === void 0 ? void 0 : layoutState.getColumnWidth(cell.column.key)
|
|
433
580
|
}, cell.props.sx)
|
|
434
|
-
}, mergeProps(
|
|
435
|
-
onPointerDown: stopPointerPropagation,
|
|
436
|
-
onMouseDown: stopPointerPropagation
|
|
437
|
-
}, gridCellProps, focusProps, cell.props)), cell.rendered);
|
|
581
|
+
}, mergeProps(pointerBlockers, gridCellProps, focusProps, cell.props)), cell.rendered);
|
|
438
582
|
}
|
|
439
583
|
|
|
440
584
|
// Native checkboxes only toggle on Space, not Enter. This handler makes Enter
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
6
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
7
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
1
8
|
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
2
9
|
import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
|
|
3
10
|
import _Object$create from "@babel/runtime-corejs3/core-js-stable/object/create";
|
|
@@ -11,6 +18,7 @@ import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/inst
|
|
|
11
18
|
import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
|
|
12
19
|
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
|
13
20
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
21
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
14
22
|
function _regeneratorRuntime() { "use strict"; var r = _regenerator(), e = r.m(_regeneratorRuntime), t = (_Object$getPrototypeOf ? _Object$getPrototypeOf(e) : e.__proto__).constructor; function n(r) { var e = "function" == typeof r && r.constructor; return !!e && (e === t || "GeneratorFunction" === (e.displayName || e.name)); } var o = { "throw": 1, "return": 2, "break": 3, "continue": 3 }; function a(r) { var e, t; return function (n) { e || (e = { stop: function stop() { return t(n.a, 2); }, "catch": function _catch() { return n.v; }, abrupt: function abrupt(r, e) { return t(n.a, o[r], e); }, delegateYield: function delegateYield(r, o, a) { return e.resultName = o, t(n.d, _regeneratorValues(r), a); }, finish: function finish(r) { return t(n.f, r); } }, t = function t(r, _t, o) { n.p = e.prev, n.n = e.next; try { return r(_t, o); } finally { e.next = n.n; } }), e.resultName && (e[e.resultName] = n.v, e.resultName = void 0), e.sent = n.v, e.next = n.n; try { return r.call(this, e); } finally { n.p = e.prev, n.n = e.next; } }; } return (_regeneratorRuntime = function _regeneratorRuntime() { return { wrap: function wrap(e, t, n, o) { return r.w(a(e), t, n, o && _reverseInstanceProperty(o).call(o)); }, isGeneratorFunction: n, mark: r.m, awrap: function awrap(r, e) { return new _OverloadYield(r, e); }, AsyncIterator: _regeneratorAsyncIterator, async: function async(r, e, t, o, u) { return (n(e) ? _regeneratorAsyncGen : _regeneratorAsync)(a(r), e, t, o, u); }, keys: _regeneratorKeys, values: _regeneratorValues }; })(); }
|
|
15
23
|
function _regeneratorValues(e) { if (null != e) { var t = e["function" == typeof _Symbol && _Symbol$iterator || "@@iterator"], r = 0; if (t) return t.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) return { next: function next() { return e && r >= e.length && (e = void 0), { value: e && e[r++], done: !e }; } }; } throw new TypeError(_typeof(e) + " is not iterable"); }
|
|
16
24
|
function _regeneratorKeys(e) { var n = Object(e), r = []; for (var t in n) r.unshift(t); return function e() { for (; r.length;) if ((t = r.pop()) in n) return e.value = t, e.done = !1, e; return e.done = !0, e; }; }
|
|
@@ -26,27 +34,31 @@ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instan
|
|
|
26
34
|
import _Number$isNaN from "@babel/runtime-corejs3/core-js-stable/number/is-nan";
|
|
27
35
|
import _parseFloat from "@babel/runtime-corejs3/core-js-stable/parse-float";
|
|
28
36
|
import _sortInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/sort";
|
|
29
|
-
import
|
|
37
|
+
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
38
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
39
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context5, _context6; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context5 = ownKeys(Object(t), !0)).call(_context5, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context6 = ownKeys(Object(t))).call(_context6, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
40
|
+
import React, { useRef, useState } from 'react';
|
|
30
41
|
import { useCollator } from '@react-aria/i18n';
|
|
31
42
|
import { useAsyncList } from '@react-stately/data';
|
|
32
43
|
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
|
33
|
-
import { Badge, Box, Card, Cell, Column, Pagination, PaginationProvider, Row, TableBase, TBody, Text, THead } from '../..';
|
|
34
|
-
import { usePaginationState } from '../../hooks';
|
|
44
|
+
import { Badge, Box, Card, Cell, Column, OverlayPanel, OverlayProvider, Pagination, PaginationProvider, PanelHeader, PanelHeaderCloseButton, Row, TableBase, TableBaseEmptyState, TBody, Text, THead } from '../..';
|
|
45
|
+
import { useOverlayPanelState, usePaginationState } from '../../hooks';
|
|
35
46
|
import { items as listData } from '../../utils/devUtils/constants/items';
|
|
36
47
|
import TableReadme from './TableBase.mdx';
|
|
37
|
-
import { tableBaseArgTypes } from './tableBaseAttributes';
|
|
48
|
+
import { tableBaseArgs, tableBaseArgTypes } from './tableBaseAttributes';
|
|
38
49
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
39
50
|
export default {
|
|
40
51
|
title: 'Components/TableBase',
|
|
41
52
|
component: TableBase,
|
|
53
|
+
argTypes: tableBaseArgTypes,
|
|
54
|
+
args: _objectSpread({}, tableBaseArgs),
|
|
42
55
|
parameters: {
|
|
43
56
|
docs: {
|
|
44
57
|
page: function page() {
|
|
45
58
|
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(TableReadme, null), ___EmotionJSX(DocsLayout, null));
|
|
46
59
|
}
|
|
47
60
|
}
|
|
48
|
-
}
|
|
49
|
-
argTypes: tableBaseArgTypes
|
|
61
|
+
}
|
|
50
62
|
};
|
|
51
63
|
var headers = [{
|
|
52
64
|
key: 'type',
|
|
@@ -87,28 +99,28 @@ var statusVariant = {
|
|
|
87
99
|
Active: 'tableBaseBadge.healthy',
|
|
88
100
|
Inactive: 'tableBaseBadge.secondary'
|
|
89
101
|
};
|
|
90
|
-
export var Default =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
});
|
|
111
|
-
}
|
|
102
|
+
export var Default = {
|
|
103
|
+
render: function render(args) {
|
|
104
|
+
var isEmpty = args.loadingState === 'loading' || args.loadingState === 'sorting';
|
|
105
|
+
return ___EmotionJSX(Card, {
|
|
106
|
+
variant: "cards.tableWrapper"
|
|
107
|
+
}, ___EmotionJSX(TableBase, args, ___EmotionJSX(THead, {
|
|
108
|
+
columns: headers
|
|
109
|
+
}, function (column) {
|
|
110
|
+
return ___EmotionJSX(Column, {
|
|
111
|
+
key: column.key,
|
|
112
|
+
minWidth: 200
|
|
113
|
+
}, column.name);
|
|
114
|
+
}), ___EmotionJSX(TBody, {
|
|
115
|
+
items: isEmpty ? [] : objects
|
|
116
|
+
}, function (item) {
|
|
117
|
+
return ___EmotionJSX(Row, {
|
|
118
|
+
key: item.id
|
|
119
|
+
}, function (columnKey) {
|
|
120
|
+
return ___EmotionJSX(Cell, null, item[columnKey]);
|
|
121
|
+
});
|
|
122
|
+
})));
|
|
123
|
+
}
|
|
112
124
|
};
|
|
113
125
|
export var MultiSelection = function MultiSelection() {
|
|
114
126
|
var _React$useState = React.useState(new _Set(['1', '3'])),
|
|
@@ -459,4 +471,184 @@ export var WithLastColumnSticky = function WithLastColumnSticky() {
|
|
|
459
471
|
return ___EmotionJSX(Cell, null, item[columnKey]);
|
|
460
472
|
});
|
|
461
473
|
})));
|
|
474
|
+
};
|
|
475
|
+
export var WithLoadingState = function WithLoadingState() {
|
|
476
|
+
return ___EmotionJSX(Card, {
|
|
477
|
+
variant: "cards.tableWrapper"
|
|
478
|
+
}, ___EmotionJSX(TableBase, {
|
|
479
|
+
caption: "Lorem ipsum",
|
|
480
|
+
"aria-label": "table",
|
|
481
|
+
loadingState: "loading"
|
|
482
|
+
}, ___EmotionJSX(THead, {
|
|
483
|
+
columns: headers
|
|
484
|
+
}, function (column) {
|
|
485
|
+
return ___EmotionJSX(Column, {
|
|
486
|
+
key: column.key,
|
|
487
|
+
minWidth: 200
|
|
488
|
+
}, column.name);
|
|
489
|
+
}), ___EmotionJSX(TBody, {
|
|
490
|
+
items: []
|
|
491
|
+
}, function () {
|
|
492
|
+
return ___EmotionJSX(Row, {
|
|
493
|
+
key: "unused"
|
|
494
|
+
}, function () {
|
|
495
|
+
return ___EmotionJSX(Cell, null, "Hello 0");
|
|
496
|
+
});
|
|
497
|
+
})));
|
|
498
|
+
};
|
|
499
|
+
export var WithEmptyState = function WithEmptyState() {
|
|
500
|
+
return ___EmotionJSX(Card, {
|
|
501
|
+
variant: "cards.tableWrapper"
|
|
502
|
+
}, ___EmotionJSX(TableBase, {
|
|
503
|
+
caption: "Custom empty state",
|
|
504
|
+
"aria-label": "table with custom empty state",
|
|
505
|
+
renderEmptyState: function renderEmptyState() {
|
|
506
|
+
return ___EmotionJSX("div", null, "No data available");
|
|
507
|
+
}
|
|
508
|
+
}, ___EmotionJSX(THead, {
|
|
509
|
+
columns: headers
|
|
510
|
+
}, function (column) {
|
|
511
|
+
return ___EmotionJSX(Column, {
|
|
512
|
+
key: column.key,
|
|
513
|
+
minWidth: 200
|
|
514
|
+
}, column.name);
|
|
515
|
+
}), ___EmotionJSX(TBody, {
|
|
516
|
+
items: []
|
|
517
|
+
}, function () {
|
|
518
|
+
return ___EmotionJSX(Row, {
|
|
519
|
+
key: "unused"
|
|
520
|
+
}, function () {
|
|
521
|
+
return ___EmotionJSX(Cell, null, "Hello 2");
|
|
522
|
+
});
|
|
523
|
+
})));
|
|
524
|
+
};
|
|
525
|
+
export var DefaultEmptyState = function DefaultEmptyState() {
|
|
526
|
+
return ___EmotionJSX(Card, {
|
|
527
|
+
variant: "cards.tableWrapper"
|
|
528
|
+
}, ___EmotionJSX(TableBase, {
|
|
529
|
+
caption: "Default empty state",
|
|
530
|
+
"aria-label": "table with default empty state"
|
|
531
|
+
}, ___EmotionJSX(THead, {
|
|
532
|
+
columns: headers
|
|
533
|
+
}, function (column) {
|
|
534
|
+
return ___EmotionJSX(Column, {
|
|
535
|
+
key: column.key,
|
|
536
|
+
minWidth: 200
|
|
537
|
+
}, column.name);
|
|
538
|
+
}), ___EmotionJSX(TBody, {
|
|
539
|
+
items: []
|
|
540
|
+
}, function () {
|
|
541
|
+
return ___EmotionJSX(Row, {
|
|
542
|
+
key: "unused"
|
|
543
|
+
}, function () {
|
|
544
|
+
return ___EmotionJSX(Cell, null, "Hello 1");
|
|
545
|
+
});
|
|
546
|
+
})));
|
|
547
|
+
};
|
|
548
|
+
export var DefaultEmptyStateWithButton = function DefaultEmptyStateWithButton() {
|
|
549
|
+
var handleAddItem = function handleAddItem() {
|
|
550
|
+
// eslint-disable-next-line no-console
|
|
551
|
+
console.log('Add button clicked!');
|
|
552
|
+
};
|
|
553
|
+
return ___EmotionJSX(Card, {
|
|
554
|
+
variant: "cards.tableWrapper"
|
|
555
|
+
}, ___EmotionJSX(TableBase, {
|
|
556
|
+
caption: "Empty state with action button",
|
|
557
|
+
"aria-label": "table with empty state and action button",
|
|
558
|
+
renderEmptyState: function renderEmptyState() {
|
|
559
|
+
return ___EmotionJSX(TableBaseEmptyState, {
|
|
560
|
+
headerLabel: "No items available",
|
|
561
|
+
descriptionLabel: "Click the button below to add a new item",
|
|
562
|
+
addButtonLabel: "Add Item",
|
|
563
|
+
onAddButtonPress: handleAddItem
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
}, ___EmotionJSX(THead, {
|
|
567
|
+
columns: headers
|
|
568
|
+
}, function (column) {
|
|
569
|
+
return ___EmotionJSX(Column, {
|
|
570
|
+
key: column.key,
|
|
571
|
+
minWidth: 200
|
|
572
|
+
}, column.name);
|
|
573
|
+
}), ___EmotionJSX(TBody, {
|
|
574
|
+
items: []
|
|
575
|
+
}, function () {
|
|
576
|
+
return ___EmotionJSX(Row, {
|
|
577
|
+
key: "unused"
|
|
578
|
+
}, function () {
|
|
579
|
+
return ___EmotionJSX(Cell, null, "Hello 3");
|
|
580
|
+
});
|
|
581
|
+
})));
|
|
582
|
+
};
|
|
583
|
+
export var RowActions = function RowActions() {
|
|
584
|
+
var _useState3 = useState(null),
|
|
585
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
586
|
+
selectedKey = _useState4[0],
|
|
587
|
+
setSelectedKey = _useState4[1];
|
|
588
|
+
var _useOverlayPanelState = useOverlayPanelState(),
|
|
589
|
+
panelState = _useOverlayPanelState.state,
|
|
590
|
+
onClose = _useOverlayPanelState.onClose;
|
|
591
|
+
var panelTriggerRef = useRef(null);
|
|
592
|
+
var triggerRefAsButton = panelTriggerRef;
|
|
593
|
+
var selectedObject = _findInstanceProperty(objects).call(objects, function (obj) {
|
|
594
|
+
return String(obj.id) === String(selectedKey);
|
|
595
|
+
});
|
|
596
|
+
var handleClose = function handleClose() {
|
|
597
|
+
onClose(panelState, triggerRefAsButton);
|
|
598
|
+
};
|
|
599
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(Card, {
|
|
600
|
+
variant: "cards.tableWrapper"
|
|
601
|
+
}, ___EmotionJSX(TableBase, {
|
|
602
|
+
"aria-label": "Row actions table",
|
|
603
|
+
selectionMode: "none",
|
|
604
|
+
onRowAction: function onRowAction(key) {
|
|
605
|
+
setSelectedKey(key);
|
|
606
|
+
panelState.open();
|
|
607
|
+
},
|
|
608
|
+
ref: panelTriggerRef
|
|
609
|
+
}, ___EmotionJSX(THead, {
|
|
610
|
+
columns: headers
|
|
611
|
+
}, function (column) {
|
|
612
|
+
return ___EmotionJSX(Column, {
|
|
613
|
+
key: column.key,
|
|
614
|
+
minWidth: 200
|
|
615
|
+
}, column.name);
|
|
616
|
+
}), ___EmotionJSX(TBody, {
|
|
617
|
+
items: objects
|
|
618
|
+
}, function (item) {
|
|
619
|
+
return ___EmotionJSX(Row, {
|
|
620
|
+
key: item.id
|
|
621
|
+
}, function (columnKey) {
|
|
622
|
+
return ___EmotionJSX(Cell, null, item[columnKey]);
|
|
623
|
+
});
|
|
624
|
+
}))), (panelState.isOpen || panelState.isTransitioning) && ___EmotionJSX(OverlayPanel, {
|
|
625
|
+
isOpen: panelState.isOpen,
|
|
626
|
+
isTransitioning: panelState.isTransitioning,
|
|
627
|
+
state: panelState,
|
|
628
|
+
triggerRef: triggerRefAsButton,
|
|
629
|
+
sx: {
|
|
630
|
+
p: 0
|
|
631
|
+
}
|
|
632
|
+
}, ___EmotionJSX(PanelHeader, {
|
|
633
|
+
data: {
|
|
634
|
+
text: selectedObject ? selectedObject.type : '',
|
|
635
|
+
subtext: selectedObject ? selectedObject.date : ''
|
|
636
|
+
}
|
|
637
|
+
}, ___EmotionJSX(PanelHeaderCloseButton, {
|
|
638
|
+
onPress: handleClose
|
|
639
|
+
})), selectedObject && ___EmotionJSX(Box, {
|
|
640
|
+
sx: {
|
|
641
|
+
p: 'lg'
|
|
642
|
+
}
|
|
643
|
+
}, ___EmotionJSX(Text, null, "Type: ".concat(selectedObject.type)), ___EmotionJSX(Text, null, "Date: ".concat(selectedObject.date)), ___EmotionJSX(Text, null, "Additional Grant: ".concat(selectedObject.additional_grant)), ___EmotionJSX(Text, null, "Total Grant: ".concat(selectedObject.total_grant)))));
|
|
644
|
+
};
|
|
645
|
+
RowActions.parameters = {
|
|
646
|
+
a11y: {
|
|
647
|
+
config: {
|
|
648
|
+
rules: [{
|
|
649
|
+
id: 'color-contrast',
|
|
650
|
+
enabled: false
|
|
651
|
+
}]
|
|
652
|
+
}
|
|
653
|
+
}
|
|
462
654
|
};
|