1 | import { __rest } from "tslib";
|
2 | import * as React from 'react';
|
3 | import styles from '@patternfly/react-styles/css/components/Tabs/tabs';
|
4 | import { TabButton } from './TabButton';
|
5 | import { TabsContext } from './TabsContext';
|
6 | import { css } from '@patternfly/react-styles';
|
7 | import { Tooltip } from '../Tooltip';
|
8 | import { Button } from '../Button';
|
9 | import TimesIcon from '@patternfly/react-icons/dist/esm/icons/times-icon';
|
10 | const TabBase = (_a) => {
|
11 | var { title, eventKey, tabContentRef, id: childId, tabContentId, className: childClassName = '', ouiaId: childOuiaId, isDisabled, isAriaDisabled, inoperableEvents = ['onClick', 'onKeyPress'], href, innerRef, tooltip, closeButtonAriaLabel, isCloseDisabled = false } = _a, props = __rest(_a, ["title", "eventKey", "tabContentRef", "id", "tabContentId", "className", "ouiaId", "isDisabled", "isAriaDisabled", "inoperableEvents", "href", "innerRef", "tooltip", "closeButtonAriaLabel", "isCloseDisabled"]);
|
12 | const preventedEvents = inoperableEvents.reduce((handlers, eventToPrevent) => (Object.assign(Object.assign({}, handlers), { [eventToPrevent]: (event) => {
|
13 | event.preventDefault();
|
14 | } })), {});
|
15 | const { mountOnEnter, localActiveKey, unmountOnExit, uniqueId, handleTabClick, handleTabClose } = React.useContext(TabsContext);
|
16 | let ariaControls = tabContentId ? `${tabContentId}` : `pf-tab-section-${eventKey}-${childId || uniqueId}`;
|
17 | if ((mountOnEnter || unmountOnExit) && eventKey !== localActiveKey) {
|
18 | ariaControls = undefined;
|
19 | }
|
20 | const isButtonElement = Boolean(!href);
|
21 | const getDefaultTabIdx = () => {
|
22 | if (isDisabled) {
|
23 | return isButtonElement ? null : -1;
|
24 | }
|
25 | else if (isAriaDisabled) {
|
26 | return null;
|
27 | }
|
28 | };
|
29 | const tabButton = (React.createElement(TabButton, Object.assign({ parentInnerRef: innerRef, className: css(styles.tabsLink, isDisabled && href && styles.modifiers.disabled, isAriaDisabled && styles.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), title));
|
30 | return (React.createElement("li", { className: css(styles.tabsItem, eventKey === localActiveKey && styles.modifiers.current, handleTabClose && styles.modifiers.action, handleTabClose && (isDisabled || isAriaDisabled) && styles.modifiers.disabled, childClassName), role: "presentation" },
|
31 | tooltip ? React.createElement(Tooltip, Object.assign({}, tooltip.props), tabButton) : tabButton,
|
32 | handleTabClose !== undefined && (React.createElement("span", { className: css(styles.tabsItemClose) },
|
33 | React.createElement(Button, { variant: "plain", "aria-label": closeButtonAriaLabel || 'Close tab', onClick: (event) => handleTabClose(event, eventKey, tabContentRef), isDisabled: isCloseDisabled },
|
34 | React.createElement("span", { className: css(styles.tabsItemCloseIcon) },
|
35 | React.createElement(TimesIcon, null)))))));
|
36 | };
|
37 | export const Tab = React.forwardRef((props, ref) => React.createElement(TabBase, Object.assign({ innerRef: ref }, props)));
|
38 | Tab.displayName = 'Tab';
|
39 |
|
\ | No newline at end of file |