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 (42 loc) 2.69 kB
import { jsxs, Fragment, jsx } from 'react/jsx-runtime'; import { splitChildren } from '../../splitChildren.mjs'; import { Component } from 'react'; import { minifyCss } from '../../minifyCss.mjs'; import { getModalCss as getComponentCss$C } from '../../../../../../components/dist/styles/esm/styles-entry.mjs'; import { createTopLayerController, parseAndGetAriaAttributes, showDialog } from '../../../../../../components/dist/utils/esm/utils-entry.mjs'; import { DialogBase } from './dialog-base.mjs'; /** * @slot {"name": "header", "description": "Renders a header section above the content area." } * @slot {"name": "", "description": "Default slot for the main content." } * @slot {"name": "footer", "description": "Shows a sticky footer section, flowing under the content area when scrollable." } * * @controlled {"props": ["open"], "event": "dismiss"} */ class DSRModal extends Component { host; dialog; scroller; footer; hasHeader; hasFooter; topLayer = createTopLayerController({ getElement: () => this.props.dialog, isShown: () => !!this.props.dialog?.open, show: () => showDialog(this.props.dialog, this.props.scroller), hide: () => this.props.dialog?.close(), }); render() { const { namedSlotChildren} = splitChildren(this.props.children); const hasHeader = namedSlotChildren.filter(({ props: { slot } }) => slot === 'header').length > 0; const hasFooter = namedSlotChildren.filter(({ props: { slot } }) => slot === 'footer').length > 0; this.props.disableCloseButton ? false : this.props.dismissButton; // TODO: why do we validate only when opened? const style = minifyCss(getComponentCss$C(this.props.open, this.props.background, this.props.backdrop, this.props.fullscreen, this.props.dismissButton, hasHeader, hasFooter)); return (jsxs(Fragment, { children: [jsxs("template", { shadowroot: "open", shadowrootmode: "open", children: [jsx("style", { dangerouslySetInnerHTML: { __html: style } }), jsx(DialogBase, { host: null, inert: !this.props.open, dismissable: this.props.dismissButton ?? undefined, containerClass: "modal", header: hasHeader ? jsx("slot", { name: "header" }) : undefined, footer: hasFooter ? jsx("slot", { name: "footer" }) : undefined, ariaAttributes: parseAndGetAriaAttributes({ 'aria-modal': true, ...(hasHeader && { 'aria-label': this.props.ariaLabel }), ...parseAndGetAriaAttributes(this.props.aria), }), children: jsx("slot", {}) })] }), this.props.children] })); } } export { DSRModal };