@activecollab/components
Version:
ActiveCollab Components
104 lines (103 loc) • 3.91 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.MultiAvatar = void 0;
var _react = _interopRequireWildcard(require("react"));
var _Styles = require("./Styles");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
/**
* @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