first commit

This commit is contained in:
2026-06-24 09:48:54 +02:00
commit 41e62ddcad
33739 changed files with 4266226 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 WorkOS
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+3
View File
@@ -0,0 +1,3 @@
# `react-avatar`
View docs [here](https://radix-ui.com/primitives/docs/components/avatar).
+21
View File
@@ -0,0 +1,21 @@
import * as _radix_ui_react_context from '@radix-ui/react-context';
import * as React from 'react';
import { Primitive } from '@radix-ui/react-primitive';
declare const createAvatarScope: _radix_ui_react_context.CreateScope;
type ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error';
type PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
interface AvatarProps extends PrimitiveSpanProps {
}
declare const Avatar: React.ForwardRefExoticComponent<AvatarProps & React.RefAttributes<HTMLSpanElement>>;
type PrimitiveImageProps = React.ComponentPropsWithoutRef<typeof Primitive.img>;
interface AvatarImageProps extends PrimitiveImageProps {
onLoadingStatusChange?: (status: ImageLoadingStatus) => void;
}
declare const AvatarImage: React.ForwardRefExoticComponent<AvatarImageProps & React.RefAttributes<HTMLImageElement>>;
interface AvatarFallbackProps extends PrimitiveSpanProps {
delayMs?: number;
}
declare const AvatarFallback: React.ForwardRefExoticComponent<AvatarFallbackProps & React.RefAttributes<HTMLSpanElement>>;
export { Avatar, AvatarFallback, type AvatarFallbackProps, AvatarImage, type AvatarImageProps, type AvatarProps, AvatarFallback as Fallback, AvatarImage as Image, Avatar as Root, createAvatarScope };
+21
View File
@@ -0,0 +1,21 @@
import * as _radix_ui_react_context from '@radix-ui/react-context';
import * as React from 'react';
import { Primitive } from '@radix-ui/react-primitive';
declare const createAvatarScope: _radix_ui_react_context.CreateScope;
type ImageLoadingStatus = 'idle' | 'loading' | 'loaded' | 'error';
type PrimitiveSpanProps = React.ComponentPropsWithoutRef<typeof Primitive.span>;
interface AvatarProps extends PrimitiveSpanProps {
}
declare const Avatar: React.ForwardRefExoticComponent<AvatarProps & React.RefAttributes<HTMLSpanElement>>;
type PrimitiveImageProps = React.ComponentPropsWithoutRef<typeof Primitive.img>;
interface AvatarImageProps extends PrimitiveImageProps {
onLoadingStatusChange?: (status: ImageLoadingStatus) => void;
}
declare const AvatarImage: React.ForwardRefExoticComponent<AvatarImageProps & React.RefAttributes<HTMLImageElement>>;
interface AvatarFallbackProps extends PrimitiveSpanProps {
delayMs?: number;
}
declare const AvatarFallback: React.ForwardRefExoticComponent<AvatarFallbackProps & React.RefAttributes<HTMLSpanElement>>;
export { Avatar, AvatarFallback, type AvatarFallbackProps, AvatarImage, type AvatarImageProps, type AvatarProps, AvatarFallback as Fallback, AvatarImage as Image, Avatar as Root, createAvatarScope };
+183
View File
@@ -0,0 +1,183 @@
"use strict";
"use client";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var index_exports = {};
__export(index_exports, {
Avatar: () => Avatar,
AvatarFallback: () => AvatarFallback,
AvatarImage: () => AvatarImage,
Fallback: () => AvatarFallback,
Image: () => AvatarImage,
Root: () => Avatar,
createAvatarScope: () => createAvatarScope
});
module.exports = __toCommonJS(index_exports);
// src/avatar.tsx
var React = __toESM(require("react"));
var import_react_context = require("@radix-ui/react-context");
var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
var import_react_use_layout_effect = require("@radix-ui/react-use-layout-effect");
var import_react_primitive = require("@radix-ui/react-primitive");
var import_jsx_runtime = require("react/jsx-runtime");
var AVATAR_NAME = "Avatar";
var [createAvatarContext, createAvatarScope] = (0, import_react_context.createContextScope)(AVATAR_NAME);
var STATIC_IMAGE_COUNT_STATE = [
0,
() => void 0
];
var [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
var Avatar = React.forwardRef(
(props, forwardedRef) => {
const { __scopeAvatar, ...avatarProps } = props;
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
const [imageCount, setImageCount] = useImageCount();
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
AvatarProvider,
{
scope: __scopeAvatar,
imageLoadingStatus,
setImageLoadingStatus,
imageCount,
setImageCount,
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.span, { ...avatarProps, ref: forwardedRef })
}
);
}
);
Avatar.displayName = AVATAR_NAME;
var IMAGE_NAME = "AvatarImage";
var AvatarImage = React.forwardRef(
(props, forwardedRef) => {
const { __scopeAvatar, src, onLoadingStatusChange, ...imageProps } = props;
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
useUpdateImageCount(context.setImageCount);
const imageLoadingStatus = useImageLoadingStatus(src, {
referrerPolicy: imageProps.referrerPolicy,
crossOrigin: imageProps.crossOrigin,
loadingStatus: context.imageLoadingStatus,
setLoadingStatus: context.setImageLoadingStatus
});
const handleLoadingStatusChange = (0, import_react_use_callback_ref.useCallbackRef)((status) => {
onLoadingStatusChange?.(status);
});
const loadingStatusRef = React.useRef(imageLoadingStatus);
(0, import_react_use_layout_effect.useLayoutEffect)(() => {
const previousLoadingStatus = loadingStatusRef.current;
loadingStatusRef.current = imageLoadingStatus;
if (imageLoadingStatus !== previousLoadingStatus) {
handleLoadingStatusChange(imageLoadingStatus);
}
}, [imageLoadingStatus, handleLoadingStatusChange]);
return imageLoadingStatus === "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.img, { ...imageProps, ref: forwardedRef, src }) : null;
}
);
AvatarImage.displayName = IMAGE_NAME;
var FALLBACK_NAME = "AvatarFallback";
var AvatarFallback = React.forwardRef(
(props, forwardedRef) => {
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
const [canRender, setCanRender] = React.useState(delayMs === void 0);
React.useEffect(() => {
if (delayMs !== void 0) {
const timerId = window.setTimeout(() => setCanRender(true), delayMs);
return () => window.clearTimeout(timerId);
}
}, [delayMs]);
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_primitive.Primitive.span, { ...fallbackProps, ref: forwardedRef }) : null;
}
);
AvatarFallback.displayName = FALLBACK_NAME;
function useImageLoadingStatus(src, {
loadingStatus,
setLoadingStatus,
referrerPolicy,
crossOrigin
}) {
(0, import_react_use_layout_effect.useLayoutEffect)(() => {
if (!src) {
setLoadingStatus("error");
return;
}
const image = new window.Image();
const handleLoad = (event) => {
const image2 = event.currentTarget;
setLoadingStatus(getImageLoadingStatus(image2));
};
const handleError = () => setLoadingStatus("error");
image.addEventListener("load", handleLoad);
image.addEventListener("error", handleError);
if (referrerPolicy) {
image.referrerPolicy = referrerPolicy;
}
image.crossOrigin = crossOrigin ?? null;
image.src = src;
setLoadingStatus(getImageLoadingStatus(image));
return () => {
image.removeEventListener("load", handleLoad);
image.removeEventListener("error", handleError);
setLoadingStatus("idle");
};
}, [src, crossOrigin, referrerPolicy, setLoadingStatus]);
return loadingStatus;
}
function getImageLoadingStatus(image) {
return image.complete ? image.naturalWidth > 0 ? "loaded" : "error" : "loading";
}
function useImageCount() {
let state = STATIC_IMAGE_COUNT_STATE;
if (true) {
state = React.useState(0);
const [imageCount] = state;
const hasWarnedRef = React.useRef(false);
React.useEffect(() => {
if (imageCount > 1 && !hasWarnedRef.current) {
hasWarnedRef.current = true;
console.warn(
"Avatar: Only one `Avatar.Image` component should be rendered per `Avatar.Root`, but multiple were detected. This will lead to unexpected behavior."
);
}
}, [imageCount]);
}
return state;
}
function useUpdateImageCount(setImageCount) {
if (true) {
React.useEffect(() => {
setImageCount((imageCount) => imageCount + 1);
return () => {
setImageCount((imageCount) => imageCount - 1);
};
}, [setImageCount]);
}
}
//# sourceMappingURL=index.js.map
File diff suppressed because one or more lines are too long
+151
View File
@@ -0,0 +1,151 @@
"use client";
// src/avatar.tsx
import * as React from "react";
import { createContextScope } from "@radix-ui/react-context";
import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
import { useLayoutEffect } from "@radix-ui/react-use-layout-effect";
import { Primitive } from "@radix-ui/react-primitive";
import { jsx } from "react/jsx-runtime";
var AVATAR_NAME = "Avatar";
var [createAvatarContext, createAvatarScope] = createContextScope(AVATAR_NAME);
var STATIC_IMAGE_COUNT_STATE = [
0,
() => void 0
];
var [AvatarProvider, useAvatarContext] = createAvatarContext(AVATAR_NAME);
var Avatar = React.forwardRef(
(props, forwardedRef) => {
const { __scopeAvatar, ...avatarProps } = props;
const [imageLoadingStatus, setImageLoadingStatus] = React.useState("idle");
const [imageCount, setImageCount] = useImageCount();
return /* @__PURE__ */ jsx(
AvatarProvider,
{
scope: __scopeAvatar,
imageLoadingStatus,
setImageLoadingStatus,
imageCount,
setImageCount,
children: /* @__PURE__ */ jsx(Primitive.span, { ...avatarProps, ref: forwardedRef })
}
);
}
);
Avatar.displayName = AVATAR_NAME;
var IMAGE_NAME = "AvatarImage";
var AvatarImage = React.forwardRef(
(props, forwardedRef) => {
const { __scopeAvatar, src, onLoadingStatusChange, ...imageProps } = props;
const context = useAvatarContext(IMAGE_NAME, __scopeAvatar);
useUpdateImageCount(context.setImageCount);
const imageLoadingStatus = useImageLoadingStatus(src, {
referrerPolicy: imageProps.referrerPolicy,
crossOrigin: imageProps.crossOrigin,
loadingStatus: context.imageLoadingStatus,
setLoadingStatus: context.setImageLoadingStatus
});
const handleLoadingStatusChange = useCallbackRef((status) => {
onLoadingStatusChange?.(status);
});
const loadingStatusRef = React.useRef(imageLoadingStatus);
useLayoutEffect(() => {
const previousLoadingStatus = loadingStatusRef.current;
loadingStatusRef.current = imageLoadingStatus;
if (imageLoadingStatus !== previousLoadingStatus) {
handleLoadingStatusChange(imageLoadingStatus);
}
}, [imageLoadingStatus, handleLoadingStatusChange]);
return imageLoadingStatus === "loaded" ? /* @__PURE__ */ jsx(Primitive.img, { ...imageProps, ref: forwardedRef, src }) : null;
}
);
AvatarImage.displayName = IMAGE_NAME;
var FALLBACK_NAME = "AvatarFallback";
var AvatarFallback = React.forwardRef(
(props, forwardedRef) => {
const { __scopeAvatar, delayMs, ...fallbackProps } = props;
const context = useAvatarContext(FALLBACK_NAME, __scopeAvatar);
const [canRender, setCanRender] = React.useState(delayMs === void 0);
React.useEffect(() => {
if (delayMs !== void 0) {
const timerId = window.setTimeout(() => setCanRender(true), delayMs);
return () => window.clearTimeout(timerId);
}
}, [delayMs]);
return canRender && context.imageLoadingStatus !== "loaded" ? /* @__PURE__ */ jsx(Primitive.span, { ...fallbackProps, ref: forwardedRef }) : null;
}
);
AvatarFallback.displayName = FALLBACK_NAME;
function useImageLoadingStatus(src, {
loadingStatus,
setLoadingStatus,
referrerPolicy,
crossOrigin
}) {
useLayoutEffect(() => {
if (!src) {
setLoadingStatus("error");
return;
}
const image = new window.Image();
const handleLoad = (event) => {
const image2 = event.currentTarget;
setLoadingStatus(getImageLoadingStatus(image2));
};
const handleError = () => setLoadingStatus("error");
image.addEventListener("load", handleLoad);
image.addEventListener("error", handleError);
if (referrerPolicy) {
image.referrerPolicy = referrerPolicy;
}
image.crossOrigin = crossOrigin ?? null;
image.src = src;
setLoadingStatus(getImageLoadingStatus(image));
return () => {
image.removeEventListener("load", handleLoad);
image.removeEventListener("error", handleError);
setLoadingStatus("idle");
};
}, [src, crossOrigin, referrerPolicy, setLoadingStatus]);
return loadingStatus;
}
function getImageLoadingStatus(image) {
return image.complete ? image.naturalWidth > 0 ? "loaded" : "error" : "loading";
}
function useImageCount() {
let state = STATIC_IMAGE_COUNT_STATE;
if (true) {
state = React.useState(0);
const [imageCount] = state;
const hasWarnedRef = React.useRef(false);
React.useEffect(() => {
if (imageCount > 1 && !hasWarnedRef.current) {
hasWarnedRef.current = true;
console.warn(
"Avatar: Only one `Avatar.Image` component should be rendered per `Avatar.Root`, but multiple were detected. This will lead to unexpected behavior."
);
}
}, [imageCount]);
}
return state;
}
function useUpdateImageCount(setImageCount) {
if (true) {
React.useEffect(() => {
setImageCount((imageCount) => imageCount + 1);
return () => {
setImageCount((imageCount) => imageCount - 1);
};
}, [setImageCount]);
}
}
export {
Avatar,
AvatarFallback,
AvatarImage,
AvatarFallback as Fallback,
AvatarImage as Image,
Avatar as Root,
createAvatarScope
};
//# sourceMappingURL=index.mjs.map
File diff suppressed because one or more lines are too long
+72
View File
@@ -0,0 +1,72 @@
{
"name": "@radix-ui/react-avatar",
"version": "1.2.0",
"license": "MIT",
"source": "./src/index.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"files": [
"dist",
"README.md"
],
"sideEffects": false,
"dependencies": {
"@radix-ui/react-context": "1.1.4",
"@radix-ui/react-primitive": "2.1.6",
"@radix-ui/react-use-callback-ref": "1.1.2",
"@radix-ui/react-use-is-hydrated": "0.1.1",
"@radix-ui/react-use-layout-effect": "1.1.2"
},
"devDependencies": {
"@types/react": "^19.2.2",
"@types/react-dom": "^19.2.2",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"typescript": "^5.9.3",
"@repo/builder": "0.0.0",
"@repo/typescript-config": "0.0.0"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
},
"homepage": "https://radix-ui.com/primitives",
"repository": {
"type": "git",
"url": "git+https://github.com/radix-ui/primitives.git",
"directory": "packages/react/avatar"
},
"bugs": {
"url": "https://github.com/radix-ui/primitives/issues"
},
"scripts": {
"lint": "oxlint --max-warnings 0 src",
"clean": "rm -rf dist",
"reset": "rm -rf dist node_modules",
"typecheck": "tsc --noEmit",
"build": "radix-build"
},
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
}