UNPKG

@patternfly/react-core

Version:

This library provides a set of common React components for use with the PatternFly reference implementation.

46 lines 3.28 kB
import { __rest } from "tslib"; import { jsx as _jsx } from "react/jsx-runtime"; import { useContext, useEffect } from 'react'; import styles from '@patternfly/react-styles/css/components/Page/page.mjs'; import { css } from '@patternfly/react-styles'; import { formatBreakpointMods } from '../../helpers/util'; import { PageContext } from './PageContext'; import { PageBody } from './PageBody'; export var PageSectionVariants; (function (PageSectionVariants) { PageSectionVariants["default"] = "default"; PageSectionVariants["secondary"] = "secondary"; })(PageSectionVariants || (PageSectionVariants = {})); export var PageSectionTypes; (function (PageSectionTypes) { PageSectionTypes["default"] = "default"; PageSectionTypes["subNav"] = "subnav"; PageSectionTypes["breadcrumb"] = "breadcrumb"; PageSectionTypes["tabs"] = "tabs"; PageSectionTypes["wizard"] = "wizard"; })(PageSectionTypes || (PageSectionTypes = {})); const variantType = { [PageSectionTypes.default]: styles.pageMainSection, [PageSectionTypes.subNav]: styles.pageMainSubnav, [PageSectionTypes.breadcrumb]: styles.pageMainBreadcrumb, [PageSectionTypes.tabs]: styles.pageMainTabs, [PageSectionTypes.wizard]: styles.pageMainWizard }; const variantStyle = { [PageSectionVariants.default]: '', [PageSectionVariants.secondary]: styles.modifiers.secondary }; export const PageSection = (_a) => { var { className = '', children, variant = 'default', type = 'default', padding, isFilled, isWidthLimited = false, isCenterAligned = false, stickyOnBreakpoint, hasShadowTop = false, hasShadowBottom = false, hasOverflowScroll = false, 'aria-label': ariaLabel, component = 'section', hasBodyWrapper = true } = _a, props = __rest(_a, ["className", "children", "variant", "type", "padding", "isFilled", "isWidthLimited", "isCenterAligned", "stickyOnBreakpoint", "hasShadowTop", "hasShadowBottom", "hasOverflowScroll", 'aria-label', "component", "hasBodyWrapper"]); const { height, getVerticalBreakpoint } = useContext(PageContext); useEffect(() => { if (hasOverflowScroll && !ariaLabel) { /* eslint-disable no-console */ console.warn('PageSection: An accessible aria-label is required when hasOverflowScroll is set to true.'); } }, [hasOverflowScroll, ariaLabel]); const Component = component; return (_jsx(Component, Object.assign({}, props, { className: css(variantType[type], formatBreakpointMods(padding, styles), formatBreakpointMods(stickyOnBreakpoint, styles, 'sticky-', getVerticalBreakpoint(height), true), type === PageSectionTypes.default && variantStyle[variant], isFilled === false && styles.modifiers.noFill, isFilled === true && styles.modifiers.fill, isWidthLimited && styles.modifiers.limitWidth, isWidthLimited && isCenterAligned && type !== PageSectionTypes.subNav && styles.modifiers.alignCenter, hasShadowTop && styles.modifiers.shadowTop, hasShadowBottom && styles.modifiers.shadowBottom, hasOverflowScroll && styles.modifiers.overflowScroll, className) }, (hasOverflowScroll && { tabIndex: 0 }), { "aria-label": ariaLabel, children: hasBodyWrapper ? _jsx(PageBody, { children: children }) : children }))); }; PageSection.displayName = 'PageSection'; //# sourceMappingURL=PageSection.js.map