UNPKG

@shakthillc/components

Version:

React generic components for shakthi products

96 lines (76 loc) 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require("react"); var _react2 = _interopRequireDefault(_react); var _AvatarModule = require("./Avatar.module.css"); var _AvatarModule2 = _interopRequireDefault(_AvatarModule); var _propTypes = 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 _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var Avatar = function (_React$PureComponent) { _inherits(Avatar, _React$PureComponent); function Avatar() { _classCallCheck(this, Avatar); return _possibleConstructorReturn(this, (Avatar.__proto__ || Object.getPrototypeOf(Avatar)).apply(this, arguments)); } _createClass(Avatar, [{ key: "returnColor", value: function returnColor() { var color = ["#a3a398", "#b7a1f9", "#40a78c", "#D0EAF1", "#8FBCBC", "#cbcef9", "#76a5b4", "#5b9d60", "#B1DC88"]; return color[Math.floor(Math.random() * color.length)]; } }, { key: "returnNode", value: function returnNode() { var _props = this.props, imageUrl = _props.imageUrl, text = _props.text, size = _props.size; if (imageUrl && imageUrl !== "") { return _react2.default.createElement("div", { className: _AvatarModule2.default["avatar-img"], style: { backgroundImage: "url(" + imageUrl + ")", width: "" + size, height: "" + size } }); } else { return _react2.default.createElement( "div", { className: _AvatarModule2.default["avatar"], style: { width: size, height: size, backgroundColor: this.returnColor(), lineHeight: size } }, text[0].toUpperCase() ); } } }, { key: "render", value: function render() { return this.returnNode(); } }]); return Avatar; }(_react2.default.PureComponent); exports.default = Avatar; Avatar.defaultProps = { imageUrl: "", size: "24px" }; Avatar.propTypes = { imageUrl: _propTypes.PropTypes.string, text: _propTypes.PropTypes.string, size: _propTypes.PropTypes.string };