@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
103 lines (102 loc) • 5.8 kB
JavaScript
"use client";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
const _excluded = ["modalContent", "navContent", "headerContent", "alignContent", "className", "preventCoreStyle", "spacing", "fullscreen", "noAnimation", "noAnimationOnMobile", "minWidth", "maxWidth", "variant", "confirmType", "icon", "description", "hideDecline", "hideConfirm", "onConfirm", "onDecline", "declineText", "confirmText"];
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 classnames from 'classnames';
import { isTrue, findElementInChildren, validateDOMAttributes } from '../../shared/component-helper';
import ScrollView from '../../fragments/scroll-view/ScrollView';
import DialogHeader from './parts/DialogHeader';
import DialogNavigation from './parts/DialogNavigation';
import DialogAction from './parts/DialogAction';
import { getContent } from '../modal/helpers';
import ModalContext from '../modal/ModalContext';
import { checkMinMaxWidth } from '../drawer/helpers';
import ModalHeaderBar from '../modal/parts/ModalHeaderBar';
import ModalHeader from '../modal/parts/ModalHeader';
import IconPrimary from '../icon-primary/IconPrimary';
export default function DialogContent(_ref) {
let {
modalContent = null,
navContent = null,
headerContent = null,
alignContent = null,
className = null,
preventCoreStyle = null,
spacing = true,
fullscreen,
noAnimation = false,
noAnimationOnMobile = false,
minWidth: min_width = null,
maxWidth: max_width = null,
variant = 'information',
confirmType = 'info',
icon = null,
description,
hideDecline,
hideConfirm,
onConfirm,
onDecline,
declineText,
confirmText
} = _ref,
rest = _objectWithoutProperties(_ref, _excluded);
const context = useContext(ModalContext);
const {
minWidth,
maxWidth
} = checkMinMaxWidth(min_width, max_width);
const content = modalContent || getContent(typeof rest.children === 'function' ? Object.freeze(_objectSpread(_objectSpread({}, rest), {}, {
close: context === null || context === void 0 ? void 0 : context.close
})) : rest);
if (alignContent === null) {
alignContent = variant === 'information' ? 'left' : 'centered';
}
const contentParams = _objectSpread({
className: classnames('dnb-dialog', isTrue(fullscreen) ? `dnb-dialog--fullscreen` : fullscreen === 'auto' && `dnb-dialog--auto-fullscreen`, className, !isTrue(preventCoreStyle) && 'dnb-core-style', variant && `dnb-dialog--${variant}`, isTrue(spacing) && 'dnb-dialog--spacing', alignContent && `dnb-dialog__align--${alignContent}`, isTrue(context === null || context === void 0 ? void 0 : context.hide) && `dnb-dialog--hide`, isTrue(noAnimation) && `dnb-dialog--no-animation`, isTrue(noAnimationOnMobile) && `dnb-dialog--no-animation-on-mobile`),
style: (minWidth || maxWidth) && {
minWidth,
maxWidth
},
onClick: context === null || context === void 0 ? void 0 : context.preventClick,
onTouchStart: context === null || context === void 0 ? void 0 : context.preventClick,
onKeyDown: context === null || context === void 0 ? void 0 : context.onKeyDownHandler
}, rest);
const navExists = findElementInChildren(content, cur => cur.type === DialogNavigation || cur.type === ModalHeaderBar);
const headerExists = findElementInChildren(content, cur => cur.type === DialogHeader || cur.type === ModalHeader);
const actionExists = findElementInChildren(content, cur => cur.type === DialogAction);
const dialogActionProps = {
onConfirm,
onDecline,
declineText,
confirmText,
hideDecline,
hideConfirm
};
validateDOMAttributes({}, contentParams);
return React.createElement("div", contentParams, React.createElement(ScrollView, {
ref: context === null || context === void 0 ? void 0 : context.scrollRef
}, React.createElement("div", {
tabIndex: -1,
className: "dnb-dialog__inner dnb-no-focus",
ref: context === null || context === void 0 ? void 0 : context.contentRef
}, !navExists && React.createElement(DialogNavigation, null, navContent), icon && React.createElement("div", {
className: "dnb-dialog__icon"
}, React.createElement(IconPrimary, {
border: true,
key: "dialog-icon",
icon: icon,
"aria-hidden": true,
className: classnames('dnb-dialog__icon__primary', 'dnb-dialog__icon--' + confirmType)
})), !headerExists && React.createElement(DialogHeader, {
title: context === null || context === void 0 ? void 0 : context.title,
size: variant === 'information' ? 'x-large' : 'large'
}, headerContent), React.createElement("div", {
id: (context === null || context === void 0 ? void 0 : context.contentId) + '-content',
className: "dnb-dialog__content"
}, description, content), variant === 'confirmation' && !actionExists && React.createElement(DialogAction, dialogActionProps))));
}
DialogContent._supportsSpacingProps = true;
//# sourceMappingURL=DialogContent.js.map