@eccenca/gui-elements
Version:
GUI elements based on other libraries, usable in React application, written in Typescript.
54 lines • 3 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React, { useEffect, useRef } from "react";
// FIXME: re-evaluate if polyfill is necessary
// we currently need a polyfill for inert because Firefox do not support it natively atm
// @see https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/inert#browser_compatibility
import "wicg-inert";
import { CLASSPREFIX as eccgui } from "../../configuration/constants.js";
import Spinner from "./../Spinner/Spinner.js";
/**
* Wrap content that need to be blocked from user interactions
* It also has options to display a spinner as overlay.
*/
export var InteractionGate = function (_a) {
var children = _a.children, className = _a.className, _b = _a.inert, inert = _b === void 0 ? false : _b, _c = _a.showSpinner, showSpinner = _c === void 0 ? false : _c, _d = _a.spinnerProps, spinnerProps = _d === void 0 ? {} : _d, _e = _a.useParentPositioning, useParentPositioning = _e === void 0 ? false : _e, otherProps = __rest(_a, ["children", "className", "inert", "showSpinner", "spinnerProps", "useParentPositioning"]);
var domRef = useRef(null);
useEffect(function () {
// we currently cannot add inert property directly to the div because react types module seem not to know it
if (inert) {
domRef.current.setAttribute("inert", "");
}
else {
domRef.current.removeAttribute("inert");
}
}, [inert]);
return (React.createElement("div", { className: "".concat(eccgui, "-interactiongate__wrapper") +
(useParentPositioning ? " ".concat(eccgui, "-interactiongate__wrapper--tunnelpositioning") : "") },
React.createElement("div", __assign({ ref: domRef, className: "".concat(eccgui, "-interactiongate") +
(inert ? " ".concat(eccgui, "-interactiongate--inert") : "") +
(className ? " ".concat(className) : "") }, otherProps), children),
showSpinner && (React.createElement(Spinner, __assign({ showLocalBackdrop: true }, spinnerProps, { className: "".concat(eccgui, "-interactiongate__spinner") })))));
};
export default InteractionGate;
//# sourceMappingURL=InteractionGate.js.map