UNPKG

@activecollab/components

Version:

ActiveCollab Components

71 lines 2.48 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose"; const _excluded = ["url", "alt", "size", "className", "imgClassName", "children"]; import React, { forwardRef, useState } from "react"; import { StyledAvatar, StyledWrapper } from "./Styles"; import { SkeletonLoader } from "../Loaders"; /** * @component Avatar * @description * The Avatar component is used to represent user, and displays the profile picture, initials or fallback icon. * * @prop {url} - The image url of the Avatar. * @prop {size} - controls the size of an Avatar (width and height) in pixels. * @prop {alt} - alt attribute of the img. * @prop {imgClassName} - class name that attaches to img element nested in Wrapper * * @example * <Avatar url="https://faces-img.xcdn.link/image-lorem-face-954.jpg" alt="Profile picture of John" /> * * @example * <Avatar * url="https://faces-img.xcdn.link/image-lorem-face-954.jpg" * alt="Profile picture of John"> * <Badge size={8} backgroundColor="green" position="bottom-left" /> * </Avatar> * * @see * https://system.activecollab.com/?path=/story/components-button-indicators-avatar--avatar * @see * https://design.activecollab.com/docs/components/avatar */ export const Avatar = /*#__PURE__*/forwardRef((_ref, ref) => { let url = _ref.url, _ref$alt = _ref.alt, alt = _ref$alt === void 0 ? "Avatar Image" : _ref$alt, _ref$size = _ref.size, size = _ref$size === void 0 ? 24 : _ref$size, className = _ref.className, imgClassName = _ref.imgClassName, children = _ref.children, rest = _objectWithoutPropertiesLoose(_ref, _excluded); const _useState = useState(false), imageLoaded = _useState[0], setImageLoaded = _useState[1]; return /*#__PURE__*/React.createElement(StyledWrapper, { className: className }, children, /*#__PURE__*/React.createElement(StyledAvatar, _extends({ ref: ref, src: url, alt: alt, width: size, height: size, onLoad: () => { setImageLoaded(true); }, role: "img", className: imgClassName, style: { display: imageLoaded ? "block" : "none" } }, rest)), !imageLoaded && /*#__PURE__*/React.createElement(SkeletonLoader, { "data-testid": "loader", style: { width: size, height: size, borderRadius: "100%" } })); }); Avatar.displayName = "Avatar"; //# sourceMappingURL=Avatar.js.map