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