@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
60 lines (59 loc) • 1.91 kB
JavaScript
"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 "core-js/modules/web.dom-collections.iterator.js";
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