@pingux/astro 2.130.4-alpha.0 → 2.131.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/GridList/GridList.d.ts +3 -0
- package/lib/cjs/components/GridList/GridList.js +56 -0
- package/lib/cjs/components/GridList/GridList.mdx +68 -0
- package/lib/cjs/components/GridList/GridList.stories.d.ts +185 -0
- package/lib/cjs/components/GridList/GridList.stories.js +137 -0
- package/lib/cjs/components/GridList/GridList.styles.d.ts +18 -0
- package/lib/cjs/components/GridList/GridList.styles.js +27 -0
- package/lib/cjs/components/GridList/GridList.test.d.ts +1 -0
- package/lib/cjs/components/GridList/GridList.test.js +153 -0
- package/lib/cjs/components/GridList/GridListRow.d.ts +4 -0
- package/lib/cjs/components/GridList/GridListRow.js +88 -0
- package/lib/cjs/components/GridList/gridListAttributes.d.ts +170 -0
- package/lib/cjs/components/GridList/gridListAttributes.js +178 -0
- package/lib/cjs/components/GridList/index.d.ts +2 -0
- package/lib/cjs/components/GridList/index.js +21 -0
- package/lib/cjs/components/TreeView/InsertionIndicator.js +19 -14
- package/lib/cjs/components/TreeView/TreeView.styles.js +2 -1
- package/lib/cjs/components/TreeView/index.js +7 -0
- package/lib/cjs/hooks/index.d.ts +2 -0
- package/lib/cjs/hooks/index.js +14 -0
- package/lib/cjs/hooks/useGridList/index.d.ts +1 -0
- package/lib/cjs/hooks/useGridList/index.js +14 -0
- package/lib/cjs/hooks/useGridList/useGridList.d.ts +18 -0
- package/lib/cjs/hooks/useGridList/useGridList.js +175 -0
- package/lib/cjs/hooks/useGridListItem/index.d.ts +1 -0
- package/lib/cjs/hooks/useGridListItem/index.js +14 -0
- package/lib/cjs/hooks/useGridListItem/useGridListItem.d.ts +308 -0
- package/lib/cjs/hooks/useGridListItem/useGridListItem.js +67 -0
- package/lib/cjs/hooks/useReorderableCollection/index.d.ts +1 -0
- package/lib/cjs/hooks/useReorderableCollection/index.js +14 -0
- package/lib/cjs/hooks/useReorderableCollection/useReorderableCollection.d.ts +9 -0
- package/lib/cjs/hooks/useReorderableCollection/useReorderableCollection.js +99 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +15 -0
- package/lib/cjs/styles/themes/next-gen/convertedComponentList.js +1 -1
- package/lib/cjs/styles/variants/variants.js +2 -0
- package/lib/cjs/types/dnd.d.ts +66 -0
- package/lib/cjs/types/dnd.js +6 -0
- package/lib/cjs/types/gridList.d.ts +59 -0
- package/lib/cjs/types/gridList.js +6 -0
- package/lib/components/GridList/GridList.js +44 -0
- package/lib/components/GridList/GridList.mdx +68 -0
- package/lib/components/GridList/GridList.stories.js +124 -0
- package/lib/components/GridList/GridList.styles.js +19 -0
- package/lib/components/GridList/GridList.test.js +149 -0
- package/lib/components/GridList/GridListRow.js +74 -0
- package/lib/components/GridList/gridListAttributes.js +170 -0
- package/lib/components/GridList/index.js +2 -0
- package/lib/components/TreeView/InsertionIndicator.js +19 -14
- package/lib/components/TreeView/TreeView.styles.js +2 -1
- package/lib/components/TreeView/index.js +1 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/useGridList/index.js +1 -0
- package/lib/hooks/useGridList/useGridList.js +166 -0
- package/lib/hooks/useGridListItem/index.js +1 -0
- package/lib/hooks/useGridListItem/useGridListItem.js +59 -0
- package/lib/hooks/useReorderableCollection/index.js +1 -0
- package/lib/hooks/useReorderableCollection/useReorderableCollection.js +91 -0
- package/lib/index.js +1 -0
- package/lib/styles/themes/next-gen/convertedComponentList.js +1 -1
- package/lib/styles/variants/variants.js +2 -0
- package/lib/types/dnd.js +1 -0
- package/lib/types/gridList.js +1 -0
- package/package.json +3 -2
package/lib/cjs/index.js
CHANGED
@@ -71,6 +71,8 @@ var _exportNames = {
|
|
71
71
|
FileInputField: true,
|
72
72
|
Footer: true,
|
73
73
|
Grid: true,
|
74
|
+
GridList: true,
|
75
|
+
GridListRow: true,
|
74
76
|
HelpHint: true,
|
75
77
|
Icon: true,
|
76
78
|
NoticeIcon: true,
|
@@ -476,6 +478,18 @@ _Object$defineProperty(exports, "Grid", {
|
|
476
478
|
return _Grid["default"];
|
477
479
|
}
|
478
480
|
});
|
481
|
+
_Object$defineProperty(exports, "GridList", {
|
482
|
+
enumerable: true,
|
483
|
+
get: function get() {
|
484
|
+
return _GridList["default"];
|
485
|
+
}
|
486
|
+
});
|
487
|
+
_Object$defineProperty(exports, "GridListRow", {
|
488
|
+
enumerable: true,
|
489
|
+
get: function get() {
|
490
|
+
return _GridList.GridListRow;
|
491
|
+
}
|
492
|
+
});
|
479
493
|
_Object$defineProperty(exports, "HelpHint", {
|
480
494
|
enumerable: true,
|
481
495
|
get: function get() {
|
@@ -1444,6 +1458,7 @@ _forEachInstanceProperty(_context25 = _Object$keys(_Footer)).call(_context25, fu
|
|
1444
1458
|
});
|
1445
1459
|
});
|
1446
1460
|
var _Grid = _interopRequireDefault(require("./components/Grid"));
|
1461
|
+
var _GridList = _interopRequireWildcard(require("./components/GridList"));
|
1447
1462
|
var _HelpHint = _interopRequireWildcard(require("./components/HelpHint"));
|
1448
1463
|
_forEachInstanceProperty(_context26 = _Object$keys(_HelpHint)).call(_context26, function (key) {
|
1449
1464
|
if (key === "default" || key === "__esModule") return;
|
@@ -5,7 +5,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
6
6
|
});
|
7
7
|
exports.nextGenOnlyComponents = exports["default"] = exports.componentSpecificNextGenBlacklist = exports.astroBlacklistStory = void 0;
|
8
|
-
var nextGenConvertedComponents = ['DataTable', 'Message', 'Button', 'Badge', 'IconButton', 'CheckboxField', 'Messages', 'PopoverMenu', 'TextField', 'PasswordField', 'SearchField', 'SelectField', 'Modal', 'RadioField', 'MultiValuesField', 'TextAreaField', 'RadioGroupField', 'RockerButtonGroup', 'Tabs', 'ProgressBar', 'NavBar', 'OverlayPanel', 'AstroProvider', 'ListView', 'NavigationHeader', 'Avatar', 'MultivaluesField', 'Text', 'Link', 'Card', 'IconWrapper', 'ComboBoxField', 'CodeView', 'Sticker Sheet', 'NextGen ListViewItem', 'Skeleton', 'TooltipTrigger', 'ListViewItem', 'Pagination', 'Callout', 'Table', 'TableBase', 'ArrayField', 'ColorField', 'LinkSelectField', 'NumberField', 'SwitchField', 'Base Components', 'SliderField'];
|
8
|
+
var nextGenConvertedComponents = ['GridList', 'DataTable', 'Message', 'Button', 'Badge', 'IconButton', 'CheckboxField', 'Messages', 'PopoverMenu', 'TextField', 'PasswordField', 'SearchField', 'SelectField', 'Modal', 'RadioField', 'MultiValuesField', 'TextAreaField', 'RadioGroupField', 'RockerButtonGroup', 'Tabs', 'ProgressBar', 'NavBar', 'OverlayPanel', 'AstroProvider', 'ListView', 'NavigationHeader', 'Avatar', 'MultivaluesField', 'Text', 'Link', 'Card', 'IconWrapper', 'ComboBoxField', 'CodeView', 'Sticker Sheet', 'NextGen ListViewItem', 'Skeleton', 'TooltipTrigger', 'ListViewItem', 'Pagination', 'Callout', 'Table', 'TableBase', 'ArrayField', 'ColorField', 'LinkSelectField', 'NumberField', 'SwitchField', 'Base Components', 'SliderField'];
|
9
9
|
var componentSpecificNextGenBlacklist = {
|
10
10
|
AstroProvider: ['Default', 'With Custom Theme Override'],
|
11
11
|
Badge: ['Status Badge Variants', 'Badge With Left Slot And Icon', 'Callout Badges', 'Removable'],
|
@@ -32,6 +32,7 @@ var _DataTable = _interopRequireDefault(require("../../components/DataTable/Data
|
|
32
32
|
var _EnvironmentalBreadcrumb = _interopRequireDefault(require("../../components/EnvironmentBreadcrumb/EnvironmentalBreadcrumb.styles"));
|
33
33
|
var _FieldHelperText = _interopRequireDefault(require("../../components/FieldHelperText/FieldHelperText.styles"));
|
34
34
|
var _Footer = _interopRequireDefault(require("../../components/Footer/Footer.styles"));
|
35
|
+
var _GridList = _interopRequireDefault(require("../../components/GridList/GridList.styles"));
|
35
36
|
var _HelpHint = _interopRequireDefault(require("../../components/HelpHint/HelpHint.styles"));
|
36
37
|
var _imageUpload = _interopRequireDefault(require("../../components/ImageUploadField/imageUpload"));
|
37
38
|
var _ListBox = _interopRequireDefault(require("../../components/ListBox/ListBox.styles"));
|
@@ -87,6 +88,7 @@ var _default = _objectSpread(_objectSpread({
|
|
87
88
|
environmentBreadcrumb: _EnvironmentalBreadcrumb["default"],
|
88
89
|
fieldHelperText: _FieldHelperText["default"],
|
89
90
|
footer: _Footer["default"],
|
91
|
+
gridList: _GridList["default"],
|
90
92
|
helpHint: _HelpHint["default"],
|
91
93
|
imageUpload: _imageUpload["default"],
|
92
94
|
listBox: _ListBox["default"],
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import { Key, RefObject } from 'react';
|
2
|
+
import { Collection, ListData, ListState, MultipleSelectionManager } from 'react-stately';
|
3
|
+
import { DraggableCollectionEndEvent, DraggableCollectionMoveEvent, DraggableCollectionStartEvent, DragItem, DragPreviewRenderer, DragTypes, DropOperation, DroppableCollectionDropEvent, DroppableCollectionEnterEvent, DroppableCollectionExitEvent, DroppableCollectionInsertDropEvent, DroppableCollectionOnItemDropEvent, DroppableCollectionReorderEvent, DroppableCollectionRootDropEvent, DropTarget, DropTargetDelegate, ItemDropTarget } from '@react-aria/dnd';
|
4
|
+
import { DraggableCollectionState, DroppableCollectionState } from '@react-stately/dnd';
|
5
|
+
import type { DroppableCollectionActivateEvent, Node } from '@react-types/shared';
|
6
|
+
export interface DraggableCollectionStateOptions {
|
7
|
+
collection?: Collection<Node<object>>;
|
8
|
+
getAllowedDropOperations?: () => DropOperation[];
|
9
|
+
getItems?: (keys: Iterable<Key | string | number>) => DragItem[];
|
10
|
+
isDisabled?: boolean;
|
11
|
+
onDragEnd?: (e: DraggableCollectionEndEvent) => void;
|
12
|
+
onDragMove?: (e: DraggableCollectionMoveEvent) => void;
|
13
|
+
onDragStart?: (e: DraggableCollectionStartEvent) => void;
|
14
|
+
preview?: RefObject<DragPreviewRenderer | null>;
|
15
|
+
selectionManager?: MultipleSelectionManager;
|
16
|
+
}
|
17
|
+
export interface DroppableCollectionOptions {
|
18
|
+
acceptedDragTypes?: 'all' | Array<string | symbol>;
|
19
|
+
dropTargetDelegate?: DropTargetDelegate;
|
20
|
+
getDropOperation?: ((target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]) => DropOperation);
|
21
|
+
onDrop?: (e: DroppableCollectionDropEvent) => void;
|
22
|
+
onDropActivate?: (e: DroppableCollectionActivateEvent) => void;
|
23
|
+
onDropEnter?: (e: DroppableCollectionEnterEvent) => void;
|
24
|
+
onDropEvent?: (e: DroppableCollectionEnterEvent) => void;
|
25
|
+
onDropExit?: (e: DroppableCollectionExitEvent) => void;
|
26
|
+
onInsert?: (e: DroppableCollectionInsertDropEvent) => void;
|
27
|
+
onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void;
|
28
|
+
onKeyDown?: (e: KeyboardEvent) => void;
|
29
|
+
onMove?: (e: DroppableCollectionReorderEvent) => void;
|
30
|
+
onReorder?: (e: DroppableCollectionReorderEvent) => void;
|
31
|
+
onRootDrop?: (e: DroppableCollectionRootDropEvent) => void;
|
32
|
+
shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean;
|
33
|
+
}
|
34
|
+
export interface DroppableCollectionStateOptions {
|
35
|
+
collection?: Collection<Node<object>>;
|
36
|
+
getDropOperation?: ((target: DropTarget, types: DragTypes, allowedOperations: DropOperation[]) => DropOperation);
|
37
|
+
isDisabled?: boolean;
|
38
|
+
onDrop?: (e: DroppableCollectionDropEvent) => void;
|
39
|
+
onDropActivate?: (e: DroppableCollectionActivateEvent) => void;
|
40
|
+
onDropEnter?: (e: DroppableCollectionEnterEvent) => void;
|
41
|
+
onDropEvent?: (e: DroppableCollectionEnterEvent) => void;
|
42
|
+
onDropExit?: (e: DroppableCollectionExitEvent) => void;
|
43
|
+
onInsert?: (e: DroppableCollectionInsertDropEvent) => void;
|
44
|
+
onItemDrop?: (e: DroppableCollectionOnItemDropEvent) => void;
|
45
|
+
onMove?: (e: DroppableCollectionReorderEvent) => void;
|
46
|
+
onReorder?: (e: DroppableCollectionReorderEvent) => void;
|
47
|
+
onRootDrop?: (e: DroppableCollectionRootDropEvent) => void;
|
48
|
+
selectionManager?: MultipleSelectionManager;
|
49
|
+
shouldAcceptItemDrop?: (target: ItemDropTarget, types: DragTypes) => boolean;
|
50
|
+
}
|
51
|
+
export interface GridListRowProps {
|
52
|
+
dragState: DraggableCollectionState;
|
53
|
+
dropState: DroppableCollectionState;
|
54
|
+
isReorderable?: boolean;
|
55
|
+
item: Node<object>;
|
56
|
+
state: ListState<object>;
|
57
|
+
}
|
58
|
+
export interface UseReorderableCollectionProps {
|
59
|
+
draggableCollectionStateOptions: DraggableCollectionStateOptions;
|
60
|
+
droppableCollectionStateOptions: DroppableCollectionStateOptions;
|
61
|
+
isReorderable?: boolean;
|
62
|
+
list: ListData<object>;
|
63
|
+
ref: React.RefObject<HTMLUListElement>;
|
64
|
+
state: ListState<object>;
|
65
|
+
useDroppableCollectionOptions: DroppableCollectionOptions;
|
66
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import { Key, RefObject } from 'react';
|
2
|
+
import { Collection, DisabledBehavior, ListState, SelectionBehavior } from 'react-stately';
|
3
|
+
import { DraggableCollectionState, DroppableCollectionState } from '@react-stately/dnd';
|
4
|
+
import type { FocusStrategy, KeyboardDelegate, Node } from '@react-types/shared';
|
5
|
+
import { DraggableCollectionStateOptions, DroppableCollectionOptions, DroppableCollectionStateOptions } from './dnd';
|
6
|
+
export interface GridListProps extends SharedGridProps {
|
7
|
+
isReorderable?: boolean;
|
8
|
+
}
|
9
|
+
export type GridListRowProps = SharedGridListItemProps;
|
10
|
+
export interface GridRowProps {
|
11
|
+
isReorderable?: boolean;
|
12
|
+
}
|
13
|
+
export interface ReorderableProps extends DraggableCollectionStateOptions, DroppableCollectionOptions, DroppableCollectionStateOptions {
|
14
|
+
}
|
15
|
+
interface SharedGridListItemProps {
|
16
|
+
dragState: DraggableCollectionState;
|
17
|
+
dropState: DroppableCollectionState;
|
18
|
+
isFocusEscaped?: boolean;
|
19
|
+
isReorderable?: boolean;
|
20
|
+
item: Node<object>;
|
21
|
+
state: ListState<object>;
|
22
|
+
}
|
23
|
+
interface SharedGridProps {
|
24
|
+
isReorderable?: boolean;
|
25
|
+
}
|
26
|
+
export interface UseGridListItemProps extends SharedGridListItemProps {
|
27
|
+
cellRef: React.Ref<HTMLDivElement>;
|
28
|
+
ref: RefObject<HTMLElement>;
|
29
|
+
}
|
30
|
+
export interface UseGridListProps extends ReorderableProps {
|
31
|
+
allowDuplicateSelectionEvents?: boolean;
|
32
|
+
autoFocus?: boolean | FocusStrategy;
|
33
|
+
children?: React.ReactNode;
|
34
|
+
collection: Collection<Node<object>>;
|
35
|
+
defaultSelectedKeys?: Iterable<Key> | 'all';
|
36
|
+
disabledBehavior?: DisabledBehavior;
|
37
|
+
disabledKeys?: Iterable<Key>;
|
38
|
+
disallowEmptySelection?: boolean;
|
39
|
+
disallowTypeAhead?: boolean;
|
40
|
+
escapeKeyBehavior?: 'clearSelection' | 'none';
|
41
|
+
filter?: (item: object, filterText: string) => boolean;
|
42
|
+
getKey?: (item: object) => Key;
|
43
|
+
initialFilterText?: string;
|
44
|
+
initialSelectedKeys?: 'all' | Iterable<Key>;
|
45
|
+
isReorderable?: boolean;
|
46
|
+
items: Iterable<object>;
|
47
|
+
keyboardDelegate?: KeyboardDelegate;
|
48
|
+
keyboardNavigationBehavior?: 'arrow' | 'tab';
|
49
|
+
linkBehavior?: 'action' | 'selection' | 'overridde';
|
50
|
+
onAction?: (key: Key) => void;
|
51
|
+
onSelectionChange?: (keys: Selection) => void;
|
52
|
+
ref: React.RefObject<HTMLUListElement>;
|
53
|
+
selectedKeys?: Iterable<Key> | 'all';
|
54
|
+
selectionBehavior?: SelectionBehavior;
|
55
|
+
selectionMode?: 'none' | 'single' | 'multiple';
|
56
|
+
shouldFocusWrap?: boolean;
|
57
|
+
shouldSelectOnPressUp?: boolean;
|
58
|
+
}
|
59
|
+
export {};
|
@@ -0,0 +1,44 @@
|
|
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";
|
9
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
12
|
+
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
13
|
+
import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
|
14
|
+
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; }
|
15
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
16
|
+
import React, { useRef } from 'react';
|
17
|
+
import { mergeProps } from 'react-aria';
|
18
|
+
import useGridList from '../../hooks/useGridList';
|
19
|
+
import { Box } from '../../index';
|
20
|
+
import GridListRow from './GridListRow';
|
21
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
22
|
+
var GridList = function GridList(props) {
|
23
|
+
var _context, _context2;
|
24
|
+
var ref = useRef(null);
|
25
|
+
var _useGridList = useGridList(_objectSpread(_objectSpread({}, props), {}, {
|
26
|
+
ref: ref
|
27
|
+
})),
|
28
|
+
collectionProps = _useGridList.collectionProps,
|
29
|
+
gridListItemProps = _useGridList.gridListItemProps,
|
30
|
+
gridProps = _useGridList.gridProps,
|
31
|
+
state = _useGridList.state;
|
32
|
+
return ___EmotionJSX(Box, _extends({}, mergeProps(gridProps, collectionProps), {
|
33
|
+
ref: ref,
|
34
|
+
className: "list",
|
35
|
+
variant: "gridList.container",
|
36
|
+
gap: "sm"
|
37
|
+
}), _mapInstanceProperty(_context = _concatInstanceProperty(_context2 = []).call(_context2, _Array$from(state.collection))).call(_context, function (item) {
|
38
|
+
return ___EmotionJSX(GridListRow, _extends({
|
39
|
+
key: item.key,
|
40
|
+
item: item
|
41
|
+
}, gridListItemProps));
|
42
|
+
}));
|
43
|
+
};
|
44
|
+
export default GridList;
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import { Meta } from '@storybook/addon-docs';
|
2
|
+
|
3
|
+
<Meta title="Components/GridList" />
|
4
|
+
|
5
|
+
# GridList
|
6
|
+
|
7
|
+
The `GridList` component is used to display a list of items in a grid-like structure. It supports features like reordering, keyboard navigation, and drag-and-drop functionality.
|
8
|
+
|
9
|
+
This component should:
|
10
|
+
- Be used to display items in a structured grid format.
|
11
|
+
- Support reordering and drag-and-drop functionality for enhanced interactivity.
|
12
|
+
|
13
|
+
It shouldn’t be used for simple lists that do not require grid-like behavior or advanced interactions.
|
14
|
+
|
15
|
+
### Required Components
|
16
|
+
|
17
|
+
This component requires [Item].
|
18
|
+
|
19
|
+
---
|
20
|
+
|
21
|
+
## Accessibility
|
22
|
+
|
23
|
+
This component adheres to the [WAI-ARIA Grid](https://www.w3.org/WAI/ARIA/apg/patterns/grid/) accessibility guidelines.
|
24
|
+
|
25
|
+
### Keyboard Navigation
|
26
|
+
|
27
|
+
These keys provide additional functionality to the component:
|
28
|
+
|
29
|
+
| Key Combination | Functionality |
|
30
|
+
| --------------- | ---------------------------------------------------------------------------------------------------------------- |
|
31
|
+
| `Tab` | Moves focus to the next focusable element, within the row. (keyboardNavigationBehavior="tab") |
|
32
|
+
| `Shift + Tab` | Moves focus to the previous focusable element, within the row. (keyboardNavigationBehavior="tab") |
|
33
|
+
| `Arrow Keys` | Navigates between items in the grid. (Up/Down in all modes, Left/Right in keyboardNavigationBehavior="arrow") |
|
34
|
+
| `Home` | Moves focus to the first row in the grid. |
|
35
|
+
| `End` | Moves focus to the last row in the grid. |
|
36
|
+
|
37
|
+
### Screen Readers
|
38
|
+
|
39
|
+
This component uses the following attributes to assist screen readers:
|
40
|
+
- The **`role="grid"`** attribute is used to indicate the grid structure.
|
41
|
+
- The **`aria-label`** attribute provides an accessible name for the grid.
|
42
|
+
- The **`role="row"`** attribute is used to indicate the row structure.
|
43
|
+
- The **`role="gridcell"`** attribute is used to indicate the cell structure.
|
44
|
+
- The **`aria-selected`** attribute indicates whether an item is selected.
|
45
|
+
- The **`draggable`** attribute indicates whether an item is draggable.
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
## Examples
|
50
|
+
|
51
|
+
### Default GridList
|
52
|
+
|
53
|
+
```tsx
|
54
|
+
import { GridList, Item } from '@pingux/astro';
|
55
|
+
|
56
|
+
const items = [
|
57
|
+
{ name: 'Item 1', key: 'item1' },
|
58
|
+
{ name: 'Item 2', key: 'item2' },
|
59
|
+
{ name: 'Item 3', key: 'item3' },
|
60
|
+
];
|
61
|
+
|
62
|
+
<GridList items={items}>
|
63
|
+
{item => (
|
64
|
+
<Item key={item.key} textValue={item.name}>
|
65
|
+
{item.name}
|
66
|
+
</Item>
|
67
|
+
)}
|
68
|
+
</GridList>;
|
@@ -0,0 +1,124 @@
|
|
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";
|
9
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
11
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
12
|
+
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; }
|
13
|
+
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; }
|
14
|
+
import React, { useRef, useState } from 'react';
|
15
|
+
import { Item } from 'react-stately';
|
16
|
+
import MinusIcon from '@pingux/mdi-react/MinusIcon';
|
17
|
+
import PlusIcon from '@pingux/mdi-react/PlusIcon';
|
18
|
+
import DocsLayout from '../../../.storybook/storybookDocsLayout';
|
19
|
+
import { Box, GridList, Icon, IconButton, Menu, OverlayProvider, PopoverMenu, Text, TextField } from '../../index';
|
20
|
+
import GridListReadme from './GridList.mdx';
|
21
|
+
import { gridListArgTypes } from './gridListAttributes';
|
22
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
23
|
+
export default {
|
24
|
+
title: 'Components/GridList',
|
25
|
+
component: GridList,
|
26
|
+
argTypes: _objectSpread({}, gridListArgTypes),
|
27
|
+
parameters: {
|
28
|
+
docs: {
|
29
|
+
source: {
|
30
|
+
type: 'code'
|
31
|
+
},
|
32
|
+
page: function page() {
|
33
|
+
return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(GridListReadme, null), ___EmotionJSX(DocsLayout, null));
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
};
|
38
|
+
var items = [{
|
39
|
+
name: 'rhino',
|
40
|
+
key: 'rhino'
|
41
|
+
}, {
|
42
|
+
name: 'lion',
|
43
|
+
key: 'lion'
|
44
|
+
}, {
|
45
|
+
name: 'zebra',
|
46
|
+
key: 'zebra'
|
47
|
+
}];
|
48
|
+
var ExampleComponent = function ExampleComponent(_ref) {
|
49
|
+
var label = _ref.label;
|
50
|
+
var ref = useRef(null);
|
51
|
+
var _useState = useState(false),
|
52
|
+
_useState2 = _slicedToArray(_useState, 2),
|
53
|
+
isOpen = _useState2[0],
|
54
|
+
setIsOpen = _useState2[1];
|
55
|
+
return ___EmotionJSX(Box, {
|
56
|
+
isRow: true,
|
57
|
+
sx: {
|
58
|
+
alignItems: 'center'
|
59
|
+
},
|
60
|
+
gap: "sm"
|
61
|
+
}, ___EmotionJSX(TextField, {
|
62
|
+
"aria-label": label,
|
63
|
+
ref: ref,
|
64
|
+
defaultValue: label,
|
65
|
+
"data-testid": "".concat(label, "-text-field")
|
66
|
+
}), ___EmotionJSX(Box, {
|
67
|
+
isRow: true,
|
68
|
+
sx: {
|
69
|
+
alignItems: 'center'
|
70
|
+
},
|
71
|
+
gap: "md"
|
72
|
+
}, ___EmotionJSX(IconButton, {
|
73
|
+
"aria-label": "delete row"
|
74
|
+
}, ___EmotionJSX(Icon, {
|
75
|
+
icon: MinusIcon,
|
76
|
+
title: {
|
77
|
+
name: 'delete icon'
|
78
|
+
}
|
79
|
+
})), ___EmotionJSX(IconButton, {
|
80
|
+
"aria-label": "add row"
|
81
|
+
}, ___EmotionJSX(Icon, {
|
82
|
+
icon: PlusIcon,
|
83
|
+
title: {
|
84
|
+
name: 'add icon'
|
85
|
+
}
|
86
|
+
})), ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(PopoverMenu, {
|
87
|
+
isOpen: isOpen,
|
88
|
+
onOpenChange: setIsOpen
|
89
|
+
}, ___EmotionJSX(IconButton, {
|
90
|
+
"aria-label": "more options",
|
91
|
+
variant: "inverted"
|
92
|
+
}, ___EmotionJSX(Icon, {
|
93
|
+
icon: MinusIcon,
|
94
|
+
size: "md",
|
95
|
+
title: {
|
96
|
+
name: 'Dots Vertical Icon'
|
97
|
+
}
|
98
|
+
})), ___EmotionJSX(Menu, null, ___EmotionJSX(Item, {
|
99
|
+
key: "edit"
|
100
|
+
}, "Edit"), ___EmotionJSX(Item, {
|
101
|
+
key: "duplicate"
|
102
|
+
}, "Duplicate"), ___EmotionJSX(Item, {
|
103
|
+
key: "delete",
|
104
|
+
textValue: "delete"
|
105
|
+
}, ___EmotionJSX(Text, {
|
106
|
+
color: "critical.bright"
|
107
|
+
}, "Delete")))))));
|
108
|
+
};
|
109
|
+
export var Default = function Default(args) {
|
110
|
+
return ___EmotionJSX(GridList, _extends({
|
111
|
+
items: items,
|
112
|
+
isReorderable: true,
|
113
|
+
keyboardNavigationBehavior: "tab"
|
114
|
+
}, args), function (item) {
|
115
|
+
return ___EmotionJSX(Item, {
|
116
|
+
textValue: item.name,
|
117
|
+
key: item.name,
|
118
|
+
"data-id": item.name
|
119
|
+
}, ___EmotionJSX(ExampleComponent, {
|
120
|
+
label: item.name,
|
121
|
+
key: item.name
|
122
|
+
}));
|
123
|
+
});
|
124
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
var container = {
|
2
|
+
'&.is-focused': {
|
3
|
+
outline: 'none !important'
|
4
|
+
},
|
5
|
+
':focus': {
|
6
|
+
outline: 'none'
|
7
|
+
}
|
8
|
+
};
|
9
|
+
var rowContainer = {
|
10
|
+
alignItems: 'center',
|
11
|
+
alignContent: 'center',
|
12
|
+
'&.is-dragging': {
|
13
|
+
opacity: 0.4
|
14
|
+
}
|
15
|
+
};
|
16
|
+
export default {
|
17
|
+
container: container,
|
18
|
+
rowContainer: rowContainer
|
19
|
+
};
|
@@ -0,0 +1,149 @@
|
|
1
|
+
import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
|
2
|
+
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
3
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
4
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context3; _forEachInstanceProperty(_context3 = ["next", "throw", "return"]).call(_context3, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context4; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context4 = this.tryEntries).call(_context4, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
6
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
7
|
+
import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
|
8
|
+
import _Object$create from "@babel/runtime-corejs3/core-js-stable/object/create";
|
9
|
+
import _Object$getPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/get-prototype-of";
|
10
|
+
import _Object$setPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/set-prototype-of";
|
11
|
+
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
12
|
+
import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reverse";
|
13
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
14
|
+
import React from 'react';
|
15
|
+
import userEvent from '@testing-library/user-event';
|
16
|
+
import { Item } from '../..';
|
17
|
+
import { fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
|
18
|
+
import GridList from './GridList';
|
19
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
20
|
+
var items = [{
|
21
|
+
name: 'Item 1',
|
22
|
+
key: 'item1'
|
23
|
+
}, {
|
24
|
+
name: 'Item 2',
|
25
|
+
key: 'item2'
|
26
|
+
}, {
|
27
|
+
name: 'Item 3',
|
28
|
+
key: 'item3'
|
29
|
+
}];
|
30
|
+
var getDefaultComponent = function getDefaultComponent(props) {
|
31
|
+
return render(___EmotionJSX(GridList, _extends({
|
32
|
+
items: items
|
33
|
+
}, props), function (item) {
|
34
|
+
return ___EmotionJSX(Item, {
|
35
|
+
key: item.key,
|
36
|
+
textValue: item.name
|
37
|
+
}, item.name);
|
38
|
+
}));
|
39
|
+
};
|
40
|
+
describe('GridList Component', function () {
|
41
|
+
test('renders GridList with items', function () {
|
42
|
+
getDefaultComponent({});
|
43
|
+
var list = screen.getByRole('grid');
|
44
|
+
expect(list).toBeInTheDocument();
|
45
|
+
var listItems = screen.getAllByRole('row');
|
46
|
+
expect(listItems).toHaveLength(items.length);
|
47
|
+
_forEachInstanceProperty(items).call(items, function (item) {
|
48
|
+
expect(screen.getByText(item.name)).toBeInTheDocument();
|
49
|
+
});
|
50
|
+
});
|
51
|
+
test('renders GridListRow for each item', function () {
|
52
|
+
getDefaultComponent();
|
53
|
+
var rows = screen.getAllByRole('row');
|
54
|
+
expect(rows).toHaveLength(items.length);
|
55
|
+
});
|
56
|
+
test('handles keyboard navigation', function () {
|
57
|
+
getDefaultComponent();
|
58
|
+
var rows = screen.getAllByRole('row');
|
59
|
+
userEvent.tab();
|
60
|
+
expect(rows[0]).toHaveClass('is-focused');
|
61
|
+
fireEvent.keyDown(rows[0], {
|
62
|
+
key: 'ArrowDown'
|
63
|
+
});
|
64
|
+
expect(rows[1]).toHaveClass('is-focused');
|
65
|
+
fireEvent.keyDown(rows[1], {
|
66
|
+
key: 'ArrowUp'
|
67
|
+
});
|
68
|
+
expect(rows[0]).toHaveClass('is-focused');
|
69
|
+
});
|
70
|
+
test('handles drag and drop functionality', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
71
|
+
var onReorder, rows, list, buttons, insertionIndicator;
|
72
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
73
|
+
while (1) switch (_context.prev = _context.next) {
|
74
|
+
case 0:
|
75
|
+
onReorder = jest.fn();
|
76
|
+
getDefaultComponent({
|
77
|
+
isReorderable: true,
|
78
|
+
onReorder: onReorder
|
79
|
+
});
|
80
|
+
rows = screen.getAllByRole('row');
|
81
|
+
list = screen.getByRole('grid');
|
82
|
+
buttons = screen.getAllByRole('button');
|
83
|
+
userEvent.tab();
|
84
|
+
fireEvent.keyDown(rows[0], {
|
85
|
+
key: 'ArrowRight'
|
86
|
+
});
|
87
|
+
fireEvent.keyUp(rows[0], {
|
88
|
+
key: 'ArrowRight'
|
89
|
+
});
|
90
|
+
fireEvent.keyDown(buttons[0], {
|
91
|
+
key: 'Enter'
|
92
|
+
});
|
93
|
+
fireEvent.keyUp(buttons[0], {
|
94
|
+
key: 'Enter'
|
95
|
+
});
|
96
|
+
_context.next = 12;
|
97
|
+
return screen.findByTestId('insertion-indicator');
|
98
|
+
case 12:
|
99
|
+
insertionIndicator = _context.sent;
|
100
|
+
userEvent.type(list, '{arrowdown}');
|
101
|
+
userEvent.type(insertionIndicator, '{enter}');
|
102
|
+
expect(onReorder).toHaveBeenCalled();
|
103
|
+
case 16:
|
104
|
+
case "end":
|
105
|
+
return _context.stop();
|
106
|
+
}
|
107
|
+
}, _callee);
|
108
|
+
})));
|
109
|
+
test('able to drop at bottom', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
110
|
+
var onReorder, rows, list, buttons, insertionIndicator;
|
111
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
112
|
+
while (1) switch (_context2.prev = _context2.next) {
|
113
|
+
case 0:
|
114
|
+
onReorder = jest.fn();
|
115
|
+
getDefaultComponent({
|
116
|
+
isReorderable: true,
|
117
|
+
onReorder: onReorder
|
118
|
+
});
|
119
|
+
rows = screen.getAllByRole('row');
|
120
|
+
list = screen.getByRole('grid');
|
121
|
+
buttons = screen.getAllByRole('button');
|
122
|
+
userEvent.tab();
|
123
|
+
fireEvent.keyDown(rows[0], {
|
124
|
+
key: 'ArrowRight'
|
125
|
+
});
|
126
|
+
fireEvent.keyUp(rows[0], {
|
127
|
+
key: 'ArrowRight'
|
128
|
+
});
|
129
|
+
fireEvent.keyDown(buttons[0], {
|
130
|
+
key: 'Enter'
|
131
|
+
});
|
132
|
+
fireEvent.keyUp(buttons[0], {
|
133
|
+
key: 'Enter'
|
134
|
+
});
|
135
|
+
_context2.next = 12;
|
136
|
+
return screen.findByTestId('insertion-indicator');
|
137
|
+
case 12:
|
138
|
+
insertionIndicator = _context2.sent;
|
139
|
+
userEvent.type(list, '{arrowdown}');
|
140
|
+
userEvent.type(list, '{arrowdown}');
|
141
|
+
userEvent.type(insertionIndicator, '{enter}');
|
142
|
+
expect(onReorder).toHaveBeenCalled();
|
143
|
+
case 17:
|
144
|
+
case "end":
|
145
|
+
return _context2.stop();
|
146
|
+
}
|
147
|
+
}, _callee2);
|
148
|
+
})));
|
149
|
+
});
|