@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
68 lines (67 loc) • 2.09 kB
JavaScript
;
"use client";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Toolbar;
var _react = require("react");
var _clsx = _interopRequireDefault(require("clsx"));
var _index = require("../../../hooks/index.js");
var _ToolbarContext = _interopRequireDefault(require("./ToolbarContext.js"));
var _FieldBoundaryContext = _interopRequireDefault(require("../../../DataContext/FieldBoundary/FieldBoundaryContext.js"));
var _index2 = require("../../../../../elements/index.js");
var _index3 = require("../../../../../components/index.js");
var _Space = _interopRequireDefault(require("../../../../../components/Space.js"));
var _jsxRuntime = require("react/jsx-runtime");
var _Hr;
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function Toolbar(props) {
const {
errorInSection
} = (0, _index.useTranslation)().SectionEditContainer;
const {
children,
className,
onEdit,
onDone,
onCancel,
...rest
} = props;
const {
hasError,
hasVisibleError
} = (0, _react.useContext)(_FieldBoundaryContext.default) || {};
const [showError, setShowError] = (0, _react.useState)(false);
(0, _react.useEffect)(() => {
if (showError && !hasError) {
setShowError(false);
}
}, [hasError, showError]);
return (0, _jsxRuntime.jsxs)(_Space.default, {
className: (0, _clsx.default)('dnb-forms-section-toolbar', className),
...rest,
children: [_Hr || (_Hr = (0, _jsxRuntime.jsx)(_index2.Hr, {
space: 0
})), (0, _jsxRuntime.jsx)(_ToolbarContext.default, {
value: {
setShowError,
onEdit,
onDone,
onCancel
},
children: (0, _jsxRuntime.jsx)(_index3.Flex.Horizontal, {
top: "x-small",
gap: "large",
children: children
})
}), (0, _jsxRuntime.jsx)(_index3.FormStatus, {
show: showError && hasVisibleError,
shellSpace: {
top: 'x-small'
},
noAnimation: false,
children: errorInSection
})]
});
}
//# sourceMappingURL=Toolbar.js.map