@teamsnap/teamsnap-ui
Version:
a CSS component library for TeamSnap
108 lines (107 loc) • 5.08 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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;
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var PropTypes = __importStar(require("prop-types"));
var Popup = /** @class */ (function (_super) {
__extends(Popup, _super);
function Popup(props) {
var _this = _super.call(this, props) || this;
_this.state = {
isPopupOpen: false
};
_this.popupRef = React.createRef();
return _this;
}
Popup.prototype.handleBodyClick = function () {
if (this.popupRef && this.popupRef.current)
this.setState({
isPopupOpen: false
});
};
Popup.prototype.togglePopup = function () {
var isPopupOpen = this.state.isPopupOpen;
if (!isPopupOpen) {
document.body.addEventListener("click", this.handleBodyClick.bind(this), { capture: true });
}
else {
document.body.removeEventListener("click", this.handleBodyClick.bind(this));
}
this.setState({
isPopupOpen: !isPopupOpen
});
};
Popup.prototype.render = function () {
var dirString = this.props.direction.reduce(function (acc, cur) {
return acc + (" Popup-container--" + cur);
}, "");
return (React.createElement("div", { className: "Popup " + this.props.popUpMods, ref: this.popupRef },
React.createElement("button", { className: "Button " + this.props.buttonMods, onClick: this.togglePopup.bind(this) }, this.props.buttonText),
React.createElement("div", { className: "Popup-container " + dirString + " " + (this.state.isPopupOpen ? "is-open" : ""), style: this.props.popupStyle },
React.createElement("div", { className: "Popup-content u-padMd" },
React.createElement("div", { className: "u-textLeft" }, this.props.popUpText),
React.createElement("div", { className: "u-textCenter u-spaceTopMd" },
React.createElement("button", { onClick: this.props.onCancel, className: "u-spaceRightSm Button " + this.props.cancelButtonMods }, this.props.cancelButtonText),
React.createElement("button", { onClick: this.props.onAccept, className: "Button " + this.props.confirmButtonMods }, this.props.confirmButtonText))))));
};
Popup.propTypes = {
popUpMods: PropTypes.string,
popUpText: PropTypes.oneOfType([PropTypes.string, PropTypes.element])
.isRequired,
direction: PropTypes.arrayOf(PropTypes.oneOf(["down", "right", "left", "rightHang", "leftHang", "overlay"])),
popupStyle: PropTypes.object,
buttonText: PropTypes.oneOfType([PropTypes.string, PropTypes.func, PropTypes.element])
.isRequired,
buttonMods: PropTypes.string,
confirmButtonText: PropTypes.string,
confirmButtonMods: PropTypes.string,
cancelButtonText: PropTypes.string,
cancelButtonMods: PropTypes.string,
onAccept: PropTypes.func.isRequired,
onCancel: PropTypes.func
};
Popup.defaultProps = {
direction: ["overlay"],
popUpMods: "",
buttonMods: "Button--small",
confirmButtonText: "Confirm",
confirmButtonMods: "Button--primary",
cancelButtonText: "Cancel",
cancelButtonMods: "Button--negative",
};
return Popup;
}(React.Component));
exports.default = Popup;