@carbon/ibm-security
Version:
Carbon for Cloud & Cognitive IBM Security UI components
57 lines (55 loc) • 2.21 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["className", "large", "profile"];
/**
* @file Profile image.
* @copyright IBM Security 2019
*/
import classnames from 'classnames';
import PropTypes from 'prop-types';
import React from 'react';
import { getComponentNamespace } from '../../globals/namespace';
export var namespace = getComponentNamespace('profile-image');
/**
* Profile image component.
* @param {Record<string, any>} props Profile image props.
* @returns {ProfileImage} Profile image instance.
*/
var ProfileImage = function ProfileImage(_ref) {
var className = _ref.className,
large = _ref.large,
profile = _ref.profile,
other = _objectWithoutProperties(_ref, _excluded);
var classNames = classnames(namespace, className, _defineProperty({}, "".concat(namespace, "--large"), large));
return profile.image_url ? /*#__PURE__*/React.createElement("img", _extends({
className: classNames,
alt: "".concat(profile.name.first_name, " ").concat(profile.name.surname),
src: profile.image_url
}, other)) : /*#__PURE__*/React.createElement("span", _extends({
className: classNames
}, other), "".concat(profile.name.first_name.charAt(0)).concat(profile.name.surname.charAt(0)));
};
ProfileImage.defaultProps = {
className: null,
large: false
};
ProfileImage.propTypes = {
/** @type {string} Extra classes. */
className: PropTypes.string,
/** @type {boolean} Determines whether the profile image is large or not. */
large: PropTypes.bool,
/** @type {Record<string, any>} An object list of profile information. */
profile: PropTypes.shape({
/** @type {string} Profile image URL. */
image_url: PropTypes.string,
/** @type {Record<string, string>} An object list of profile name information. */
name: PropTypes.shape({
/** @type {string} First name. */
first_name: PropTypes.string.isRequired,
/** @type {string} Surname. */
surname: PropTypes.string.isRequired
}).isRequired
}).isRequired
};
export default ProfileImage;