UNPKG

@eccenca/gui-elements

Version:

GUI elements based on other libraries, usable in React application, written in Typescript.

83 lines 6.06 kB
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; }; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; import React from "react"; import { CLASSPREFIX as eccgui } from "../../configuration/constants.js"; import IconButton from "../Icon/IconButton.js"; import { Card, CardActions, CardContent, CardHeader, CardOptions, CardTitle } from "./../Card/index.js"; import Divider from "./../Separation/Divider.js"; import Modal from "./Modal.js"; /** * Simplifies the dialog display by providing a direct `Card` template for the `Modal` element. * Inherits all properties from `Modal`. */ export var SimpleDialog = function (_a) { var _b, _c; var children = _a.children, _d = _a.canOutsideClickClose, canOutsideClickClose = _d === void 0 ? false : _d, _e = _a.canEscapeKeyClose, canEscapeKeyClose = _e === void 0 ? false : _e, _f = _a.title, title = _f === void 0 ? "" : _f, _g = _a.actions, actions = _g === void 0 ? null : _g, _h = _a.notifications, notifications = _h === void 0 ? null : _h, _j = _a.hasBorder, hasBorder = _j === void 0 ? false : _j, _k = _a.preventSimpleClosing, preventSimpleClosing = _k === void 0 ? false : _k, _l = _a.enforceFocus, enforceFocus = _l === void 0 ? false : _l, intent = _a.intent, headerOptions = _a.headerOptions, _m = _a.showFullScreenToggler, showFullScreenToggler = _m === void 0 ? false : _m, _o = _a.startInFullScreenMode, startInFullScreenMode = _o === void 0 ? false : _o, size = _a.size, actionsProps = _a.actionsProps, otherProps = __rest(_a, ["children", "canOutsideClickClose", "canEscapeKeyClose", "title", "actions", "notifications", "hasBorder", "preventSimpleClosing", "enforceFocus", "intent", "headerOptions", "showFullScreenToggler", "startInFullScreenMode", "size", "actionsProps"]); var _p = __read(React.useState(startInFullScreenMode), 2), displayFullscreen = _p[0], setDisplayFullscreen = _p[1]; var showToggler = startInFullScreenMode || showFullScreenToggler; var intentClassName = intent ? "".concat(eccgui, "-intent--").concat(intent) : ""; var wrapperDivProps = __assign(__assign({}, modalPreventEvents), otherProps.wrapperDivProps); return (React.createElement(Modal, __assign({ enforceFocus: enforceFocus }, otherProps, { wrapperDivProps: wrapperDivProps, "data-test-id": (_b = otherProps["data-test-id"]) !== null && _b !== void 0 ? _b : "simpleDialogWidget", canOutsideClickClose: canOutsideClickClose || !preventSimpleClosing, canEscapeKeyClose: canEscapeKeyClose || !preventSimpleClosing, size: displayFullscreen ? "fullscreen" : size }), React.createElement(Card, { className: intentClassName }, title || headerOptions || showToggler ? (React.createElement(CardHeader, null, React.createElement(CardTitle, { className: intentClassName }, title), headerOptions || showToggler ? (React.createElement(CardOptions, null, headerOptions, showToggler && (React.createElement(IconButton, { name: displayFullscreen ? "toggler-minimize" : "toggler-maximize", onClick: function () { return setDisplayFullscreen(!displayFullscreen); } })))) : (React.createElement(React.Fragment, null)))) : null, hasBorder && React.createElement(Divider, null), React.createElement(CardContent, null, children), hasBorder && React.createElement(Divider, null), !!notifications && (React.createElement(CardContent, { className: "".concat(eccgui, "-dialog__notifications") }, notifications)), actions && (React.createElement(CardActions, __assign({}, actionsProps, { inverseDirection: true, className: "".concat((_c = actionsProps === null || actionsProps === void 0 ? void 0 : actionsProps.className) !== null && _c !== void 0 ? _c : "", " ").concat(intentClassName) }), actions))))); }; /** Events that should be prevented to bubble up from a modal that goes beyond the most simple version of a modal, e.g. * allows to drag or supports hot keys etc. */ export var modalPreventEvents = { // Prevent certain events from leaving the modal, so that e.g. react-flow does not receive these events doing unexpected stuff onContextMenu: function (event) { return event.stopPropagation(); }, onDrag: function (event) { return event.stopPropagation(); }, onDragStart: function (event) { return event.stopPropagation(); }, onDragEnd: function (event) { return event.stopPropagation(); }, // The following prevents some drop-downs to not close anymore when clicking outside of them // onMouseDown: (event: BaseSyntheticEvent) => event.stopPropagation(), onMouseUp: function (event) { return event.stopPropagation(); }, onClick: function (event) { return event.stopPropagation(); }, }; export default SimpleDialog; //# sourceMappingURL=SimpleDialog.js.map