@eccenca/gui-elements
Version:
GUI elements based on other libraries, usable in React application, written in Typescript.
73 lines • 3.85 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InteractionGate = void 0;
const react_1 = __importStar(require("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
require("wicg-inert");
const constants_1 = require("../../configuration/constants");
const Spinner_1 = __importDefault(require("./../Spinner/Spinner"));
/**
* Wrap content that need to be blocked from user interactions
* It also has options to display a spinner as overlay.
*/
const InteractionGate = (_a) => {
var { children, className, inert = false, showSpinner = false, spinnerProps = {}, useParentPositioning = false } = _a, otherProps = __rest(_a, ["children", "className", "inert", "showSpinner", "spinnerProps", "useParentPositioning"]);
const domRef = (0, react_1.useRef)(null);
(0, react_1.useEffect)(() => {
// 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_1.default.createElement("div", { className: `${constants_1.CLASSPREFIX}-interactiongate__wrapper` +
(useParentPositioning ? ` ${constants_1.CLASSPREFIX}-interactiongate__wrapper--tunnelpositioning` : "") },
react_1.default.createElement("div", Object.assign({ ref: domRef, className: `${constants_1.CLASSPREFIX}-interactiongate` +
(inert ? ` ${constants_1.CLASSPREFIX}-interactiongate--inert` : "") +
(className ? ` ${className}` : "") }, otherProps), children),
showSpinner && (react_1.default.createElement(Spinner_1.default, Object.assign({ showLocalBackdrop: true }, spinnerProps, { className: `${constants_1.CLASSPREFIX}-interactiongate__spinner` })))));
};
exports.InteractionGate = InteractionGate;
exports.default = exports.InteractionGate;
//# sourceMappingURL=InteractionGate.js.map