Avatar Group
shadcn-ui-blocks/avatar-12FreeComponent
Group of avatars component
Install it
npx shadcn@latest add https://shadcnui-blocks.com/r/avatar-12.jsonSource
1import * as React from "react";2import { cn } from "@/lib/utils";3import { Avatar, AvatarFallback, AvatarImage } from "@/registry/ui/avatar";45type AvatarProps = React.ComponentProps<typeof Avatar>;67interface AvatarGroupProps extends React.ComponentProps<"div"> {8 children: React.ReactElement<AvatarProps>[];9 max?: number;10}1112const AvatarGroup = ({13 children,14 max,15 className,16 ...props17}: AvatarGroupProps) => {18 const totalAvatars = React.Children.count(children);19 const displayedAvatars = React.Children.toArray(children)20 .slice(0, max)21 .reverse();22 const remainingAvatars = max ? Math.max(totalAvatars - max, 1) : 0;2324 return (25 <div26 className={cn("flex flex-row-reverse items-center", className)}27 {...props}28 >29 {remainingAvatars > 0 && (30 <Avatar className="relative -ml-2 ring-2 ring-background hover:z-10">31 <AvatarFallback className="bg-muted-foreground text-white">32 +{remainingAvatars}33 </AvatarFallback>34 </Avatar>35 )}36 {displayedAvatars.map((avatar, index) => {37 if (!React.isValidElement(avatar)) {38 return null;39 }4041 return (42 <div className="relative -ml-2 hover:z-10" key={index}>43 {React.cloneElement(avatar as React.ReactElement<AvatarProps>, {44 className: "ring-2 ring-background",45 })}46 </div>47 );48 })}49 </div>50 );51};5253export default function AvatarGroupDemo() {54 return (55 <AvatarGroup>56 <Avatar className="-ml-2 cursor-pointer first:ml-0">57 <AvatarImage alt="@shadcn" src="https://github.com/shadcn.png" />58 <AvatarFallback className="bg-indigo-500 text-white">CN</AvatarFallback>59 </Avatar>60 <Avatar className="-ml-2 cursor-pointer first:ml-0">61 <AvatarFallback className="bg-green-600 text-white">CN</AvatarFallback>62 </Avatar>63 <Avatar className="-ml-2 cursor-pointer first:ml-0">64 <AvatarFallback className="bg-red-500 text-white">AB</AvatarFallback>65 </Avatar>66 <Avatar className="-ml-2 cursor-pointer first:ml-0">67 <AvatarFallback className="bg-indigo-500 text-white">VK</AvatarFallback>68 </Avatar>69 <Avatar className="-ml-2 cursor-pointer first:ml-0">70 <AvatarFallback className="bg-orange-500 text-white">RS</AvatarFallback>71 </Avatar>72 </AvatarGroup>73 );74}
What it pulls in
Other registry items
Files it writes
More from Shadcn UI Blocks
All 542 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Default Accordionaccordion-01 | Shadcn UI Blocks | Components | Free | no deps | |
| Outline Accordionaccordion-02 | Shadcn UI Blocks | Components | Free | no deps | |
| Box Accordionaccordion-03 | Shadcn UI Blocks | Components | Free | no deps | |
| Contained Accordionaccordion-04 | Shadcn UI Blocks | Components | Free | no deps | |
| Box Contained Accordionaccordion-05 | Shadcn UI Blocks | Components | Free | no deps | |
| Tabs Accordionaccordion-06 | Shadcn UI Blocks | Components | Free | no deps | |
| Highlight Active Item Accordionaccordion-07 | Shadcn UI Blocks | Components | Free | no deps | |
| Multiple Expanded at a time Accordionaccordion-08 | Shadcn UI Blocks | Components | Free | no deps |
