UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

137 lines (136 loc) 5.08 kB
"use client"; import _extends from "@babel/runtime/helpers/esm/extends"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; const _excluded = ["id", "rootId", "contentId", "focusSelector", "labelledBy", "directDomReturn", "disabled", "variant", "title", "dialogTitle", "closeTitle", "spacing", "verticalAlignment", "noAnimation", "noAnimationOnMobile", "animationDuration", "triggerAttributes", "hideCloseButton", "fullscreen", "onOpen", "onClose", "onClosePrevent", "openModal", "closeModal", "preventClose", "preventOverlayClose", "openState", "openDelay", "trigger", "omitTriggerButton", "overlayClass", "contentClass", "contentRef", "scrollRef", "top", "bottom", "left", "right", "space"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import React, { useContext } from 'react'; import Modal from '../modal/Modal'; import DialogContent from './DialogContent'; import DialogBody from './parts/DialogBody'; import DialogHeader from './parts/DialogHeader'; import DialogNavigation from './parts/DialogNavigation'; import classnames from 'classnames'; import Context from '../../shared/Context'; import DialogAction from './parts/DialogAction'; import { extendPropsWithContext } from '../../shared/component-helper'; 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, rootId, contentId, focusSelector, labelledBy, directDomReturn, disabled, variant, title, dialogTitle, closeTitle, spacing, verticalAlignment, noAnimation, noAnimationOnMobile, animationDuration, triggerAttributes, hideCloseButton, fullscreen, onOpen, onClose, onClosePrevent, openModal, closeModal, preventClose, preventOverlayClose, openState, openDelay, trigger, omitTriggerButton = false, overlayClass, contentClass, contentRef, scrollRef, top, bottom, left, right, space } = propsWithContext, props = _objectWithoutProperties(propsWithContext, _excluded); 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, openState, directDomReturn, rootId, onOpen, onClose, onClosePrevent, openModal, closeModal, omitTriggerButton: currentOmitTriggerButton, trigger, triggerAttributes, overlayClass, top, bottom, left, right, space, contentRef, scrollRef }; const dialogProps = _objectSpread(_objectSpread({}, props), {}, { noAnimation, noAnimationOnMobile, fullscreen: currentFullscreen, spacing, variant }); return React.createElement(Modal, _extends({}, modalProps, { dialogRole: variant == 'information' ? 'dialog' : 'alertdialog', contentClass: classnames('dnb-dialog__root', contentClass) }), React.createElement(DialogContent, dialogProps)); } Dialog.Body = DialogBody; Dialog.Header = DialogHeader; Dialog.Navigation = DialogNavigation; Dialog.Action = DialogAction; Dialog._supportsSpacingProps = true; export default Dialog; //# sourceMappingURL=Dialog.js.map