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.

39 lines (36 loc) 1.82 kB
"use client"; import { jsx } from 'react/jsx-runtime'; import { forwardRef, useRef } from 'react'; import { useEventCallback, usePrefix, useBrowserLayoutEffect, useMergedClass } from '../../hooks.mjs'; import { syncRef } from '../../utils.mjs'; import { DSRModal } from '../dsr-components/modal.mjs'; const PModal = /*#__PURE__*/ forwardRef(({ aria, backdrop = 'blur', background = 'canvas', disableBackdropClick = false, dismissButton = true, fullscreen = false, onDismiss, onMotionHiddenEnd, onMotionVisibleEnd, open = false, className, children, ...rest }, ref) => { const elementRef = useRef(undefined); useEventCallback(elementRef, 'dismiss', onDismiss); useEventCallback(elementRef, 'motionHiddenEnd', onMotionHiddenEnd); useEventCallback(elementRef, 'motionVisibleEnd', onMotionVisibleEnd); const WebComponentTag = usePrefix('p-modal'); const propsToSync = [aria, backdrop, background, disableBackdropClick, dismissButton, fullscreen, open]; useBrowserLayoutEffect(() => { const { current } = elementRef; ['aria', 'backdrop', 'background', 'disableBackdropClick', 'dismissButton', 'fullscreen', 'open'].forEach((propName, i) => (current[propName] = propsToSync[i])); }, propsToSync); const props = { ...rest, // @ts-ignore ...(!process.browser ? { children: (jsx(DSRModal, { aria, backdrop, background, disableBackdropClick, dismissButton, fullscreen, open, children })), } : { children, suppressHydrationWarning: true, }), 'data-ssr': '', class: useMergedClass(elementRef, className), ref: syncRef(elementRef, ref) }; // @ts-ignore return jsx(WebComponentTag, { ...props }); }); export { PModal };