| 1 |
"use strict"; |
| 2 |
Object.defineProperty(exports, "__esModule", { value: true }); |
| 3 |
exports.Page = exports.PageLayouts = 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 page_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/Page/page")); |
| 8 |
const react_styles_1 = require("@patternfly/react-styles"); |
| 9 |
const t_global_breakpoint_xl_1 = tslib_1.__importDefault(require('@patternfly/react-tokens/dist/js/t_global_breakpoint_xl')); |
| 10 |
const util_1 = require("../../helpers/util"); |
| 11 |
const Drawer_1 = require("../Drawer"); |
| 12 |
const PageBreadcrumb_1 = require("./PageBreadcrumb"); |
| 13 |
const PageGroup_1 = require("./PageGroup"); |
| 14 |
const resizeObserver_1 = require("../../helpers/resizeObserver"); |
| 15 |
const util_2 = require("../../helpers/util"); |
| 16 |
const PageContext_1 = require("./PageContext"); |
| 17 |
const PageBody_1 = require("./PageBody"); |
| 18 |
var PageLayouts; |
| 19 |
(function (PageLayouts) { |
| 20 |
PageLayouts["vertical"] = "vertical"; |
| 21 |
PageLayouts["horizontal"] = "horizontal"; |
| 22 |
})(PageLayouts || (exports.PageLayouts = PageLayouts = {})); |
| 23 |
class Page extends react_1.Component { |
| 24 |
constructor(props) { |
| 25 |
super(props); |
| 26 |
this.mainRef = (0, react_1.createRef)(); |
| 27 |
this.pageRef = (0, react_1.createRef)(); |
| 28 |
this.observer = () => { }; |
| 29 |
this.getWindowWidth = () => { |
| 30 |
if (util_1.canUseDOM) { |
| 31 |
return this.pageRef.current ? this.pageRef.current.clientWidth : window.innerWidth; |
| 32 |
} |
| 33 |
else { |
| 34 |
return 1200; |
| 35 |
} |
| 36 |
}; |
| 37 |
this.isMobile = () => |
| 38 |
// eslint-disable-next-line radix |
| 39 |
this.getWindowWidth() < Number.parseInt(t_global_breakpoint_xl_1.default.value, 10) * 16; |
| 40 |
this.resize = (_event) => { |
| 41 |
var _a; |
| 42 |
const { onPageResize } = this.props; |
| 43 |
const mobileView = this.isMobile(); |
| 44 |
if (onPageResize) { |
| 45 |
onPageResize(_event, { mobileView, windowSize: this.getWindowWidth() }); |
| 46 |
} |
| 47 |
if (mobileView !== this.state.mobileView) { |
| 48 |
this.setState({ mobileView }); |
| 49 |
} |
| 50 |
if ((_a = this.pageRef) === null || _a === void 0 ? void 0 : _a.current) { |
| 51 |
const currentWidth = this.pageRef.current.clientWidth; |
| 52 |
const currentHeight = this.pageRef.current.clientHeight; |
| 53 |
if (this.state.width !== currentWidth) { |
| 54 |
this.setState({ width: currentWidth }); |
| 55 |
} |
| 56 |
if (this.state.height !== currentHeight) { |
| 57 |
this.setState({ height: currentHeight }); |
| 58 |
} |
| 59 |
} |
| 60 |
}; |
| 61 |
this.handleResize = (0, util_1.debounce)(this.resize, 250); |
| 62 |
this.handleMainClick = () => { |
| 63 |
if (this.isMobile() && this.state.mobileIsSidebarOpen && this.mainRef.current) { |
| 64 |
this.setState({ mobileIsSidebarOpen: false }); |
| 65 |
} |
| 66 |
}; |
| 67 |
this.onSidebarToggleMobile = () => { |
| 68 |
this.setState((prevState) => ({ |
| 69 |
mobileIsSidebarOpen: !prevState.mobileIsSidebarOpen |
| 70 |
})); |
| 71 |
}; |
| 72 |
this.onSidebarToggleDesktop = () => { |
| 73 |
this.setState((prevState) => ({ |
| 74 |
desktopIsSidebarOpen: !prevState.desktopIsSidebarOpen |
| 75 |
})); |
| 76 |
}; |
| 77 |
const { isManagedSidebar, defaultManagedSidebarIsOpen } = props; |
| 78 |
const managedSidebarOpen = !isManagedSidebar ? true : defaultManagedSidebarIsOpen; |
| 79 |
this.state = { |
| 80 |
desktopIsSidebarOpen: managedSidebarOpen, |
| 81 |
mobileIsSidebarOpen: false, |
| 82 |
mobileView: false, |
| 83 |
width: null, |
| 84 |
height: null |
| 85 |
}; |
| 86 |
} |
| 87 |
componentDidMount() { |
| 88 |
const { isManagedSidebar, onPageResize } = this.props; |
| 89 |
if (isManagedSidebar || onPageResize) { |
| 90 |
this.observer = (0, resizeObserver_1.getResizeObserver)(this.pageRef.current, this.handleResize); |
| 91 |
const currentRef = this.mainRef.current; |
| 92 |
if (currentRef) { |
| 93 |
currentRef.addEventListener('mousedown', this.handleMainClick); |
| 94 |
currentRef.addEventListener('touchstart', this.handleMainClick); |
| 95 |
} |
| 96 |
// Initial check if should be shown |
| 97 |
this.resize(); |
| 98 |
} |
| 99 |
} |
| 100 |
componentWillUnmount() { |
| 101 |
const { isManagedSidebar, onPageResize } = this.props; |
| 102 |
if (isManagedSidebar || onPageResize) { |
| 103 |
this.observer(); |
| 104 |
const currentRef = this.mainRef.current; |
| 105 |
if (currentRef) { |
| 106 |
currentRef.removeEventListener('mousedown', this.handleMainClick); |
| 107 |
currentRef.removeEventListener('touchstart', this.handleMainClick); |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
render() { |
| 112 |
const _a = this.props, { banner, breadcrumb, isBreadcrumbWidthLimited, className, children, variant, isDockExpanded = false, isDockTextExpanded = false, masthead, dockContent, sidebar, notificationDrawer, isNotificationDrawerExpanded, onNotificationDrawerExpand, drawerDefaultSize, drawerMinSize, drawerMaxSize, isHorizontalSubnavWidthLimited, skipToContent, role, mainContainerId, isManagedSidebar, |
| 113 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 114 |
defaultManagedSidebarIsOpen, |
| 115 |
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 116 |
onPageResize, getBreakpoint, getVerticalBreakpoint, mainAriaLabel, mainTabIndex, mainComponent, horizontalSubnav, isHorizontalSubnavGrouped, isBreadcrumbGrouped, additionalGroupedContent, groupProps, breadcrumbProps, isContentFilled } = _a, rest = tslib_1.__rest(_a, ["banner", "breadcrumb", "isBreadcrumbWidthLimited", "className", "children", "variant", "isDockExpanded", "isDockTextExpanded", "masthead", "dockContent", "sidebar", "notificationDrawer", "isNotificationDrawerExpanded", "onNotificationDrawerExpand", "drawerDefaultSize", "drawerMinSize", "drawerMaxSize", "isHorizontalSubnavWidthLimited", "skipToContent", "role", "mainContainerId", "isManagedSidebar", "defaultManagedSidebarIsOpen", "onPageResize", "getBreakpoint", "getVerticalBreakpoint", "mainAriaLabel", "mainTabIndex", "mainComponent", "horizontalSubnav", "isHorizontalSubnavGrouped", "isBreadcrumbGrouped", "additionalGroupedContent", "groupProps", "breadcrumbProps", "isContentFilled"]); |
| 117 |
const { mobileView, mobileIsSidebarOpen, desktopIsSidebarOpen, width, height } = this.state; |
| 118 |
const context = { |
| 119 |
isManagedSidebar, |
| 120 |
onSidebarToggle: mobileView ? this.onSidebarToggleMobile : this.onSidebarToggleDesktop, |
| 121 |
isSidebarOpen: mobileView ? mobileIsSidebarOpen : desktopIsSidebarOpen, |
| 122 |
isMobile: mobileView, |
| 123 |
width, |
| 124 |
height, |
| 125 |
getBreakpoint, |
| 126 |
getVerticalBreakpoint |
| 127 |
}; |
| 128 |
let nav = null; |
| 129 |
if (horizontalSubnav) { |
| 130 |
nav = ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(page_1.default.pageMainSubnav, isHorizontalSubnavWidthLimited && page_1.default.modifiers.limitWidth), children: (0, jsx_runtime_1.jsx)(PageBody_1.PageBody, { children: horizontalSubnav }) })); |
| 131 |
} |
| 132 |
const crumb = breadcrumb ? ((0, jsx_runtime_1.jsx)(PageBreadcrumb_1.PageBreadcrumb, { stickyOnBreakpoint: breadcrumbProps === null || breadcrumbProps === void 0 ? void 0 : breadcrumbProps.stickyOnBreakpoint, isWidthLimited: isBreadcrumbWidthLimited, children: (0, jsx_runtime_1.jsx)(PageBody_1.PageBody, { children: breadcrumb }) })) : null; |
| 133 |
const isGrouped = isHorizontalSubnavGrouped || isBreadcrumbGrouped || additionalGroupedContent; |
| 134 |
const group = isGrouped ? ((0, jsx_runtime_1.jsxs)(PageGroup_1.PageGroup, Object.assign({}, groupProps, { children: [isHorizontalSubnavGrouped && nav, banner, isBreadcrumbGrouped && crumb, additionalGroupedContent] }))) : null; |
| 135 |
const Component = mainComponent; |
| 136 |
const main = ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(page_1.default.pageMainContainer, isContentFilled && page_1.default.modifiers.fill), children: (0, jsx_runtime_1.jsxs)(Component, { ref: this.mainRef, role: role, id: mainContainerId, className: (0, react_styles_1.css)(page_1.default.pageMain), tabIndex: mainTabIndex, "aria-label": mainAriaLabel, children: [group, !isHorizontalSubnavGrouped && nav, banner, !isBreadcrumbGrouped && crumb, children] }) })); |
| 137 |
const panelContent = ((0, jsx_runtime_1.jsx)(Drawer_1.DrawerPanelContent, { defaultSize: drawerDefaultSize, minSize: drawerMinSize, maxSize: drawerMaxSize, children: notificationDrawer })); |
| 138 |
return ((0, jsx_runtime_1.jsx)(PageContext_1.PageContextProvider, { value: context, children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ ref: this.pageRef }, rest, { className: (0, react_styles_1.css)(page_1.default.page, variant === 'docked' && page_1.default.modifiers.docked, width !== null && height !== null && 'pf-m-resize-observer', width !== null && `pf-m-breakpoint-${getBreakpoint(width)}`, height !== null && `pf-m-height-breakpoint-${getVerticalBreakpoint(height)}`, sidebar === null && page_1.default.modifiers.noSidebar, className), children: [skipToContent, variant === 'docked' ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [masthead, (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(page_1.default.pageDock, isDockExpanded && page_1.default.modifiers.expanded, isDockTextExpanded && page_1.default.modifiers.textExpanded), children: (0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(page_1.default.pageDockMain), children: dockContent }) })] })) : (masthead), sidebar, notificationDrawer && ((0, jsx_runtime_1.jsx)("div", { className: (0, react_styles_1.css)(page_1.default.pageDrawer), children: (0, jsx_runtime_1.jsx)(Drawer_1.Drawer, { isExpanded: isNotificationDrawerExpanded, onExpand: (event) => onNotificationDrawerExpand(event), children: (0, jsx_runtime_1.jsx)(Drawer_1.DrawerContent, { panelContent: panelContent, children: main }) }) })), !notificationDrawer && main] })) })); |
| 139 |
} |
| 140 |
} |
| 141 |
exports.Page = Page; |
| 142 |
Page.displayName = 'Page'; |
| 143 |
Page.defaultProps = { |
| 144 |
isManagedSidebar: false, |
| 145 |
isBreadcrumbWidthLimited: false, |
| 146 |
defaultManagedSidebarIsOpen: true, |
| 147 |
mainTabIndex: -1, |
| 148 |
isNotificationDrawerExpanded: false, |
| 149 |
onNotificationDrawerExpand: () => null, |
| 150 |
mainComponent: 'main', |
| 151 |
getBreakpoint: util_2.getBreakpoint, |
| 152 |
getVerticalBreakpoint: util_2.getVerticalBreakpoint |
| 153 |
}; |
| 154 |
//# sourceMappingURL=Page.js.map |