@pingux/astro 2.214.0 → 2.215.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/TableBase/TableBase.js +119 -20
- package/lib/cjs/components/TableBase/TableBase.stories.js +74 -1
- 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 +462 -66
- package/lib/cjs/components/TableBase/tableBaseAttributes.d.ts +1 -0
- package/lib/cjs/components/TableBase/tableBaseAttributes.js +3 -0
- package/lib/cjs/types/tableBase.d.ts +6 -0
- package/lib/components/OverlayPanel/OverlayPanel.js +7 -1
- package/lib/components/OverlayPanel/OverlayPanel.test.js +64 -0
- package/lib/components/TableBase/TableBase.js +116 -17
- package/lib/components/TableBase/TableBase.stories.js +76 -3
- package/lib/components/TableBase/TableBase.styles.js +3 -0
- package/lib/components/TableBase/TableBase.test.js +462 -66
- package/lib/components/TableBase/tableBaseAttributes.js +3 -0
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ export interface TableBaseProps<T extends object> extends TableProps<T>, Omit<Ba
|
|
|
22
22
|
onResizeStart?: ResizeHandler;
|
|
23
23
|
onResize?: ResizeHandler;
|
|
24
24
|
onResizeEnd?: ResizeHandler;
|
|
25
|
+
onRowAction?: (key: Key) => void;
|
|
25
26
|
}
|
|
26
27
|
export interface TableRowGroupProps extends BaseProp {
|
|
27
28
|
type: 'thead' | 'tbody';
|
|
@@ -57,12 +58,17 @@ export interface TableRowProps<T> extends BaseProp {
|
|
|
57
58
|
children: ReactNode;
|
|
58
59
|
className?: string;
|
|
59
60
|
hasSelectionCheckboxes?: boolean;
|
|
61
|
+
hasActions?: boolean;
|
|
62
|
+
isActiveRow?: boolean;
|
|
63
|
+
registerRef?: (key: Key, el: HTMLElement | null) => void;
|
|
64
|
+
onRowFocus?: (key: Key) => void;
|
|
60
65
|
}
|
|
61
66
|
export interface TableCellProps<T> extends BaseProp {
|
|
62
67
|
cell: GridNode<T>;
|
|
63
68
|
state: TableState<T>;
|
|
64
69
|
className?: string;
|
|
65
70
|
layoutState: TableColumnResizeState<T>;
|
|
71
|
+
hasActions?: boolean;
|
|
66
72
|
}
|
|
67
73
|
export interface TableCheckboxCellProps<T> extends BaseProp {
|
|
68
74
|
cell: GridNode<T>;
|
|
@@ -2,8 +2,9 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
|
2
2
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
4
4
|
var _excluded = ["children", "isOpen", "isTransitioning", "onClose", "className", "state", "size", "triggerRef"];
|
|
5
|
-
import React, { forwardRef } from 'react';
|
|
5
|
+
import React, { forwardRef, useEffect } from 'react';
|
|
6
6
|
import { FocusScope } from 'react-aria';
|
|
7
|
+
import { setInteractionModality } from '@react-aria/interactions';
|
|
7
8
|
import { Box } from '../..';
|
|
8
9
|
import { useLocalOrForwardRef, useOverlayPanelState, useStatusClasses } from '../../hooks';
|
|
9
10
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
@@ -21,6 +22,11 @@ var OverlayPanel = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
21
22
|
var _useOverlayPanelState = useOverlayPanelState(),
|
|
22
23
|
onClose = _useOverlayPanelState.onClose;
|
|
23
24
|
var overlayPanelRef = useLocalOrForwardRef(ref);
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
if (isOpen) {
|
|
27
|
+
setInteractionModality('keyboard');
|
|
28
|
+
}
|
|
29
|
+
}, [isOpen]);
|
|
24
30
|
|
|
25
31
|
// this is code to avoid regressions -- implementations that do not use the
|
|
26
32
|
// useMountTransition hook will not break, because this className gives the
|
|
@@ -1,9 +1,26 @@
|
|
|
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";
|
|
8
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
1
9
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
10
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
11
|
+
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; }
|
|
12
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
2
13
|
import React from 'react';
|
|
14
|
+
import { setInteractionModality } from '@react-aria/interactions';
|
|
3
15
|
import { fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
|
4
16
|
import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
|
|
5
17
|
import OverlayPanel from './OverlayPanel';
|
|
6
18
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
|
19
|
+
jest.mock('@react-aria/interactions', function () {
|
|
20
|
+
return _objectSpread(_objectSpread({}, jest.requireActual('@react-aria/interactions')), {}, {
|
|
21
|
+
setInteractionModality: jest.fn()
|
|
22
|
+
});
|
|
23
|
+
});
|
|
7
24
|
var testId = 'test-overlayPanel';
|
|
8
25
|
var defaultProps = {
|
|
9
26
|
'data-testid': testId
|
|
@@ -151,4 +168,51 @@ test('triggerRef.current.focus() does not fire when key other than esc is presse
|
|
|
151
168
|
charCode: 65
|
|
152
169
|
});
|
|
153
170
|
expect(focusFunction).not.toHaveBeenCalled();
|
|
171
|
+
});
|
|
172
|
+
test('sets interaction modality to keyboard when panel opens', function () {
|
|
173
|
+
getComponent({
|
|
174
|
+
isOpen: true,
|
|
175
|
+
children: ___EmotionJSX("div", null, "Test")
|
|
176
|
+
});
|
|
177
|
+
expect(setInteractionModality).toHaveBeenCalledWith('keyboard');
|
|
178
|
+
});
|
|
179
|
+
test('does not set interaction modality to keyboard when panel is closed', function () {
|
|
180
|
+
setInteractionModality.mockClear();
|
|
181
|
+
getComponent({
|
|
182
|
+
isOpen: false,
|
|
183
|
+
children: ___EmotionJSX("div", null, "Test")
|
|
184
|
+
});
|
|
185
|
+
expect(setInteractionModality).not.toHaveBeenCalledWith('keyboard');
|
|
186
|
+
});
|
|
187
|
+
test('sets interaction modality to keyboard when panel transitions from closed to open', function () {
|
|
188
|
+
var _getComponent = getComponent({
|
|
189
|
+
isOpen: false,
|
|
190
|
+
children: ___EmotionJSX("div", null, "Test")
|
|
191
|
+
}),
|
|
192
|
+
rerender = _getComponent.rerender;
|
|
193
|
+
setInteractionModality.mockClear();
|
|
194
|
+
rerender(___EmotionJSX(OverlayPanel, _extends({}, defaultProps, {
|
|
195
|
+
isOpen: true
|
|
196
|
+
}), ___EmotionJSX("div", null, "Test")));
|
|
197
|
+
expect(setInteractionModality).toHaveBeenCalledWith('keyboard');
|
|
198
|
+
});
|
|
199
|
+
test('sets interaction modality to keyboard on re-open after close', function () {
|
|
200
|
+
var _getComponent2 = getComponent({
|
|
201
|
+
isOpen: true,
|
|
202
|
+
children: ___EmotionJSX("div", null, "Test")
|
|
203
|
+
}),
|
|
204
|
+
rerender = _getComponent2.rerender;
|
|
205
|
+
setInteractionModality.mockClear();
|
|
206
|
+
|
|
207
|
+
// Close the panel
|
|
208
|
+
rerender(___EmotionJSX(OverlayPanel, _extends({}, defaultProps, {
|
|
209
|
+
isOpen: false
|
|
210
|
+
}), ___EmotionJSX("div", null, "Test")));
|
|
211
|
+
expect(setInteractionModality).not.toHaveBeenCalledWith('keyboard');
|
|
212
|
+
|
|
213
|
+
// Re-open — modality must be forced to keyboard again
|
|
214
|
+
rerender(___EmotionJSX(OverlayPanel, _extends({}, defaultProps, {
|
|
215
|
+
isOpen: true
|
|
216
|
+
}), ___EmotionJSX("div", null, "Test")));
|
|
217
|
+
expect(setInteractionModality).toHaveBeenCalledWith('keyboard');
|
|
154
218
|
});
|
|
@@ -10,13 +10,15 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
|
10
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
|
11
11
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
|
12
12
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
|
13
|
-
var _excluded = ["caption", "selectionMode", "selectionBehavior", "hasSelectionCheckboxes", "isStickyHeader", "className", "isLastColumnSticky", "onResizeStart", "onResize", "onResizeEnd"],
|
|
13
|
+
var _excluded = ["caption", "selectionMode", "selectionBehavior", "hasSelectionCheckboxes", "isStickyHeader", "className", "isLastColumnSticky", "onResizeStart", "onResize", "onResizeEnd", "onRowAction"],
|
|
14
14
|
_excluded2 = ["caption"],
|
|
15
15
|
_excluded3 = ["type", "children", "className", "isSticky"];
|
|
16
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
17
|
-
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
|
18
16
|
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
17
|
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; }
|
|
18
|
+
import _Map from "@babel/runtime-corejs3/core-js-stable/map";
|
|
19
|
+
import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
|
|
20
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
21
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
|
20
22
|
import React, { forwardRef, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
21
23
|
import { useFocusRing } from '@react-aria/focus';
|
|
22
24
|
import { useHover, usePress } from '@react-aria/interactions';
|
|
@@ -59,21 +61,91 @@ var TableBase = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
59
61
|
onResizeStart = props.onResizeStart,
|
|
60
62
|
onResize = props.onResize,
|
|
61
63
|
onResizeEnd = props.onResizeEnd,
|
|
64
|
+
onRowAction = props.onRowAction,
|
|
62
65
|
others = _objectWithoutProperties(props, _excluded);
|
|
63
66
|
var tableRef = useLocalOrForwardRef(ref);
|
|
64
67
|
var headerRef = useRef(null);
|
|
65
68
|
var scrollRef = useRef(null);
|
|
66
69
|
var bodyRef = useRef(null);
|
|
70
|
+
// Map of row key -> <tr> DOM element, used to focus the clicked row after onRowAction fires.
|
|
71
|
+
var rowRefMap = useRef(new _Map());
|
|
72
|
+
// Guard flag: set to true just before onRowAction fires so the subsequent blur
|
|
73
|
+
// event (caused by an OverlayPanel FocusScope stealing focus) does not clear
|
|
74
|
+
// activeRowKey prematurely. Resets to false after the blur handler runs.
|
|
75
|
+
var actionJustFired = useRef(false);
|
|
67
76
|
var _useState = useState(0),
|
|
68
77
|
_useState2 = _slicedToArray(_useState, 2),
|
|
69
78
|
tableWidth = _useState2[0],
|
|
70
79
|
setTableWidth = _useState2[1];
|
|
80
|
+
var _useState3 = useState(null),
|
|
81
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
82
|
+
activeRowKey = _useState4[0],
|
|
83
|
+
setActiveRowKey = _useState4[1];
|
|
84
|
+
var registerRowRef = useCallback(function (key, el) {
|
|
85
|
+
if (el) {
|
|
86
|
+
rowRefMap.current.set(key, el);
|
|
87
|
+
} else {
|
|
88
|
+
rowRefMap.current["delete"](key);
|
|
89
|
+
}
|
|
90
|
+
}, []);
|
|
91
|
+
var wrappedOnRowAction = useCallback(function (key) {
|
|
92
|
+
// Toggle off if clicking the already-active row
|
|
93
|
+
setActiveRowKey(function (prev) {
|
|
94
|
+
return prev === key ? null : key;
|
|
95
|
+
});
|
|
96
|
+
// Signal that a row action just fired so handleTableBlur skips the clear.
|
|
97
|
+
// This prevents OverlayPanel's FocusScope autoFocus from triggering a false
|
|
98
|
+
// positive blur that would remove the active-row highlight.
|
|
99
|
+
actionJustFired.current = true;
|
|
100
|
+
onRowAction === null || onRowAction === void 0 || onRowAction(key);
|
|
101
|
+
// Move DOM focus to the clicked row's <tr> so React Aria can handle arrow-key
|
|
102
|
+
// navigation from that row after a mouse click.
|
|
103
|
+
var rowEl = rowRefMap.current.get(key);
|
|
104
|
+
if (rowEl) {
|
|
105
|
+
rowEl.focus();
|
|
106
|
+
}
|
|
107
|
+
// Reset the guard after the current event loop tick so any FocusScope
|
|
108
|
+
// autoFocus steal (which fires synchronously) is absorbed, but subsequent
|
|
109
|
+
// genuine blur events (Tab away, click outside) are not.
|
|
110
|
+
_setTimeout(function () {
|
|
111
|
+
actionJustFired.current = false;
|
|
112
|
+
}, 0);
|
|
113
|
+
}, [onRowAction]);
|
|
114
|
+
|
|
115
|
+
// Called when any row receives focus. If the newly focused row is different
|
|
116
|
+
// from the active row (set by a click), clear activeRowKey so arrow-key
|
|
117
|
+
// navigation does not leave stale active-row highlights on multiple rows.
|
|
118
|
+
// Skip when actionJustFired is true — that focus event is the programmatic
|
|
119
|
+
// rowEl.focus() inside wrappedOnRowAction, not user navigation.
|
|
120
|
+
var handleRowFocus = useCallback(function (key) {
|
|
121
|
+
if (actionJustFired.current) return;
|
|
122
|
+
setActiveRowKey(function (prev) {
|
|
123
|
+
return prev !== null && prev !== key ? null : prev;
|
|
124
|
+
});
|
|
125
|
+
}, []);
|
|
126
|
+
|
|
127
|
+
// Clear activeRowKey when focus leaves the table entirely.
|
|
128
|
+
// Skip the clear if a row action just fired (e.g. OverlayPanel FocusScope
|
|
129
|
+
// autoFocus stealing focus) — that is not a genuine focus-out.
|
|
130
|
+
var handleTableBlur = useCallback(function (e) {
|
|
131
|
+
if (actionJustFired.current) {
|
|
132
|
+
actionJustFired.current = false;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
var relatedTarget = e.relatedTarget;
|
|
136
|
+
var scrollEl = scrollRef.current;
|
|
137
|
+
var focusMovedOutside = !relatedTarget || !scrollEl || !scrollEl.contains(relatedTarget);
|
|
138
|
+
if (focusMovedOutside) {
|
|
139
|
+
setActiveRowKey(null);
|
|
140
|
+
}
|
|
141
|
+
}, []);
|
|
71
142
|
var state = useTableState(_objectSpread(_objectSpread({}, props), {}, {
|
|
72
143
|
showSelectionCheckboxes: hasSelectionCheckboxes || selectionMode === 'multiple' && selectionBehavior !== 'replace'
|
|
73
144
|
}));
|
|
74
145
|
var collection = state.collection;
|
|
75
146
|
var _useTable = useTable(_objectSpread(_objectSpread({}, props), {}, {
|
|
76
|
-
scrollRef: scrollRef
|
|
147
|
+
scrollRef: scrollRef,
|
|
148
|
+
onRowAction: onRowAction ? wrappedOnRowAction : undefined
|
|
77
149
|
}), state, tableRef),
|
|
78
150
|
gridProps = _useTable.gridProps;
|
|
79
151
|
var getDefaultWidth = useCallback(function (node) {
|
|
@@ -110,7 +182,8 @@ var TableBase = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
110
182
|
}),
|
|
111
183
|
classNames = _useStatusClasses.classNames;
|
|
112
184
|
return ___EmotionJSX(Box, {
|
|
113
|
-
ref: scrollRef
|
|
185
|
+
ref: scrollRef,
|
|
186
|
+
onBlur: handleTableBlur
|
|
114
187
|
}, ___EmotionJSX(Box, _extends({
|
|
115
188
|
as: "table",
|
|
116
189
|
display: "table",
|
|
@@ -165,7 +238,11 @@ var TableBase = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
165
238
|
key: row.key,
|
|
166
239
|
item: row,
|
|
167
240
|
state: state,
|
|
168
|
-
hasSelectionCheckboxes: hasSelectionCheckboxes
|
|
241
|
+
hasSelectionCheckboxes: hasSelectionCheckboxes,
|
|
242
|
+
hasActions: !!onRowAction,
|
|
243
|
+
isActiveRow: row.key === activeRowKey,
|
|
244
|
+
registerRef: registerRowRef,
|
|
245
|
+
onRowFocus: handleRowFocus
|
|
169
246
|
}, _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
247
|
return cell.props.isSelectionCell ? ___EmotionJSX(TableCheckboxCell, {
|
|
171
248
|
key: cell.key,
|
|
@@ -176,7 +253,8 @@ var TableBase = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
176
253
|
key: cell.key,
|
|
177
254
|
cell: cell,
|
|
178
255
|
state: state,
|
|
179
|
-
layoutState: layoutState
|
|
256
|
+
layoutState: layoutState,
|
|
257
|
+
hasActions: !!onRowAction
|
|
180
258
|
});
|
|
181
259
|
}));
|
|
182
260
|
}))));
|
|
@@ -344,8 +422,18 @@ function TableRow(props) {
|
|
|
344
422
|
state = props.state,
|
|
345
423
|
children = props.children,
|
|
346
424
|
className = props.className,
|
|
347
|
-
hasSelectionCheckboxes = props.hasSelectionCheckboxes
|
|
425
|
+
hasSelectionCheckboxes = props.hasSelectionCheckboxes,
|
|
426
|
+
hasActions = props.hasActions,
|
|
427
|
+
isActiveRow = props.isActiveRow,
|
|
428
|
+
registerRef = props.registerRef,
|
|
429
|
+
onRowFocus = props.onRowFocus;
|
|
348
430
|
var ref = useRef(null);
|
|
431
|
+
|
|
432
|
+
// Register this row's DOM element so wrappedOnRowAction can focus it programmatically.
|
|
433
|
+
var setRef = useCallback(function (el) {
|
|
434
|
+
ref.current = el;
|
|
435
|
+
registerRef === null || registerRef === void 0 || registerRef(item.key, el);
|
|
436
|
+
}, [item.key, registerRef]);
|
|
349
437
|
var _useTableRow = useTableRow({
|
|
350
438
|
node: item
|
|
351
439
|
}, state, ref),
|
|
@@ -380,12 +468,18 @@ function TableRow(props) {
|
|
|
380
468
|
e.preventDefault();
|
|
381
469
|
state.selectionManager.toggleSelection(item.key);
|
|
382
470
|
}, [isDisabled, item.key, state.selectionManager]);
|
|
471
|
+
var rowFocusProps = useCallback(function (e) {
|
|
472
|
+
if (e.currentTarget === e.target) {
|
|
473
|
+
onRowFocus === null || onRowFocus === void 0 || onRowFocus(item.key);
|
|
474
|
+
}
|
|
475
|
+
}, [item.key, onRowFocus]);
|
|
383
476
|
var _useStatusClasses5 = useStatusClasses(className, {
|
|
384
477
|
isSelected: isSelected,
|
|
385
478
|
isHovered: isHovered,
|
|
386
479
|
isPressed: isPressed,
|
|
387
|
-
isFocused: isFocusVisible,
|
|
388
|
-
isDisabled: isDisabled
|
|
480
|
+
isFocused: isFocusVisible || !!isActiveRow,
|
|
481
|
+
isDisabled: isDisabled,
|
|
482
|
+
'has-actions': hasActions
|
|
389
483
|
}),
|
|
390
484
|
classNames = _useStatusClasses5.classNames;
|
|
391
485
|
return ___EmotionJSX(Box, _extends({
|
|
@@ -394,16 +488,18 @@ function TableRow(props) {
|
|
|
394
488
|
className: classNames,
|
|
395
489
|
variant: "tableBase.row"
|
|
396
490
|
}, mergeProps(rowProps, focusProps, hoverProps, pressProps, {
|
|
397
|
-
onKeyDown: enterKeyProps
|
|
491
|
+
onKeyDown: enterKeyProps,
|
|
492
|
+
onFocus: rowFocusProps
|
|
398
493
|
}), {
|
|
399
|
-
ref:
|
|
494
|
+
ref: setRef
|
|
400
495
|
}), children);
|
|
401
496
|
}
|
|
402
497
|
function TableCell(props) {
|
|
403
498
|
var cell = props.cell,
|
|
404
499
|
state = props.state,
|
|
405
500
|
className = props.className,
|
|
406
|
-
layoutState = props.layoutState
|
|
501
|
+
layoutState = props.layoutState,
|
|
502
|
+
hasActions = props.hasActions;
|
|
407
503
|
var ref = useRef(null);
|
|
408
504
|
var _useTableCell = useTableCell({
|
|
409
505
|
node: cell
|
|
@@ -419,9 +515,15 @@ function TableCell(props) {
|
|
|
419
515
|
useHandleFocusRef(ref);
|
|
420
516
|
|
|
421
517
|
// Prevents pointer events reaching the row's press handler, allowing native text-selection drags.
|
|
518
|
+
// Skipped when the table has row actions so that clicks on cells bubble up
|
|
519
|
+
// and trigger onRowAction.
|
|
422
520
|
var stopPointerPropagation = useCallback(function (e) {
|
|
423
521
|
e.stopPropagation();
|
|
424
522
|
}, []);
|
|
523
|
+
var pointerBlockers = hasActions ? {} : {
|
|
524
|
+
onPointerDown: stopPointerPropagation,
|
|
525
|
+
onMouseDown: stopPointerPropagation
|
|
526
|
+
};
|
|
425
527
|
return ___EmotionJSX(Box, _extends({
|
|
426
528
|
as: "td",
|
|
427
529
|
display: "table-cell",
|
|
@@ -431,10 +533,7 @@ function TableCell(props) {
|
|
|
431
533
|
sx: _objectSpread({
|
|
432
534
|
width: layoutState === null || layoutState === void 0 ? void 0 : layoutState.getColumnWidth(cell.column.key)
|
|
433
535
|
}, cell.props.sx)
|
|
434
|
-
}, mergeProps(
|
|
435
|
-
onPointerDown: stopPointerPropagation,
|
|
436
|
-
onMouseDown: stopPointerPropagation
|
|
437
|
-
}, gridCellProps, focusProps, cell.props)), cell.rendered);
|
|
536
|
+
}, mergeProps(pointerBlockers, gridCellProps, focusProps, cell.props)), cell.rendered);
|
|
438
537
|
}
|
|
439
538
|
|
|
440
539
|
// Native checkboxes only toggle on Space, not Enter. This handler makes Enter
|
|
@@ -26,12 +26,13 @@ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instan
|
|
|
26
26
|
import _Number$isNaN from "@babel/runtime-corejs3/core-js-stable/number/is-nan";
|
|
27
27
|
import _parseFloat from "@babel/runtime-corejs3/core-js-stable/parse-float";
|
|
28
28
|
import _sortInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/sort";
|
|
29
|
-
import
|
|
29
|
+
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
30
|
+
import React, { useRef, useState } from 'react';
|
|
30
31
|
import { useCollator } from '@react-aria/i18n';
|
|
31
32
|
import { useAsyncList } from '@react-stately/data';
|
|
32
33
|
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';
|
|
34
|
+
import { Badge, Box, Card, Cell, Column, OverlayPanel, OverlayProvider, Pagination, PaginationProvider, PanelHeader, PanelHeaderCloseButton, Row, TableBase, TBody, Text, THead } from '../..';
|
|
35
|
+
import { useOverlayPanelState, usePaginationState } from '../../hooks';
|
|
35
36
|
import { items as listData } from '../../utils/devUtils/constants/items';
|
|
36
37
|
import TableReadme from './TableBase.mdx';
|
|
37
38
|
import { tableBaseArgTypes } from './tableBaseAttributes';
|
|
@@ -459,4 +460,76 @@ export var WithLastColumnSticky = function WithLastColumnSticky() {
|
|
|
459
460
|
return ___EmotionJSX(Cell, null, item[columnKey]);
|
|
460
461
|
});
|
|
461
462
|
})));
|
|
463
|
+
};
|
|
464
|
+
export var RowActions = function RowActions() {
|
|
465
|
+
var _useState3 = useState(null),
|
|
466
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
467
|
+
selectedKey = _useState4[0],
|
|
468
|
+
setSelectedKey = _useState4[1];
|
|
469
|
+
var _useOverlayPanelState = useOverlayPanelState(),
|
|
470
|
+
panelState = _useOverlayPanelState.state,
|
|
471
|
+
onClose = _useOverlayPanelState.onClose;
|
|
472
|
+
var panelTriggerRef = useRef(null);
|
|
473
|
+
var triggerRefAsButton = panelTriggerRef;
|
|
474
|
+
var selectedObject = _findInstanceProperty(objects).call(objects, function (obj) {
|
|
475
|
+
return String(obj.id) === String(selectedKey);
|
|
476
|
+
});
|
|
477
|
+
var handleClose = function handleClose() {
|
|
478
|
+
onClose(panelState, triggerRefAsButton);
|
|
479
|
+
};
|
|
480
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(Card, {
|
|
481
|
+
variant: "cards.tableWrapper"
|
|
482
|
+
}, ___EmotionJSX(TableBase, {
|
|
483
|
+
"aria-label": "Row actions table",
|
|
484
|
+
selectionMode: "none",
|
|
485
|
+
onRowAction: function onRowAction(key) {
|
|
486
|
+
setSelectedKey(key);
|
|
487
|
+
panelState.open();
|
|
488
|
+
},
|
|
489
|
+
ref: panelTriggerRef
|
|
490
|
+
}, ___EmotionJSX(THead, {
|
|
491
|
+
columns: headers
|
|
492
|
+
}, function (column) {
|
|
493
|
+
return ___EmotionJSX(Column, {
|
|
494
|
+
key: column.key,
|
|
495
|
+
minWidth: 200
|
|
496
|
+
}, column.name);
|
|
497
|
+
}), ___EmotionJSX(TBody, {
|
|
498
|
+
items: objects
|
|
499
|
+
}, function (item) {
|
|
500
|
+
return ___EmotionJSX(Row, {
|
|
501
|
+
key: item.id
|
|
502
|
+
}, function (columnKey) {
|
|
503
|
+
return ___EmotionJSX(Cell, null, item[columnKey]);
|
|
504
|
+
});
|
|
505
|
+
}))), (panelState.isOpen || panelState.isTransitioning) && ___EmotionJSX(OverlayPanel, {
|
|
506
|
+
isOpen: panelState.isOpen,
|
|
507
|
+
isTransitioning: panelState.isTransitioning,
|
|
508
|
+
state: panelState,
|
|
509
|
+
triggerRef: triggerRefAsButton,
|
|
510
|
+
sx: {
|
|
511
|
+
p: 0
|
|
512
|
+
}
|
|
513
|
+
}, ___EmotionJSX(PanelHeader, {
|
|
514
|
+
data: {
|
|
515
|
+
text: selectedObject ? selectedObject.type : '',
|
|
516
|
+
subtext: selectedObject ? selectedObject.date : ''
|
|
517
|
+
}
|
|
518
|
+
}, ___EmotionJSX(PanelHeaderCloseButton, {
|
|
519
|
+
onPress: handleClose
|
|
520
|
+
})), selectedObject && ___EmotionJSX(Box, {
|
|
521
|
+
sx: {
|
|
522
|
+
p: 'lg'
|
|
523
|
+
}
|
|
524
|
+
}, ___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)))));
|
|
525
|
+
};
|
|
526
|
+
RowActions.parameters = {
|
|
527
|
+
a11y: {
|
|
528
|
+
config: {
|
|
529
|
+
rules: [{
|
|
530
|
+
id: 'color-contrast',
|
|
531
|
+
enabled: false
|
|
532
|
+
}]
|
|
533
|
+
}
|
|
534
|
+
}
|
|
462
535
|
};
|