@tamagui/avatar 1.0.1-beta.75 → 1.0.1-beta.76
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/esm/Avatar.js +50 -21
- package/dist/esm/Avatar.js.map +1 -1
- package/package.json +6 -6
package/dist/esm/Avatar.js
CHANGED
|
@@ -1,3 +1,34 @@
|
|
|
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
|
+
};
|
|
1
32
|
import {
|
|
2
33
|
getVariableValue,
|
|
3
34
|
getVariantExtras,
|
|
@@ -14,13 +45,13 @@ const [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME)
|
|
|
14
45
|
const [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
15
46
|
const IMAGE_NAME = "AvatarImage";
|
|
16
47
|
const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
17
|
-
var
|
|
18
|
-
const { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
19
|
-
},
|
|
48
|
+
var _b;
|
|
49
|
+
const _a = props, { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
50
|
+
} } = _a, imageProps = __objRest(_a, ["__scopeAvatar", "src", "onLoadingStatusChange"]);
|
|
20
51
|
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
21
52
|
const [status, setStatus] = React.useState("idle");
|
|
22
53
|
const extras = getVariantExtras(props);
|
|
23
|
-
const shapeSize = getVariableValue((
|
|
54
|
+
const shapeSize = getVariableValue((_b = getShapeSize(context.size, extras)) == null ? void 0 : _b.width);
|
|
24
55
|
React.useEffect(() => {
|
|
25
56
|
setStatus("idle");
|
|
26
57
|
}, [JSON.stringify(src)]);
|
|
@@ -31,13 +62,12 @@ const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
|
31
62
|
return /* @__PURE__ */ React.createElement(YStack, {
|
|
32
63
|
fullscreen: true,
|
|
33
64
|
zIndex: 1
|
|
34
|
-
}, /* @__PURE__ */ React.createElement(Image, {
|
|
35
|
-
fullscreen: true
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
...imageProps,
|
|
65
|
+
}, /* @__PURE__ */ React.createElement(Image, __spreadProps(__spreadValues(__spreadValues({
|
|
66
|
+
fullscreen: true
|
|
67
|
+
}, typeof shapeSize === "number" && !isNaN(shapeSize) && {
|
|
68
|
+
width: shapeSize,
|
|
69
|
+
height: shapeSize
|
|
70
|
+
}), imageProps), {
|
|
41
71
|
ref: forwardedRef,
|
|
42
72
|
src,
|
|
43
73
|
onError: () => {
|
|
@@ -46,7 +76,7 @@ const AvatarImage = React.forwardRef((props, forwardedRef) => {
|
|
|
46
76
|
onLoad: () => {
|
|
47
77
|
setStatus("loaded");
|
|
48
78
|
}
|
|
49
|
-
}));
|
|
79
|
+
})));
|
|
50
80
|
});
|
|
51
81
|
AvatarImage.displayName = IMAGE_NAME;
|
|
52
82
|
const FALLBACK_NAME = "AvatarFallback";
|
|
@@ -57,7 +87,7 @@ const AvatarFallbackFrame = styled(YStack, {
|
|
|
57
87
|
zIndex: 0
|
|
58
88
|
});
|
|
59
89
|
const AvatarFallback = AvatarFallbackFrame.extractable(React.forwardRef((props, forwardedRef) => {
|
|
60
|
-
const { __scopeAvatar, delayMs,
|
|
90
|
+
const _a = props, { __scopeAvatar, delayMs } = _a, fallbackProps = __objRest(_a, ["__scopeAvatar", "delayMs"]);
|
|
61
91
|
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
62
92
|
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
63
93
|
React.useEffect(() => {
|
|
@@ -66,10 +96,9 @@ const AvatarFallback = AvatarFallbackFrame.extractable(React.forwardRef((props,
|
|
|
66
96
|
return () => clearTimeout(timerId);
|
|
67
97
|
}
|
|
68
98
|
}, [delayMs]);
|
|
69
|
-
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ React.createElement(AvatarFallbackFrame, {
|
|
70
|
-
...fallbackProps,
|
|
99
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ React.createElement(AvatarFallbackFrame, __spreadProps(__spreadValues({}, fallbackProps), {
|
|
71
100
|
ref: forwardedRef
|
|
72
|
-
}) : null;
|
|
101
|
+
})) : null;
|
|
73
102
|
}));
|
|
74
103
|
AvatarFallback.displayName = FALLBACK_NAME;
|
|
75
104
|
const AvatarFrame = styled(Square, {
|
|
@@ -78,18 +107,18 @@ const AvatarFrame = styled(Square, {
|
|
|
78
107
|
overflow: "hidden"
|
|
79
108
|
});
|
|
80
109
|
const Avatar = withStaticProperties(React.forwardRef((props, forwardedRef) => {
|
|
81
|
-
const { __scopeAvatar, size = "$4",
|
|
110
|
+
const _a = props, { __scopeAvatar, size = "$4" } = _a, avatarProps = __objRest(_a, ["__scopeAvatar", "size"]);
|
|
82
111
|
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
83
112
|
return /* @__PURE__ */ React.createElement(AvatarProvider, {
|
|
84
113
|
size,
|
|
85
114
|
scope: __scopeAvatar,
|
|
86
115
|
imageLoadingStatus,
|
|
87
116
|
onImageLoadingStatusChange: setImageLoadingStatus
|
|
88
|
-
}, /* @__PURE__ */ React.createElement(AvatarFrame, {
|
|
89
|
-
size
|
|
90
|
-
|
|
117
|
+
}, /* @__PURE__ */ React.createElement(AvatarFrame, __spreadProps(__spreadValues({
|
|
118
|
+
size
|
|
119
|
+
}, avatarProps), {
|
|
91
120
|
ref: forwardedRef
|
|
92
|
-
}));
|
|
121
|
+
})));
|
|
93
122
|
}), {
|
|
94
123
|
Image: AvatarImage,
|
|
95
124
|
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": "AAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AACA;AACA;AACA;AAEA,MAAM,cAAc;AAGpB,MAAM,CAAC,qBAAqB,qBAAqB,mBAAmB,WAAW;AAU/E,MAAM,CAAC,gBAAgB,oBAAoB,oBAAwC,WAAW;AAM9F,MAAM,aAAa;AAMnB,MAAM,cAAc,MAAM,WACxB,CAAC,OAAsC,iBAAiB;AA3C1D;AA4CI,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AACA;AACA;AACA;AACA;AAEA,MAAM,cAAc;AAGpB,MAAM,CAAC,qBAAqB,qBAAqB,mBAAmB,WAAW;AAU/E,MAAM,CAAC,gBAAgB,oBAAoB,oBAAwC,WAAW;AAM9F,MAAM,aAAa;AAMnB,MAAM,cAAc,MAAM,WACxB,CAAC,OAAsC,iBAAiB;AA3C1D;AA4CI,QAAgF,YAAxE,iBAAe,KAAK,wBAAwB,MAAM;AAAA,EAAC,MAAqB,IAAf,uBAAe,IAAf,CAAzD,iBAAe,OAAK;AAC5B,QAAM,UAAU,iBAAiB,YAAY,aAAa;AAC1D,QAAM,CAAC,QAAQ,aAAa,MAAM,SAA6B,MAAM;AACrE,QAAM,SAAS,iBAAiB,KAAK;AACrC,QAAM,YAAY,iBAAiB,mBAAa,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;AAE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/F,QAAuD,YAA/C,iBAAe,OAAO,SAAyB,IAAhB,wBAAgB,IAAhB,CAA/B,iBAAe;AACvB,QAAM,CAAC,oBAAoB,yBAAyB,MAAM,SAA6B,MAAM;AAC7F,SACE,oCAAC;AAAA,IACC;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA,4BAA4B;AAAA,KAE5B,oCAAC;AAAA,IAAY;AAAA,KAAgB,cAA5B;AAAA,IAAyC,KAAK;AAAA,IAAc,CAC/D;AAEJ,CAAC,GACD;AAAA,EACE,OAAO;AAAA,EACP,UAAU;AACZ,CACF;AAEA,OAAO,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/avatar",
|
|
3
|
-
"version": "1.0.1-beta.
|
|
3
|
+
"version": "1.0.1-beta.76",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@radix-ui/react-use-callback-ref": "^0.1.0",
|
|
25
|
-
"@tamagui/core": "^1.0.1-beta.
|
|
26
|
-
"@tamagui/image": "^1.0.1-beta.
|
|
27
|
-
"@tamagui/shapes": "^1.0.1-beta.
|
|
28
|
-
"@tamagui/text": "^1.0.1-beta.
|
|
25
|
+
"@tamagui/core": "^1.0.1-beta.76",
|
|
26
|
+
"@tamagui/image": "^1.0.1-beta.76",
|
|
27
|
+
"@tamagui/shapes": "^1.0.1-beta.76",
|
|
28
|
+
"@tamagui/text": "^1.0.1-beta.76"
|
|
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.76",
|
|
37
37
|
"@types/react-dom": "^18.0.3",
|
|
38
38
|
"@types/react-native": "^0.67.3",
|
|
39
39
|
"react": "*",
|