UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

114 lines (113 loc) 4.71 kB
"use client"; import React, { useContext } from 'react'; import clsx from 'clsx'; import { 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"; import withComponentMarkers from "../../shared/helpers/withComponentMarkers.js"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; export default function DialogContent({ modalContent = null, navContent = null, headerContent = null, alignContent = null, className = null, preventCoreStyle = null, spacing = true, fullscreen, noAnimation = false, noAnimationOnMobile = false, minWidth: minWidthProp = null, maxWidth: maxWidthProp = null, variant = 'information', confirmType = 'information', icon = null, description, hideDecline, hideConfirm, onConfirm, onDecline, declineText, confirmText, ...rest }) { const context = useContext(ModalContext); const { minWidth, maxWidth } = checkMinMaxWidth(minWidthProp, maxWidthProp); 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: clsx('dnb-dialog', fullscreen === true ? `dnb-dialog--fullscreen` : fullscreen === 'auto' && `dnb-dialog--auto-fullscreen`, className, !preventCoreStyle && 'dnb-core-style', variant && `dnb-dialog--${variant}`, spacing && 'dnb-dialog--spacing', alignContent && `dnb-dialog__align--${alignContent}`, (context === null || context === void 0 ? void 0 : context.hide) && `dnb-dialog--hide`, noAnimation && `dnb-dialog--no-animation`, 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 _jsx("div", { ...contentParams, children: _jsx(ScrollView, { ref: context === null || context === void 0 ? void 0 : context.scrollRef, children: _jsxs("div", { tabIndex: -1, className: "dnb-dialog__inner dnb-no-focus", ref: context === null || context === void 0 ? void 0 : context.contentRef, children: [!navExists && _jsx(DialogNavigation, { children: navContent }), icon && _jsx("div", { className: "dnb-dialog__icon", children: _jsx(IconPrimary, { border: true, icon: icon, "aria-hidden": true, className: clsx('dnb-dialog__icon__primary', 'dnb-dialog__icon--' + confirmType) }, "dialog-icon") }), !headerExists && _jsx(DialogHeader, { title: context === null || context === void 0 ? void 0 : context.title, size: variant === 'information' ? 'x-large' : 'large', children: headerContent }), _jsxs("div", { id: (context === null || context === void 0 ? void 0 : context.contentId) + '-content', className: "dnb-dialog__content", children: [description, content] }), variant === 'confirmation' && !actionExists && _jsx(DialogAction, { ...dialogActionProps })] }) }) }); } withComponentMarkers(DialogContent, { _supportsSpacingProps: true }); //# sourceMappingURL=DialogContent.js.map