@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
99 lines (98 loc) • 4.44 kB
JavaScript
"use client";
import React, { useContext } from 'react';
import classnames from 'classnames';
import { isTrue, findElementInChildren, validateDOMAttributes } from "../../shared/component-helper.js";
import ScrollView from "../../fragments/scroll-view/ScrollView.js";
import DialogHeader from "./parts/DialogHeader.js";
import DialogNavigation from "./parts/DialogNavigation.js";
import DialogAction from "./parts/DialogAction.js";
import { getContent } from "../modal/helpers.js";
import ModalContext from "../modal/ModalContext.js";
import { checkMinMaxWidth } from "../drawer/helpers.js";
import ModalHeaderBar from "../modal/parts/ModalHeaderBar.js";
import ModalHeader from "../modal/parts/ModalHeader.js";
import IconPrimary from "../icon-primary/IconPrimary.js";
export default function DialogContent({
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,
...rest
}) {
const context = useContext(ModalContext);
const {
minWidth,
maxWidth
} = checkMinMaxWidth(min_width, max_width);
const content = modalContent || getContent(typeof rest.children === 'function' ? Object.freeze({
...rest,
close: context === null || context === void 0 ? void 0 : context.close
}) : rest);
if (alignContent === null) {
alignContent = variant === 'information' ? 'left' : 'centered';
}
const contentParams = {
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