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