Skip to content

Commit

Permalink
feat(react): add new component avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
johancs.mm@gmail.com committed Mar 27, 2024
1 parent 2e30b93 commit c3dd3ac
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ _Layout_
_Display_

- [ ] Card
- [ ] Avatar
- [x] Avatar
- [ ] Accordion
- [x] Alert
- [x] Alert Dialog
Expand Down
1 change: 1 addition & 0 deletions lib/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@desing-system/theme": "workspace:*",
"@radix-ui/react-alert-dialog": "1.0.5",
"@radix-ui/react-aspect-ratio": "1.0.3",
"@radix-ui/react-avatar": "1.0.4",
"@radix-ui/react-slot": "1.0.2",
"class-variance-authority": "0.7.0",
"clsx": "2.1.0",
Expand Down
48 changes: 48 additions & 0 deletions lib/react/src/components/avatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as React from 'react'
import * as AvatarPrimitive from '@radix-ui/react-avatar'

import { cn } from '../lib/cn'

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 size-10 shrink-0 overflow-hidden rounded-full',
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 }
1 change: 1 addition & 0 deletions lib/react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './components/carousel'
export * from './components/alert-dialog'
export * from './components/badge'
export * from './components/aspect-ratio'
export * from './components/avatar'
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.

0 comments on commit c3dd3ac

Please sign in to comment.