UNPKG

es6-react-admin-lte

Version:

An AdminLTE Template made to use as React components.

193 lines (161 loc) 9.46 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var HeaderUserMenu = /*#__PURE__*/function (_React$Component) { _inherits(HeaderUserMenu, _React$Component); var _super = _createSuper(HeaderUserMenu); function HeaderUserMenu(props) { var _this; _classCallCheck(this, HeaderUserMenu); _this = _super.call(this, props); _this.state = { open: false }; _this.toggleDropdown = _this.toggleDropdown.bind(_assertThisInitialized(_this)); _this.clickLinks = _this.clickLinks.bind(_assertThisInitialized(_this)); return _this; } _createClass(HeaderUserMenu, [{ key: "toggleDropdown", value: function toggleDropdown(e) { if (e.type === 'blur' && this.state.open || e.type !== 'blur') { this.setState({ open: !this.state.open }); } } }, { key: "clickLinks", value: function clickLinks(e) { e.preventDefault(); e.stopPropagation(); switch (e.currentTarget.id.replace('user-menu-', '')) { case 'followers': if (this.props.followersOnClick) { this.props.followersOnClick(); } break; case 'sales': if (this.props.salesOnClick) { this.props.salesOnClick(); } break; case 'friends': if (this.props.friendsOnClick) { this.props.friendsOnClick(); } break; case 'profile': if (this.props.profileOnClick) { this.props.profileOnClick(); } break; default: break; } } }, { key: "render", value: function render() { return /*#__PURE__*/_react["default"].createElement("li", { className: "dropdown user user-menu".concat(this.state.open ? ' open' : ''), tabIndex: "0", onBlur: this.toggleDropdown }, /*#__PURE__*/_react["default"].createElement("a", { className: "dropdown-toggle", "data-toggle": "dropdown-menu", onClick: this.toggleDropdown }, this.props.img ? /*#__PURE__*/_react["default"].createElement("img", { src: this.props.img, className: "user-image", alt: "User Avatar" }) : '', /*#__PURE__*/_react["default"].createElement("span", { className: "hidden-xs" }, this.props.username)), /*#__PURE__*/_react["default"].createElement("ul", { className: "dropdown-menu" }, /*#__PURE__*/_react["default"].createElement("li", { className: "user-header" }, this.props.img ? /*#__PURE__*/_react["default"].createElement("img", { src: this.props.img, className: "img-circle", alt: "User Avatar" }) : '', /*#__PURE__*/_react["default"].createElement("p", null, this.props.name, this.props.jobTitle ? " - ".concat(this.props.jobTitle) : '', /*#__PURE__*/_react["default"].createElement("small", null, "Member since ", this.props.joined))), this.props.friendsLink || this.props.salesLink || this.props.followersLink || this.props.friendsOnClick || this.props.salesOnClick || this.props.followersOnClick || this.props.children ? /*#__PURE__*/_react["default"].createElement("li", { className: "user-body" }, this.props.children, this.props.followersLink || this.props.followersOnClick ? /*#__PURE__*/_react["default"].createElement("div", { className: "col-xs-4 text-center" }, /*#__PURE__*/_react["default"].createElement("a", { id: "user-menu-followers", href: this.props.followersLink, onClick: this.clickLinks }, "Followers")) : '', this.props.salesLink || this.props.salesOnClick ? /*#__PURE__*/_react["default"].createElement("div", { className: "col-xs-4 text-center" }, /*#__PURE__*/_react["default"].createElement("a", { id: "user-menu-sales", href: this.props.salesLink, onClick: this.clickLinks }, "Sales")) : '', this.props.friendsLink || this.props.friendsOnClick ? /*#__PURE__*/_react["default"].createElement("div", { className: "col-xs-4 text-center" }, /*#__PURE__*/_react["default"].createElement("a", { id: "user-menu-friends", href: this.props.friendsLink, onClick: this.clickLinks }, "Friends")) : '') : '', /*#__PURE__*/_react["default"].createElement("li", { className: "user-footer" }, this.props.profileLink || this.props.profileOnClick ? /*#__PURE__*/_react["default"].createElement("div", { className: "pull-left" }, /*#__PURE__*/_react["default"].createElement("a", { id: "user-menu-profile", href: this.props.profileLink, onClick: this.clickLinks, className: "btn btn-default btn-flat" }, "Profile")) : '', this.props.signOut ? /*#__PURE__*/_react["default"].createElement("div", { className: this.props.profileLink || this.props.profileOnClick ? 'pull-right' : 'text-center' }, /*#__PURE__*/_react["default"].createElement("a", { className: "btn btn-default btn-flat", onClick: this.props.signOut }, "Sign Out")) : ''))); } }]); return HeaderUserMenu; }(_react["default"].Component); HeaderUserMenu.propTypes = { username: _propTypes["default"].string, name: _propTypes["default"].string, jobTitle: _propTypes["default"].string, img: _propTypes["default"].string, profileLink: _propTypes["default"].string, profileOnClick: _propTypes["default"].func, followersLink: _propTypes["default"].string, followersOnClick: _propTypes["default"].func, salesLink: _propTypes["default"].string, salesOnClick: _propTypes["default"].func, friendsLink: _propTypes["default"].string, friendsOnClick: _propTypes["default"].func, joined: _propTypes["default"].string, signOut: _propTypes["default"].func }; HeaderUserMenu.defaultProps = { username: '', name: '', joined: '' }; var _default = HeaderUserMenu; exports["default"] = _default; module.exports = exports.default; //# sourceMappingURL=header-user-menu.js.map