@patternfly/react-core 4.211.5 → 4.213.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/esm/components/Tabs/Tab.d.ts +5 -1
  3. package/dist/esm/components/Tabs/Tab.d.ts.map +1 -1
  4. package/dist/esm/components/Tabs/Tab.js +10 -3
  5. package/dist/esm/components/Tabs/Tab.js.map +1 -1
  6. package/dist/esm/components/Tabs/Tabs.d.ts +6 -0
  7. package/dist/esm/components/Tabs/Tabs.d.ts.map +1 -1
  8. package/dist/esm/components/Tabs/Tabs.js +14 -4
  9. package/dist/esm/components/Tabs/Tabs.js.map +1 -1
  10. package/dist/esm/components/Tabs/TabsContext.d.ts +1 -0
  11. package/dist/esm/components/Tabs/TabsContext.d.ts.map +1 -1
  12. package/dist/esm/components/Tabs/TabsContext.js +2 -1
  13. package/dist/esm/components/Tabs/TabsContext.js.map +1 -1
  14. package/dist/js/components/Tabs/Tab.d.ts +5 -1
  15. package/dist/js/components/Tabs/Tab.d.ts.map +1 -1
  16. package/dist/js/components/Tabs/Tab.js +10 -3
  17. package/dist/js/components/Tabs/Tab.js.map +1 -1
  18. package/dist/js/components/Tabs/Tabs.d.ts +6 -0
  19. package/dist/js/components/Tabs/Tabs.d.ts.map +1 -1
  20. package/dist/js/components/Tabs/Tabs.js +14 -4
  21. package/dist/js/components/Tabs/Tabs.js.map +1 -1
  22. package/dist/js/components/Tabs/TabsContext.d.ts +1 -0
  23. package/dist/js/components/Tabs/TabsContext.d.ts.map +1 -1
  24. package/dist/js/components/Tabs/TabsContext.js +2 -1
  25. package/dist/js/components/Tabs/TabsContext.js.map +1 -1
  26. package/dist/umd/react-core.js +36 -21
  27. package/dist/umd/react-core.min.js +1 -1
  28. package/package.json +5 -5
  29. package/src/components/Tabs/Tab.tsx +32 -2
  30. package/src/components/Tabs/Tabs.tsx +28 -2
  31. package/src/components/Tabs/TabsContext.ts +7 -1
  32. package/src/components/Tabs/__tests__/Tabs.test.tsx +22 -0
  33. package/src/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap +13 -13
  34. package/src/components/Tabs/examples/Tabs.md +7 -0
  35. package/src/components/Tabs/examples/TabsDynamic.tsx +64 -0
@@ -6,6 +6,7 @@ export interface TabsContextProps {
6
6
  localActiveKey: string | number;
7
7
  uniqueId: string;
8
8
  handleTabClick: (event: React.MouseEvent<HTMLElement, MouseEvent>, eventKey: number | string, tabContentRef: React.RefObject<any>) => void;
9
+ handleTabClose: (event: React.MouseEvent<HTMLElement, MouseEvent>, eventKey: number | string, tabContentRef?: React.RefObject<any>) => void;
9
10
  }
10
11
  export declare const TabsContext: React.Context<TabsContextProps>;
11
12
  export declare const TabsContextProvider: React.Provider<TabsContextProps>;
@@ -1 +1 @@
1
- {"version":3,"file":"TabsContext.d.ts","sourceRoot":"","sources":["../../../../src/components/Tabs/TabsContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,SAAS,GAAG,UAAU,CAAC;IAChC,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,CACd,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,EAChD,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,KAChC,IAAI,CAAC;CACX;AAED,eAAO,MAAM,WAAW,iCAOtB,CAAC;AAEH,eAAO,MAAM,mBAAmB,kCAAuB,CAAC;AACxD,eAAO,MAAM,mBAAmB,kCAAuB,CAAC"}
1
+ {"version":3,"file":"TabsContext.d.ts","sourceRoot":"","sources":["../../../../src/components/Tabs/TabsContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,SAAS,GAAG,UAAU,CAAC;IAChC,YAAY,EAAE,OAAO,CAAC;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,CACd,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,EAChD,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,KAChC,IAAI,CAAC;IACV,cAAc,EAAE,CACd,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,EAChD,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,KACjC,IAAI,CAAC;CACX;AAED,eAAO,MAAM,WAAW,iCAQtB,CAAC;AAEH,eAAO,MAAM,mBAAmB,kCAAuB,CAAC;AACxD,eAAO,MAAM,mBAAmB,kCAAuB,CAAC"}
@@ -9,7 +9,8 @@ exports.TabsContext = React.createContext({
9
9
  unmountOnExit: false,
10
10
  localActiveKey: '',
11
11
  uniqueId: '',
12
- handleTabClick: () => null
12
+ handleTabClick: () => null,
13
+ handleTabClose: undefined
13
14
  });
14
15
  exports.TabsContextProvider = exports.TabsContext.Provider;
15
16
  exports.TabsContextConsumer = exports.TabsContext.Consumer;
@@ -1 +1 @@
1
- {"version":3,"file":"TabsContext.js","sourceRoot":"","sources":["../../../../src/components/Tabs/TabsContext.ts"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAelB,QAAA,WAAW,GAAG,KAAK,CAAC,aAAa,CAAmB;IAC/D,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,KAAK;IACpB,cAAc,EAAE,EAAE;IAClB,QAAQ,EAAE,EAAE;IACZ,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;CAC3B,CAAC,CAAC;AAEU,QAAA,mBAAmB,GAAG,mBAAW,CAAC,QAAQ,CAAC;AAC3C,QAAA,mBAAmB,GAAG,mBAAW,CAAC,QAAQ,CAAC"}
1
+ {"version":3,"file":"TabsContext.js","sourceRoot":"","sources":["../../../../src/components/Tabs/TabsContext.ts"],"names":[],"mappings":";;;;AAAA,qDAA+B;AAoBlB,QAAA,WAAW,GAAG,KAAK,CAAC,aAAa,CAAmB;IAC/D,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,KAAK;IACpB,cAAc,EAAE,EAAE;IAClB,QAAQ,EAAE,EAAE;IACZ,cAAc,EAAE,GAAG,EAAE,CAAC,IAAI;IAC1B,cAAc,EAAE,SAAS;CAC1B,CAAC,CAAC;AAEU,QAAA,mBAAmB,GAAG,mBAAW,CAAC,QAAQ,CAAC;AAC3C,QAAA,mBAAmB,GAAG,mBAAW,CAAC,QAAQ,CAAC"}
@@ -18271,17 +18271,18 @@
18271
18271
  unmountOnExit: false,
18272
18272
  localActiveKey: '',
18273
18273
  uniqueId: '',
18274
- handleTabClick: () => null
18274
+ handleTabClick: () => null,
18275
+ handleTabClose: undefined
18275
18276
  });
18276
18277
  const TabsContextProvider = TabsContext.Provider;
18277
18278
  const TabsContextConsumer = TabsContext.Consumer;
18278
18279
 
18279
18280
  const TabBase = (_a) => {
18280
- var { title, eventKey, tabContentRef, id: childId, tabContentId, className: childClassName = '', ouiaId: childOuiaId, isDisabled, isAriaDisabled, inoperableEvents = ['onClick', 'onKeyPress'], href, innerRef, tooltip } = _a, props = __rest$1(_a, ["title", "eventKey", "tabContentRef", "id", "tabContentId", "className", "ouiaId", "isDisabled", "isAriaDisabled", "inoperableEvents", "href", "innerRef", "tooltip"]);
18281
+ 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$1(_a, ["title", "eventKey", "tabContentRef", "id", "tabContentId", "className", "ouiaId", "isDisabled", "isAriaDisabled", "inoperableEvents", "href", "innerRef", "tooltip", "closeButtonAriaLabel", "isCloseDisabled"]);
18281
18282
  const preventedEvents = inoperableEvents.reduce((handlers, eventToPrevent) => (Object.assign(Object.assign({}, handlers), { [eventToPrevent]: (event) => {
18282
18283
  event.preventDefault();
18283
18284
  } })), {});
18284
- const { mountOnEnter, localActiveKey, unmountOnExit, uniqueId, handleTabClick } = React__namespace.useContext(TabsContext);
18285
+ const { mountOnEnter, localActiveKey, unmountOnExit, uniqueId, handleTabClick, handleTabClose } = React__namespace.useContext(TabsContext);
18285
18286
  let ariaControls = tabContentId ? `${tabContentId}` : `pf-tab-section-${eventKey}-${childId || uniqueId}`;
18286
18287
  if ((mountOnEnter || unmountOnExit) && eventKey !== localActiveKey) {
18287
18288
  ariaControls = undefined;
@@ -18296,11 +18297,29 @@
18296
18297
  }
18297
18298
  };
18298
18299
  const tabButton = (React__namespace.createElement(TabButton, Object.assign({ parentInnerRef: innerRef, className: css(styles$h.tabsLink, isDisabled && href && styles$h.modifiers.disabled, isAriaDisabled && styles$h.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));
18299
- return (React__namespace.createElement("li", { className: css(styles$h.tabsItem, eventKey === localActiveKey && styles$h.modifiers.current, childClassName), role: "presentation" }, tooltip ? React__namespace.createElement(Tooltip, Object.assign({}, tooltip.props), tabButton) : tabButton));
18300
+ return (React__namespace.createElement("li", { className: css(styles$h.tabsItem, eventKey === localActiveKey && styles$h.modifiers.current, handleTabClose && styles$h.modifiers.action, handleTabClose && (isDisabled || isAriaDisabled) && styles$h.modifiers.disabled, childClassName), role: "presentation" },
18301
+ tooltip ? React__namespace.createElement(Tooltip, Object.assign({}, tooltip.props), tabButton) : tabButton,
18302
+ handleTabClose !== undefined && (React__namespace.createElement("span", { className: css(styles$h.tabsItemClose) },
18303
+ React__namespace.createElement(Button, { variant: "plain", "aria-label": closeButtonAriaLabel || 'Close tab', onClick: (event) => handleTabClose(event, eventKey, tabContentRef), isDisabled: isCloseDisabled },
18304
+ React__namespace.createElement("span", { className: css(styles$h.tabsItemCloseIcon) },
18305
+ React__namespace.createElement(TimesIcon$1, null)))))));
18300
18306
  };
18301
18307
  const Tab = React__namespace.forwardRef((props, ref) => React__namespace.createElement(TabBase, Object.assign({ innerRef: ref }, props)));
18302
18308
  Tab.displayName = 'Tab';
18303
18309
 
18310
+ const PlusIconConfig = {
18311
+ name: 'PlusIcon',
18312
+ height: 512,
18313
+ width: 448,
18314
+ svgPath: 'M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z',
18315
+ yOffset: 0,
18316
+ xOffset: 0,
18317
+ };
18318
+
18319
+ const PlusIcon = createIcon(PlusIconConfig);
18320
+
18321
+ var PlusIcon$1 = PlusIcon;
18322
+
18304
18323
  Promise.resolve().then(function () { return tabContent; });
18305
18324
  var styles$g = {
18306
18325
  "modifiers": {
@@ -18471,16 +18490,21 @@
18471
18490
  clearTimeout(this.scrollTimeout);
18472
18491
  }
18473
18492
  componentDidUpdate(prevProps) {
18474
- const { activeKey, mountOnEnter } = this.props;
18493
+ const { activeKey, mountOnEnter, children } = this.props;
18475
18494
  const { shownKeys } = this.state;
18476
18495
  if (prevProps.activeKey !== activeKey && mountOnEnter && shownKeys.indexOf(activeKey) < 0) {
18477
18496
  this.setState({
18478
18497
  shownKeys: shownKeys.concat(activeKey)
18479
18498
  });
18480
18499
  }
18500
+ if (prevProps.children &&
18501
+ children &&
18502
+ React__namespace.Children.toArray(prevProps.children).length !== React__namespace.Children.toArray(children).length) {
18503
+ this.handleScrollButtons();
18504
+ }
18481
18505
  }
18482
18506
  render() {
18483
- const _a = this.props, { className, children, activeKey, defaultActiveKey, id, isFilled, isSecondary, isVertical, isBox, hasBorderBottom, hasSecondaryBorderBottom, leftScrollAriaLabel, rightScrollAriaLabel, 'aria-label': ariaLabel, component, ouiaId, ouiaSafe, mountOnEnter, unmountOnExit, usePageInsets, inset, variant, expandable, isExpanded, defaultIsExpanded, toggleText, toggleAriaLabel, onToggle } = _a, props = __rest$1(_a, ["className", "children", "activeKey", "defaultActiveKey", "id", "isFilled", "isSecondary", "isVertical", "isBox", "hasBorderBottom", "hasSecondaryBorderBottom", "leftScrollAriaLabel", "rightScrollAriaLabel", 'aria-label', "component", "ouiaId", "ouiaSafe", "mountOnEnter", "unmountOnExit", "usePageInsets", "inset", "variant", "expandable", "isExpanded", "defaultIsExpanded", "toggleText", "toggleAriaLabel", "onToggle"]);
18507
+ const _a = this.props, { className, children, activeKey, defaultActiveKey, id, isFilled, isSecondary, isVertical, isBox, hasBorderBottom, hasSecondaryBorderBottom, leftScrollAriaLabel, rightScrollAriaLabel, 'aria-label': ariaLabel, component, ouiaId, ouiaSafe, mountOnEnter, unmountOnExit, usePageInsets, inset, variant, expandable, isExpanded, defaultIsExpanded, toggleText, toggleAriaLabel, addButtonAriaLabel, onToggle, onClose, onAdd } = _a, props = __rest$1(_a, ["className", "children", "activeKey", "defaultActiveKey", "id", "isFilled", "isSecondary", "isVertical", "isBox", "hasBorderBottom", "hasSecondaryBorderBottom", "leftScrollAriaLabel", "rightScrollAriaLabel", 'aria-label', "component", "ouiaId", "ouiaSafe", "mountOnEnter", "unmountOnExit", "usePageInsets", "inset", "variant", "expandable", "isExpanded", "defaultIsExpanded", "toggleText", "toggleAriaLabel", "addButtonAriaLabel", "onToggle", "onClose", "onAdd"]);
18484
18508
  const { showScrollButtons, disableLeftScrollButton, disableRightScrollButton, shownKeys, uncontrolledActiveKey, uncontrolledIsExpandedLocal } = this.state;
18485
18509
  const filteredChildren = React__namespace.Children.toArray(children)
18486
18510
  .filter(Boolean)
@@ -18504,7 +18528,8 @@
18504
18528
  unmountOnExit,
18505
18529
  localActiveKey,
18506
18530
  uniqueId,
18507
- handleTabClick: (...args) => this.handleTabClick(...args)
18531
+ handleTabClick: (...args) => this.handleTabClick(...args),
18532
+ handleTabClose: onClose
18508
18533
  } },
18509
18534
  React__namespace.createElement(Component, Object.assign({ "aria-label": ariaLabel, className: css(styles$h.tabs, isFilled && styles$h.modifiers.fill, isSecondary && styles$h.modifiers.secondary, isVertical && styles$h.modifiers.vertical, isVertical && expandable && formatBreakpointMods(expandable, styles$h), isVertical && expandable && isExpandedLocal && styles$h.modifiers.expanded, isBox && styles$h.modifiers.box, showScrollButtons && !isVertical && styles$h.modifiers.scrollable, usePageInsets && styles$h.modifiers.pageInsets, !hasBorderBottom && styles$h.modifiers.noBorderBottom, hasSecondaryBorderBottom && styles$h.modifiers.borderBottom, formatBreakpointMods(inset, styles$h), variantStyle[variant], className) }, getOUIAProps(Tabs.displayName, ouiaId !== undefined ? ouiaId : this.state.ouiaStateId, ouiaSafe), { id: id && id }, props),
18510
18535
  expandable && isVertical && (React__namespace.createElement(GenerateId, null, randomId => (React__namespace.createElement("div", { className: css(styles$h.tabsToggle) },
@@ -18517,7 +18542,10 @@
18517
18542
  React__namespace.createElement(AngleLeftIcon$1, null)),
18518
18543
  React__namespace.createElement("ul", { className: css(styles$h.tabsList), ref: this.tabList, onScroll: this.handleScrollButtons, role: "tablist" }, filteredChildren),
18519
18544
  React__namespace.createElement("button", { className: css(styles$h.tabsScrollButton, isSecondary && buttonStyles.modifiers.secondary), "aria-label": rightScrollAriaLabel, onClick: this.scrollRight, disabled: disableRightScrollButton, "aria-hidden": disableRightScrollButton },
18520
- React__namespace.createElement(AngleRightIcon$1, null))),
18545
+ React__namespace.createElement(AngleRightIcon$1, null)),
18546
+ onAdd !== undefined && (React__namespace.createElement("span", { className: css(styles$h.tabsAdd) },
18547
+ React__namespace.createElement(Button, { variant: "plain", "aria-label": addButtonAriaLabel || 'Add tab', onClick: onAdd },
18548
+ React__namespace.createElement(PlusIcon$1, null))))),
18521
18549
  filteredChildren
18522
18550
  .filter(child => child.props.children &&
18523
18551
  !(unmountOnExit && child.props.eventKey !== localActiveKey) &&
@@ -19607,19 +19635,6 @@
19607
19635
  "numberInputUnit": "pf-c-number-input__unit"
19608
19636
  };
19609
19637
 
19610
- const PlusIconConfig = {
19611
- name: 'PlusIcon',
19612
- height: 512,
19613
- width: 448,
19614
- svgPath: 'M416 208H272V64c0-17.67-14.33-32-32-32h-32c-17.67 0-32 14.33-32 32v144H32c-17.67 0-32 14.33-32 32v32c0 17.67 14.33 32 32 32h144v144c0 17.67 14.33 32 32 32h32c17.67 0 32-14.33 32-32V304h144c17.67 0 32-14.33 32-32v-32c0-17.67-14.33-32-32-32z',
19615
- yOffset: 0,
19616
- xOffset: 0,
19617
- };
19618
-
19619
- const PlusIcon = createIcon(PlusIconConfig);
19620
-
19621
- var PlusIcon$1 = PlusIcon;
19622
-
19623
19638
  const defaultKeyDownHandler = (args) => (event) => {
19624
19639
  if (KEY_CODES.ARROW_UP === event.keyCode && args.onPlus) {
19625
19640
  event.preventDefault();