UNPKG

@activecollab/components

Version:

ActiveCollab Components

105 lines (104 loc) 4.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MultiAvatar = void 0; var _react = _interopRequireWildcard(require("react")); var _Styles = require("./Styles"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * @component MultiAvatar * @description * The MultiAvatar component is used to represent user, and displays the profile picture, initials or fallback icon. * * @prop {url} - The image urls of the MultiAvatar. * @prop {size} - controls the size of an MultiAvatar (width and height) in pixels. * @prop {alt} - alt attributes of the imgs. * * @example * <MultiAvatar * url={["https://faces-img.xcdn.link/image-lorem-face-954.jpg", "https://faces-img.xcdn.link/image-lorem-face-953.jpg"]} * alt={["Profile picture of John", "Profile picture of Sarah"]} /> * * @example * <MultiAvatar * url={["https://faces-img.xcdn.link/image-lorem-face-954.jpg", "https://faces-img.xcdn.link/image-lorem-face-953.jpg"]} * alt={["Profile picture of John", "Profile picture of Sarah"]} * > * <Badge /> * </MultiAvatar> * * @see * https://system.activecollab.com/?path=/story/components-button-indicators-avatar--avatar * @see * https://design.activecollab.com/docs/components/avatar */ var MultiAvatar = exports.MultiAvatar = function MultiAvatar(_ref) { var url = _ref.url, alt = _ref.alt, _ref$size = _ref.size, size = _ref$size === void 0 ? 24 : _ref$size, className = _ref.className, children = _ref.children; var setSize = (0, _react.useCallback)(function (i) { switch (url.length) { case 1: return { width: "".concat(size, "px"), height: "".concat(size, "px") }; case 2: return { width: "".concat(size / 2, "px"), height: "".concat(size, "px") }; case 3: if (i === 0) { return { width: "".concat(size / 2, "px"), height: "".concat(size, "px") }; } else { return { width: "".concat(size / 2, "px"), height: "".concat(size / 2, "px") }; } default: return { width: "".concat(size / 2, "px"), height: "".concat(size / 2, "px") }; } }, [size, url.length]); var slicedUrl = (0, _react.useMemo)(function () { if ((url === null || url === void 0 ? void 0 : url.length) > 4) { return url.slice(0, 4); } return url; }, [url]); return /*#__PURE__*/_react.default.createElement("span", { className: "tw-relative tw-inline-flex" }, /*#__PURE__*/_react.default.createElement(_Styles.StyledMultiAvatar, { style: { width: "".concat(size, "px"), height: "".concat(size, "px") }, className: className, $urlCount: url.length }, slicedUrl.map(function (v, i) { return /*#__PURE__*/_react.default.createElement(_Styles.StyledMultiAvatarInner, { style: setSize(i), className: "c-multi-avatar__wrapper", key: "avatar_".concat(i) }, /*#__PURE__*/_react.default.createElement("img", { src: v, alt: alt && alt[i] ? alt[i] : "avatar_".concat(i), width: size, height: size })); })), children); }; MultiAvatar.displayName = "MultiAvatar"; //# sourceMappingURL=MultiAvatar.js.map