@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.
47 lines (44 loc) • 3.05 kB
JavaScript
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
import { splitChildren } from '../../splitChildren.mjs';
import { Component } from 'react';
import { minifyCss } from '../../minifyCss.mjs';
import { getFlyoutCss as getComponentCss$V } 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 sticky 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." }
* @slot {"name": "sub-footer", "description": "Renders additional content below the footer, such as legal information or FAQs. It appears when the flyout has enough space or when the user scrolls to the end." }
*
* @controlled {"props": ["open"], "event": "dismiss"}
*/
class DSRFlyout extends Component {
host;
dialog;
scroller;
header;
footer;
hasHeader;
hasFooter;
hasSubFooter;
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;
const hasSubFooter = namedSlotChildren.filter(({ props: { slot } }) => slot === 'sub-footer').length > 0;
const style = minifyCss(getComponentCss$V(this.props.open, this.props.background, this.props.backdrop, this.props.position, hasHeader, hasFooter, hasSubFooter, this.props.footerBehavior, this.props.fullscreen));
return (jsxs(Fragment, { children: [jsxs("template", { shadowroot: "open", shadowrootmode: "open", children: [jsx("style", { dangerouslySetInnerHTML: { __html: style } }), jsx(DialogBase, { host: null, dismissable: true, containerClass: "flyout", header: hasHeader ? jsx("slot", { name: "header" }) : undefined, footer: hasFooter ? jsx("slot", { name: "footer" }) : undefined, subFooter: hasSubFooter ? jsx("slot", { name: "sub-footer" }) : undefined, ariaAttributes: parseAndGetAriaAttributes({
'aria-modal': true,
...{ 'aria-label': hasHeader ? namedSlotChildren.find(({ props: { slot } }) => slot === 'header')?.props.children : 'Flyout' },
...parseAndGetAriaAttributes(this.props.aria),
}), children: jsx("slot", {}) })] }), this.props.children] }));
}
}
export { DSRFlyout };