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.

33 lines (30 loc) 2.61 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 { getInlineNotificationCss as getComponentCss$S } from '../../../../../../components/dist/styles/esm/styles-entry.mjs'; import { getInlineNotificationAriaAttributes } from '../../../../../../components/dist/utils/esm/utils-entry.mjs'; import { NotificationBase } from './notification-base.mjs'; import { PButton } from '../components/button.wrapper.mjs'; import { PButtonPure } from '../components/button-pure.wrapper.mjs'; /** * @slot {"name": "heading", "description": "Defines the heading of the inline notification. Can be used as an alternative to the `heading` prop for rich content." } * @slot {"name": "", "description": "Default slot for the inline notification description content." } */ class DSRInlineNotification extends Component { host; hasHeadingSlot; render() { const { namedSlotChildren} = splitChildren(this.props.children); const hasHeadingSlot = namedSlotChildren.filter(({ props: { slot } }) => slot === 'heading').length > 0; const headingText = this.props.heading ? this.props.heading : namedSlotChildren.find(({ props: { slot } }) => slot === 'heading')?.props.children; const style = minifyCss(getComponentCss$S(this.props.state, !!this.props.actionLabel, this.props.dismissButton, !!(this.props.heading || hasHeadingSlot))); return (jsxs(Fragment, { children: [jsxs("template", { shadowroot: "open", shadowrootmode: "open", children: [jsx("style", { dangerouslySetInnerHTML: { __html: style } }), jsx(NotificationBase, { ...getInlineNotificationAriaAttributes(this.props.state, headingText), heading: this.props.heading, headingTag: this.props.headingTag, hasHeadingSlot: hasHeadingSlot, description: this.props.description, ...(this.props.actionLabel && { actionLabel: (jsx(PButtonPure, { className: "action", icon: this.props.actionIcon, loading: this.props.actionLoading, children: this.props.actionLabel })), }), ...(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 notification" })), }) })] }), this.props.children] })); } } export { DSRInlineNotification };