UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

59 lines (58 loc) 1.85 kB
"use client"; import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _Hr; const _excluded = ["children", "className", "onEdit", "onDone", "onCancel"]; import React, { useContext, useEffect, useState } from 'react'; import classnames from 'classnames'; import { useTranslation } from '../../../hooks'; import ToolbarContext from './ToolbarContext'; import FieldBoundaryContext from '../../../DataContext/FieldBoundary/FieldBoundaryContext'; import { Hr } from '../../../../../elements'; import { Flex, FormStatus } from '../../../../../components'; import Space from '../../../../../components/Space'; export default function Toolbar(props) { const { errorInSection } = useTranslation().SectionEditContainer; const { children, className, onEdit, onDone, onCancel } = props, rest = _objectWithoutProperties(props, _excluded); const { hasError, hasVisibleError } = useContext(FieldBoundaryContext) || {}; const [showError, setShowError] = useState(false); useEffect(() => { if (showError && !hasError) { setShowError(false); } }, [hasError, showError]); return React.createElement(Space, _extends({ className: classnames('dnb-forms-section-toolbar', className) }, rest), _Hr || (_Hr = React.createElement(Hr, { space: 0 })), React.createElement(ToolbarContext.Provider, { value: { setShowError, onEdit, onDone, onCancel } }, React.createElement(Flex.Horizontal, { top: "x-small", gap: "large" }, children)), React.createElement(FormStatus, { show: showError && hasVisibleError, shellSpace: { top: 'x-small' }, no_animation: false }, errorInSection)); } //# sourceMappingURL=Toolbar.js.map