| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.Toolbar = exports.ToolbarColorVariant = 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 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 ToolbarLabelGroupContent_1 = require("./ToolbarLabelGroupContent"); |
| 11 |
const util_1 = require("../../helpers/util"); |
| 12 |
const helpers_1 = require("../../helpers"); |
| 13 |
const SSRSafeIds_1 = require("../../helpers/SSRSafeIds/SSRSafeIds"); |
| 14 |
const PageContext_1 = require("../Page/PageContext"); |
| 15 |
var ToolbarColorVariant; |
| 16 |
(function (ToolbarColorVariant) { |
| 17 |
ToolbarColorVariant["default"] = "default"; |
| 18 |
ToolbarColorVariant["primary"] = "primary"; |
| 19 |
ToolbarColorVariant["secondary"] = "secondary"; |
| 20 |
ToolbarColorVariant["noBackground"] = "no-background"; |
| 21 |
})(ToolbarColorVariant || (exports.ToolbarColorVariant = ToolbarColorVariant = {})); |
| 22 |
class Toolbar extends react_1.Component { |
| 23 |
constructor() { |
| 24 |
super(...arguments); |
| 25 |
this.labelGroupContentRef = (0, react_1.createRef)(); |
| 26 |
this.staticFilterInfo = {}; |
| 27 |
this.hasNoPadding = false; |
| 28 |
this.state = { |
| 29 |
isManagedToggleExpanded: false, |
| 30 |
filterInfo: {}, |
| 31 |
windowWidth: 1200 |
| 32 |
}; |
| 33 |
this.isToggleManaged = () => !(this.props.isExpanded || !!this.props.toggleIsExpanded); |
| 34 |
this.toggleIsExpanded = () => { |
| 35 |
this.setState((prevState) => ({ |
| 36 |
isManagedToggleExpanded: !prevState.isManagedToggleExpanded |
| 37 |
})); |
| 38 |
}; |
| 39 |
this.closeExpandableContent = (e) => { |
| 40 |
if (e.target.innerWidth !== this.state.windowWidth) { |
| 41 |
this.setState(() => ({ |
| 42 |
isManagedToggleExpanded: false, |
| 43 |
windowWidth: e.target.innerWidth |
| 44 |
})); |
| 45 |
} |
| 46 |
}; |
| 47 |
this.updateNumberFilters = (categoryName, numberOfFilters) => { |
| 48 |
const filterInfoToUpdate = Object.assign({}, this.staticFilterInfo); |
| 49 |
if (!filterInfoToUpdate.hasOwnProperty(categoryName) || filterInfoToUpdate[categoryName] !== numberOfFilters) { |
| 50 |
filterInfoToUpdate[categoryName] = numberOfFilters; |
| 51 |
this.staticFilterInfo = filterInfoToUpdate; |
| 52 |
this.setState({ filterInfo: filterInfoToUpdate }); |
| 53 |
} |
| 54 |
}; |
| 55 |
this.getNumberOfFilters = () => Object.values(this.state.filterInfo).reduce((acc, cur) => acc + cur, 0); |
| 56 |
this.renderToolbar = (randomId, generatedOuiaId) => { |
| 57 |
const _a = this.props, { hasNoPadding, clearAllFilters, clearFiltersButtonText, collapseListedFiltersBreakpoint, isExpanded: isExpandedProp, toggleIsExpanded, className, children, isFullHeight, isStatic, isStickyBase, isStickyStuck, inset, isSticky, isVertical, ouiaId, numberOfFiltersText, customLabelGroupContent, colorVariant = ToolbarColorVariant.default } = _a, props = tslib_1.__rest(_a, ["hasNoPadding", "clearAllFilters", "clearFiltersButtonText", "collapseListedFiltersBreakpoint", "isExpanded", "toggleIsExpanded", "className", "children", "isFullHeight", "isStatic", "isStickyBase", "isStickyStuck", "inset", "isSticky", "isVertical", "ouiaId", "numberOfFiltersText", "customLabelGroupContent", "colorVariant"]); |
| 58 |
const { isManagedToggleExpanded } = this.state; |
| 59 |
const isToggleManaged = this.isToggleManaged(); |
| 60 |
const isExpanded = isToggleManaged ? isManagedToggleExpanded : isExpandedProp; |
| 61 |
const numberOfFilters = this.getNumberOfFilters(); |
| 62 |
const showClearFiltersButton = numberOfFilters > 0; |
| 63 |
return ((0, jsx_runtime_1.jsx)(PageContext_1.PageContext.Consumer, { children: ({ width, getBreakpoint }) => ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: (0, react_styles_1.css)(toolbar_1.default.toolbar, hasNoPadding && toolbar_1.default.modifiers.noPadding, isFullHeight && toolbar_1.default.modifiers.fullHeight, isStatic && toolbar_1.default.modifiers.static, isSticky && toolbar_1.default.modifiers.sticky, isStickyBase && toolbar_1.default.modifiers.stickyBase, isStickyStuck && toolbar_1.default.modifiers.stickyStuck, isVertical && toolbar_1.default.modifiers.vertical, (0, util_1.formatBreakpointMods)(inset, toolbar_1.default, '', getBreakpoint(width)), colorVariant === 'primary' && toolbar_1.default.modifiers.primary, colorVariant === 'secondary' && toolbar_1.default.modifiers.secondary, colorVariant === 'no-background' && toolbar_1.default.modifiers.noBackground, className), id: randomId }, (0, helpers_1.getOUIAProps)(Toolbar.displayName, ouiaId !== undefined ? ouiaId : generatedOuiaId), props, { children: (0, jsx_runtime_1.jsxs)(ToolbarUtils_1.ToolbarContext.Provider, { value: { |
| 64 |
isExpanded, |
| 65 |
toggleIsExpanded: isToggleManaged ? this.toggleIsExpanded : toggleIsExpanded, |
| 66 |
labelGroupContentRef: this.labelGroupContentRef, |
| 67 |
updateNumberFilters: this.updateNumberFilters, |
| 68 |
numberOfFilters, |
| 69 |
clearAllFilters, |
| 70 |
clearFiltersButtonText, |
| 71 |
showClearFiltersButton, |
| 72 |
toolbarId: randomId, |
| 73 |
customLabelGroupContent |
| 74 |
}, children: [children, (0, jsx_runtime_1.jsx)(ToolbarLabelGroupContent_1.ToolbarLabelGroupContent, { isExpanded: isExpanded, labelGroupContentRef: this.labelGroupContentRef, clearAllFilters: clearAllFilters, showClearFiltersButton: showClearFiltersButton, clearFiltersButtonText: clearFiltersButtonText, numberOfFilters: numberOfFilters, numberOfFiltersText: numberOfFiltersText, collapseListedFiltersBreakpoint: collapseListedFiltersBreakpoint, customLabelGroupContent: customLabelGroupContent })] }) }))) })); |
| 75 |
}; |
| 76 |
} |
| 77 |
componentDidMount() { |
| 78 |
if (util_1.canUseDOM) { |
| 79 |
this.setState({ windowWidth: window.innerWidth }); |
| 80 |
} |
| 81 |
if (this.isToggleManaged() && util_1.canUseDOM) { |
| 82 |
window.addEventListener('resize', this.closeExpandableContent); |
| 83 |
} |
| 84 |
} |
| 85 |
componentWillUnmount() { |
| 86 |
if (this.isToggleManaged() && util_1.canUseDOM) { |
| 87 |
window.removeEventListener('resize', this.closeExpandableContent); |
| 88 |
} |
| 89 |
} |
| 90 |
render() { |
| 91 |
return ((0, jsx_runtime_1.jsx)(SSRSafeIds_1.SSRSafeIds, { prefix: "pf-random-id-", ouiaComponentType: "Toolbar", children: (generatedId, generatedOuiaId) => this.renderToolbar(this.props.id || generatedId, generatedOuiaId) })); |
| 92 |
} |
| 93 |
} |
| 94 |
exports.Toolbar = Toolbar; |
| 95 |
Toolbar.displayName = 'Toolbar'; |
| 96 |
//# sourceMappingURL=Toolbar.js.map |