UNPKG

@porsche-design-system/components-react

Version:

Porsche Design System is a component library designed to help developers create the best experience for software or services distributed by Dr. Ing. h.c. F. Porsche AG.

45 lines (41 loc) 3.14 kB
'use strict'; var jsxRuntime = require('react/jsx-runtime'); var react = require('react'); require('../../provider.cjs'); var splitChildren = require('../../splitChildren.cjs'); var minifyCss = require('../../minifyCss.cjs'); var stylesEntry = require('../../../../../../components/dist/styles/esm/styles-entry.cjs'); var utilsEntry = require('../../../../../../components/dist/utils/esm/utils-entry.cjs'); var notificationBase = require('./notification-base.cjs'); var button_wrapper = require('../components/button.wrapper.cjs'); /** * @slot {"name": "heading", "description": "Defines the heading of the banner. Can be used as an alternative to the `heading` prop for rich content." } * @slot {"name": "", "description": "Default slot for the banner description content." } * @slot {"name": "description", "description": "Deprecated: Use the default slot instead.", "isDeprecated": true } * * @controlled {"props": ["open"], "event": "dismiss"} */ class DSRBanner extends react.Component { host; refPopover; refDismiss; hasHeadingSlot; hasDescriptionSlot; topLayer = utilsEntry.createTopLayerController({ getElement: () => this.props.refPopover, isShown: () => !!this.props.refPopover?.matches(':popover-open'), show: () => this.props.refPopover?.showPopover(), hide: () => this.props.refPopover?.hidePopover(), }); render() { const { namedSlotChildren} = splitChildren.splitChildren(this.props.children); const hasHeadingSlot = namedSlotChildren.filter(({ props: { slot } }) => slot === 'heading').length > 0; const hasDescriptionSlot = namedSlotChildren.filter(({ props: { slot } }) => slot === 'description').length > 0; const headingText = this.props.heading ? this.props.heading : namedSlotChildren.find(({ props: { slot } }) => slot === 'heading')?.props.children; const style = minifyCss.minifyCss(stylesEntry.getBannerCss(this.props.open, this.props.position, this.props.state, this.props.dismissButton, !!(this.props.heading || hasHeadingSlot))); return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("template", { shadowroot: "open", shadowrootmode: "open", children: [jsxRuntime.jsx("style", { dangerouslySetInnerHTML: { __html: style } }), jsxRuntime.jsx("div", { popover: "manual", "aria-hidden": this.props.open ? 'false' : 'true', ...utilsEntry.getBannerAriaAttributes(this.props.state, headingText), children: jsxRuntime.jsx(notificationBase.NotificationBase, { heading: this.props.heading, headingTag: this.props.headingTag, hasHeadingSlot: hasHeadingSlot, description: this.props.description, hasDescriptionSlot: hasDescriptionSlot, ...(this.props.dismissButton && { dismissButton: (jsxRuntime.jsx(button_wrapper.PButton, { className: "dismiss", type: "button", variant: "secondary", icon: "close", hideLabel: true, compact: true, ...(headingText ? { aria: { 'aria-description': headingText } } : {}), children: "Close banner" })), }) }) })] }), this.props.children] })); } } exports.DSRBanner = DSRBanner;