Skip to content

Commit

Permalink
Merge pull request #14 from team-nabi/NABI-84
Browse files Browse the repository at this point in the history
🎉 Avatar 공통 컴포넌트 구현
  • Loading branch information
juyeon-park authored Oct 30, 2023
2 parents 969c403 + 4763b0d commit b911966
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"chromatic": "bash ./scripts/chromatic_publish.sh"
},
"dependencies": {
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-icons": "^1.3.0",
Expand Down
27 changes: 27 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/components/ui/Avatar/Avatar.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Meta, StoryObj } from '@storybook/react'
import { Avatar, AvatarImage, AvatarFallback } from './Avatar'

const meta = {
title: 'UI/Avatar',
component: Avatar,
tags: ['autodocs'],
argTypes: {},
} satisfies Meta<typeof Avatar>

export default meta
type Story = StoryObj<typeof meta>

export const Normal: Story = {
args: {},
render: () => {
return (
<>
<Avatar size="sm">
<AvatarImage src="https://github.com/shadcn.png" />
<AvatarFallback>NB</AvatarFallback>
</Avatar>
<Avatar size="md">
<AvatarImage src="https://github.com/shadcn.png" />
<AvatarFallback>NB</AvatarFallback>
</Avatar>
<Avatar size="lg">
<AvatarImage src="https://github.com/shadcn.png" />
<AvatarFallback>NB</AvatarFallback>
</Avatar>
</>
)
},
}
67 changes: 67 additions & 0 deletions src/components/ui/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use client'

import * as React from 'react'
import * as AvatarPrimitive from '@radix-ui/react-avatar'
import { cva, type VariantProps } from 'class-variance-authority'
import { cn } from '@/utils'

const avatarVariants = cva(
'relative flex shrink-0 overflow-hidden rounded-full',
{
variants: {
size: {
sm: 'w-6 h-6',
md: 'w-10 h-10',
lg: 'w-[100px] h-[100px]',
},
},
},
)

export interface AvatarProps
extends React.HTMLAttributes<HTMLSpanElement>,
VariantProps<typeof avatarVariants> {
ref?: React.Ref<HTMLSpanElement>
}

const Avatar = React.forwardRef<
React.ElementRef<typeof AvatarPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root> &
VariantProps<typeof avatarVariants>
>(({ className, size, ...props }: AvatarProps, ref) => (
<AvatarPrimitive.Root
ref={ref}
className={cn(avatarVariants({ size }), className)}
{...props}
/>
))
Avatar.displayName = AvatarPrimitive.Root.displayName

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

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 ',
className,
)}
{...props}
/>
))
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName

export { Avatar, AvatarImage, AvatarFallback }
3 changes: 3 additions & 0 deletions src/components/ui/Avatar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Avatar, AvatarImage, AvatarFallback } from './Avatar'

export { Avatar, AvatarImage, AvatarFallback }

0 comments on commit b911966

Please sign in to comment.