@tamagui/avatar 1.0.1-beta.108 → 1.0.1-beta.109
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 +22 -48
- package/dist/cjs/Avatar.js.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/Avatar.js +21 -50
- package/dist/esm/Avatar.js.map +1 -1
- package/package.json +7 -7
package/dist/cjs/Avatar.js
CHANGED
|
@@ -1,38 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
var __objRest = (source, exclude) => {
|
|
25
|
-
var target = {};
|
|
26
|
-
for (var prop in source)
|
|
27
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
if (source != null && __getOwnPropSymbols)
|
|
30
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
-
target[prop] = source[prop];
|
|
33
|
-
}
|
|
34
|
-
return target;
|
|
35
|
-
};
|
|
36
8
|
var __export = (target, all) => {
|
|
37
9
|
for (var name in all)
|
|
38
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -68,13 +40,13 @@ const [createAvatarContext, createAvatarScope] = (0, import_create_context.creat
|
|
|
68
40
|
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
69
41
|
const IMAGE_NAME = "AvatarImage";
|
|
70
42
|
const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
71
|
-
var
|
|
72
|
-
const
|
|
73
|
-
}
|
|
43
|
+
var _a;
|
|
44
|
+
const { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
45
|
+
}, ...imageProps } = props;
|
|
74
46
|
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
75
47
|
const [status, setStatus] = React.useState("idle");
|
|
76
48
|
const extras = (0, import_core.getVariantExtras)(props);
|
|
77
|
-
const shapeSize = (0, import_core.getVariableValue)((
|
|
49
|
+
const shapeSize = (0, import_core.getVariableValue)((_a = (0, import_shapes.getShapeSize)(context.size, extras)) == null ? void 0 : _a.width);
|
|
78
50
|
React.useEffect(() => {
|
|
79
51
|
setStatus("idle");
|
|
80
52
|
}, [JSON.stringify(src)]);
|
|
@@ -85,12 +57,13 @@ const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
|
85
57
|
return /* @__PURE__ */ React.createElement(import_stacks.YStack, {
|
|
86
58
|
fullscreen: true,
|
|
87
59
|
zIndex: 1
|
|
88
|
-
}, /* @__PURE__ */ React.createElement(import_image.Image,
|
|
89
|
-
fullscreen: true
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
60
|
+
}, /* @__PURE__ */ React.createElement(import_image.Image, {
|
|
61
|
+
fullscreen: true,
|
|
62
|
+
...typeof shapeSize === "number" && !isNaN(shapeSize) && {
|
|
63
|
+
width: shapeSize,
|
|
64
|
+
height: shapeSize
|
|
65
|
+
},
|
|
66
|
+
...imageProps,
|
|
94
67
|
ref: forwardedRef,
|
|
95
68
|
src,
|
|
96
69
|
onError: () => {
|
|
@@ -99,7 +72,7 @@ const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
|
99
72
|
onLoad: () => {
|
|
100
73
|
setStatus("loaded");
|
|
101
74
|
}
|
|
102
|
-
}))
|
|
75
|
+
}));
|
|
103
76
|
});
|
|
104
77
|
AvatarImage.displayName = IMAGE_NAME;
|
|
105
78
|
const FALLBACK_NAME = "AvatarFallback";
|
|
@@ -110,7 +83,7 @@ const AvatarFallbackFrame = (0, import_core.styled)(import_stacks.YStack, {
|
|
|
110
83
|
zIndex: 0
|
|
111
84
|
});
|
|
112
85
|
const AvatarFallback = AvatarFallbackFrame.extractable(React.forwardRef((props, forwardedRef) => {
|
|
113
|
-
const
|
|
86
|
+
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
|
|
114
87
|
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
115
88
|
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
116
89
|
React.useEffect(() => {
|
|
@@ -119,9 +92,10 @@ const AvatarFallback = AvatarFallbackFrame.extractable(React.forwardRef((props,
|
|
|
119
92
|
return () => clearTimeout(timerId);
|
|
120
93
|
}
|
|
121
94
|
}, [delayMs]);
|
|
122
|
-
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ React.createElement(AvatarFallbackFrame,
|
|
95
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ React.createElement(AvatarFallbackFrame, {
|
|
96
|
+
...fallbackProps,
|
|
123
97
|
ref: forwardedRef
|
|
124
|
-
})
|
|
98
|
+
}) : null;
|
|
125
99
|
}));
|
|
126
100
|
AvatarFallback.displayName = FALLBACK_NAME;
|
|
127
101
|
const AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
|
|
@@ -130,18 +104,18 @@ const AvatarFrame = (0, import_core.styled)(import_shapes.Square, {
|
|
|
130
104
|
overflow: "hidden"
|
|
131
105
|
});
|
|
132
106
|
const Avatar = (0, import_core.withStaticProperties)(React.forwardRef((props, forwardedRef) => {
|
|
133
|
-
const
|
|
107
|
+
const { __scopeAvatar, size = "$4", ...avatarProps } = props;
|
|
134
108
|
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
135
109
|
return /* @__PURE__ */ React.createElement(AvatarProvider, {
|
|
136
110
|
size,
|
|
137
111
|
scope: __scopeAvatar,
|
|
138
112
|
imageLoadingStatus,
|
|
139
113
|
onImageLoadingStatusChange: setImageLoadingStatus
|
|
140
|
-
}, /* @__PURE__ */ React.createElement(AvatarFrame,
|
|
141
|
-
size
|
|
142
|
-
|
|
114
|
+
}, /* @__PURE__ */ React.createElement(AvatarFrame, {
|
|
115
|
+
size,
|
|
116
|
+
...avatarProps,
|
|
143
117
|
ref: forwardedRef
|
|
144
|
-
}))
|
|
118
|
+
}));
|
|
145
119
|
}), {
|
|
146
120
|
Image: AvatarImage,
|
|
147
121
|
Fallback: AvatarFallback
|
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] = 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(getShapeSize(context.size, extras)?.width) 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>((props: ScopedProps<AvatarProps>, forwardedRef) => {\n const { __scopeAvatar, size = '$4', ...avatarProps } = props\n const [imageLoadingStatus, setImageLoadingStatus] = 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 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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,kBAQO;AACP,4BAA0C;AAC1C,mBAAkC;AAClC,oBAAqC;AACrC,oBAAuB;AACvB,YAAuB;AAEvB,MAAM,cAAc;AAGpB,MAAM,CAAC,qBAAqB,qBAAqB,8CAAmB,WAAW;AAU/E,MAAM,CAAC,gBAAgB,oBAAoB,oBAAwC,WAAW;AAM9F,MAAM,aAAa;AAMnB,MAAM,cAAc,MAAM,WACxB,CAAC,OAAsC,iBAAiB;AA3C1D;AA4CI,QAAM,EAAE,eAAe,KAAK,wBAAwB,MAAM;AAAA,EAAC,MAAM,eAAe;AAChF,QAAM,UAAU,iBAAiB,YAAY,aAAa;AAC1D,QAAM,CAAC,QAAQ,aAAa,MAAM,SAA6B,MAAM;AACrE,QAAM,SAAS,kCAAiB,KAAK;AACrC,QAAM,YAAY,kCAAiB,sCAAa,QAAQ,MAAM,MAAM,MAAjC,mBAAoC,KAAK;AAE5E,QAAM,UAAU,MAAM;AACpB,cAAU,MAAM;AAAA,EAClB,GAAG,CAAC,KAAK,UAAU,GAAG,CAAC,CAAC;AAExB,QAAM,UAAU,MAAM;AACpB,0BAAsB,MAAM;AAC5B,YAAQ,2BAA2B,MAAM;AAAA,EAC3C,GAAG,CAAC,MAAM,CAAC;AAEX,SACE,oCAAC;AAAA,IAAO,YAAU;AAAA,IAAC,QAAQ;AAAA,KACzB,oCAAC;AAAA,IACC,YAAU;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F,SACE,oCAAC;AAAA,IACC;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA,4BAA4B;AAAA,KAE5B,oCAAC;AAAA,IAAY;AAAA,IAAa,GAAG;AAAA,IAAa,KAAK;AAAA,GAAc,CAC/D;AAEJ,CAAC,GACD;AAAA,EACE,OAAO;AAAA,EACP,UAAU;AACZ,CACF;AAEA,OAAO,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
package/dist/cjs/index.js.map
CHANGED
package/dist/esm/Avatar.js
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
var __objRest = (source, exclude) => {
|
|
21
|
-
var target = {};
|
|
22
|
-
for (var prop in source)
|
|
23
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
-
target[prop] = source[prop];
|
|
25
|
-
if (source != null && __getOwnPropSymbols)
|
|
26
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
-
target[prop] = source[prop];
|
|
29
|
-
}
|
|
30
|
-
return target;
|
|
31
|
-
};
|
|
32
1
|
import {
|
|
33
2
|
getVariableValue,
|
|
34
3
|
getVariantExtras,
|
|
@@ -45,13 +14,13 @@ const [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME)
|
|
|
45
14
|
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
46
15
|
const IMAGE_NAME = "AvatarImage";
|
|
47
16
|
const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
48
|
-
var
|
|
49
|
-
const
|
|
50
|
-
}
|
|
17
|
+
var _a;
|
|
18
|
+
const { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
19
|
+
}, ...imageProps } = props;
|
|
51
20
|
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
52
21
|
const [status, setStatus] = React.useState("idle");
|
|
53
22
|
const extras = getVariantExtras(props);
|
|
54
|
-
const shapeSize = getVariableValue((
|
|
23
|
+
const shapeSize = getVariableValue((_a = getShapeSize(context.size, extras)) == null ? void 0 : _a.width);
|
|
55
24
|
React.useEffect(() => {
|
|
56
25
|
setStatus("idle");
|
|
57
26
|
}, [JSON.stringify(src)]);
|
|
@@ -62,12 +31,13 @@ const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
|
62
31
|
return /* @__PURE__ */ React.createElement(YStack, {
|
|
63
32
|
fullscreen: true,
|
|
64
33
|
zIndex: 1
|
|
65
|
-
}, /* @__PURE__ */ React.createElement(Image,
|
|
66
|
-
fullscreen: true
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
34
|
+
}, /* @__PURE__ */ React.createElement(Image, {
|
|
35
|
+
fullscreen: true,
|
|
36
|
+
...typeof shapeSize === "number" && !isNaN(shapeSize) && {
|
|
37
|
+
width: shapeSize,
|
|
38
|
+
height: shapeSize
|
|
39
|
+
},
|
|
40
|
+
...imageProps,
|
|
71
41
|
ref: forwardedRef,
|
|
72
42
|
src,
|
|
73
43
|
onError: () => {
|
|
@@ -76,7 +46,7 @@ const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
|
76
46
|
onLoad: () => {
|
|
77
47
|
setStatus("loaded");
|
|
78
48
|
}
|
|
79
|
-
}))
|
|
49
|
+
}));
|
|
80
50
|
});
|
|
81
51
|
AvatarImage.displayName = IMAGE_NAME;
|
|
82
52
|
const FALLBACK_NAME = "AvatarFallback";
|
|
@@ -87,7 +57,7 @@ const AvatarFallbackFrame = styled(YStack, {
|
|
|
87
57
|
zIndex: 0
|
|
88
58
|
});
|
|
89
59
|
const AvatarFallback = AvatarFallbackFrame.extractable(React.forwardRef((props, forwardedRef) => {
|
|
90
|
-
const
|
|
60
|
+
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
|
|
91
61
|
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
92
62
|
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
93
63
|
React.useEffect(() => {
|
|
@@ -96,9 +66,10 @@ const AvatarFallback = AvatarFallbackFrame.extractable(React.forwardRef((props,
|
|
|
96
66
|
return () => clearTimeout(timerId);
|
|
97
67
|
}
|
|
98
68
|
}, [delayMs]);
|
|
99
|
-
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ React.createElement(AvatarFallbackFrame,
|
|
69
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ React.createElement(AvatarFallbackFrame, {
|
|
70
|
+
...fallbackProps,
|
|
100
71
|
ref: forwardedRef
|
|
101
|
-
})
|
|
72
|
+
}) : null;
|
|
102
73
|
}));
|
|
103
74
|
AvatarFallback.displayName = FALLBACK_NAME;
|
|
104
75
|
const AvatarFrame = styled(Square, {
|
|
@@ -107,18 +78,18 @@ const AvatarFrame = styled(Square, {
|
|
|
107
78
|
overflow: "hidden"
|
|
108
79
|
});
|
|
109
80
|
const Avatar = withStaticProperties(React.forwardRef((props, forwardedRef) => {
|
|
110
|
-
const
|
|
81
|
+
const { __scopeAvatar, size = "$4", ...avatarProps } = props;
|
|
111
82
|
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
112
83
|
return /* @__PURE__ */ React.createElement(AvatarProvider, {
|
|
113
84
|
size,
|
|
114
85
|
scope: __scopeAvatar,
|
|
115
86
|
imageLoadingStatus,
|
|
116
87
|
onImageLoadingStatusChange: setImageLoadingStatus
|
|
117
|
-
}, /* @__PURE__ */ React.createElement(AvatarFrame,
|
|
118
|
-
size
|
|
119
|
-
|
|
88
|
+
}, /* @__PURE__ */ React.createElement(AvatarFrame, {
|
|
89
|
+
size,
|
|
90
|
+
...avatarProps,
|
|
120
91
|
ref: forwardedRef
|
|
121
|
-
}))
|
|
92
|
+
}));
|
|
122
93
|
}), {
|
|
123
94
|
Image: AvatarImage,
|
|
124
95
|
Fallback: AvatarFallback
|
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] = 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(getShapeSize(context.size, extras)?.width) 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>((props: ScopedProps<AvatarProps>, forwardedRef) => {\n const { __scopeAvatar, size = '$4', ...avatarProps } = props\n const [imageLoadingStatus, setImageLoadingStatus] = 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 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": "
|
|
5
|
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
"version": "1.0.1-beta.109",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"clean:build": "tamagui-build clean:build"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
25
|
-
"@tamagui/image": "^1.0.1-beta.
|
|
26
|
-
"@tamagui/shapes": "^1.0.1-beta.
|
|
27
|
-
"@tamagui/text": "^1.0.1-beta.
|
|
28
|
-
"@tamagui/use-event": "^1.0.1-beta.
|
|
24
|
+
"@tamagui/core": "^1.0.1-beta.109",
|
|
25
|
+
"@tamagui/image": "^1.0.1-beta.109",
|
|
26
|
+
"@tamagui/shapes": "^1.0.1-beta.109",
|
|
27
|
+
"@tamagui/text": "^1.0.1-beta.109",
|
|
28
|
+
"@tamagui/use-event": "^1.0.1-beta.109"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"react": "*",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"react-native": "*"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@tamagui/build": "^1.0.1-beta.
|
|
36
|
+
"@tamagui/build": "^1.0.1-beta.109",
|
|
37
37
|
"@types/react-dom": "^18.0.3",
|
|
38
38
|
"@types/react-native": "^0.69.2",
|
|
39
39
|
"react": "*",
|