@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
57 lines (56 loc) • 1.66 kB
JavaScript
"use client";
import _extends from "@babel/runtime/helpers/esm/extends";
var _Hr;
import React, { useContext, useEffect, useState } from 'react';
import classnames from 'classnames';
import { useTranslation } from "../../../hooks/index.js";
import ToolbarContext from "./ToolbarContext.js";
import FieldBoundaryContext from "../../../DataContext/FieldBoundary/FieldBoundaryContext.js";
import { Hr } from "../../../../../elements/index.js";
import { Flex, FormStatus } from "../../../../../components/index.js";
import Space from "../../../../../components/Space.js";
export default function Toolbar(props) {
const {
errorInSection
} = useTranslation().SectionEditContainer;
const {
children,
className,
onEdit,
onDone,
onCancel,
...rest
} = props;
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