Repository URL to install this package:
|
Version:
3.15.0 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames2 = _interopRequireDefault(require("classnames"));
var _Icon = _interopRequireDefault(require("../../visuals/Icon"));
var _Menu = _interopRequireDefault(require("../../controls/Menu"));
var _UserAvatar = _interopRequireDefault(require("../UserAvatar"));
var _Button = require("../../controls/Button/Button");
var _Menu2 = require("../../controls/Menu/Menu");
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 _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); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
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 _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 _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var ArrowDown = function ArrowDown(props) {
return _react["default"].createElement("svg", props, _react["default"].createElement("path", {
d: "M7.41 7.84L12 12.42l4.59-4.58L18 9.25l-6 6-6-6z",
fill: "currentColor"
}));
};
ArrowDown.defaultProps = {
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 24 24"
};
var HELP_LINK = 'https://help.doodle.com';
var hasLabel = function hasLabel(_ref) {
var label = _ref.label;
return Boolean(label);
};
var UserMenu = /*#__PURE__*/function (_Component) {
_inherits(UserMenu, _Component);
function UserMenu() {
_classCallCheck(this, UserMenu);
return _possibleConstructorReturn(this, _getPrototypeOf(UserMenu).apply(this, arguments));
}
_createClass(UserMenu, [{
key: "render",
value: function render() {
var _this$props = this.props,
name = _this$props.name,
avatar = _this$props.avatar,
onClickLogout = _this$props.onClickLogout,
messages = _this$props.messages,
customItems = _this$props.customItems,
variant = _this$props.variant,
dimension = _this$props.dimension;
var defaultItems = [{
label: messages.dashboard,
to: '/dashboard'
}, {
label: messages.account,
to: '/account'
}];
var menuItems = [].concat(_toConsumableArray(defaultItems.filter(hasLabel)), _toConsumableArray(customItems), [{
label: messages.help,
to: HELP_LINK
}, {
label: messages.logout,
action: onClickLogout
}]);
var menuClassNames = (0, _classnames2["default"])('UserMenu', _defineProperty({}, "UserMenu--".concat(dimension), dimension));
return _react["default"].createElement(_Menu["default"], {
className: menuClassNames,
variant: variant,
horizontalAlign: "right",
items: menuItems,
dimension: dimension
}, _react["default"].createElement(_UserAvatar["default"], {
name: name,
avatar: avatar
}), _react["default"].createElement(_Icon["default"], {
icon: ArrowDown
}));
}
}]);
return UserMenu;
}(_react.Component);
_defineProperty(UserMenu, "propTypes", {
name: _propTypes["default"].string.isRequired,
avatar: _propTypes["default"].string,
onClickLogout: _propTypes["default"].func.isRequired,
messages: _propTypes["default"].shape({
dashboard: _propTypes["default"].node,
account: _propTypes["default"].node,
help: _propTypes["default"].node.isRequired,
logout: _propTypes["default"].node.isRequired
}).isRequired,
customItems: _propTypes["default"].arrayOf(_propTypes["default"].shape({
label: _propTypes["default"].shape({
id: _propTypes["default"].string,
defaultMessage: _propTypes["default"].string
}).isRequired,
to: _propTypes["default"].string,
action: _propTypes["default"].func
})),
variant: _propTypes["default"].oneOf(_Button.buttonVariants),
dimension: _propTypes["default"].oneOf(_Menu2.menuDimensions)
});
_defineProperty(UserMenu, "defaultProps", {
avatar: null,
customItems: [],
variant: 'linkWhite',
dimension: _Menu2.defaultMenuDimension
});
var _default = UserMenu;
exports["default"] = _default;