|
1 |
| -import { isNumber } from "@resolid/utils"; |
2 |
| -import { type CSSProperties, useState } from "react"; |
3 |
| -import type { ImageLoadStatus } from "../../hooks"; |
4 |
| -import type { PrimitiveProps } from "../../primitives"; |
5 |
| -import { tx } from "../../utils"; |
6 |
| -import { AvatarContext, AvatarStatusContext } from "./avatar-context"; |
7 |
| -import { type AvatarBaseProps, useAvatarGroup } from "./avatar-group-context"; |
| 1 | +import { AvatarRoot, type AvatarRootProps } from "./avatar-root"; |
8 | 2 |
|
9 |
| -export type AvatarProps = { |
10 |
| - /** |
11 |
| - * 头像的人名 |
12 |
| - */ |
13 |
| - name?: string; |
14 |
| -} & AvatarBaseProps; |
| 3 | +export type AvatarProps = AvatarRootProps; |
15 | 4 |
|
16 |
| -export const Avatar = (props: PrimitiveProps<"div", AvatarProps>) => { |
17 |
| - const group = useAvatarGroup(true); |
| 5 | +export const Avatar = AvatarRoot; |
18 | 6 |
|
19 |
| - const { |
20 |
| - name, |
21 |
| - size = group?.size ?? 64, |
22 |
| - radius = group?.radius ?? "full", |
23 |
| - className, |
24 |
| - style, |
25 |
| - children, |
26 |
| - ...rest |
27 |
| - } = props; |
28 |
| - |
29 |
| - const sizeStyle = isNumber(size) ? `${size}px` : size; |
30 |
| - const radiusStyle = isNumber(radius) && radius > 0 ? `${radius}px` : undefined; |
31 |
| - const radiusClass = radiusStyle |
32 |
| - ? "rounded-(--rv)" |
33 |
| - : radius == "full" |
34 |
| - ? "rounded-full" |
35 |
| - : radius == true |
36 |
| - ? "rounded-md" |
37 |
| - : ""; |
38 |
| - |
39 |
| - const [imageLoadStatus, setImageLoadStatus] = useState<ImageLoadStatus>("idle"); |
40 |
| - |
41 |
| - return ( |
42 |
| - <div |
43 |
| - style={{ ...style, "--sv": sizeStyle, "--rv": radiusStyle } as CSSProperties} |
44 |
| - className={tx( |
45 |
| - "size-(--sv) relative inline-flex shrink-0 select-none items-center justify-center", |
46 |
| - radiusClass, |
47 |
| - group && "border-bg-normal not-first:ms-(--pv) border-2", |
48 |
| - !className?.split(" ").some((cls) => cls.startsWith("bg-")) && "bg-bg-subtlest", |
49 |
| - className, |
50 |
| - )} |
51 |
| - {...rest} |
52 |
| - > |
53 |
| - <AvatarContext value={{ name, radiusClass }}> |
54 |
| - <AvatarStatusContext value={{ imageLoadStatus, setImageLoadStatus }}>{children}</AvatarStatusContext> |
55 |
| - </AvatarContext> |
56 |
| - </div> |
57 |
| - ); |
58 |
| -}; |
| 7 | +export { AvatarFallback } from "./avatar-fallback"; |
| 8 | +export { AvatarImage } from "./avatar-image"; |
| 9 | +export { AvatarIndicator } from "./avatar-indicator"; |
0 commit comments