| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.Tab = 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 tabs_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Tabs/tabs")); |
| 8 |
const TabButton_1 = require("./TabButton"); |
| 9 |
const TabsContext_1 = require("./TabsContext"); |
| 10 |
const react_styles_1 = require("@patternfly/react-styles"); |
| 11 |
const Tooltip_1 = require("../Tooltip"); |
| 12 |
const rh_microns_close_icon_1 = tslib_1.__importDefault(require('@patternfly/react-icons/dist/js/icons/rh-microns-close-icon')); |
| 13 |
const TabAction_1 = require("./TabAction"); |
| 14 |
const TabBase = (_a) => { |
| 15 |
var { title, eventKey, tabContentRef, id: childId, tabContentId, className: childClassName = '', ouiaId: childOuiaId, isDisabled, isAriaDisabled, inoperableEvents = ['onClick', 'onKeyPress'], href, innerRef, tooltip, closeButtonAriaLabel, isCloseDisabled = false, actions } = _a, props = tslib_1.__rest(_a, ["title", "eventKey", "tabContentRef", "id", "tabContentId", "className", "ouiaId", "isDisabled", "isAriaDisabled", "inoperableEvents", "href", "innerRef", "tooltip", "closeButtonAriaLabel", "isCloseDisabled", "actions"]); |
| 16 |
const preventedEvents = inoperableEvents.reduce((handlers, eventToPrevent) => (Object.assign(Object.assign({}, handlers), { [eventToPrevent]: (event) => { |
| 17 |
event.preventDefault(); |
| 18 |
} })), {}); |
| 19 |
const { mountOnEnter, localActiveKey, unmountOnExit, uniqueId, setAccentStyles, handleTabClick, handleTabClose } = (0, react_1.useContext)(TabsContext_1.TabsContext); |
| 20 |
let ariaControls = tabContentId ? `${tabContentId}` : `pf-tab-section-${eventKey}-${childId || uniqueId}`; |
| 21 |
if ((mountOnEnter || unmountOnExit) && eventKey !== localActiveKey) { |
| 22 |
ariaControls = undefined; |
| 23 |
} |
| 24 |
const isButtonElement = Boolean(!href); |
| 25 |
const getDefaultTabIdx = () => { |
| 26 |
if (isDisabled) { |
| 27 |
return isButtonElement ? null : -1; |
| 28 |
} |
| 29 |
else if (isAriaDisabled) { |
| 30 |
return null; |
| 31 |
} |
| 32 |
}; |
| 33 |
const tabButton = ((0, jsx_runtime_1.jsx)(TabButton_1.TabButton, Object.assign({ parentInnerRef: innerRef, className: (0, react_styles_1.css)(tabs_1.default.tabsLink, isDisabled && href && tabs_1.default.modifiers.disabled, isAriaDisabled && tabs_1.default.modifiers.ariaDisabled), disabled: isButtonElement ? isDisabled : null, "aria-disabled": isDisabled || isAriaDisabled, tabIndex: getDefaultTabIdx(), onClick: (event) => handleTabClick(event, eventKey, tabContentRef) }, (isAriaDisabled ? preventedEvents : null), { id: `pf-tab-${eventKey}-${childId || uniqueId}`, "aria-controls": ariaControls, tabContentRef: tabContentRef, ouiaId: childOuiaId, href: href, role: "tab", "aria-selected": eventKey === localActiveKey }, props, { children: title }))); |
| 34 |
(0, react_1.useEffect)(() => { |
| 35 |
setAccentStyles(true); |
| 36 |
}, [title, actions]); |
| 37 |
return ((0, jsx_runtime_1.jsxs)("li", { className: (0, react_styles_1.css)(tabs_1.default.tabsItem, eventKey === localActiveKey && tabs_1.default.modifiers.current, (handleTabClose || actions) && tabs_1.default.modifiers.action, (isDisabled || isAriaDisabled) && tabs_1.default.modifiers.disabled, childClassName), role: "presentation", children: [tooltip ? (0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, Object.assign({}, tooltip.props, { children: tabButton })) : tabButton, actions && actions, handleTabClose !== undefined && ((0, jsx_runtime_1.jsx)(TabAction_1.TabAction, { "aria-label": closeButtonAriaLabel || 'Close tab', onClick: (event) => handleTabClose(event, eventKey, tabContentRef), isDisabled: isCloseDisabled, children: (0, jsx_runtime_1.jsx)(rh_microns_close_icon_1.default, {}) }))] })); |
| 38 |
}; |
| 39 |
exports.Tab = (0, react_1.forwardRef)((props, ref) => (0, jsx_runtime_1.jsx)(TabBase, Object.assign({ innerRef: ref }, props))); |
| 40 |
exports.Tab.displayName = 'Tab'; |
| 41 |
//# sourceMappingURL=Tab.js.map |