Repository URL to install this package:
|
Version:
8.1.0-rc.1 ▾
|
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _commonMessages = require("@doodle/common-messages");
var _Button = _interopRequireWildcard(require("../../controls/Button/Button"));
var _helper = _interopRequireDefault(require("../../utils/helper"));
var _translate = require("../../utils/translate");
var _UserMenu = _interopRequireDefault(require("../UserMenu"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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); 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 } }); 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; } 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 { Date.prototype.toString.call(Reflect.construct(Date, [], 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); }
/**
* The HeaderWidget (or user area), is a component representing the current user
* state. It changes appearance depending on whether there's a logged-in user or
* not. If a user is logged in, it displays the `UserMenu` for that user. If no
* user is logged in, it displays a sign up and a log in button.
*
* It's an independent component that can be used anywhere but is mainly
* intended to be placed inside an instance of the `Header` component (usually
* on the right-hand side).
*
* This previously lived in the lib-users-api-connector but was moved here.
*/
var HeaderWidget = /*#__PURE__*/function (_Component) {
_inherits(HeaderWidget, _Component);
var _super = _createSuper(HeaderWidget);
function HeaderWidget(props) {
var _this;
_classCallCheck(this, HeaderWidget);
_this = _super.call(this, props);
_this.handleClickLogin = _this.handleClickLogin.bind(_assertThisInitialized(_this));
_this.handleClickSignup = _this.handleClickSignup.bind(_assertThisInitialized(_this));
return _this;
}
/**
* Handles calling the onClickLogin and passes the default behaviour
* into the onClickLogin callback as an argument.
* To override or add behaviour, see onClickLogin prop.
*/
_createClass(HeaderWidget, [{
key: "handleClickLogin",
value: function handleClickLogin() {
var onClickLogin = this.props.onClickLogin;
onClickLogin(function () {
return (0, _helper["default"])('/login');
});
}
/**
* Handles calling the onClickSignup and passes the default behaviour
* into the onClickSignup callback as an argument.
* To override or add behaviour, see onClickSignup prop.
*/
}, {
key: "handleClickSignup",
value: function handleClickSignup() {
var onClickSignup = this.props.onClickSignup;
onClickSignup(function () {
return (0, _helper["default"])('/signup');
});
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
isLoggedIn = _this$props.isLoggedIn,
onClickLogout = _this$props.onClickLogout,
username = _this$props.username,
userAvatar = _this$props.userAvatar,
userMenuItems = _this$props.userMenuItems,
shouldHideAuthDialog = _this$props.shouldHideAuthDialog,
buttonVariant = _this$props.buttonVariant,
loginSignupButtonsVariant = _this$props.loginSignupButtonsVariant,
hideName = _this$props.hideName,
intl = _this$props.intl,
isOrgAdmin = _this$props.isOrgAdmin,
showSignUp = _this$props.showSignUp;
var elementsArray = [];
if (isLoggedIn) {
elementsArray.push( /*#__PURE__*/_react["default"].createElement(_UserMenu["default"], {
key: "user-menu",
name: hideName ? null : username,
avatar: userAvatar,
onClickLogout: onClickLogout,
customItems: userMenuItems,
variant: buttonVariant,
intl: intl,
isOrgAdmin: isOrgAdmin
}));
} else if (!shouldHideAuthDialog && showSignUp) {
elementsArray.push( /*#__PURE__*/_react["default"].createElement(_Button["default"], {
className: "HeaderWidget-signupButton u-padRight",
variant: loginSignupButtonsVariant,
dimension: "compact",
onClick: this.handleClickSignup,
key: "signup-button"
}, (0, _translate.translate)(_commonMessages.messages.signup, intl)), /*#__PURE__*/_react["default"].createElement(_Button["default"], {
className: "HeaderWidget-loginButton",
variant: loginSignupButtonsVariant,
dimension: "compact",
onClick: this.handleClickLogin,
key: "login-button"
}, (0, _translate.translate)(_commonMessages.messages.login, intl)));
} else if (!shouldHideAuthDialog) {
elementsArray.push( /*#__PURE__*/_react["default"].createElement(_Button["default"], {
className: "HeaderWidget-loginButton",
variant: loginSignupButtonsVariant,
dimension: "compact",
onClick: this.handleClickLogin,
key: "login-button"
}, (0, _translate.translate)(_commonMessages.messages.login, intl)));
}
return /*#__PURE__*/_react["default"].createElement("div", {
className: "HeaderWidget"
}, elementsArray);
}
}]);
return HeaderWidget;
}(_react.Component);
HeaderWidget.propTypes = {
/** Check if the user is logged in */
isLoggedIn: _propTypes["default"].bool.isRequired,
/**
* Callback executed when the user clicks on the "Login" button.
* It can be overridden to add custom functionality such as tracking.
* You can execute the default button behaviour within onClickLogin by running
* the function provided as first parameter. If your custom code is asynchronous,
* run the default behaviour as callback of your asynchronous action. This guarantees
* that your custom action completes before navigating to another page.
* @param {Function} defaultBehaviour - Function to execute the default click behaviour
*/
onClickLogin: _propTypes["default"].func,
/**
* Callback executed when the user clicks on the "Logout" button.
* It can be overridden to add custom functionality such as tracking.
* You can execute the default button behaviour within onClickLogout by running
* the function provided as first parameter. If your custom code is asynchronous,
* run the default behaviour as callback of your asynchronous action. This guarantees
* that your custom action completes before navigating to another page.
* @param {Function} defaultBehaviour - Function to execute the default click behaviour
*/
onClickLogout: _propTypes["default"].func,
/**
* Callback executed when the user clicks on the "Signup" button.
* It can be overridden to add custom functionality such as tracking.
* You can execute the default button behaviour within onClickSignup by running
* the function provided as first parameter. If your custom code is asynchronous,
* run the default behaviour as callback of your asynchronous action. This guarantees
* that your custom action completes before navigating to another page.
* @param {Function} defaultBehaviour - Function to execute the default click behaviour
*/
onClickSignup: _propTypes["default"].func,
/** User name coming from user object */
username: _propTypes["default"].string,
/** User avatar coming from user object */
userAvatar: _propTypes["default"].string,
/** If logged in user is admin of an organization */
isOrgAdmin: _propTypes["default"].bool,
/** Menu Items passed into the UserMenu
*/
userMenuItems: _propTypes["default"].array,
/** Hide Auth Dialog - defaults to false
*/
shouldHideAuthDialog: _propTypes["default"].bool,
/** Defaults to linkDark */
buttonVariant: _propTypes["default"].oneOf(_Button.buttonVariants),
/** Defaults to whiteWithBorder */
loginSignupButtonsVariant: _propTypes["default"].oneOf(_Button.buttonVariants),
/** Do not display user's name - defaults to false */
hideName: _propTypes["default"].bool,
/** Object for internationalization */
intl: _propTypes["default"].object,
/** Show Sign Up Button - defaults to true */
showSignUp: _propTypes["default"].bool
};
HeaderWidget.defaultProps = {
onClickLogin: function onClickLogin(defaultBehaviour) {
return defaultBehaviour();
},
onClickLogout: function onClickLogout(defaultBehaviour) {
return defaultBehaviour();
},
onClickSignup: function onClickSignup(defaultBehaviour) {
return defaultBehaviour();
},
username: null,
userAvatar: null,
isOrgAdmin: false,
userMenuItems: [],
shouldHideAuthDialog: false,
buttonVariant: 'linkDark',
loginSignupButtonsVariant: 'whiteWithBorder',
hideName: false,
intl: null,
showSignUp: true
};
var _default = HeaderWidget;
exports["default"] = _default;