| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.ActionsColumn = void 0; |
| 4 |
const tslib_1 = require("tslib"); |
| 5 |
const jsx_runtime_1 = require("react/jsx-runtime"); |
| 6 |
const react_1 = require("react"); |
| 7 |
const react_2 = require("react"); |
| 8 |
const Dropdown_1 = require('@patternfly/react-core/dist/js/components/Dropdown'); |
| 9 |
const Button_1 = require('@patternfly/react-core/dist/js/components/Button'); |
| 10 |
const Divider_1 = require('@patternfly/react-core/dist/js/components/Divider'); |
| 11 |
const MenuToggle_1 = require('@patternfly/react-core/dist/js/components/MenuToggle'); |
| 12 |
const rh_ui_ellipsis_vertical_fill_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-ui-ellipsis-vertical-fill-icon')); |
| 13 |
const Tooltip_1 = require('@patternfly/react-core/dist/js/components/Tooltip'); |
| 14 |
const ActionsColumnBase = (_a) => { |
| 15 |
var { items, isDisabled, rowData, extraData, actionsToggle, popperProps = { |
| 16 |
position: 'end', |
| 17 |
direction: 'down' |
| 18 |
}, innerRef, firstActionItemRef, isOnOpenChangeDisabled = false } = _a, props = tslib_1.__rest(_a, ["items", "isDisabled", "rowData", "extraData", "actionsToggle", "popperProps", "innerRef", "firstActionItemRef", "isOnOpenChangeDisabled"]); |
| 19 |
const [isOpen, setIsOpen] = (0, react_2.useState)(false); |
| 20 |
const onToggle = () => { |
| 21 |
setIsOpen(!isOpen); |
| 22 |
}; |
| 23 |
const onActionClick = (event, onClick) => { |
| 24 |
// Only prevent default if onClick is provided. This allows href support. |
| 25 |
if (onClick) { |
| 26 |
event.preventDefault(); |
| 27 |
// tslint:disable-next-line:no-unused-expression |
| 28 |
onClick(event, extraData && extraData.rowIndex, rowData, extraData); |
| 29 |
} |
| 30 |
}; |
| 31 |
return ((0, jsx_runtime_1.jsxs)(react_2.Fragment, { children: [items |
| 32 |
.filter((item) => item.isOutsideDropdown) |
| 33 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 34 |
.map((_a, key) => { |
| 35 |
var { title, itemKey, onClick, isOutsideDropdown } = _a, props = tslib_1.__rest(_a, ["title", "itemKey", "onClick", "isOutsideDropdown"]); |
| 36 |
return typeof title === 'string' ? ((0, react_1.createElement)(Button_1.Button, Object.assign({ onClick: (event) => onActionClick(event, onClick) }, props, { isDisabled: isDisabled, key: itemKey || `outside_dropdown_${key}`, "data-key": itemKey || `outside_dropdown_${key}` }), title)) : ((0, react_2.cloneElement)(title, Object.assign({ onClick, isDisabled }, props))); |
| 37 |
}), (0, jsx_runtime_1.jsx)(Dropdown_1.Dropdown, Object.assign({ isOpen: isOpen, onOpenChange: !isOnOpenChangeDisabled ? (isOpen) => setIsOpen(isOpen) : undefined, toggle: (toggleRef) => actionsToggle ? (actionsToggle({ onToggle, isOpen, isDisabled, toggleRef })) : ((0, jsx_runtime_1.jsx)(MenuToggle_1.MenuToggle, { "aria-label": "Kebab toggle", ref: toggleRef, onClick: onToggle, isExpanded: isOpen, isDisabled: isDisabled, variant: "plain", icon: (0, jsx_runtime_1.jsx)(rh_ui_ellipsis_vertical_fill_icon_1.default, {}) })) }, (rowData && rowData.actionProps), { ref: innerRef }, props, { popperProps: popperProps, children: (0, jsx_runtime_1.jsx)(Dropdown_1.DropdownList, { children: items |
| 38 |
.filter((item) => !item.isOutsideDropdown) |
| 39 |
.map((_a, index) => { |
| 40 |
var { title, itemKey, onClick, tooltipProps, isSeparator, shouldCloseOnClick = true } = _a, props = tslib_1.__rest(_a, ["title", "itemKey", "onClick", "tooltipProps", "isSeparator", "shouldCloseOnClick"]); |
| 41 |
if (isSeparator) { |
| 42 |
return (0, jsx_runtime_1.jsx)(Divider_1.Divider, { "data-key": itemKey || index }, itemKey || index); |
| 43 |
} |
| 44 |
const item = ((0, react_1.createElement)(Dropdown_1.DropdownItem, Object.assign({ onClick: (event) => { |
| 45 |
onActionClick(event, onClick); |
| 46 |
shouldCloseOnClick && onToggle(); |
| 47 |
} }, props, { key: itemKey || index, "data-key": itemKey || index, ref: index === 0 ? firstActionItemRef : undefined }), title)); |
| 48 |
if (tooltipProps === null || tooltipProps === void 0 ? void 0 : tooltipProps.content) { |
| 49 |
return ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, Object.assign({}, tooltipProps, { children: item }), itemKey || index)); |
| 50 |
} |
| 51 |
else { |
| 52 |
return item; |
| 53 |
} |
| 54 |
}) }) }))] })); |
| 55 |
}; |
| 56 |
exports.ActionsColumn = (0, react_2.forwardRef)((props, ref) => ((0, jsx_runtime_1.jsx)(ActionsColumnBase, Object.assign({}, props, { innerRef: ref })))); |
| 57 |
exports.ActionsColumn.displayName = 'ActionsColumn'; |
| 58 |
//# sourceMappingURL=ActionsColumn.js.map |