UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

65 lines (64 loc) 2.74 kB
"use client"; import _extends from "@babel/runtime-corejs3/helpers/esm/extends"; var _DoneButton, _CancelButton; import React, { useCallback, useContext, useMemo, useRef } from 'react'; import classnames from 'classnames'; import { convertJsxToString } from "../../../../../shared/component-helper.js"; import { Flex } from "../../../../../components/index.js"; import { Lead } from "../../../../../elements/index.js"; import FieldBoundaryProvider from "../../../DataContext/FieldBoundary/FieldBoundaryProvider.js"; import SectionContainerContext from "../containers/SectionContainerContext.js"; import Toolbar from "../Toolbar/Toolbar.js"; import DoneButton from "./DoneButton.js"; import CancelButton from "./CancelButton.js"; import SectionContainer from "../containers/SectionContainer.js"; function EditContainer(props) { const { children, className, title, onDone, onCancel, ...restProps } = props || {}; const ariaLabel = useMemo(() => convertJsxToString(title), [title]); const { containerMode, initialContainerMode, validateInitially, switchContainerMode, disableEditing } = useContext(SectionContainerContext) || {}; const omitFocusManagementRef = useRef(false); const onPathError = useCallback((path, error) => { if (disableEditing) { return; } if (initialContainerMode === 'auto' && containerMode !== 'edit' && error instanceof Error) { omitFocusManagementRef.current = true; switchContainerMode === null || switchContainerMode === void 0 || switchContainerMode('edit'); } }, [containerMode, disableEditing, initialContainerMode, switchContainerMode]); const hasToolbar = React.Children.toArray(children).some(child => { return (child === null || child === void 0 ? void 0 : child['type']) === Toolbar; }); return React.createElement(FieldBoundaryProvider, { showErrors: validateInitially, onPathError: onPathError }, React.createElement(SectionContainer, _extends({ mode: "edit", ariaLabel: ariaLabel, omitFocusManagementRef: omitFocusManagementRef, className: classnames('dnb-forms-section-edit-block', className) }, restProps), React.createElement(Flex.Stack, null, title && React.createElement(Lead, { size: "basis" }, title), children, hasToolbar ? null : React.createElement(Toolbar, { onDone: onDone, onCancel: onCancel }, _DoneButton || (_DoneButton = React.createElement(DoneButton, null)), _CancelButton || (_CancelButton = React.createElement(CancelButton, null)))))); } EditContainer.DoneButton = DoneButton; EditContainer.CancelButton = CancelButton; EditContainer._supportsSpacingProps = true; export default EditContainer; //# sourceMappingURL=EditContainer.js.map