@tamagui/avatar 2.7.7 → 3.0.0-beta.643.1
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.
- package/dist/cjs/Avatar.cjs +103 -122
- package/dist/cjs/Avatar.native.cjs +151 -0
- package/dist/cjs/Avatar.native.js +109 -140
- package/dist/cjs/Avatar.native.js.map +1 -1
- package/dist/cjs/index.cjs +10 -11
- package/dist/cjs/index.native.cjs +21 -0
- package/dist/cjs/index.native.js +10 -10
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/Avatar.mjs +83 -94
- package/dist/esm/Avatar.mjs.map +1 -1
- package/dist/esm/Avatar.native.js +90 -114
- package/dist/esm/Avatar.native.js.map +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/index.native.js +1 -2
- package/dist/jsx/Avatar.mjs +83 -94
- package/dist/jsx/Avatar.mjs.map +1 -1
- package/dist/jsx/Avatar.native.cjs +151 -0
- package/dist/jsx/Avatar.native.js +109 -140
- package/dist/jsx/Avatar.native.js.map +1 -1
- package/dist/jsx/index.js +1 -2
- package/dist/jsx/index.mjs +1 -2
- package/dist/jsx/index.native.cjs +21 -0
- package/dist/jsx/index.native.js +10 -10
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +10 -10
- package/src/Avatar.tsx +31 -29
- package/types/Avatar.d.ts +55 -60
- package/types/Avatar.d.ts.map +1 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js.map +0 -1
- package/dist/jsx/index.js.map +0 -1
- package/dist/jsx/index.mjs.map +0 -1
package/dist/cjs/Avatar.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -5,40 +6,33 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
5
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
8
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
for (var name in all) __defProp(target, name, {
|
|
10
|
+
get: all[name],
|
|
11
|
+
enumerable: true
|
|
12
|
+
});
|
|
12
13
|
};
|
|
13
14
|
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
21
22
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
+
value: mod,
|
|
25
|
+
enumerable: true
|
|
30
26
|
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
28
|
var Avatar_exports = {};
|
|
35
29
|
__export(Avatar_exports, {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
Avatar: () => Avatar,
|
|
31
|
+
AvatarFallback: () => AvatarFallback,
|
|
32
|
+
AvatarFallbackFrame: () => AvatarFallbackFrame,
|
|
33
|
+
AvatarFrame: () => AvatarFrame,
|
|
34
|
+
AvatarImage: () => AvatarImage,
|
|
35
|
+
createAvatarScope: () => createAvatarScope
|
|
42
36
|
});
|
|
43
37
|
module.exports = __toCommonJS(Avatar_exports);
|
|
44
38
|
var import_core = require("@tamagui/core");
|
|
@@ -53,108 +47,95 @@ const AVATAR_NAME = "Avatar";
|
|
|
53
47
|
const [createAvatarContext, createAvatarScope] = (0, import_create_context.createContextScope)(AVATAR_NAME);
|
|
54
48
|
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
55
49
|
const IMAGE_NAME = "AvatarImage";
|
|
56
|
-
const AvatarImage =
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
onLoad: () => {
|
|
100
|
-
setStatus("loaded");
|
|
101
|
-
}
|
|
102
|
-
})
|
|
103
|
-
});
|
|
50
|
+
const AvatarImage = (0, import_core.createRefComponent)((props, forwardedRef) => {
|
|
51
|
+
const { __scopeAvatar, src, source, onLoadingStatusChange = () => {}, ...imageProps } = props;
|
|
52
|
+
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
53
|
+
const [status, setStatus] = React.useState("idle");
|
|
54
|
+
const resolvedSrc = src || (source && typeof source === "object" && "uri" in source ? source.uri : source);
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
if (!resolvedSrc) {
|
|
57
|
+
setStatus("error");
|
|
58
|
+
} else {
|
|
59
|
+
setStatus("idle");
|
|
60
|
+
}
|
|
61
|
+
}, [resolvedSrc]);
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
onLoadingStatusChange(status);
|
|
64
|
+
context.onImageLoadingStatusChange(status);
|
|
65
|
+
}, [status]);
|
|
66
|
+
if (!resolvedSrc) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, {
|
|
70
|
+
position: "absolute",
|
|
71
|
+
inset: 0,
|
|
72
|
+
zIndex: 1,
|
|
73
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image.Image, {
|
|
74
|
+
position: "absolute",
|
|
75
|
+
top: 0,
|
|
76
|
+
left: 0,
|
|
77
|
+
right: 0,
|
|
78
|
+
bottom: 0,
|
|
79
|
+
objectFit: "cover",
|
|
80
|
+
width: "100%",
|
|
81
|
+
height: "100%",
|
|
82
|
+
...imageProps,
|
|
83
|
+
ref: forwardedRef,
|
|
84
|
+
src: resolvedSrc,
|
|
85
|
+
onError: () => {
|
|
86
|
+
setStatus("error");
|
|
87
|
+
},
|
|
88
|
+
onLoad: () => {
|
|
89
|
+
setStatus("loaded");
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
});
|
|
104
93
|
});
|
|
105
94
|
AvatarImage.displayName = IMAGE_NAME;
|
|
106
95
|
const FALLBACK_NAME = "AvatarFallback";
|
|
107
96
|
const AvatarFallbackFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
97
|
+
displayName: FALLBACK_NAME,
|
|
98
|
+
position: "absolute",
|
|
99
|
+
inset: 0,
|
|
100
|
+
zIndex: 0
|
|
112
101
|
});
|
|
113
|
-
const AvatarFallback =
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
|
|
128
|
-
...fallbackProps,
|
|
129
|
-
ref: forwardedRef
|
|
130
|
-
}) : null;
|
|
102
|
+
const AvatarFallback = (0, import_core.createStyledHOC)(AvatarFallbackFrame, (props, forwardedRef) => {
|
|
103
|
+
const { __scopeAvatar, delay, ...fallbackProps } = props;
|
|
104
|
+
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
105
|
+
const [canRender, setCanRender] = React.useState(delay === void 0);
|
|
106
|
+
React.useEffect(() => {
|
|
107
|
+
if (delay !== void 0) {
|
|
108
|
+
const timerId = setTimeout(() => setCanRender(true), delay);
|
|
109
|
+
return () => clearTimeout(timerId);
|
|
110
|
+
}
|
|
111
|
+
}, [delay]);
|
|
112
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
|
|
113
|
+
...fallbackProps,
|
|
114
|
+
ref: forwardedRef
|
|
115
|
+
}) : null;
|
|
131
116
|
});
|
|
132
117
|
AvatarFallback.displayName = FALLBACK_NAME;
|
|
133
118
|
const AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
119
|
+
displayName: AVATAR_NAME,
|
|
120
|
+
position: "relative",
|
|
121
|
+
overflow: "hidden"
|
|
137
122
|
});
|
|
138
|
-
const Avatar = (0, import_helpers.withStaticProperties)(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
...avatarProps,
|
|
153
|
-
ref: forwardedRef
|
|
154
|
-
})
|
|
155
|
-
});
|
|
123
|
+
const Avatar = (0, import_helpers.withStaticProperties)((0, import_core.createRefComponent)((props, forwardedRef) => {
|
|
124
|
+
const { __scopeAvatar, size = true, ...avatarProps } = props;
|
|
125
|
+
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
126
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarProvider, {
|
|
127
|
+
size,
|
|
128
|
+
scope: __scopeAvatar,
|
|
129
|
+
imageLoadingStatus,
|
|
130
|
+
onImageLoadingStatusChange: setImageLoadingStatus,
|
|
131
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFrame, {
|
|
132
|
+
size,
|
|
133
|
+
...avatarProps,
|
|
134
|
+
ref: forwardedRef
|
|
135
|
+
})
|
|
136
|
+
});
|
|
156
137
|
}), {
|
|
157
|
-
|
|
158
|
-
|
|
138
|
+
Image: AvatarImage,
|
|
139
|
+
Fallback: AvatarFallback
|
|
159
140
|
});
|
|
160
|
-
Avatar.displayName = AVATAR_NAME;
|
|
141
|
+
Avatar.displayName = AVATAR_NAME;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all) __defProp(target, name, {
|
|
12
|
+
get: all[name],
|
|
13
|
+
enumerable: true
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
19
|
+
get: () => from[key],
|
|
20
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: true
|
|
28
|
+
}) : target, mod));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var Avatar_exports = {};
|
|
31
|
+
__export(Avatar_exports, {
|
|
32
|
+
Avatar: () => Avatar,
|
|
33
|
+
AvatarFallback: () => AvatarFallback,
|
|
34
|
+
AvatarFallbackFrame: () => AvatarFallbackFrame,
|
|
35
|
+
AvatarFrame: () => AvatarFrame,
|
|
36
|
+
AvatarImage: () => AvatarImage,
|
|
37
|
+
createAvatarScope: () => createAvatarScope
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(Avatar_exports);
|
|
40
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
41
|
+
var import_core = require("@tamagui/core");
|
|
42
|
+
var import_create_context = require("@tamagui/create-context");
|
|
43
|
+
var import_helpers = require("@tamagui/helpers");
|
|
44
|
+
var import_image = require("@tamagui/image");
|
|
45
|
+
var import_shapes = require("@tamagui/shapes");
|
|
46
|
+
var import_stacks = require("@tamagui/stacks");
|
|
47
|
+
var React = __toESM(require("react"), 1);
|
|
48
|
+
function _type_of(obj) {
|
|
49
|
+
"@swc/helpers - typeof";
|
|
50
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
51
|
+
}
|
|
52
|
+
var AVATAR_NAME = "Avatar";
|
|
53
|
+
var [createAvatarContext, createAvatarScope] = (0, import_create_context.createContextScope)(AVATAR_NAME);
|
|
54
|
+
var [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
55
|
+
var IMAGE_NAME = "AvatarImage";
|
|
56
|
+
var AvatarImage = (0, import_core.createRefComponent)(function(props, forwardedRef) {
|
|
57
|
+
var { __scopeAvatar, src, source, onLoadingStatusChange = function() {}, ...imageProps } = props;
|
|
58
|
+
var context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
59
|
+
var [status, setStatus] = React.useState("idle");
|
|
60
|
+
var resolvedSrc = src || (source && (typeof source === "undefined" ? "undefined" : _type_of(source)) === "object" && "uri" in source ? source.uri : source);
|
|
61
|
+
React.useEffect(function() {
|
|
62
|
+
if (!resolvedSrc) {
|
|
63
|
+
setStatus("error");
|
|
64
|
+
} else {
|
|
65
|
+
setStatus("idle");
|
|
66
|
+
}
|
|
67
|
+
}, [resolvedSrc]);
|
|
68
|
+
React.useEffect(function() {
|
|
69
|
+
onLoadingStatusChange(status);
|
|
70
|
+
context.onImageLoadingStatusChange(status);
|
|
71
|
+
}, [status]);
|
|
72
|
+
if (!resolvedSrc) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, {
|
|
76
|
+
position: "absolute",
|
|
77
|
+
inset: 0,
|
|
78
|
+
zIndex: 1,
|
|
79
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_image.Image, {
|
|
80
|
+
position: "absolute",
|
|
81
|
+
top: 0,
|
|
82
|
+
left: 0,
|
|
83
|
+
right: 0,
|
|
84
|
+
bottom: 0,
|
|
85
|
+
objectFit: "cover",
|
|
86
|
+
width: "100%",
|
|
87
|
+
height: "100%",
|
|
88
|
+
...imageProps,
|
|
89
|
+
ref: forwardedRef,
|
|
90
|
+
src: resolvedSrc,
|
|
91
|
+
onError: function() {
|
|
92
|
+
setStatus("error");
|
|
93
|
+
},
|
|
94
|
+
onLoad: function() {
|
|
95
|
+
setStatus("loaded");
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
AvatarImage.displayName = IMAGE_NAME;
|
|
101
|
+
var FALLBACK_NAME = "AvatarFallback";
|
|
102
|
+
var AvatarFallbackFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
103
|
+
displayName: FALLBACK_NAME,
|
|
104
|
+
position: "absolute",
|
|
105
|
+
inset: 0,
|
|
106
|
+
zIndex: 0
|
|
107
|
+
});
|
|
108
|
+
var AvatarFallback = (0, import_core.createStyledHOC)(AvatarFallbackFrame, function(props, forwardedRef) {
|
|
109
|
+
var { __scopeAvatar, delay, ...fallbackProps } = props;
|
|
110
|
+
var context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
111
|
+
var [canRender, setCanRender] = React.useState(delay === void 0);
|
|
112
|
+
React.useEffect(function() {
|
|
113
|
+
if (delay !== void 0) {
|
|
114
|
+
var timerId = setTimeout(function() {
|
|
115
|
+
return setCanRender(true);
|
|
116
|
+
}, delay);
|
|
117
|
+
return function() {
|
|
118
|
+
return clearTimeout(timerId);
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}, [delay]);
|
|
122
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFallbackFrame, {
|
|
123
|
+
...fallbackProps,
|
|
124
|
+
ref: forwardedRef
|
|
125
|
+
}) : null;
|
|
126
|
+
});
|
|
127
|
+
AvatarFallback.displayName = FALLBACK_NAME;
|
|
128
|
+
var AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
|
|
129
|
+
displayName: AVATAR_NAME,
|
|
130
|
+
position: "relative",
|
|
131
|
+
overflow: "hidden"
|
|
132
|
+
});
|
|
133
|
+
var Avatar = (0, import_helpers.withStaticProperties)((0, import_core.createRefComponent)(function(props, forwardedRef) {
|
|
134
|
+
var { __scopeAvatar, size = true, ...avatarProps } = props;
|
|
135
|
+
var [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarProvider, {
|
|
137
|
+
size,
|
|
138
|
+
scope: __scopeAvatar,
|
|
139
|
+
imageLoadingStatus,
|
|
140
|
+
onImageLoadingStatusChange: setImageLoadingStatus,
|
|
141
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFrame, {
|
|
142
|
+
size,
|
|
143
|
+
...avatarProps,
|
|
144
|
+
ref: forwardedRef
|
|
145
|
+
})
|
|
146
|
+
});
|
|
147
|
+
}), {
|
|
148
|
+
Image: AvatarImage,
|
|
149
|
+
Fallback: AvatarFallback
|
|
150
|
+
});
|
|
151
|
+
Avatar.displayName = AVATAR_NAME;
|