@radix-ui/react-avatar 1.1.0-rc.2 → 1.1.0-rc.4
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/index.d.mts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +125 -115
- package/dist/index.js.map +3 -3
- package/dist/index.mjs.map +2 -2
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import * as Radix from '@radix-ui/react-primitive';
|
|
3
2
|
import { Primitive } from '@radix-ui/react-primitive';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
type Scope<C = any> = {
|
|
6
5
|
[scopeName: string]: React.Context<C>[];
|
|
7
6
|
} | undefined;
|
|
8
|
-
|
|
7
|
+
type ScopeHook = (scope: Scope) => {
|
|
9
8
|
[__scopeProp: string]: Scope;
|
|
10
9
|
};
|
|
11
10
|
interface CreateScope {
|
|
@@ -14,12 +13,12 @@ interface CreateScope {
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
declare const createAvatarScope: CreateScope;
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
type ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error';
|
|
17
|
+
type PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
|
|
19
18
|
interface AvatarProps extends PrimitiveSpanProps {
|
|
20
19
|
}
|
|
21
20
|
declare const Avatar: React.ForwardRefExoticComponent<AvatarProps & React.RefAttributes<HTMLSpanElement>>;
|
|
22
|
-
|
|
21
|
+
type PrimitiveImageProps = React.ComponentPropsWithoutRef<typeof Primitive.img>;
|
|
23
22
|
interface AvatarImageProps extends PrimitiveImageProps {
|
|
24
23
|
onLoadingStatusChange?: (status: ImageLoadingStatus) => void;
|
|
25
24
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import * as Radix from '@radix-ui/react-primitive';
|
|
3
2
|
import { Primitive } from '@radix-ui/react-primitive';
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
type Scope<C = any> = {
|
|
6
5
|
[scopeName: string]: React.Context<C>[];
|
|
7
6
|
} | undefined;
|
|
8
|
-
|
|
7
|
+
type ScopeHook = (scope: Scope) => {
|
|
9
8
|
[__scopeProp: string]: Scope;
|
|
10
9
|
};
|
|
11
10
|
interface CreateScope {
|
|
@@ -14,12 +13,12 @@ interface CreateScope {
|
|
|
14
13
|
}
|
|
15
14
|
|
|
16
15
|
declare const createAvatarScope: CreateScope;
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
type ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error';
|
|
17
|
+
type PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
|
|
19
18
|
interface AvatarProps extends PrimitiveSpanProps {
|
|
20
19
|
}
|
|
21
20
|
declare const Avatar: React.ForwardRefExoticComponent<AvatarProps & React.RefAttributes<HTMLSpanElement>>;
|
|
22
|
-
|
|
21
|
+
type PrimitiveImageProps = React.ComponentPropsWithoutRef<typeof Primitive.img>;
|
|
23
22
|
interface AvatarImageProps extends PrimitiveImageProps {
|
|
24
23
|
onLoadingStatusChange?: (status: ImageLoadingStatus) => void;
|
|
25
24
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,122 +1,132 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
mod
|
|
31
|
-
));
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
84
|
-
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
85
|
-
React.useEffect(() => {
|
|
86
|
-
if (delayMs !== void 0) {
|
|
87
|
-
const timerId = window.setTimeout(() => setCanRender(true), delayMs);
|
|
88
|
-
return () => window.clearTimeout(timerId);
|
|
89
|
-
}
|
|
90
|
-
}, [delayMs]);
|
|
91
|
-
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.span, { ...fallbackProps, ref: forwardedRef }) : null;
|
|
92
|
-
}
|
|
93
|
-
);
|
|
94
|
-
AvatarFallback.displayName = FALLBACK_NAME;
|
|
95
|
-
function useImageLoadingStatus(src) {
|
|
96
|
-
const [loadingStatus, setLoadingStatus] = React.useState("idle");
|
|
31
|
+
// packages/react/avatar/src/index.ts
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
Avatar: () => Avatar,
|
|
35
|
+
AvatarFallback: () => AvatarFallback,
|
|
36
|
+
AvatarImage: () => AvatarImage,
|
|
37
|
+
Fallback: () => Fallback,
|
|
38
|
+
Image: () => Image,
|
|
39
|
+
Root: () => Root,
|
|
40
|
+
createAvatarScope: () => createAvatarScope
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
|
43
|
+
|
|
44
|
+
// packages/react/avatar/src/Avatar.tsx
|
|
45
|
+
var React = __toESM(require("react"));
|
|
46
|
+
var import_react_context = require("@radix-ui/react-context");
|
|
47
|
+
var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
|
|
48
|
+
var import_react_use_layout_effect = require("@radix-ui/react-use-layout-effect");
|
|
49
|
+
var import_react_primitive = require("@radix-ui/react-primitive");
|
|
50
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
51
|
+
var AVATAR_NAME = "Avatar";
|
|
52
|
+
var [createAvatarContext, createAvatarScope] = (0, import_react_context.createContextScope)(AVATAR_NAME);
|
|
53
|
+
var [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
|
|
54
|
+
var Avatar = React.forwardRef(
|
|
55
|
+
(props, forwardedRef) => {
|
|
56
|
+
const { __scopeAvatar, ...avatarProps } = props;
|
|
57
|
+
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
|
|
58
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
59
|
+
AvatarProvider,
|
|
60
|
+
{
|
|
61
|
+
scope: __scopeAvatar,
|
|
62
|
+
imageLoadingStatus,
|
|
63
|
+
onImageLoadingStatusChange: setImageLoadingStatus,
|
|
64
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.span, { ...avatarProps, ref: forwardedRef })
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
Avatar.displayName = AVATAR_NAME;
|
|
70
|
+
var IMAGE_NAME = "AvatarImage";
|
|
71
|
+
var AvatarImage = React.forwardRef(
|
|
72
|
+
(props, forwardedRef) => {
|
|
73
|
+
const { __scopeAvatar, src, onLoadingStatusChange = () => {
|
|
74
|
+
}, ...imageProps } = props;
|
|
75
|
+
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
|
|
76
|
+
const imageLoadingStatus = useImageLoadingStatus(src);
|
|
77
|
+
const handleLoadingStatusChange = (0, import_react_use_callback_ref.useCallbackRef)((status) => {
|
|
78
|
+
onLoadingStatusChange(status);
|
|
79
|
+
context.onImageLoadingStatusChange(status);
|
|
80
|
+
});
|
|
97
81
|
(0, import_react_use_layout_effect.useLayoutEffect)(() => {
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
return;
|
|
82
|
+
if (imageLoadingStatus !== "idle") {
|
|
83
|
+
handleLoadingStatusChange(imageLoadingStatus);
|
|
101
84
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const updateStatus = (status) => () => {
|
|
105
|
-
if (!isMounted) return;
|
|
106
|
-
setLoadingStatus(status);
|
|
107
|
-
};
|
|
108
|
-
setLoadingStatus("loading");
|
|
109
|
-
image.onload = updateStatus("loaded");
|
|
110
|
-
image.onerror = updateStatus("error");
|
|
111
|
-
image.src = src;
|
|
112
|
-
return () => {
|
|
113
|
-
isMounted = false;
|
|
114
|
-
};
|
|
115
|
-
}, [src]);
|
|
116
|
-
return loadingStatus;
|
|
85
|
+
}, [imageLoadingStatus, handleLoadingStatusChange]);
|
|
86
|
+
return imageLoadingStatus === "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.img, { ...imageProps, ref: forwardedRef, src }) : null;
|
|
117
87
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
88
|
+
);
|
|
89
|
+
AvatarImage.displayName = IMAGE_NAME;
|
|
90
|
+
var FALLBACK_NAME = "AvatarFallback";
|
|
91
|
+
var AvatarFallback = React.forwardRef(
|
|
92
|
+
(props, forwardedRef) => {
|
|
93
|
+
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
|
|
94
|
+
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
|
|
95
|
+
const [canRender, setCanRender] = React.useState(delayMs === void 0);
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
if (delayMs !== void 0) {
|
|
98
|
+
const timerId = window.setTimeout(() => setCanRender(true), delayMs);
|
|
99
|
+
return () => window.clearTimeout(timerId);
|
|
100
|
+
}
|
|
101
|
+
}, [delayMs]);
|
|
102
|
+
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.span, { ...fallbackProps, ref: forwardedRef }) : null;
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
AvatarFallback.displayName = FALLBACK_NAME;
|
|
106
|
+
function useImageLoadingStatus(src) {
|
|
107
|
+
const [loadingStatus, setLoadingStatus] = React.useState("idle");
|
|
108
|
+
(0, import_react_use_layout_effect.useLayoutEffect)(() => {
|
|
109
|
+
if (!src) {
|
|
110
|
+
setLoadingStatus("error");
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
let isMounted = true;
|
|
114
|
+
const image = new window.Image();
|
|
115
|
+
const updateStatus = (status) => () => {
|
|
116
|
+
if (!isMounted) return;
|
|
117
|
+
setLoadingStatus(status);
|
|
118
|
+
};
|
|
119
|
+
setLoadingStatus("loading");
|
|
120
|
+
image.onload = updateStatus("loaded");
|
|
121
|
+
image.onerror = updateStatus("error");
|
|
122
|
+
image.src = src;
|
|
123
|
+
return () => {
|
|
124
|
+
isMounted = false;
|
|
125
|
+
};
|
|
126
|
+
}, [src]);
|
|
127
|
+
return loadingStatus;
|
|
128
|
+
}
|
|
129
|
+
var Root = Avatar;
|
|
130
|
+
var Image = AvatarImage;
|
|
131
|
+
var Fallback = AvatarFallback;
|
|
122
132
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/Avatar.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type
|
|
5
|
-
"mappings": "
|
|
3
|
+
"sources": ["../src/index.ts", "../src/Avatar.tsx"],
|
|
4
|
+
"sourcesContent": ["'use client';\nexport {\n createAvatarScope,\n //\n Avatar,\n AvatarImage,\n AvatarFallback,\n //\n Root,\n Image,\n Fallback,\n} from './Avatar';\nexport type { AvatarProps, AvatarImageProps, AvatarFallbackProps } from './Avatar';\n", "import * as React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Avatar\n * -----------------------------------------------------------------------------------------------*/\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 imageLoadingStatus: ImageLoadingStatus;\n onImageLoadingStatusChange(status: ImageLoadingStatus): void;\n};\n\nconst [AvatarProvider, useAvatarContext] = createAvatarContext<AvatarContextValue>(AVATAR_NAME);\n\ntype AvatarElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface AvatarProps extends PrimitiveSpanProps {}\n\nconst Avatar = React.forwardRef<AvatarElement, AvatarProps>(\n (props: ScopedProps<AvatarProps>, forwardedRef) => {\n const { __scopeAvatar, ...avatarProps } = props;\n const [imageLoadingStatus, setImageLoadingStatus] = React.useState<ImageLoadingStatus>('idle');\n return (\n <AvatarProvider\n scope={__scopeAvatar}\n imageLoadingStatus={imageLoadingStatus}\n onImageLoadingStatusChange={setImageLoadingStatus}\n >\n <Primitive.span {...avatarProps} ref={forwardedRef} />\n </AvatarProvider>\n );\n }\n);\n\nAvatar.displayName = AVATAR_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarImage\n * -----------------------------------------------------------------------------------------------*/\n\nconst IMAGE_NAME = 'AvatarImage';\n\ntype AvatarImageElement = React.ElementRef<typeof Primitive.img>;\ntype PrimitiveImageProps = React.ComponentPropsWithoutRef<typeof Primitive.img>;\ninterface AvatarImageProps extends PrimitiveImageProps {\n onLoadingStatusChange?: (status: ImageLoadingStatus) => void;\n}\n\nconst AvatarImage = React.forwardRef<AvatarImageElement, AvatarImageProps>(\n (props: ScopedProps<AvatarImageProps>, forwardedRef) => {\n const { __scopeAvatar, src, onLoadingStatusChange = () => {}, ...imageProps } = props;\n const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);\n const imageLoadingStatus = useImageLoadingStatus(src);\n const handleLoadingStatusChange = useCallbackRef((status: ImageLoadingStatus) => {\n onLoadingStatusChange(status);\n context.onImageLoadingStatusChange(status);\n });\n\n useLayoutEffect(() => {\n if (imageLoadingStatus !== 'idle') {\n handleLoadingStatusChange(imageLoadingStatus);\n }\n }, [imageLoadingStatus, handleLoadingStatusChange]);\n\n return imageLoadingStatus === 'loaded' ? (\n <Primitive.img {...imageProps} ref={forwardedRef} src={src} />\n ) : null;\n }\n);\n\nAvatarImage.displayName = IMAGE_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarFallback\n * -----------------------------------------------------------------------------------------------*/\n\nconst FALLBACK_NAME = 'AvatarFallback';\n\ntype AvatarFallbackElement = React.ElementRef<typeof Primitive.span>;\ninterface AvatarFallbackProps extends PrimitiveSpanProps {\n delayMs?: number;\n}\n\nconst AvatarFallback = React.forwardRef<AvatarFallbackElement, 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 = window.setTimeout(() => setCanRender(true), delayMs);\n return () => window.clearTimeout(timerId);\n }\n }, [delayMs]);\n\n return canRender && context.imageLoadingStatus !== 'loaded' ? (\n <Primitive.span {...fallbackProps} ref={forwardedRef} />\n ) : null;\n }\n);\n\nAvatarFallback.displayName = FALLBACK_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction useImageLoadingStatus(src?: string) {\n const [loadingStatus, setLoadingStatus] = React.useState<ImageLoadingStatus>('idle');\n\n useLayoutEffect(() => {\n if (!src) {\n setLoadingStatus('error');\n return;\n }\n\n let isMounted = true;\n const image = new window.Image();\n\n const updateStatus = (status: ImageLoadingStatus) => () => {\n if (!isMounted) return;\n setLoadingStatus(status);\n };\n\n setLoadingStatus('loading');\n image.onload = updateStatus('loaded');\n image.onerror = updateStatus('error');\n image.src = src;\n\n return () => {\n isMounted = false;\n };\n }, [src]);\n\n return loadingStatus;\n}\nconst Root = Avatar;\nconst Image = AvatarImage;\nconst Fallback = AvatarFallback;\n\nexport {\n createAvatarScope,\n //\n Avatar,\n AvatarImage,\n AvatarFallback,\n //\n Root,\n Image,\n Fallback,\n};\nexport type { AvatarProps, AvatarImageProps, AvatarFallbackProps };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,2BAAmC;AACnC,oCAA+B;AAC/B,qCAAgC;AAChC,6BAA0B;AAoClB;AA5BR,IAAM,cAAc;AAGpB,IAAM,CAAC,qBAAqB,iBAAiB,QAAI,yCAAmB,WAAW;AAS/E,IAAM,CAAC,gBAAgB,gBAAgB,IAAI,oBAAwC,WAAW;AAM9F,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,MAAM,aAAa,IAAI,GAAG,OAAO;AACnE,eAAO,MAAM,OAAO,aAAa,OAAO;AAAA,MAC1C;AAAA,IACF,GAAG,CAAC,OAAO,CAAC;AAEZ,WAAO,aAAa,QAAQ,uBAAuB,WACjD,4CAAC,iCAAU,MAAV,EAAgB,GAAG,eAAe,KAAK,cAAc,IACpD;AAAA,EACN;AACF;AAEA,eAAe,cAAc;AAI7B,SAAS,sBAAsB,KAAc;AAC3C,QAAM,CAAC,eAAe,gBAAgB,IAAU,eAA6B,MAAM;AAEnF,sDAAgB,MAAM;AACpB,QAAI,CAAC,KAAK;AACR,uBAAiB,OAAO;AACxB;AAAA,IACF;AAEA,QAAI,YAAY;AAChB,UAAM,QAAQ,IAAI,OAAO,MAAM;AAE/B,UAAM,eAAe,CAAC,WAA+B,MAAM;AACzD,UAAI,CAAC,UAAW;AAChB,uBAAiB,MAAM;AAAA,IACzB;AAEA,qBAAiB,SAAS;AAC1B,UAAM,SAAS,aAAa,QAAQ;AACpC,UAAM,UAAU,aAAa,OAAO;AACpC,UAAM,MAAM;AAEZ,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AAER,SAAO;AACT;AACA,IAAM,OAAO;AACb,IAAM,QAAQ;AACd,IAAM,WAAW;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/Avatar.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type
|
|
5
|
-
"mappings": ";;;AAAA,YAAY,WAAW;AACvB,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nimport { createContextScope } from '@radix-ui/react-context';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\nimport { useLayoutEffect } from '@radix-ui/react-use-layout-effect';\nimport { Primitive } from '@radix-ui/react-primitive';\n\nimport type { Scope } from '@radix-ui/react-context';\n\n/* -------------------------------------------------------------------------------------------------\n * Avatar\n * -----------------------------------------------------------------------------------------------*/\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 imageLoadingStatus: ImageLoadingStatus;\n onImageLoadingStatusChange(status: ImageLoadingStatus): void;\n};\n\nconst [AvatarProvider, useAvatarContext] = createAvatarContext<AvatarContextValue>(AVATAR_NAME);\n\ntype AvatarElement = React.ElementRef<typeof Primitive.span>;\ntype PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;\ninterface AvatarProps extends PrimitiveSpanProps {}\n\nconst Avatar = React.forwardRef<AvatarElement, AvatarProps>(\n (props: ScopedProps<AvatarProps>, forwardedRef) => {\n const { __scopeAvatar, ...avatarProps } = props;\n const [imageLoadingStatus, setImageLoadingStatus] = React.useState<ImageLoadingStatus>('idle');\n return (\n <AvatarProvider\n scope={__scopeAvatar}\n imageLoadingStatus={imageLoadingStatus}\n onImageLoadingStatusChange={setImageLoadingStatus}\n >\n <Primitive.span {...avatarProps} ref={forwardedRef} />\n </AvatarProvider>\n );\n }\n);\n\nAvatar.displayName = AVATAR_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarImage\n * -----------------------------------------------------------------------------------------------*/\n\nconst IMAGE_NAME = 'AvatarImage';\n\ntype AvatarImageElement = React.ElementRef<typeof Primitive.img>;\ntype PrimitiveImageProps = React.ComponentPropsWithoutRef<typeof Primitive.img>;\ninterface AvatarImageProps extends PrimitiveImageProps {\n onLoadingStatusChange?: (status: ImageLoadingStatus) => void;\n}\n\nconst AvatarImage = React.forwardRef<AvatarImageElement, AvatarImageProps>(\n (props: ScopedProps<AvatarImageProps>, forwardedRef) => {\n const { __scopeAvatar, src, onLoadingStatusChange = () => {}, ...imageProps } = props;\n const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);\n const imageLoadingStatus = useImageLoadingStatus(src);\n const handleLoadingStatusChange = useCallbackRef((status: ImageLoadingStatus) => {\n onLoadingStatusChange(status);\n context.onImageLoadingStatusChange(status);\n });\n\n useLayoutEffect(() => {\n if (imageLoadingStatus !== 'idle') {\n handleLoadingStatusChange(imageLoadingStatus);\n }\n }, [imageLoadingStatus, handleLoadingStatusChange]);\n\n return imageLoadingStatus === 'loaded' ? (\n <Primitive.img {...imageProps} ref={forwardedRef} src={src} />\n ) : null;\n }\n);\n\nAvatarImage.displayName = IMAGE_NAME;\n\n/* -------------------------------------------------------------------------------------------------\n * AvatarFallback\n * -----------------------------------------------------------------------------------------------*/\n\nconst FALLBACK_NAME = 'AvatarFallback';\n\ntype AvatarFallbackElement = React.ElementRef<typeof Primitive.span>;\ninterface AvatarFallbackProps extends PrimitiveSpanProps {\n delayMs?: number;\n}\n\nconst AvatarFallback = React.forwardRef<AvatarFallbackElement, 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 = window.setTimeout(() => setCanRender(true), delayMs);\n return () => window.clearTimeout(timerId);\n }\n }, [delayMs]);\n\n return canRender && context.imageLoadingStatus !== 'loaded' ? (\n <Primitive.span {...fallbackProps} ref={forwardedRef} />\n ) : null;\n }\n);\n\nAvatarFallback.displayName = FALLBACK_NAME;\n\n/* -----------------------------------------------------------------------------------------------*/\n\nfunction useImageLoadingStatus(src?: string) {\n const [loadingStatus, setLoadingStatus] = React.useState<ImageLoadingStatus>('idle');\n\n useLayoutEffect(() => {\n if (!src) {\n setLoadingStatus('error');\n return;\n }\n\n let isMounted = true;\n const image = new window.Image();\n\n const updateStatus = (status: ImageLoadingStatus) => () => {\n if (!isMounted) return;\n setLoadingStatus(status);\n };\n\n setLoadingStatus('loading');\n image.onload = updateStatus('loaded');\n image.onerror = updateStatus('error');\n image.src = src;\n\n return () => {\n isMounted = false;\n };\n }, [src]);\n\n return loadingStatus;\n}\nconst Root = Avatar;\nconst Image = AvatarImage;\nconst Fallback = AvatarFallback;\n\nexport {\n createAvatarScope,\n //\n Avatar,\n AvatarImage,\n AvatarFallback,\n //\n Root,\n Image,\n Fallback,\n};\nexport type { AvatarProps, AvatarImageProps, AvatarFallbackProps };\n"],
|
|
5
|
+
"mappings": ";;;AAAA,YAAY,WAAW;AACvB,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAoClB;AA5BR,IAAM,cAAc;AAGpB,IAAM,CAAC,qBAAqB,iBAAiB,IAAI,mBAAmB,WAAW;AAS/E,IAAM,CAAC,gBAAgB,gBAAgB,IAAI,oBAAwC,WAAW;AAM9F,IAAM,SAAe;AAAA,EACnB,CAAC,OAAiC,iBAAiB;AACjD,UAAM,EAAE,eAAe,GAAG,YAAY,IAAI;AAC1C,UAAM,CAAC,oBAAoB,qBAAqB,IAAU,eAA6B,MAAM;AAC7F,WACE;AAAA,MAAC;AAAA;AAAA,QACC,OAAO;AAAA,QACP;AAAA,QACA,4BAA4B;AAAA,QAE5B,8BAAC,UAAU,MAAV,EAAgB,GAAG,aAAa,KAAK,cAAc;AAAA;AAAA,IACtD;AAAA,EAEJ;AACF;AAEA,OAAO,cAAc;AAMrB,IAAM,aAAa;AAQnB,IAAM,cAAoB;AAAA,EACxB,C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xB;AAAA,IACF;AAEA,QAAI,YAAY;AAChB,UAAM,QAAQ,IAAI,OAAO,MAAM;AAE/B,UAAM,eAAe,CAAC,WAA+B,MAAM;AACzD,UAAI,CAAC,UAAW;AAChB,uBAAiB,MAAM;AAAA,IACzB;AAEA,qBAAiB,SAAS;AAC1B,UAAM,SAAS,aAAa,QAAQ;AACpC,UAAM,UAAU,aAAa,OAAO;AACpC,UAAM,MAAM;AAEZ,WAAO,MAAM;AACX,kBAAY;AAAA,IACd;AAAA,EACF,GAAG,CAAC,GAAG,CAAC;AAER,SAAO;AACT;AACA,IAAM,OAAO;AACb,IAAM,QAAQ;AACd,IAAM,WAAW;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@radix-ui/react-avatar",
|
|
3
|
-
"version": "1.1.0-rc.
|
|
3
|
+
"version": "1.1.0-rc.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"version": "yarn version"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@radix-ui/react-context": "1.1.0-rc.
|
|
32
|
-
"@radix-ui/react-primitive": "
|
|
33
|
-
"@radix-ui/react-use-callback-ref": "1.1.0-rc.
|
|
34
|
-
"@radix-ui/react-use-layout-effect": "1.1.0-rc.
|
|
31
|
+
"@radix-ui/react-context": "1.1.0-rc.4",
|
|
32
|
+
"@radix-ui/react-primitive": "2.0.0-rc.1",
|
|
33
|
+
"@radix-ui/react-use-callback-ref": "1.1.0-rc.4",
|
|
34
|
+
"@radix-ui/react-use-layout-effect": "1.1.0-rc.4"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
37
|
"@types/react": "*",
|
|
38
38
|
"@types/react-dom": "*",
|
|
39
|
-
"react": "^16.8 || ^17.0 || ^18.0",
|
|
40
|
-
"react-dom": "^16.8 || ^17.0 || ^18.0"
|
|
39
|
+
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0",
|
|
40
|
+
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
43
43
|
"@types/react": {
|