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.

43 lines (40 loc) 3.02 kB
import { jsxs, Fragment, jsx } from 'react/jsx-runtime'; import { Component } from 'react'; import '../../provider.mjs'; import { splitChildren } from '../../splitChildren.mjs'; import { minifyCss } from '../../minifyCss.mjs'; import { getBannerCss as getComponentCss$18 } from '../../../../../../components/dist/styles/esm/styles-entry.mjs'; import { createTopLayerController, getBannerAriaAttributes } from '../../../../../../components/dist/utils/esm/utils-entry.mjs'; import { NotificationBase } from './notification-base.mjs'; import { PButton } from '../components/button.wrapper.mjs'; /** * @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 Component { host; refPopover; refDismiss; hasHeadingSlot; hasDescriptionSlot; topLayer = 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(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(getComponentCss$18(this.props.open, this.props.position, this.props.state, this.props.dismissButton, !!(this.props.heading || hasHeadingSlot))); return (jsxs(Fragment, { children: [jsxs("template", { shadowroot: "open", shadowrootmode: "open", children: [jsx("style", { dangerouslySetInnerHTML: { __html: style } }), jsx("div", { popover: "manual", "aria-hidden": this.props.open ? 'false' : 'true', ...getBannerAriaAttributes(this.props.state, headingText), children: jsx(NotificationBase, { heading: this.props.heading, headingTag: this.props.headingTag, hasHeadingSlot: hasHeadingSlot, description: this.props.description, hasDescriptionSlot: hasDescriptionSlot, ...(this.props.dismissButton && { dismissButton: (jsx(PButton, { className: "dismiss", type: "button", variant: "secondary", icon: "close", hideLabel: true, compact: true, ...(headingText ? { aria: { 'aria-description': headingText } } : {}), children: "Close banner" })), }) }) })] }), this.props.children] })); } } export { DSRBanner };