- "content": "\"use client\";\n\nimport \"@seed-design/stylesheet/avatar.css\";\nimport \"@seed-design/stylesheet/avatarStack.css\";\n\nimport { Slot } from \"@radix-ui/react-slot\";\nimport { useAvatar, type UseAvatarProps } from \"@seed-design/react-avatar\";\nimport { avatar, type AvatarVariantProps } from \"@seed-design/recipe/avatar\";\nimport {\n avatarStack,\n type AvatarStackVariantProps,\n} from \"@seed-design/recipe/avatarStack\";\nimport clsx from \"clsx\";\nimport * as React from \"react\";\n\nimport { createStyleContext } from \"../util/createStyleContext\";\n\nconst { rootSlot, childSlot } = createStyleContext(avatar);\n\nconst UseAvatarContext = React.createContext<ReturnType<\n typeof useAvatar\n> | null>(null);\n\nconst AvatarGroupContext = React.createContext<AvatarVariantProps | null>(null);\n\nexport interface AvatarProps\n extends React.HTMLAttributes<HTMLDivElement>,\n AvatarVariantProps,\n UseAvatarProps {\n asChild?: boolean;\n}\n\nexport const Avatar = React.forwardRef<HTMLDivElement, AvatarProps>(\n ({ className, size, children, asChild = false, ...otherProps }, ref) => {\n const Comp = asChild ? Slot : \"div\";\n const groupProps = React.useContext(AvatarGroupContext);\n\n const { classNames, StyleProvider } = rootSlot({\n size: groupProps?.size ?? size,\n });\n const api = useAvatar({ ...otherProps });\n return (\n <Comp\n ref={ref}\n className={clsx(classNames.root, className)}\n {...api.rootProps}\n {...api.restProps}\n >\n <StyleProvider>\n <UseAvatarContext.Provider value={api}>\n {children}\n </UseAvatarContext.Provider>\n </StyleProvider>\n </Comp>\n );\n },\n);\nAvatar.displayName = \"Avatar\";\n\nexport interface AvatarImageProps\n extends React.ImgHTMLAttributes<HTMLImageElement> {\n asChild?: boolean;\n}\n\nexport const AvatarImage = React.forwardRef<HTMLImageElement, AvatarImageProps>(\n (props, ref) => {\n const { asChild = false, className, src, ...otherProps } = props;\n\n const Comp = asChild ? Slot : \"img\";\n const { classNames } = childSlot();\n const { getImageProps } = React.useContext(UseAvatarContext)!;\n const imageProps = getImageProps({ src });\n\n return (\n <Comp\n ref={ref}\n className={clsx(classNames.image, className)}\n {...imageProps}\n {...otherProps}\n />\n );\n },\n);\nAvatarImage.displayName = \"AvatarImage\";\n\nexport interface AvatarFallbackProps\n extends React.HTMLAttributes<HTMLDivElement> {\n asChild?: boolean;\n}\n\nexport const AvatarFallback = React.forwardRef<\n HTMLDivElement,\n AvatarFallbackProps\n>((props, ref) => {\n const { asChild = false, className, ...otherProps } = props;\n\n const Comp = asChild ? Slot : \"div\";\n const { classNames } = childSlot();\n const { fallbackProps } = React.useContext(UseAvatarContext)!;\n return (\n <Comp\n ref={ref}\n className={clsx(classNames.fallback, className)}\n {...fallbackProps}\n {...otherProps}\n />\n );\n});\nAvatarFallback.displayName = \"AvatarFallback\";\n\nexport interface AvatarBadgeProps extends React.HTMLAttributes<HTMLDivElement> {\n asChild?: boolean;\n}\n\nexport const AvatarBadge = React.forwardRef<HTMLDivElement, AvatarBadgeProps>(\n (props, ref) => {\n const { asChild = false, className, ...otherProps } = props;\n\n const Comp = asChild ? Slot : \"div\";\n const { classNames } = childSlot();\n return (\n <Comp\n ref={ref}\n className={clsx(classNames.badge, className)}\n {...otherProps}\n />\n );\n },\n);\nAvatarBadge.displayName = \"AvatarBadge\";\n\ninterface AvatarStackProps\n extends React.HTMLAttributes<HTMLDivElement>,\n AvatarStackVariantProps {}\n\nexport const AvatarStack = React.forwardRef<HTMLDivElement, AvatarStackProps>(\n ({ className, children, size, ...otherProps }, ref) => {\n const classNames = avatarStack({ size });\n const avatars = React.Children.toArray(children);\n return (\n <div\n ref={ref}\n className={clsx(classNames.root, className)}\n {...otherProps}\n >\n <AvatarGroupContext.Provider value={{ size }}>\n {avatars.map((avatar, index) => (\n <div\n key={index}\n className={classNames.item}\n // style={{\n // zIndex: avatars.length - index,\n // }}\n >\n {avatar}\n </div>\n ))}\n </AvatarGroupContext.Provider>\n </div>\n );\n },\n);\n"
0 commit comments