1 | import { __rest } from "tslib";
|
2 | import * as React from 'react';
|
3 | import * as ReactDOM from 'react-dom';
|
4 | import styles from '@patternfly/react-styles/css/components/Toolbar/toolbar';
|
5 | import { css } from '@patternfly/react-styles';
|
6 | import { ToolbarContext, ToolbarContentContext } from './ToolbarUtils';
|
7 | import { Button } from '../Button';
|
8 | import globalBreakpointLg from '@patternfly/react-tokens/dist/esm/global_breakpoint_lg';
|
9 | import { formatBreakpointMods, toCamel, canUseDOM } from '../../helpers/util';
|
10 | import { PageContext } from '../Page/Page';
|
11 | export class ToolbarToggleGroup extends React.Component {
|
12 | constructor() {
|
13 | super(...arguments);
|
14 | this.isContentPopup = () => {
|
15 | const viewportSize = canUseDOM ? window.innerWidth : 1200;
|
16 | const lgBreakpointValue = parseInt(globalBreakpointLg.value);
|
17 | return viewportSize < lgBreakpointValue;
|
18 | };
|
19 | }
|
20 | render() {
|
21 | const _a = this.props, { toggleIcon, variant, visibility, visiblity, breakpoint, alignment, spacer, spaceItems, className, children } = _a, props = __rest(_a, ["toggleIcon", "variant", "visibility", "visiblity", "breakpoint", "alignment", "spacer", "spaceItems", "className", "children"]);
|
22 | if (!breakpoint && !toggleIcon) {
|
23 |
|
24 | console.error('ToolbarToggleGroup will not be visible without a breakpoint or toggleIcon.');
|
25 | }
|
26 | if (visiblity !== undefined) {
|
27 |
|
28 | console.warn('The ToolbarToggleGroup visiblity prop has been deprecated. ' +
|
29 | 'Please use the correctly spelled visibility prop instead.');
|
30 | }
|
31 | return (React.createElement(PageContext.Consumer, null, ({ width, getBreakpoint }) => (React.createElement(ToolbarContext.Consumer, null, ({ isExpanded, toggleIsExpanded }) => (React.createElement(ToolbarContentContext.Consumer, null, ({ expandableContentRef, expandableContentId }) => {
|
32 | if (expandableContentRef.current && expandableContentRef.current.classList) {
|
33 | if (isExpanded) {
|
34 | expandableContentRef.current.classList.add(styles.modifiers.expanded);
|
35 | }
|
36 | else {
|
37 | expandableContentRef.current.classList.remove(styles.modifiers.expanded);
|
38 | }
|
39 | }
|
40 | const breakpointMod = {};
|
41 | breakpointMod[breakpoint] = 'show';
|
42 | return (React.createElement("div", Object.assign({ className: css(styles.toolbarGroup, styles.modifiers.toggleGroup, variant &&
|
43 | styles.modifiers[toCamel(variant)], formatBreakpointMods(breakpointMod, styles, '', getBreakpoint(width)), formatBreakpointMods(visibility || visiblity, styles, '', getBreakpoint(width)), formatBreakpointMods(alignment, styles, '', getBreakpoint(width)), formatBreakpointMods(spacer, styles, '', getBreakpoint(width)), formatBreakpointMods(spaceItems, styles, '', getBreakpoint(width)), className) }, props),
|
44 | React.createElement("div", { className: css(styles.toolbarToggle) },
|
45 | React.createElement(Button, Object.assign({ variant: "plain", onClick: toggleIsExpanded, "aria-label": "Show Filters" }, (isExpanded && { 'aria-expanded': true }), { "aria-haspopup": isExpanded && this.isContentPopup(), "aria-controls": expandableContentId }), toggleIcon)),
|
46 | isExpanded
|
47 | ? ReactDOM.createPortal(children, expandableContentRef.current.firstElementChild)
|
48 | : children));
|
49 | }))))));
|
50 | }
|
51 | }
|
52 | ToolbarToggleGroup.displayName = 'ToolbarToggleGroup';
|
53 |
|
\ | No newline at end of file |