UNPKG

dh-c

Version:

The front-end development engineers jimberton gulp react component

95 lines (73 loc) 3.26 kB
'use strict'; exports.__esModule = true; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _icon = require('../icon'); var _icon2 = _interopRequireDefault(_icon); 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$Component) { _inherits(Avatar, _React$Component); function Avatar(props) { _classCallCheck(this, Avatar); return _possibleConstructorReturn(this, _React$Component.call(this, props)); } Avatar.prototype.renderChildren = function renderChildren() { var _props = this.props, src = _props.src, icon = _props.icon, children = _props.children; if (children) { return children; } else if (src && typeof src === 'string') { return _react2.default.createElement('img', { src: src }); } else if (icon && typeof icon === 'string') { return _react2.default.createElement(_icon2.default, { type: icon }); } else { return _react2.default.createElement(_icon2.default, { type: 'destroy' }); } }; Avatar.prototype.render = function render() { var _props2 = this.props, backgroundColor = _props2.backgroundColor, size = _props2.size, fontSize = _props2.fontSize, color = _props2.color, radius = _props2.radius; return _react2.default.createElement( 'div', { style: { width: size, height: size, fontSize: fontSize, backgroundColor: backgroundColor, color: color }, className: (0, _classnames2.default)('dh-avatar', { 'dh-avatar-radius': radius && typeof radius === 'boolean' }) }, this.renderChildren() ); }; return Avatar; }(_react2.default.Component); Avatar.defaultProps = { icon: 'picture', radius: true }; Avatar.propsTypes = { size: _propTypes2.default.number, src: _propTypes2.default.string, icon: _propTypes2.default.string, color: _propTypes2.default.string, fontSize: _propTypes2.default.number, backgroundColor: _propTypes2.default.string }; exports.default = Avatar;