Debian Codegraph @

node/@patternfly/react-core/dist/esm/components/Toolbar/ToolbarToggleGroup.js

raw
1 import { __rest } from "tslib";
2 import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3 import { Component, createRef } from 'react';
4 import * as ReactDOM from 'react-dom';
5 import styles from '@patternfly/react-styles/css/components/Toolbar/toolbar.mjs';
6 import { css } from '@patternfly/react-styles';
7 import { ToolbarContext, ToolbarContentContext } from './ToolbarUtils';
8 import { Button } from '../Button';
9 import globalBreakpointLg from '@patternfly/react-tokens/dist/esm/t_global_breakpoint_lg';
10 import { formatBreakpointMods, toCamel } from '../../helpers/util';
11 import { PageContext } from '../Page/PageContext';
12 import { ToolbarExpandableContent } from './ToolbarExpandableContent';
13 class ToolbarToggleGroup extends Component {
14 constructor() {
15 super(...arguments);
16 this.toggleRef = createRef();
17 this.expandableContentRef = createRef();
18 this.isContentPopup = () => {
19 const viewportSize = typeof window !== 'undefined' ? window.innerWidth : 1200;
20 const lgBreakpointValue = parseInt(globalBreakpointLg.value);
21 return viewportSize < lgBreakpointValue;
22 };
23 }
24 render() {
25 const _a = this.props, { toggleIcon, variant, visibility, breakpoint, gap, columnGap, rowGap, className, children, isExpanded, onToggle, labelContainerRef, clearAllFilters, showClearFiltersButton, clearFiltersButtonText } = _a, props = __rest(_a, ["toggleIcon", "variant", "visibility", "breakpoint", "gap", "columnGap", "rowGap", "className", "children", "isExpanded", "onToggle", "labelContainerRef", "clearAllFilters", "showClearFiltersButton", "clearFiltersButtonText"]);
26 if (!breakpoint && !toggleIcon) {
27 // eslint-disable-next-line no-console
28 console.error('ToolbarToggleGroup will not be visible without a breakpoint or toggleIcon.');
29 }
30 return (_jsx(PageContext.Consumer, { children: ({ width, getBreakpoint }) => (_jsx(ToolbarContext.Consumer, { children: ({ toggleIsExpanded: managedOnToggle }) => {
31 const _onToggle = onToggle !== undefined ? onToggle : managedOnToggle;
32 return (_jsx(ToolbarContentContext.Consumer, { children: ({ expandableContentRef, expandableContentId, labelContainerRef: managedLabelContainerRef, isExpanded: managedIsExpanded, clearAllFilters: clearAllFiltersContext, clearFiltersButtonText: clearFiltersButtonContext, showClearFiltersButton: showClearFiltersButtonContext }) => {
33 const _isExpanded = isExpanded !== undefined ? isExpanded : managedIsExpanded;
34 const _labelContainerRef = labelContainerRef !== undefined ? labelContainerRef : managedLabelContainerRef;
35 const breakpointMod = {};
36 breakpointMod[breakpoint] = 'show';
37 const expandableContent = (_jsx(ToolbarExpandableContent, { id: expandableContentId, expandableContentRef: this.expandableContentRef, isExpanded: _isExpanded, clearAllFilters: clearAllFilters || clearAllFiltersContext, showClearFiltersButton: showClearFiltersButton || showClearFiltersButtonContext, clearFiltersButtonText: clearFiltersButtonText || clearFiltersButtonContext, labelContainerRef: _labelContainerRef, children: children }));
38 const toggleButton = (_jsx("div", { className: css(styles.toolbarToggle), children: _jsx(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 })) }));
39 return (_jsxs("div", Object.assign({ className: css(styles.toolbarGroup, styles.modifiers.toggleGroup, variant &&
40 styles.modifiers[toCamel(variant)], formatBreakpointMods(breakpointMod, styles, '', getBreakpoint(width)), formatBreakpointMods(visibility, styles, '', getBreakpoint(width)), formatBreakpointMods(gap, styles, '', getBreakpoint(width)), formatBreakpointMods(columnGap, styles, '', getBreakpoint(width)), formatBreakpointMods(rowGap, styles, '', getBreakpoint(width)), className) }, props, { children: [toggleButton, _isExpanded && ReactDOM.createPortal(expandableContent, expandableContentRef.current), !_isExpanded && children] })));
41 } }));
42 } })) }));
43 }
44 }
45 ToolbarToggleGroup.displayName = 'ToolbarToggleGroup';
46 export { ToolbarToggleGroup };
47 //# sourceMappingURL=ToolbarToggleGroup.js.map