UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

138 lines (137 loc) 3.55 kB
"use client"; import React, { useContext } from 'react'; import Modal from "../modal/Modal.js"; import DialogContent from "./DialogContent.js"; import DialogBody from "./parts/DialogBody.js"; import DialogHeader from "./parts/DialogHeader.js"; import DialogNavigation from "./parts/DialogNavigation.js"; import clsx from 'clsx'; import Context from "../../shared/Context.js"; import DialogAction from "./parts/DialogAction.js"; import { extendPropsWithContext } from "../../shared/component-helper.js"; import withComponentMarkers from "../../shared/helpers/withComponentMarkers.js"; import { jsx as _jsx } from "react/jsx-runtime"; const defaultProps = { variant: 'information', spacing: true }; function Dialog(localProps) { const context = useContext(Context); const propsWithContext = extendPropsWithContext(localProps, defaultProps, context === null || context === void 0 ? void 0 : context.Dialog); const { id, contentId, focusSelector, labelledBy, directDomReturn, disabled, variant, title, dialogTitle, closeTitle, spacing, verticalAlignment, noAnimation, noAnimationOnMobile, animationDuration, triggerAttributes, hideCloseButton, fullscreen, onOpen, onClose, onClosePrevent, openModal, closeModal, preventClose, preventOverlayClose, open, openDelay, trigger, omitTriggerButton = false, overlayClass, contentClass, contentRef, scrollRef, top, bottom, left, right, space, ...props } = propsWithContext; let currentHideCloseButton = hideCloseButton; let currentOmitTriggerButton = omitTriggerButton; let currentFullscreen = fullscreen; let currentPreventOverlayClose = preventOverlayClose; if (variant === 'confirmation') { currentHideCloseButton = hideCloseButton !== undefined ? hideCloseButton : true; currentOmitTriggerButton = triggerAttributes !== undefined ? omitTriggerButton : true; currentPreventOverlayClose = preventOverlayClose !== undefined ? preventOverlayClose : true; } if (fullscreen === undefined && fullscreen !== false) { currentFullscreen = variant === 'information' ? 'auto' : false; } const modalProps = { title, id, focusSelector, labelledBy, disabled, spacing, verticalAlignment, openDelay, contentId, dialogTitle, closeTitle, hideCloseButton: currentHideCloseButton, preventClose, preventOverlayClose: currentPreventOverlayClose, animationDuration, noAnimation, noAnimationOnMobile, fullscreen: currentFullscreen, open, directDomReturn, onOpen, onClose, onClosePrevent, openModal, closeModal, omitTriggerButton: currentOmitTriggerButton, trigger, triggerAttributes, overlayClass, top, bottom, left, right, space, contentRef, scrollRef }; const dialogProps = { ...props, noAnimation, noAnimationOnMobile, fullscreen: currentFullscreen, spacing, variant }; return _jsx(Modal, { ...modalProps, dialogRole: variant === 'information' ? 'dialog' : 'alertdialog', contentClass: clsx('dnb-dialog__root', contentClass), children: _jsx(DialogContent, { ...dialogProps }) }); } Dialog.Body = DialogBody; Dialog.Header = DialogHeader; Dialog.Navigation = DialogNavigation; Dialog.Action = DialogAction; withComponentMarkers(Dialog, { _supportsSpacingProps: true }); export default Dialog; //# sourceMappingURL=Dialog.js.map