@tamagui/avatar 1.14.1 → 1.14.3
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.js +150 -1
- package/dist/cjs/Avatar.js.map +2 -2
- package/dist/cjs/index.js +18 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/Avatar.js +116 -1
- package/dist/esm/Avatar.js.map +2 -2
- package/dist/esm/Avatar.mjs +116 -1
- package/dist/esm/Avatar.mjs.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/index.mjs.map +1 -1
- package/dist/jsx/Avatar.js +107 -1
- package/dist/jsx/Avatar.js.map +2 -2
- package/dist/jsx/Avatar.mjs +107 -1
- package/dist/jsx/Avatar.mjs.map +2 -2
- package/dist/jsx/index.js +1 -1
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -1
- package/dist/jsx/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/cjs/Avatar.js
CHANGED
|
@@ -1,2 +1,151 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
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_image = require("@tamagui/image");
|
|
43
|
+
var import_shapes = require("@tamagui/shapes");
|
|
44
|
+
var import_stacks = require("@tamagui/stacks");
|
|
45
|
+
var React = __toESM(require("react"));
|
|
46
|
+
const AVATAR_NAME = "Avatar";
|
|
47
|
+
const [createAvatarContext, createAvatarScope] = (0, import_create_context.createContextScope)(AVATAR_NAME);
|
|
48
|
+
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
49
|
+
const IMAGE_NAME = "AvatarImage";
|
|
50
|
+
const AvatarImage = React.forwardRef(
|
|
51
|
+
(props, forwardedRef) => {
|
|
52
|
+
var _a;
|
|
53
|
+
const { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
54
|
+
}, ...imageProps } = props;
|
|
55
|
+
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
56
|
+
const [status, setStatus] = React.useState("idle");
|
|
57
|
+
const extras = (0, import_core.getVariantExtras)(props);
|
|
58
|
+
const shapeSize = (0, import_core.getVariableValue)(
|
|
59
|
+
(_a = (0, import_shapes.getShapeSize)(context.size, extras)) == null ? void 0 : _a.width
|
|
60
|
+
);
|
|
61
|
+
React.useEffect(() => {
|
|
62
|
+
setStatus("idle");
|
|
63
|
+
}, [JSON.stringify(src)]);
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
onLoadingStatusChange(status);
|
|
66
|
+
context.onImageLoadingStatusChange(status);
|
|
67
|
+
}, [status]);
|
|
68
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_stacks.YStack, { fullscreen: true, zIndex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
69
|
+
import_image.Image,
|
|
70
|
+
{
|
|
71
|
+
fullscreen: true,
|
|
72
|
+
...typeof shapeSize === "number" && !isNaN(shapeSize) && {
|
|
73
|
+
width: shapeSize,
|
|
74
|
+
height: shapeSize
|
|
75
|
+
},
|
|
76
|
+
...imageProps,
|
|
77
|
+
ref: forwardedRef,
|
|
78
|
+
src,
|
|
79
|
+
onError: () => {
|
|
80
|
+
setStatus("error");
|
|
81
|
+
},
|
|
82
|
+
onLoad: () => {
|
|
83
|
+
setStatus("loaded");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
) });
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
AvatarImage.displayName = IMAGE_NAME;
|
|
90
|
+
const FALLBACK_NAME = "AvatarFallback";
|
|
91
|
+
const AvatarFallbackFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
92
|
+
name: FALLBACK_NAME,
|
|
93
|
+
position: "absolute",
|
|
94
|
+
fullscreen: true,
|
|
95
|
+
zIndex: 0
|
|
96
|
+
});
|
|
97
|
+
const AvatarFallback = AvatarFallbackFrame.extractable(
|
|
98
|
+
React.forwardRef(
|
|
99
|
+
(props, forwardedRef) => {
|
|
100
|
+
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
|
|
101
|
+
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
102
|
+
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
103
|
+
React.useEffect(() => {
|
|
104
|
+
if (delayMs !== void 0) {
|
|
105
|
+
const timerId = setTimeout(() => setCanRender(true), delayMs);
|
|
106
|
+
return () => clearTimeout(timerId);
|
|
107
|
+
}
|
|
108
|
+
}, [delayMs]);
|
|
109
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFallbackFrame, { ...fallbackProps, ref: forwardedRef }) : null;
|
|
110
|
+
}
|
|
111
|
+
)
|
|
112
|
+
);
|
|
113
|
+
AvatarFallback.displayName = FALLBACK_NAME;
|
|
114
|
+
const AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
|
|
115
|
+
name: AVATAR_NAME,
|
|
116
|
+
position: "relative",
|
|
117
|
+
overflow: "hidden"
|
|
118
|
+
});
|
|
119
|
+
const Avatar = (0, import_core.withStaticProperties)(
|
|
120
|
+
React.forwardRef(
|
|
121
|
+
(props, forwardedRef) => {
|
|
122
|
+
const { __scopeAvatar, size = "$true", ...avatarProps } = props;
|
|
123
|
+
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
124
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
125
|
+
AvatarProvider,
|
|
126
|
+
{
|
|
127
|
+
size,
|
|
128
|
+
scope: __scopeAvatar,
|
|
129
|
+
imageLoadingStatus,
|
|
130
|
+
onImageLoadingStatusChange: setImageLoadingStatus,
|
|
131
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AvatarFrame, { size, ...avatarProps, ref: forwardedRef })
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
),
|
|
136
|
+
{
|
|
137
|
+
Image: AvatarImage,
|
|
138
|
+
Fallback: AvatarFallback
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
Avatar.displayName = AVATAR_NAME;
|
|
142
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
143
|
+
0 && (module.exports = {
|
|
144
|
+
Avatar,
|
|
145
|
+
AvatarFallback,
|
|
146
|
+
AvatarFallbackFrame,
|
|
147
|
+
AvatarFrame,
|
|
148
|
+
AvatarImage,
|
|
149
|
+
createAvatarScope
|
|
150
|
+
});
|
|
2
151
|
//# sourceMappingURL=Avatar.js.map
|
package/dist/cjs/Avatar.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Avatar.tsx"],
|
|
4
4
|
"sourcesContent": ["// forked from radix https://github.com/radix-ui/primitives/blob/main/packages/react/avatar/src/Avatar.tsx\n\nimport {\n GetProps,\n SizeTokens,\n TamaguiElement,\n getVariableValue,\n getVariantExtras,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { Image, ImageProps } from '@tamagui/image'\nimport { Square, getShapeSize } from '@tamagui/shapes'\nimport { YStack } from '@tamagui/stacks'\nimport * as React from 'react'\n\nconst AVATAR_NAME = 'Avatar'\n\ntype ScopedProps<P> = P & { __scopeAvatar?: Scope }\nconst [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME)\n\ntype ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error'\n\ntype AvatarContextValue = {\n size: SizeTokens\n imageLoadingStatus: ImageLoadingStatus\n onImageLoadingStatusChange(status: ImageLoadingStatus): void\n}\n\nconst [AvatarProvider, useAvatarContext] =\n createAvatarContext<AvatarContextValue>(AVATAR_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarImage\n * -----------------------------------------------------------------------------------------------*/\n\nconst IMAGE_NAME = 'AvatarImage'\n\ntype AvatarImageProps = Partial<ImageProps> & {\n onLoadingStatusChange?: (status: ImageLoadingStatus) => void\n}\n\nconst AvatarImage = React.forwardRef<TamaguiElement, AvatarImageProps>(\n (props: ScopedProps<AvatarImageProps>, forwardedRef) => {\n const { __scopeAvatar, src, onLoadingStatusChange = () => {}, ...imageProps } = props\n const context = useAvatarContext(IMAGE_NAME, __scopeAvatar)\n const [status, setStatus] = React.useState<ImageLoadingStatus>('idle')\n const extras = getVariantExtras(props)\n const shapeSize = getVariableValue(\n getShapeSize(context.size, extras)?.width\n ) as number\n\n React.useEffect(() => {\n setStatus('idle')\n }, [JSON.stringify(src)])\n\n React.useEffect(() => {\n onLoadingStatusChange(status)\n context.onImageLoadingStatusChange(status)\n }, [status])\n\n return (\n <YStack fullscreen zIndex={1}>\n <Image\n fullscreen\n {...(typeof shapeSize === 'number' &&\n !isNaN(shapeSize) && {\n width: shapeSize,\n height: shapeSize,\n })}\n {...imageProps}\n // @ts-ignore\n ref={forwardedRef}\n // @ts-ignore\n src={src}\n // onLoadStart={() => {\n // // setStatus('loading')\n // }}\n onError={() => {\n setStatus('error')\n }}\n onLoad={() => {\n setStatus('loaded')\n }}\n />\n </YStack>\n )\n }\n)\n\nAvatarImage.displayName = IMAGE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarFallback\n * -----------------------------------------------------------------------------------------------*/\n\nconst FALLBACK_NAME = 'AvatarFallback'\n\nexport const AvatarFallbackFrame = styled(YStack, {\n name: FALLBACK_NAME,\n position: 'absolute',\n fullscreen: true,\n zIndex: 0,\n})\n\ntype AvatarFallbackProps = GetProps<typeof AvatarFallbackFrame> & {\n delayMs?: number\n}\n\nconst AvatarFallback = AvatarFallbackFrame.extractable(\n React.forwardRef<TamaguiElement, AvatarFallbackProps>(\n (props: ScopedProps<AvatarFallbackProps>, forwardedRef) => {\n const { __scopeAvatar, delayMs, ...fallbackProps } = props\n const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar)\n const [canRender, setCanRender] = React.useState(delayMs === undefined)\n\n React.useEffect(() => {\n if (delayMs !== undefined) {\n const timerId = setTimeout(() => setCanRender(true), delayMs)\n return () => clearTimeout(timerId)\n }\n }, [delayMs])\n\n return canRender && context.imageLoadingStatus !== 'loaded' ? (\n <AvatarFallbackFrame {...fallbackProps} ref={forwardedRef} />\n ) : null\n }\n )\n)\n\nAvatarFallback.displayName = FALLBACK_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Avatar\n * -----------------------------------------------------------------------------------------------*/\n\nexport const AvatarFrame = styled(Square, {\n name: AVATAR_NAME,\n position: 'relative',\n overflow: 'hidden',\n})\n\ntype AvatarProps = GetProps<typeof AvatarFrame>\n\nconst Avatar = withStaticProperties(\n React.forwardRef<TamaguiElement, AvatarProps>(\n (props: ScopedProps<AvatarProps>, forwardedRef) => {\n const { __scopeAvatar, size = '$true', ...avatarProps } = props\n const [imageLoadingStatus, setImageLoadingStatus] =\n React.useState<ImageLoadingStatus>('idle')\n return (\n <AvatarProvider\n size={size}\n scope={__scopeAvatar}\n imageLoadingStatus={imageLoadingStatus}\n onImageLoadingStatusChange={setImageLoadingStatus}\n >\n <AvatarFrame size={size} {...avatarProps} ref={forwardedRef} />\n </AvatarProvider>\n )\n }\n ),\n {\n Image: AvatarImage,\n Fallback: AvatarFallback,\n }\n)\n\nAvatar.displayName = AVATAR_NAME\n\nexport { createAvatarScope, Avatar, AvatarImage, AvatarFallback }\nexport type { AvatarProps, AvatarImageProps, AvatarFallbackProps }\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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A,EACZ;AACF;AAEA,OAAO,cAAc;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./Avatar"), module.exports);
|
|
2
19
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["export * from './Avatar'\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,qBAAd;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/esm/Avatar.js
CHANGED
|
@@ -1,2 +1,117 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
getVariableValue,
|
|
4
|
+
getVariantExtras,
|
|
5
|
+
styled,
|
|
6
|
+
withStaticProperties
|
|
7
|
+
} from "@tamagui/core";
|
|
8
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
9
|
+
import { Image } from "@tamagui/image";
|
|
10
|
+
import { Square, getShapeSize } from "@tamagui/shapes";
|
|
11
|
+
import { YStack } from "@tamagui/stacks";
|
|
12
|
+
import * as React from "react";
|
|
13
|
+
const AVATAR_NAME = "Avatar";
|
|
14
|
+
const [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME);
|
|
15
|
+
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
16
|
+
const IMAGE_NAME = "AvatarImage";
|
|
17
|
+
const AvatarImage = React.forwardRef(
|
|
18
|
+
(props, forwardedRef) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
21
|
+
}, ...imageProps } = props;
|
|
22
|
+
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
23
|
+
const [status, setStatus] = React.useState("idle");
|
|
24
|
+
const extras = getVariantExtras(props);
|
|
25
|
+
const shapeSize = getVariableValue(
|
|
26
|
+
(_a = getShapeSize(context.size, extras)) == null ? void 0 : _a.width
|
|
27
|
+
);
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
setStatus("idle");
|
|
30
|
+
}, [JSON.stringify(src)]);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
onLoadingStatusChange(status);
|
|
33
|
+
context.onImageLoadingStatusChange(status);
|
|
34
|
+
}, [status]);
|
|
35
|
+
return /* @__PURE__ */ jsx(YStack, { fullscreen: true, zIndex: 1, children: /* @__PURE__ */ jsx(
|
|
36
|
+
Image,
|
|
37
|
+
{
|
|
38
|
+
fullscreen: true,
|
|
39
|
+
...typeof shapeSize === "number" && !isNaN(shapeSize) && {
|
|
40
|
+
width: shapeSize,
|
|
41
|
+
height: shapeSize
|
|
42
|
+
},
|
|
43
|
+
...imageProps,
|
|
44
|
+
ref: forwardedRef,
|
|
45
|
+
src,
|
|
46
|
+
onError: () => {
|
|
47
|
+
setStatus("error");
|
|
48
|
+
},
|
|
49
|
+
onLoad: () => {
|
|
50
|
+
setStatus("loaded");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
) });
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
AvatarImage.displayName = IMAGE_NAME;
|
|
57
|
+
const FALLBACK_NAME = "AvatarFallback";
|
|
58
|
+
const AvatarFallbackFrame = styled(YStack, {
|
|
59
|
+
name: FALLBACK_NAME,
|
|
60
|
+
position: "absolute",
|
|
61
|
+
fullscreen: true,
|
|
62
|
+
zIndex: 0
|
|
63
|
+
});
|
|
64
|
+
const AvatarFallback = AvatarFallbackFrame.extractable(
|
|
65
|
+
React.forwardRef(
|
|
66
|
+
(props, forwardedRef) => {
|
|
67
|
+
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
|
|
68
|
+
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
69
|
+
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (delayMs !== void 0) {
|
|
72
|
+
const timerId = setTimeout(() => setCanRender(true), delayMs);
|
|
73
|
+
return () => clearTimeout(timerId);
|
|
74
|
+
}
|
|
75
|
+
}, [delayMs]);
|
|
76
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ jsx(AvatarFallbackFrame, { ...fallbackProps, ref: forwardedRef }) : null;
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
AvatarFallback.displayName = FALLBACK_NAME;
|
|
81
|
+
const AvatarFrame = styled(Square, {
|
|
82
|
+
name: AVATAR_NAME,
|
|
83
|
+
position: "relative",
|
|
84
|
+
overflow: "hidden"
|
|
85
|
+
});
|
|
86
|
+
const Avatar = withStaticProperties(
|
|
87
|
+
React.forwardRef(
|
|
88
|
+
(props, forwardedRef) => {
|
|
89
|
+
const { __scopeAvatar, size = "$true", ...avatarProps } = props;
|
|
90
|
+
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
91
|
+
return /* @__PURE__ */ jsx(
|
|
92
|
+
AvatarProvider,
|
|
93
|
+
{
|
|
94
|
+
size,
|
|
95
|
+
scope: __scopeAvatar,
|
|
96
|
+
imageLoadingStatus,
|
|
97
|
+
onImageLoadingStatusChange: setImageLoadingStatus,
|
|
98
|
+
children: /* @__PURE__ */ jsx(AvatarFrame, { size, ...avatarProps, ref: forwardedRef })
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
{
|
|
104
|
+
Image: AvatarImage,
|
|
105
|
+
Fallback: AvatarFallback
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
Avatar.displayName = AVATAR_NAME;
|
|
109
|
+
export {
|
|
110
|
+
Avatar,
|
|
111
|
+
AvatarFallback,
|
|
112
|
+
AvatarFallbackFrame,
|
|
113
|
+
AvatarFrame,
|
|
114
|
+
AvatarImage,
|
|
115
|
+
createAvatarScope
|
|
116
|
+
};
|
|
2
117
|
//# sourceMappingURL=Avatar.js.map
|
package/dist/esm/Avatar.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Avatar.tsx"],
|
|
4
4
|
"sourcesContent": ["// forked from radix https://github.com/radix-ui/primitives/blob/main/packages/react/avatar/src/Avatar.tsx\n\nimport {\n GetProps,\n SizeTokens,\n TamaguiElement,\n getVariableValue,\n getVariantExtras,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { Image, ImageProps } from '@tamagui/image'\nimport { Square, getShapeSize } from '@tamagui/shapes'\nimport { YStack } from '@tamagui/stacks'\nimport * as React from 'react'\n\nconst AVATAR_NAME = 'Avatar'\n\ntype ScopedProps<P> = P & { __scopeAvatar?: Scope }\nconst [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME)\n\ntype ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error'\n\ntype AvatarContextValue = {\n size: SizeTokens\n imageLoadingStatus: ImageLoadingStatus\n onImageLoadingStatusChange(status: ImageLoadingStatus): void\n}\n\nconst [AvatarProvider, useAvatarContext] =\n createAvatarContext<AvatarContextValue>(AVATAR_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarImage\n * -----------------------------------------------------------------------------------------------*/\n\nconst IMAGE_NAME = 'AvatarImage'\n\ntype AvatarImageProps = Partial<ImageProps> & {\n onLoadingStatusChange?: (status: ImageLoadingStatus) => void\n}\n\nconst AvatarImage = React.forwardRef<TamaguiElement, AvatarImageProps>(\n (props: ScopedProps<AvatarImageProps>, forwardedRef) => {\n const { __scopeAvatar, src, onLoadingStatusChange = () => {}, ...imageProps } = props\n const context = useAvatarContext(IMAGE_NAME, __scopeAvatar)\n const [status, setStatus] = React.useState<ImageLoadingStatus>('idle')\n const extras = getVariantExtras(props)\n const shapeSize = getVariableValue(\n getShapeSize(context.size, extras)?.width\n ) as number\n\n React.useEffect(() => {\n setStatus('idle')\n }, [JSON.stringify(src)])\n\n React.useEffect(() => {\n onLoadingStatusChange(status)\n context.onImageLoadingStatusChange(status)\n }, [status])\n\n return (\n <YStack fullscreen zIndex={1}>\n <Image\n fullscreen\n {...(typeof shapeSize === 'number' &&\n !isNaN(shapeSize) && {\n width: shapeSize,\n height: shapeSize,\n })}\n {...imageProps}\n // @ts-ignore\n ref={forwardedRef}\n // @ts-ignore\n src={src}\n // onLoadStart={() => {\n // // setStatus('loading')\n // }}\n onError={() => {\n setStatus('error')\n }}\n onLoad={() => {\n setStatus('loaded')\n }}\n />\n </YStack>\n )\n }\n)\n\nAvatarImage.displayName = IMAGE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarFallback\n * -----------------------------------------------------------------------------------------------*/\n\nconst FALLBACK_NAME = 'AvatarFallback'\n\nexport const AvatarFallbackFrame = styled(YStack, {\n name: FALLBACK_NAME,\n position: 'absolute',\n fullscreen: true,\n zIndex: 0,\n})\n\ntype AvatarFallbackProps = GetProps<typeof AvatarFallbackFrame> & {\n delayMs?: number\n}\n\nconst AvatarFallback = AvatarFallbackFrame.extractable(\n React.forwardRef<TamaguiElement, AvatarFallbackProps>(\n (props: ScopedProps<AvatarFallbackProps>, forwardedRef) => {\n const { __scopeAvatar, delayMs, ...fallbackProps } = props\n const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar)\n const [canRender, setCanRender] = React.useState(delayMs === undefined)\n\n React.useEffect(() => {\n if (delayMs !== undefined) {\n const timerId = setTimeout(() => setCanRender(true), delayMs)\n return () => clearTimeout(timerId)\n }\n }, [delayMs])\n\n return canRender && context.imageLoadingStatus !== 'loaded' ? (\n <AvatarFallbackFrame {...fallbackProps} ref={forwardedRef} />\n ) : null\n }\n )\n)\n\nAvatarFallback.displayName = FALLBACK_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Avatar\n * -----------------------------------------------------------------------------------------------*/\n\nexport const AvatarFrame = styled(Square, {\n name: AVATAR_NAME,\n position: 'relative',\n overflow: 'hidden',\n})\n\ntype AvatarProps = GetProps<typeof AvatarFrame>\n\nconst Avatar = withStaticProperties(\n React.forwardRef<TamaguiElement, AvatarProps>(\n (props: ScopedProps<AvatarProps>, forwardedRef) => {\n const { __scopeAvatar, size = '$true', ...avatarProps } = props\n const [imageLoadingStatus, setImageLoadingStatus] =\n React.useState<ImageLoadingStatus>('idle')\n return (\n <AvatarProvider\n size={size}\n scope={__scopeAvatar}\n imageLoadingStatus={imageLoadingStatus}\n onImageLoadingStatusChange={setImageLoadingStatus}\n >\n <AvatarFrame size={size} {...avatarProps} ref={forwardedRef} />\n </AvatarProvider>\n )\n }\n ),\n {\n Image: AvatarImage,\n Fallback: AvatarFallback,\n }\n)\n\nAvatar.displayName = AVATAR_NAME\n\nexport { createAvatarScope, Avatar, AvatarImage, AvatarFallback }\nexport type { AvatarProps, AvatarImageProps, AvatarFallbackProps }\n"],
|
|
5
|
-
"mappings": "AAgEQ,
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "AAgEQ;AA9DR;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,0BAA0B;AAC1C,SAAS,aAAyB;AAClC,SAAS,QAAQ,oBAAoB;AACrC,SAAS,cAAc;AACvB,YAAY,WAAW;AAEvB,MAAM,cAAc;AAGpB,MAAM,CAAC,qBAAqB,iBAAiB,IAAI,mBAAmB,WAAW;AAU/E,MAAM,CAAC,gBAAgB,gBAAgB,IACrC,oBAAwC,WAAW;AAMrD,MAAM,aAAa;AAMnB,MAAM,cAAc,MAAM;AAAA,EACxB,CAAC,OAAsC,iBAAiB;AA5C1D;AA6CI,UAAM,EAAE,eAAe,KAAK,wBAAwB,MAAM;AAAA,IAAC,GAAG,GAAG,WAAW,IAAI;AAChF,UAAM,UAAU,iBAAiB,YAAY,aAAa;AAC1D,UAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,SAA6B,MAAM;AACrE,UAAM,SAAS,iBAAiB,KAAK;AACrC,UAAM,YAAY;AAAA,OAChB,kBAAa,QAAQ,MAAM,MAAM,MAAjC,mBAAoC;AAAA,IACtC;AAEA,UAAM,UAAU,MAAM;AACpB,gBAAU,MAAM;AAAA,IAClB,GAAG,CAAC,KAAK,UAAU,GAAG,CAAC,CAAC;AAExB,UAAM,UAAU,MAAM;AACpB,4BAAsB,MAAM;AAC5B,cAAQ,2BAA2B,MAAM;AAAA,IAC3C,GAAG,CAAC,MAAM,CAAC;AAEX,WACE,oBAAC,UAAO,YAAU,MAAC,QAAQ,GACzB;AAAA,MAAC;AAAA;AAAA,QACC,YAAU;AAAA,QACT,GAAI,OAAO,cAAc,YACxB,CAAC,MAAM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MAAM;AAC3C,aACE;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,OAAO;AAAA,UACP;AAAA,UACA,4BAA4B;AAAA,UAE5B,8BAAC,eAAY,MAAa,GAAG,aAAa,KAAK,cAAc;AAAA;AAAA,MAC/D;AAAA,IAEJ;AAAA,EACF;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AACF;AAEA,OAAO,cAAc;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/esm/Avatar.mjs
CHANGED
|
@@ -1,2 +1,117 @@
|
|
|
1
|
-
import{jsx
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
getVariableValue,
|
|
4
|
+
getVariantExtras,
|
|
5
|
+
styled,
|
|
6
|
+
withStaticProperties
|
|
7
|
+
} from "@tamagui/core";
|
|
8
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
9
|
+
import { Image } from "@tamagui/image";
|
|
10
|
+
import { Square, getShapeSize } from "@tamagui/shapes";
|
|
11
|
+
import { YStack } from "@tamagui/stacks";
|
|
12
|
+
import * as React from "react";
|
|
13
|
+
const AVATAR_NAME = "Avatar";
|
|
14
|
+
const [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME);
|
|
15
|
+
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
16
|
+
const IMAGE_NAME = "AvatarImage";
|
|
17
|
+
const AvatarImage = React.forwardRef(
|
|
18
|
+
(props, forwardedRef) => {
|
|
19
|
+
var _a;
|
|
20
|
+
const { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
21
|
+
}, ...imageProps } = props;
|
|
22
|
+
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
23
|
+
const [status, setStatus] = React.useState("idle");
|
|
24
|
+
const extras = getVariantExtras(props);
|
|
25
|
+
const shapeSize = getVariableValue(
|
|
26
|
+
(_a = getShapeSize(context.size, extras)) == null ? void 0 : _a.width
|
|
27
|
+
);
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
setStatus("idle");
|
|
30
|
+
}, [JSON.stringify(src)]);
|
|
31
|
+
React.useEffect(() => {
|
|
32
|
+
onLoadingStatusChange(status);
|
|
33
|
+
context.onImageLoadingStatusChange(status);
|
|
34
|
+
}, [status]);
|
|
35
|
+
return /* @__PURE__ */ jsx(YStack, { fullscreen: true, zIndex: 1, children: /* @__PURE__ */ jsx(
|
|
36
|
+
Image,
|
|
37
|
+
{
|
|
38
|
+
fullscreen: true,
|
|
39
|
+
...typeof shapeSize === "number" && !isNaN(shapeSize) && {
|
|
40
|
+
width: shapeSize,
|
|
41
|
+
height: shapeSize
|
|
42
|
+
},
|
|
43
|
+
...imageProps,
|
|
44
|
+
ref: forwardedRef,
|
|
45
|
+
src,
|
|
46
|
+
onError: () => {
|
|
47
|
+
setStatus("error");
|
|
48
|
+
},
|
|
49
|
+
onLoad: () => {
|
|
50
|
+
setStatus("loaded");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
) });
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
AvatarImage.displayName = IMAGE_NAME;
|
|
57
|
+
const FALLBACK_NAME = "AvatarFallback";
|
|
58
|
+
const AvatarFallbackFrame = styled(YStack, {
|
|
59
|
+
name: FALLBACK_NAME,
|
|
60
|
+
position: "absolute",
|
|
61
|
+
fullscreen: true,
|
|
62
|
+
zIndex: 0
|
|
63
|
+
});
|
|
64
|
+
const AvatarFallback = AvatarFallbackFrame.extractable(
|
|
65
|
+
React.forwardRef(
|
|
66
|
+
(props, forwardedRef) => {
|
|
67
|
+
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
|
|
68
|
+
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
69
|
+
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
70
|
+
React.useEffect(() => {
|
|
71
|
+
if (delayMs !== void 0) {
|
|
72
|
+
const timerId = setTimeout(() => setCanRender(true), delayMs);
|
|
73
|
+
return () => clearTimeout(timerId);
|
|
74
|
+
}
|
|
75
|
+
}, [delayMs]);
|
|
76
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ jsx(AvatarFallbackFrame, { ...fallbackProps, ref: forwardedRef }) : null;
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
AvatarFallback.displayName = FALLBACK_NAME;
|
|
81
|
+
const AvatarFrame = styled(Square, {
|
|
82
|
+
name: AVATAR_NAME,
|
|
83
|
+
position: "relative",
|
|
84
|
+
overflow: "hidden"
|
|
85
|
+
});
|
|
86
|
+
const Avatar = withStaticProperties(
|
|
87
|
+
React.forwardRef(
|
|
88
|
+
(props, forwardedRef) => {
|
|
89
|
+
const { __scopeAvatar, size = "$true", ...avatarProps } = props;
|
|
90
|
+
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
91
|
+
return /* @__PURE__ */ jsx(
|
|
92
|
+
AvatarProvider,
|
|
93
|
+
{
|
|
94
|
+
size,
|
|
95
|
+
scope: __scopeAvatar,
|
|
96
|
+
imageLoadingStatus,
|
|
97
|
+
onImageLoadingStatusChange: setImageLoadingStatus,
|
|
98
|
+
children: /* @__PURE__ */ jsx(AvatarFrame, { size, ...avatarProps, ref: forwardedRef })
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
{
|
|
104
|
+
Image: AvatarImage,
|
|
105
|
+
Fallback: AvatarFallback
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
Avatar.displayName = AVATAR_NAME;
|
|
109
|
+
export {
|
|
110
|
+
Avatar,
|
|
111
|
+
AvatarFallback,
|
|
112
|
+
AvatarFallbackFrame,
|
|
113
|
+
AvatarFrame,
|
|
114
|
+
AvatarImage,
|
|
115
|
+
createAvatarScope
|
|
116
|
+
};
|
|
2
117
|
//# sourceMappingURL=Avatar.mjs.map
|
package/dist/esm/Avatar.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Avatar.tsx"],
|
|
4
4
|
"sourcesContent": ["// forked from radix https://github.com/radix-ui/primitives/blob/main/packages/react/avatar/src/Avatar.tsx\n\nimport {\n GetProps,\n SizeTokens,\n TamaguiElement,\n getVariableValue,\n getVariantExtras,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { Image, ImageProps } from '@tamagui/image'\nimport { Square, getShapeSize } from '@tamagui/shapes'\nimport { YStack } from '@tamagui/stacks'\nimport * as React from 'react'\n\nconst AVATAR_NAME = 'Avatar'\n\ntype ScopedProps<P> = P & { __scopeAvatar?: Scope }\nconst [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME)\n\ntype ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error'\n\ntype AvatarContextValue = {\n size: SizeTokens\n imageLoadingStatus: ImageLoadingStatus\n onImageLoadingStatusChange(status: ImageLoadingStatus): void\n}\n\nconst [AvatarProvider, useAvatarContext] =\n createAvatarContext<AvatarContextValue>(AVATAR_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarImage\n * -----------------------------------------------------------------------------------------------*/\n\nconst IMAGE_NAME = 'AvatarImage'\n\ntype AvatarImageProps = Partial<ImageProps> & {\n onLoadingStatusChange?: (status: ImageLoadingStatus) => void\n}\n\nconst AvatarImage = React.forwardRef<TamaguiElement, AvatarImageProps>(\n (props: ScopedProps<AvatarImageProps>, forwardedRef) => {\n const { __scopeAvatar, src, onLoadingStatusChange = () => {}, ...imageProps } = props\n const context = useAvatarContext(IMAGE_NAME, __scopeAvatar)\n const [status, setStatus] = React.useState<ImageLoadingStatus>('idle')\n const extras = getVariantExtras(props)\n const shapeSize = getVariableValue(\n getShapeSize(context.size, extras)?.width\n ) as number\n\n React.useEffect(() => {\n setStatus('idle')\n }, [JSON.stringify(src)])\n\n React.useEffect(() => {\n onLoadingStatusChange(status)\n context.onImageLoadingStatusChange(status)\n }, [status])\n\n return (\n <YStack fullscreen zIndex={1}>\n <Image\n fullscreen\n {...(typeof shapeSize === 'number' &&\n !isNaN(shapeSize) && {\n width: shapeSize,\n height: shapeSize,\n })}\n {...imageProps}\n // @ts-ignore\n ref={forwardedRef}\n // @ts-ignore\n src={src}\n // onLoadStart={() => {\n // // setStatus('loading')\n // }}\n onError={() => {\n setStatus('error')\n }}\n onLoad={() => {\n setStatus('loaded')\n }}\n />\n </YStack>\n )\n }\n)\n\nAvatarImage.displayName = IMAGE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarFallback\n * -----------------------------------------------------------------------------------------------*/\n\nconst FALLBACK_NAME = 'AvatarFallback'\n\nexport const AvatarFallbackFrame = styled(YStack, {\n name: FALLBACK_NAME,\n position: 'absolute',\n fullscreen: true,\n zIndex: 0,\n})\n\ntype AvatarFallbackProps = GetProps<typeof AvatarFallbackFrame> & {\n delayMs?: number\n}\n\nconst AvatarFallback = AvatarFallbackFrame.extractable(\n React.forwardRef<TamaguiElement, AvatarFallbackProps>(\n (props: ScopedProps<AvatarFallbackProps>, forwardedRef) => {\n const { __scopeAvatar, delayMs, ...fallbackProps } = props\n const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar)\n const [canRender, setCanRender] = React.useState(delayMs === undefined)\n\n React.useEffect(() => {\n if (delayMs !== undefined) {\n const timerId = setTimeout(() => setCanRender(true), delayMs)\n return () => clearTimeout(timerId)\n }\n }, [delayMs])\n\n return canRender && context.imageLoadingStatus !== 'loaded' ? (\n <AvatarFallbackFrame {...fallbackProps} ref={forwardedRef} />\n ) : null\n }\n )\n)\n\nAvatarFallback.displayName = FALLBACK_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Avatar\n * -----------------------------------------------------------------------------------------------*/\n\nexport const AvatarFrame = styled(Square, {\n name: AVATAR_NAME,\n position: 'relative',\n overflow: 'hidden',\n})\n\ntype AvatarProps = GetProps<typeof AvatarFrame>\n\nconst Avatar = withStaticProperties(\n React.forwardRef<TamaguiElement, AvatarProps>(\n (props: ScopedProps<AvatarProps>, forwardedRef) => {\n const { __scopeAvatar, size = '$true', ...avatarProps } = props\n const [imageLoadingStatus, setImageLoadingStatus] =\n React.useState<ImageLoadingStatus>('idle')\n return (\n <AvatarProvider\n size={size}\n scope={__scopeAvatar}\n imageLoadingStatus={imageLoadingStatus}\n onImageLoadingStatusChange={setImageLoadingStatus}\n >\n <AvatarFrame size={size} {...avatarProps} ref={forwardedRef} />\n </AvatarProvider>\n )\n }\n ),\n {\n Image: AvatarImage,\n Fallback: AvatarFallback,\n }\n)\n\nAvatar.displayName = AVATAR_NAME\n\nexport { createAvatarScope, Avatar, AvatarImage, AvatarFallback }\nexport type { AvatarProps, AvatarImageProps, AvatarFallbackProps }\n"],
|
|
5
|
-
"mappings": "AAgEQ,
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "AAgEQ;AA9DR;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,0BAA0B;AAC1C,SAAS,aAAyB;AAClC,SAAS,QAAQ,oBAAoB;AACrC,SAAS,cAAc;AACvB,YAAY,WAAW;AAEvB,MAAM,cAAc;AAGpB,MAAM,CAAC,qBAAqB,iBAAiB,IAAI,mBAAmB,WAAW;AAU/E,MAAM,CAAC,gBAAgB,gBAAgB,IACrC,oBAAwC,WAAW;AAMrD,MAAM,aAAa;AAMnB,MAAM,cAAc,MAAM;AAAA,EACxB,CAAC,OAAsC,iBAAiB;AA5C1D;AA6CI,UAAM,EAAE,eAAe,KAAK,wBAAwB,MAAM;AAAA,IAAC,GAAG,GAAG,WAAW,IAAI;AAChF,UAAM,UAAU,iBAAiB,YAAY,aAAa;AAC1D,UAAM,CAAC,QAAQ,SAAS,IAAI,MAAM,SAA6B,MAAM;AACrE,UAAM,SAAS,iBAAiB,KAAK;AACrC,UAAM,YAAY;AAAA,OAChB,kBAAa,QAA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,uBAAuB,WACjD,oBAAC,uBAAqB,GAAG,eAAe,KAAK,cAAc,IACzD;AAAA,IACN;AAAA,EACF;AACF;AAEA,eAAe,cAAc;AAMtB,MAAM,cAAc,OAAO,QAAQ;AAAA,EACxC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,UAAU;AACZ,CAAC;AAID,MAAM,SAAS;AAAA,EACb,MAAM;AAAA,IACJ,CAAC,OAAiC,iBAAiB;AACjD,YAAM,EAAE,eAAe,OAAO,SAAS,GAAG,YAAY,IAAI;AAC1D,YAAM,CAAC,oBAAoB,qBAAqB,IAC9C,MAAM,SAA6B,MAAM;AAC3C,aACE;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,OAAO;AAAA,UACP;AAAA,UACA,4BAA4B;AAAA,UAE5B,8BAAC,eAAY,MAAa,GAAG,aAAa,KAAK,cAAc;AAAA;AAAA,MAC/D;AAAA,IAEJ;AAAA,EACF;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,UAAU;AAAA,EACZ;AACF;AAEA,OAAO,cAAc;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export*from"./Avatar";
|
|
1
|
+
export * from "./Avatar";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
package/dist/esm/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export*from"./Avatar";
|
|
1
|
+
export * from "./Avatar";
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
package/dist/jsx/Avatar.js
CHANGED
|
@@ -1,2 +1,108 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
getVariableValue,
|
|
3
|
+
getVariantExtras,
|
|
4
|
+
styled,
|
|
5
|
+
withStaticProperties
|
|
6
|
+
} from "@tamagui/core";
|
|
7
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
8
|
+
import { Image } from "@tamagui/image";
|
|
9
|
+
import { Square, getShapeSize } from "@tamagui/shapes";
|
|
10
|
+
import { YStack } from "@tamagui/stacks";
|
|
11
|
+
import * as React from "react";
|
|
12
|
+
const AVATAR_NAME = "Avatar";
|
|
13
|
+
const [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME);
|
|
14
|
+
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
15
|
+
const IMAGE_NAME = "AvatarImage";
|
|
16
|
+
const AvatarImage = React.forwardRef(
|
|
17
|
+
(props, forwardedRef) => {
|
|
18
|
+
const { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
19
|
+
}, ...imageProps } = props;
|
|
20
|
+
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
21
|
+
const [status, setStatus] = React.useState("idle");
|
|
22
|
+
const extras = getVariantExtras(props);
|
|
23
|
+
const shapeSize = getVariableValue(
|
|
24
|
+
getShapeSize(context.size, extras)?.width
|
|
25
|
+
);
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
setStatus("idle");
|
|
28
|
+
}, [JSON.stringify(src)]);
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
onLoadingStatusChange(status);
|
|
31
|
+
context.onImageLoadingStatusChange(status);
|
|
32
|
+
}, [status]);
|
|
33
|
+
return <YStack fullscreen zIndex={1}><Image
|
|
34
|
+
fullscreen
|
|
35
|
+
{...typeof shapeSize === "number" && !isNaN(shapeSize) && {
|
|
36
|
+
width: shapeSize,
|
|
37
|
+
height: shapeSize
|
|
38
|
+
}}
|
|
39
|
+
{...imageProps}
|
|
40
|
+
ref={forwardedRef}
|
|
41
|
+
src={src}
|
|
42
|
+
onError={() => {
|
|
43
|
+
setStatus("error");
|
|
44
|
+
}}
|
|
45
|
+
onLoad={() => {
|
|
46
|
+
setStatus("loaded");
|
|
47
|
+
}}
|
|
48
|
+
/></YStack>;
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
AvatarImage.displayName = IMAGE_NAME;
|
|
52
|
+
const FALLBACK_NAME = "AvatarFallback";
|
|
53
|
+
const AvatarFallbackFrame = styled(YStack, {
|
|
54
|
+
name: FALLBACK_NAME,
|
|
55
|
+
position: "absolute",
|
|
56
|
+
fullscreen: true,
|
|
57
|
+
zIndex: 0
|
|
58
|
+
});
|
|
59
|
+
const AvatarFallback = AvatarFallbackFrame.extractable(
|
|
60
|
+
React.forwardRef(
|
|
61
|
+
(props, forwardedRef) => {
|
|
62
|
+
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
|
|
63
|
+
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
64
|
+
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
if (delayMs !== void 0) {
|
|
67
|
+
const timerId = setTimeout(() => setCanRender(true), delayMs);
|
|
68
|
+
return () => clearTimeout(timerId);
|
|
69
|
+
}
|
|
70
|
+
}, [delayMs]);
|
|
71
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? <AvatarFallbackFrame {...fallbackProps} ref={forwardedRef} /> : null;
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
AvatarFallback.displayName = FALLBACK_NAME;
|
|
76
|
+
const AvatarFrame = styled(Square, {
|
|
77
|
+
name: AVATAR_NAME,
|
|
78
|
+
position: "relative",
|
|
79
|
+
overflow: "hidden"
|
|
80
|
+
});
|
|
81
|
+
const Avatar = withStaticProperties(
|
|
82
|
+
React.forwardRef(
|
|
83
|
+
(props, forwardedRef) => {
|
|
84
|
+
const { __scopeAvatar, size = "$true", ...avatarProps } = props;
|
|
85
|
+
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
86
|
+
return <AvatarProvider
|
|
87
|
+
size={size}
|
|
88
|
+
scope={__scopeAvatar}
|
|
89
|
+
imageLoadingStatus={imageLoadingStatus}
|
|
90
|
+
onImageLoadingStatusChange={setImageLoadingStatus}
|
|
91
|
+
><AvatarFrame size={size} {...avatarProps} ref={forwardedRef} /></AvatarProvider>;
|
|
92
|
+
}
|
|
93
|
+
),
|
|
94
|
+
{
|
|
95
|
+
Image: AvatarImage,
|
|
96
|
+
Fallback: AvatarFallback
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
Avatar.displayName = AVATAR_NAME;
|
|
100
|
+
export {
|
|
101
|
+
Avatar,
|
|
102
|
+
AvatarFallback,
|
|
103
|
+
AvatarFallbackFrame,
|
|
104
|
+
AvatarFrame,
|
|
105
|
+
AvatarImage,
|
|
106
|
+
createAvatarScope
|
|
107
|
+
};
|
|
2
108
|
//# sourceMappingURL=Avatar.js.map
|
package/dist/jsx/Avatar.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Avatar.tsx"],
|
|
4
4
|
"sourcesContent": ["// forked from radix https://github.com/radix-ui/primitives/blob/main/packages/react/avatar/src/Avatar.tsx\n\nimport {\n GetProps,\n SizeTokens,\n TamaguiElement,\n getVariableValue,\n getVariantExtras,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { Image, ImageProps } from '@tamagui/image'\nimport { Square, getShapeSize } from '@tamagui/shapes'\nimport { YStack } from '@tamagui/stacks'\nimport * as React from 'react'\n\nconst AVATAR_NAME = 'Avatar'\n\ntype ScopedProps<P> = P & { __scopeAvatar?: Scope }\nconst [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME)\n\ntype ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error'\n\ntype AvatarContextValue = {\n size: SizeTokens\n imageLoadingStatus: ImageLoadingStatus\n onImageLoadingStatusChange(status: ImageLoadingStatus): void\n}\n\nconst [AvatarProvider, useAvatarContext] =\n createAvatarContext<AvatarContextValue>(AVATAR_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarImage\n * -----------------------------------------------------------------------------------------------*/\n\nconst IMAGE_NAME = 'AvatarImage'\n\ntype AvatarImageProps = Partial<ImageProps> & {\n onLoadingStatusChange?: (status: ImageLoadingStatus) => void\n}\n\nconst AvatarImage = React.forwardRef<TamaguiElement, AvatarImageProps>(\n (props: ScopedProps<AvatarImageProps>, forwardedRef) => {\n const { __scopeAvatar, src, onLoadingStatusChange = () => {}, ...imageProps } = props\n const context = useAvatarContext(IMAGE_NAME, __scopeAvatar)\n const [status, setStatus] = React.useState<ImageLoadingStatus>('idle')\n const extras = getVariantExtras(props)\n const shapeSize = getVariableValue(\n getShapeSize(context.size, extras)?.width\n ) as number\n\n React.useEffect(() => {\n setStatus('idle')\n }, [JSON.stringify(src)])\n\n React.useEffect(() => {\n onLoadingStatusChange(status)\n context.onImageLoadingStatusChange(status)\n }, [status])\n\n return (\n <YStack fullscreen zIndex={1}>\n <Image\n fullscreen\n {...(typeof shapeSize === 'number' &&\n !isNaN(shapeSize) && {\n width: shapeSize,\n height: shapeSize,\n })}\n {...imageProps}\n // @ts-ignore\n ref={forwardedRef}\n // @ts-ignore\n src={src}\n // onLoadStart={() => {\n // // setStatus('loading')\n // }}\n onError={() => {\n setStatus('error')\n }}\n onLoad={() => {\n setStatus('loaded')\n }}\n />\n </YStack>\n )\n }\n)\n\nAvatarImage.displayName = IMAGE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarFallback\n * -----------------------------------------------------------------------------------------------*/\n\nconst FALLBACK_NAME = 'AvatarFallback'\n\nexport const AvatarFallbackFrame = styled(YStack, {\n name: FALLBACK_NAME,\n position: 'absolute',\n fullscreen: true,\n zIndex: 0,\n})\n\ntype AvatarFallbackProps = GetProps<typeof AvatarFallbackFrame> & {\n delayMs?: number\n}\n\nconst AvatarFallback = AvatarFallbackFrame.extractable(\n React.forwardRef<TamaguiElement, AvatarFallbackProps>(\n (props: ScopedProps<AvatarFallbackProps>, forwardedRef) => {\n const { __scopeAvatar, delayMs, ...fallbackProps } = props\n const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar)\n const [canRender, setCanRender] = React.useState(delayMs === undefined)\n\n React.useEffect(() => {\n if (delayMs !== undefined) {\n const timerId = setTimeout(() => setCanRender(true), delayMs)\n return () => clearTimeout(timerId)\n }\n }, [delayMs])\n\n return canRender && context.imageLoadingStatus !== 'loaded' ? (\n <AvatarFallbackFrame {...fallbackProps} ref={forwardedRef} />\n ) : null\n }\n )\n)\n\nAvatarFallback.displayName = FALLBACK_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Avatar\n * -----------------------------------------------------------------------------------------------*/\n\nexport const AvatarFrame = styled(Square, {\n name: AVATAR_NAME,\n position: 'relative',\n overflow: 'hidden',\n})\n\ntype AvatarProps = GetProps<typeof AvatarFrame>\n\nconst Avatar = withStaticProperties(\n React.forwardRef<TamaguiElement, AvatarProps>(\n (props: ScopedProps<AvatarProps>, forwardedRef) => {\n const { __scopeAvatar, size = '$true', ...avatarProps } = props\n const [imageLoadingStatus, setImageLoadingStatus] =\n React.useState<ImageLoadingStatus>('idle')\n return (\n <AvatarProvider\n size={size}\n scope={__scopeAvatar}\n imageLoadingStatus={imageLoadingStatus}\n onImageLoadingStatusChange={setImageLoadingStatus}\n >\n <AvatarFrame size={size} {...avatarProps} ref={forwardedRef} />\n </AvatarProvider>\n )\n }\n ),\n {\n Image: AvatarImage,\n Fallback: AvatarFallback,\n }\n)\n\nAvatar.displayName = AVATAR_NAME\n\nexport { createAvatarScope, Avatar, AvatarImage, AvatarFallback }\nexport type { AvatarProps, AvatarImageProps, AvatarFallbackProps }\n"],
|
|
5
|
-
"mappings": "AAEA,
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "AAEA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,0BAA0B;AAC1C,SAAS,aAAyB;AAClC,SAAS,QAAQ,oBAAoB;AACrC,SAAS,cAAc;AACvB,YAAY,WAAW;AAEvB,MAAM,cAAc;AAGp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StaticProperties
|
|
6
|
+
} from "@tamagui/core";
|
|
7
|
+
import { createContextScope } from "@tamagui/create-context";
|
|
8
|
+
import { Image } from "@tamagui/image";
|
|
9
|
+
import { Square, getShapeSize } from "@tamagui/shapes";
|
|
10
|
+
import { YStack } from "@tamagui/stacks";
|
|
11
|
+
import * as React from "react";
|
|
12
|
+
const AVATAR_NAME = "Avatar";
|
|
13
|
+
const [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME);
|
|
14
|
+
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
15
|
+
const IMAGE_NAME = "AvatarImage";
|
|
16
|
+
const AvatarImage = React.forwardRef(
|
|
17
|
+
(props, forwardedRef) => {
|
|
18
|
+
const { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
19
|
+
}, ...imageProps } = props;
|
|
20
|
+
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
21
|
+
const [status, setStatus] = React.useState("idle");
|
|
22
|
+
const extras = getVariantExtras(props);
|
|
23
|
+
const shapeSize = getVariableValue(
|
|
24
|
+
getShapeSize(context.size, extras)?.width
|
|
25
|
+
);
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
setStatus("idle");
|
|
28
|
+
}, [JSON.stringify(src)]);
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
onLoadingStatusChange(status);
|
|
31
|
+
context.onImageLoadingStatusChange(status);
|
|
32
|
+
}, [status]);
|
|
33
|
+
return <YStack fullscreen zIndex={1}><Image
|
|
34
|
+
fullscreen
|
|
35
|
+
{...typeof shapeSize === "number" && !isNaN(shapeSize) && {
|
|
36
|
+
width: shapeSize,
|
|
37
|
+
height: shapeSize
|
|
38
|
+
}}
|
|
39
|
+
{...imageProps}
|
|
40
|
+
ref={forwardedRef}
|
|
41
|
+
src={src}
|
|
42
|
+
onError={() => {
|
|
43
|
+
setStatus("error");
|
|
44
|
+
}}
|
|
45
|
+
onLoad={() => {
|
|
46
|
+
setStatus("loaded");
|
|
47
|
+
}}
|
|
48
|
+
/></YStack>;
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
AvatarImage.displayName = IMAGE_NAME;
|
|
52
|
+
const FALLBACK_NAME = "AvatarFallback";
|
|
53
|
+
const AvatarFallbackFrame = styled(YStack, {
|
|
54
|
+
name: FALLBACK_NAME,
|
|
55
|
+
position: "absolute",
|
|
56
|
+
fullscreen: true,
|
|
57
|
+
zIndex: 0
|
|
58
|
+
});
|
|
59
|
+
const AvatarFallback = AvatarFallbackFrame.extractable(
|
|
60
|
+
React.forwardRef(
|
|
61
|
+
(props, forwardedRef) => {
|
|
62
|
+
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
|
|
63
|
+
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
64
|
+
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
if (delayMs !== void 0) {
|
|
67
|
+
const timerId = setTimeout(() => setCanRender(true), delayMs);
|
|
68
|
+
return () => clearTimeout(timerId);
|
|
69
|
+
}
|
|
70
|
+
}, [delayMs]);
|
|
71
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? <AvatarFallbackFrame {...fallbackProps} ref={forwardedRef} /> : null;
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
);
|
|
75
|
+
AvatarFallback.displayName = FALLBACK_NAME;
|
|
76
|
+
const AvatarFrame = styled(Square, {
|
|
77
|
+
name: AVATAR_NAME,
|
|
78
|
+
position: "relative",
|
|
79
|
+
overflow: "hidden"
|
|
80
|
+
});
|
|
81
|
+
const Avatar = withStaticProperties(
|
|
82
|
+
React.forwardRef(
|
|
83
|
+
(props, forwardedRef) => {
|
|
84
|
+
const { __scopeAvatar, size = "$true", ...avatarProps } = props;
|
|
85
|
+
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
86
|
+
return <AvatarProvider
|
|
87
|
+
size={size}
|
|
88
|
+
scope={__scopeAvatar}
|
|
89
|
+
imageLoadingStatus={imageLoadingStatus}
|
|
90
|
+
onImageLoadingStatusChange={setImageLoadingStatus}
|
|
91
|
+
><AvatarFrame size={size} {...avatarProps} ref={forwardedRef} /></AvatarProvider>;
|
|
92
|
+
}
|
|
93
|
+
),
|
|
94
|
+
{
|
|
95
|
+
Image: AvatarImage,
|
|
96
|
+
Fallback: AvatarFallback
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
Avatar.displayName = AVATAR_NAME;
|
|
100
|
+
export {
|
|
101
|
+
Avatar,
|
|
102
|
+
AvatarFallback,
|
|
103
|
+
AvatarFallbackFrame,
|
|
104
|
+
AvatarFrame,
|
|
105
|
+
AvatarImage,
|
|
106
|
+
createAvatarScope
|
|
107
|
+
};
|
|
2
108
|
//# sourceMappingURL=Avatar.mjs.map
|
package/dist/jsx/Avatar.mjs.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Avatar.tsx"],
|
|
4
4
|
"sourcesContent": ["// forked from radix https://github.com/radix-ui/primitives/blob/main/packages/react/avatar/src/Avatar.tsx\n\nimport {\n GetProps,\n SizeTokens,\n TamaguiElement,\n getVariableValue,\n getVariantExtras,\n styled,\n withStaticProperties,\n} from '@tamagui/core'\nimport { Scope, createContextScope } from '@tamagui/create-context'\nimport { Image, ImageProps } from '@tamagui/image'\nimport { Square, getShapeSize } from '@tamagui/shapes'\nimport { YStack } from '@tamagui/stacks'\nimport * as React from 'react'\n\nconst AVATAR_NAME = 'Avatar'\n\ntype ScopedProps<P> = P & { __scopeAvatar?: Scope }\nconst [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME)\n\ntype ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error'\n\ntype AvatarContextValue = {\n size: SizeTokens\n imageLoadingStatus: ImageLoadingStatus\n onImageLoadingStatusChange(status: ImageLoadingStatus): void\n}\n\nconst [AvatarProvider, useAvatarContext] =\n createAvatarContext<AvatarContextValue>(AVATAR_NAME)\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarImage\n * -----------------------------------------------------------------------------------------------*/\n\nconst IMAGE_NAME = 'AvatarImage'\n\ntype AvatarImageProps = Partial<ImageProps> & {\n onLoadingStatusChange?: (status: ImageLoadingStatus) => void\n}\n\nconst AvatarImage = React.forwardRef<TamaguiElement, AvatarImageProps>(\n (props: ScopedProps<AvatarImageProps>, forwardedRef) => {\n const { __scopeAvatar, src, onLoadingStatusChange = () => {}, ...imageProps } = props\n const context = useAvatarContext(IMAGE_NAME, __scopeAvatar)\n const [status, setStatus] = React.useState<ImageLoadingStatus>('idle')\n const extras = getVariantExtras(props)\n const shapeSize = getVariableValue(\n getShapeSize(context.size, extras)?.width\n ) as number\n\n React.useEffect(() => {\n setStatus('idle')\n }, [JSON.stringify(src)])\n\n React.useEffect(() => {\n onLoadingStatusChange(status)\n context.onImageLoadingStatusChange(status)\n }, [status])\n\n return (\n <YStack fullscreen zIndex={1}>\n <Image\n fullscreen\n {...(typeof shapeSize === 'number' &&\n !isNaN(shapeSize) && {\n width: shapeSize,\n height: shapeSize,\n })}\n {...imageProps}\n // @ts-ignore\n ref={forwardedRef}\n // @ts-ignore\n src={src}\n // onLoadStart={() => {\n // // setStatus('loading')\n // }}\n onError={() => {\n setStatus('error')\n }}\n onLoad={() => {\n setStatus('loaded')\n }}\n />\n </YStack>\n )\n }\n)\n\nAvatarImage.displayName = IMAGE_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarFallback\n * -----------------------------------------------------------------------------------------------*/\n\nconst FALLBACK_NAME = 'AvatarFallback'\n\nexport const AvatarFallbackFrame = styled(YStack, {\n name: FALLBACK_NAME,\n position: 'absolute',\n fullscreen: true,\n zIndex: 0,\n})\n\ntype AvatarFallbackProps = GetProps<typeof AvatarFallbackFrame> & {\n delayMs?: number\n}\n\nconst AvatarFallback = AvatarFallbackFrame.extractable(\n React.forwardRef<TamaguiElement, AvatarFallbackProps>(\n (props: ScopedProps<AvatarFallbackProps>, forwardedRef) => {\n const { __scopeAvatar, delayMs, ...fallbackProps } = props\n const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar)\n const [canRender, setCanRender] = React.useState(delayMs === undefined)\n\n React.useEffect(() => {\n if (delayMs !== undefined) {\n const timerId = setTimeout(() => setCanRender(true), delayMs)\n return () => clearTimeout(timerId)\n }\n }, [delayMs])\n\n return canRender && context.imageLoadingStatus !== 'loaded' ? (\n <AvatarFallbackFrame {...fallbackProps} ref={forwardedRef} />\n ) : null\n }\n )\n)\n\nAvatarFallback.displayName = FALLBACK_NAME\n\n/* -------------------------------------------------------------------------------------------------\n * Avatar\n * -----------------------------------------------------------------------------------------------*/\n\nexport const AvatarFrame = styled(Square, {\n name: AVATAR_NAME,\n position: 'relative',\n overflow: 'hidden',\n})\n\ntype AvatarProps = GetProps<typeof AvatarFrame>\n\nconst Avatar = withStaticProperties(\n React.forwardRef<TamaguiElement, AvatarProps>(\n (props: ScopedProps<AvatarProps>, forwardedRef) => {\n const { __scopeAvatar, size = '$true', ...avatarProps } = props\n const [imageLoadingStatus, setImageLoadingStatus] =\n React.useState<ImageLoadingStatus>('idle')\n return (\n <AvatarProvider\n size={size}\n scope={__scopeAvatar}\n imageLoadingStatus={imageLoadingStatus}\n onImageLoadingStatusChange={setImageLoadingStatus}\n >\n <AvatarFrame size={size} {...avatarProps} ref={forwardedRef} />\n </AvatarProvider>\n )\n }\n ),\n {\n Image: AvatarImage,\n Fallback: AvatarFallback,\n }\n)\n\nAvatar.displayName = AVATAR_NAME\n\nexport { createAvatarScope, Avatar, AvatarImage, AvatarFallback }\nexport type { AvatarProps, AvatarImageProps, AvatarFallbackProps }\n"],
|
|
5
|
-
"mappings": "AAEA,
|
|
6
|
-
"names": [
|
|
5
|
+
"mappings": "AAEA;AAAA,EAIE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAgB,0BAA0B;AAC1C,SAAS,aAAyB;AAClC,SAAS,QAA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* from "./Avatar";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/jsx/index.js.map
CHANGED
package/dist/jsx/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export*from"./Avatar";
|
|
1
|
+
export * from "./Avatar";
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/jsx/index.mjs.map
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/avatar",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.3",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -31,18 +31,18 @@
|
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@tamagui/core": "1.14.
|
|
35
|
-
"@tamagui/image": "1.14.
|
|
36
|
-
"@tamagui/shapes": "1.14.
|
|
37
|
-
"@tamagui/text": "1.14.
|
|
38
|
-
"@tamagui/use-event": "1.14.
|
|
34
|
+
"@tamagui/core": "1.14.3",
|
|
35
|
+
"@tamagui/image": "1.14.3",
|
|
36
|
+
"@tamagui/shapes": "1.14.3",
|
|
37
|
+
"@tamagui/text": "1.14.3",
|
|
38
|
+
"@tamagui/use-event": "1.14.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": "*",
|
|
42
42
|
"react-native": "*"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@tamagui/build": "1.14.
|
|
45
|
+
"@tamagui/build": "1.14.3",
|
|
46
46
|
"react": "^18.2.0",
|
|
47
47
|
"react-native": "^0.71.4"
|
|
48
48
|
},
|