1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.DataListItem = void 0;
|
4 | const tslib_1 = require("tslib");
|
5 | const React = tslib_1.__importStar(require("react"));
|
6 | const react_styles_1 = require("@patternfly/react-styles");
|
7 | const data_list_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/DataList/data-list"));
|
8 | const DataList_1 = require("./DataList");
|
9 | const constants_1 = require("../../helpers/constants");
|
10 | const DataListDragButton_1 = require("./DataListDragButton");
|
11 | function findDataListDragButton(node) {
|
12 | if (!React.isValidElement(node)) {
|
13 | return null;
|
14 | }
|
15 | if (node.type === DataListDragButton_1.DataListDragButton) {
|
16 | return node;
|
17 | }
|
18 | if (node.props.children) {
|
19 | for (const child of React.Children.toArray(node.props.children)) {
|
20 | const button = findDataListDragButton(child);
|
21 | if (button) {
|
22 | return button;
|
23 | }
|
24 | }
|
25 | }
|
26 | return null;
|
27 | }
|
28 | class DataListItem extends React.Component {
|
29 | render() {
|
30 | const _a = this.props, { children, isExpanded, className, id, 'aria-labelledby': ariaLabelledBy } = _a, props = tslib_1.__rest(_a, ["children", "isExpanded", "className", "id", 'aria-labelledby']);
|
31 | return (React.createElement(DataList_1.DataListContext.Consumer, null, ({ isSelectable, selectedDataListItemId, updateSelectedDataListItem, isDraggable, dragStart, dragEnd, drop }) => {
|
32 | const selectDataListItem = (event) => {
|
33 | let target = event.target;
|
34 | while (event.currentTarget !== target) {
|
35 | if (('onclick' in target && target.onclick) ||
|
36 | target.parentNode.classList.contains(data_list_1.default.dataListItemAction) ||
|
37 | target.parentNode.classList.contains(data_list_1.default.dataListItemControl)) {
|
38 |
|
39 | return;
|
40 | }
|
41 | else {
|
42 | target = target.parentNode;
|
43 | }
|
44 | }
|
45 | updateSelectedDataListItem(id);
|
46 | };
|
47 | const onKeyDown = (event) => {
|
48 | if (event.key === constants_1.KeyTypes.Enter) {
|
49 | updateSelectedDataListItem(id);
|
50 | }
|
51 | };
|
52 |
|
53 |
|
54 |
|
55 | const dragButton = findDataListDragButton(children);
|
56 | const dragProps = isDraggable && {
|
57 | draggable: dragButton ? !dragButton.props.isDisabled : true,
|
58 | onDrop: drop,
|
59 | onDragEnd: dragEnd,
|
60 | onDragStart: dragStart
|
61 | };
|
62 | return (React.createElement("li", Object.assign({ id: id, className: react_styles_1.css(data_list_1.default.dataListItem, isExpanded && data_list_1.default.modifiers.expanded, isSelectable && data_list_1.default.modifiers.selectable, selectedDataListItemId && selectedDataListItemId === id && data_list_1.default.modifiers.selected, className), "aria-labelledby": ariaLabelledBy }, (isSelectable && { tabIndex: 0, onClick: selectDataListItem, onKeyDown }), (isSelectable && selectedDataListItemId === id && { 'aria-selected': true }), props, dragProps), React.Children.map(children, child => React.isValidElement(child) &&
|
63 | React.cloneElement(child, {
|
64 | rowid: ariaLabelledBy
|
65 | }))));
|
66 | }));
|
67 | }
|
68 | }
|
69 | exports.DataListItem = DataListItem;
|
70 | DataListItem.displayName = 'DataListItem';
|
71 | DataListItem.defaultProps = {
|
72 | isExpanded: false,
|
73 | className: '',
|
74 | id: '',
|
75 | children: null,
|
76 | 'aria-labelledby': ''
|
77 | };
|
78 |
|
\ | No newline at end of file |