UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

54 lines (53 loc) 2.35 kB
"use client"; import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _Toolbar, _Toolbar2; const _excluded = ["children", "className", "title", "toolbar", "toolbarVariant"]; import React, { useContext, useMemo } from 'react'; import classnames from 'classnames'; import { convertJsxToString } from '../../../../shared/component-helper'; import { Lead } from '../../../../elements'; import ArrayItemArea from '../Array/ArrayItemArea'; import IterateItemContext from '../IterateItemContext'; import Toolbar from '../Toolbar'; import EditButton from './EditButton'; import RemoveButton from './RemoveButton'; import { replaceItemNo } from '../ItemNo'; function ViewContainer(props) { const _ref = props || {}, { children, className, title, toolbar, toolbarVariant } = _ref, restProps = _objectWithoutProperties(_ref, _excluded); const { index, arrayValue } = useContext(IterateItemContext); const itemTitle = useMemo(() => { return replaceItemNo(title, index); }, [index, title]); let toolbarElement = toolbar; if (toolbarVariant === 'minimumOneItem' && arrayValue.length <= 1) { toolbarElement = _Toolbar || (_Toolbar = React.createElement(Toolbar, null, React.createElement(EditButton, null))); } const hasToolbar = !toolbarElement && React.Children.toArray(children).some(child => { return (child === null || child === void 0 ? void 0 : child['type']) === Toolbar; }); return React.createElement(ArrayItemArea, _extends({ mode: "view", ariaLabel: convertJsxToString(itemTitle), className: classnames('dnb-forms-section-view-block', className), toolbarVariant: toolbarVariant }, restProps), itemTitle && React.createElement(Lead, { size: "basis" }, itemTitle), children, hasToolbar ? null : toolbarElement !== null && toolbarElement !== void 0 ? toolbarElement : toolbarVariant !== 'custom' && (_Toolbar2 || (_Toolbar2 = React.createElement(Toolbar, null, React.createElement(EditButton, null), React.createElement(RemoveButton, null))))); } ViewContainer.EditButton = EditButton; ViewContainer.RemoveButton = RemoveButton; ViewContainer._supportsSpacingProps = true; export default ViewContainer; //# sourceMappingURL=ViewContainer.js.map