@homebound/beam 2.186.3 → 2.186.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Avatar = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
const Icon_1 = require("./Icon");
|
|
6
7
|
const Css_1 = require("../Css");
|
|
7
8
|
const utils_1 = require("../utils");
|
|
8
9
|
function Avatar({ src, name, size = "md", showName = false, ...others }) {
|
|
@@ -10,8 +11,8 @@ function Avatar({ src, name, size = "md", showName = false, ...others }) {
|
|
|
10
11
|
const px = sizeToPixel[size];
|
|
11
12
|
const [showFallback, setShowFallback] = (0, react_1.useState)(src === undefined);
|
|
12
13
|
const styles = Css_1.Css.br100.wPx(px).hPx(px).overflowHidden.$;
|
|
13
|
-
const img = showFallback ? ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: { ...styles, ...Css_1.Css[sizeToFallbackTypeScale[size]].
|
|
14
|
-
return showName ? ((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.dif.aic.gap1.if(size === "lg" || size === "xl").fdc.$ }, { children: [img, (0, jsx_runtime_1.jsx)("span", Object.assign({ css: Css_1.Css[sizeToTypeScale[size]].$ }, { children: name }), void 0)] }), void 0)) : (img);
|
|
14
|
+
const img = showFallback ? ((0, jsx_runtime_1.jsx)("div", Object.assign({ css: { ...styles, ...Css_1.Css[sizeToFallbackTypeScale[size]].bgGray400.gray100.df.aic.jcc.$ } }, tid, { children: name ? nameToInitials(name) : (0, jsx_runtime_1.jsx)(Icon_1.Icon, { icon: "userCircle", inc: sizeToIconInc[size] }, void 0) }), void 0)) : ((0, jsx_runtime_1.jsx)("img", Object.assign({ src: src, alt: name, css: { ...styles, ...Css_1.Css.objectCover.$ }, onError: () => setShowFallback(true), loading: "lazy" }, tid), void 0));
|
|
15
|
+
return showName && name ? ((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: Css_1.Css.dif.aic.gap1.if(size === "lg" || size === "xl").fdc.$ }, { children: [img, (0, jsx_runtime_1.jsx)("span", Object.assign({ css: Css_1.Css[sizeToTypeScale[size]].$ }, { children: name }), void 0)] }), void 0)) : (img);
|
|
15
16
|
}
|
|
16
17
|
exports.Avatar = Avatar;
|
|
17
18
|
const sizeToPixel = {
|
|
@@ -26,6 +27,12 @@ const sizeToFallbackTypeScale = {
|
|
|
26
27
|
lg: "lg",
|
|
27
28
|
xl: "xl3",
|
|
28
29
|
};
|
|
30
|
+
const sizeToIconInc = {
|
|
31
|
+
sm: 2.5,
|
|
32
|
+
md: 4,
|
|
33
|
+
lg: 5,
|
|
34
|
+
xl: 8,
|
|
35
|
+
};
|
|
29
36
|
const sizeToTypeScale = {
|
|
30
37
|
sm: "baseMd",
|
|
31
38
|
md: "baseMd",
|
|
@@ -35,7 +42,7 @@ const sizeToTypeScale = {
|
|
|
35
42
|
function nameToInitials(name) {
|
|
36
43
|
return (name
|
|
37
44
|
.split(" ")
|
|
38
|
-
.map((n) => n[0].toUpperCase())
|
|
45
|
+
.map((n) => (n.length > 0 ? n[0].toUpperCase() : ""))
|
|
39
46
|
.join("")
|
|
40
47
|
// Return at most 3 initials
|
|
41
48
|
.slice(0, 3));
|