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.

42 lines (39 loc) 2.42 kB
import { jsxs, Fragment, jsx } from 'react/jsx-runtime'; import { splitChildren } from '../../splitChildren.mjs'; import { Component } from 'react'; import { minifyCss } from '../../minifyCss.mjs'; import { getSheetCss as getComponentCss$n } 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." } * * @controlled {"props": ["open"], "event": "dismiss"} */ class DSRSheet extends Component { host; dialog; scroller; hasHeader; 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; if (this.props.open) ; const style = minifyCss(getComponentCss$n(this.props.open, this.props.background, this.props.dismissButton)); 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: "sheet", header: hasHeader ? jsx("slot", { name: "header" }) : undefined, ariaAttributes: parseAndGetAriaAttributes({ 'aria-modal': true, ...(hasHeader && { 'aria-label': namedSlotChildren.filter(({ props: { slot } }) => slot === 'header').length > 0 && namedSlotChildren.find(({ props: { slot } }) => slot === 'header')?.props.children, }), ...parseAndGetAriaAttributes(this.props.aria), }), children: jsx("slot", {}) })] }), this.props.children] })); } } export { DSRSheet };