| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.ToolbarToggleGroup = 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 ReactDOM = tslib_1.__importStar(require("react-dom")); |
| 8 |
const toolbar_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Toolbar/toolbar")); |
| 9 |
const react_styles_1 = require("@patternfly/react-styles"); |
| 10 |
const ToolbarUtils_1 = require("./ToolbarUtils"); |
| 11 |
const Button_1 = require("../Button"); |
| 12 |
const t_global_breakpoint_lg_1 = tslib_1.__importDefault(require('@patternfly/react-tokens/dist/js/t_global_breakpoint_lg')); |
| 13 |
const util_1 = require("../../helpers/util"); |
| 14 |
const PageContext_1 = require("../Page/PageContext"); |
| 15 |
const ToolbarExpandableContent_1 = require("./ToolbarExpandableContent"); |
| 16 |
class ToolbarToggleGroup extends react_1.Component { |
| 17 |
constructor() { |
| 18 |
super(...arguments); |
| 19 |
this.toggleRef = (0, react_1.createRef)(); |
| 20 |
this.expandableContentRef = (0, react_1.createRef)(); |
| 21 |
this.isContentPopup = () => { |
| 22 |
const viewportSize = typeof window !== 'undefined' ? window.innerWidth : 1200; |
| 23 |
const lgBreakpointValue = parseInt(t_global_breakpoint_lg_1.default.value); |
| 24 |
return viewportSize < lgBreakpointValue; |
| 25 |
}; |
| 26 |
} |
| 27 |
render() { |
| 28 |
const _a = this.props, { toggleIcon, variant, visibility, breakpoint, gap, columnGap, rowGap, className, children, isExpanded, onToggle, labelContainerRef, clearAllFilters, showClearFiltersButton, clearFiltersButtonText } = _a, props = tslib_1.__rest(_a, ["toggleIcon", "variant", "visibility", "breakpoint", "gap", "columnGap", "rowGap", "className", "children", "isExpanded", "onToggle", "labelContainerRef", "clearAllFilters", "showClearFiltersButton", "clearFiltersButtonText"]); |
| 29 |
if (!breakpoint && !toggleIcon) { |
| 30 |
// eslint-disable-next-line no-console |
| 31 |
console.error('ToolbarToggleGroup will not be visible without a breakpoint or toggleIcon.'); |
| 32 |
} |
| 33 |
return ((0, jsx_runtime_1.jsx)(PageContext_1.PageContext.Consumer, { children: ({ width, getBreakpoint }) => ((0, jsx_runtime_1.jsx)(ToolbarUtils_1.ToolbarContext.Consumer, { children: ({ toggleIsExpanded: managedOnToggle }) => { |
| 34 |
const _onToggle = onToggle !== undefined ? onToggle : managedOnToggle; |
| 35 |
return ((0, jsx_runtime_1.jsx)(ToolbarUtils_1.ToolbarContentContext.Consumer, { children: ({ expandableContentRef, expandableContentId, labelContainerRef: managedLabelContainerRef, isExpanded: managedIsExpanded, clearAllFilters: clearAllFiltersContext, clearFiltersButtonText: clearFiltersButtonContext, showClearFiltersButton: showClearFiltersButtonContext }) => { |
| 36 |
const _isExpanded = isExpanded !== undefined ? isExpanded : managedIsExpanded; |
| 37 |
const _labelContainerRef = labelContainerRef !== undefined ? labelContainerRef : managedLabelContainerRef; |
| 38 |
const breakpointMod = {}; |
| 39 |
breakpointMod[breakpoint] = 'show'; |
| 40 |
const expandableContent = ((0, jsx_runtime_1.jsx)(ToolbarExpandableContent_1.ToolbarExpandableContent, { id: expandableContentId, expandableContentRef: this.expandableContentRef, isExpanded: _isExpanded, clearAllFilters: clearAllFilters || clearAllFiltersContext, showClearFiltersButton: showClearFiltersButton || showClearFiltersButtonContext, clearFiltersButtonText: clearFiltersButtonText || clearFiltersButtonContext, labelContainerRef: _labelContainerRef, children: children })); |
| 41 |
const toggleButton = ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(toolbar_1.default.toolbarToggle), children: (0, jsx_runtime_1.jsx)(Button_1.Button, Object.assign({ variant: "plain", onClick: _onToggle, "aria-label": "Show Filters" }, (_isExpanded && { 'aria-expanded': true }), { "aria-haspopup": _isExpanded && this.isContentPopup(), "aria-controls": _isExpanded ? expandableContentId : undefined, ref: this.toggleRef, icon: toggleIcon })) })); |
| 42 |
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: (0, react_styles_1.css)(toolbar_1.default.toolbarGroup, toolbar_1.default.modifiers.toggleGroup, variant && |
| 43 |
toolbar_1.default.modifiers[(0, util_1.toCamel)(variant)], (0, util_1.formatBreakpointMods)(breakpointMod, toolbar_1.default, '', getBreakpoint(width)), (0, util_1.formatBreakpointMods)(visibility, toolbar_1.default, '', getBreakpoint(width)), (0, util_1.formatBreakpointMods)(gap, toolbar_1.default, '', getBreakpoint(width)), (0, util_1.formatBreakpointMods)(columnGap, toolbar_1.default, '', getBreakpoint(width)), (0, util_1.formatBreakpointMods)(rowGap, toolbar_1.default, '', getBreakpoint(width)), className) }, props, { children: [toggleButton, _isExpanded && ReactDOM.createPortal(expandableContent, expandableContentRef.current), !_isExpanded && children] }))); |
| 44 |
} })); |
| 45 |
} })) })); |
| 46 |
} |
| 47 |
} |
| 48 |
exports.ToolbarToggleGroup = ToolbarToggleGroup; |
| 49 |
ToolbarToggleGroup.displayName = 'ToolbarToggleGroup'; |
| 50 |
//# sourceMappingURL=ToolbarToggleGroup.js.map |