Skip to content

Commit

Permalink
feat: add Avatar (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
gularsson authored Nov 6, 2023
1 parent c47c674 commit a290719
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"files": [
"dist"
],
"main": "dist/index.cjs",
"module": "dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": {
".": {
"import": "./dist/index.es.js",
Expand Down
48 changes: 48 additions & 0 deletions src/components/ui/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use client"

import * as React from "react"
import * as AvatarPrimitive from "@radix-ui/react-avatar"

import { cn } from "@/lib/utils"

export const Avatar = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Root
ref={ref}
className={cn(
"relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",
className
)}
{...props}
/>
))
Avatar.displayName = AvatarPrimitive.Root.displayName

export const AvatarImage = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Image>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Image
ref={ref}
className={cn("aspect-square h-full w-full", className)}
{...props}
/>
))
AvatarImage.displayName = AvatarPrimitive.Image.displayName

export const AvatarFallback = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Fallback>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>
>(({ className, ...props }, ref) => (
<AvatarPrimitive.Fallback
ref={ref}
className={cn(
"flex h-full w-full items-center justify-center rounded-full bg-muted",
className
)}
{...props}
/>
))
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export {
SheetTitle,
SheetDescription,
} from '@/components/ui/sheet'
export { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'
31 changes: 31 additions & 0 deletions src/showroom/components/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {
Avatar,
AvatarFallback,
AvatarImage,
} from '@/components/ui/avatar'
import { Header } from '../header'
import { Code } from '../code'

export function AvatarExample() {
return <>
<Header>Avatar</Header>

<div>
<Avatar>
<AvatarImage src="https://github.com/ttab.png" alt="TT" />
<AvatarFallback>ELE</AvatarFallback>
</Avatar>
</div>

<Code code={`import {
Avatar,
AvatarFallback,
AvatarImage,
} from '@/components/ui/avatar'
<Avatar>
<AvatarImage src="https://github.com/ttab.png" alt="Elephant" />
<AvatarFallback>TT</AvatarFallback>
</Avatar>
`} />
</>
}

0 comments on commit a290719

Please sign in to comment.