Skip to content

Commit

Permalink
feat(nextjs): add component avatar (#27)
Browse files Browse the repository at this point in the history
close #20
  • Loading branch information
gerzon05 authored Mar 27, 2024
2 parents 2e30b93 + 0f8acd4 commit 0a8de5b
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
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.

8 changes: 7 additions & 1 deletion test/with-nextjs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Image from 'next/image'
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, Badge, Button } from '@design-system/react'
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, Avatar, AvatarFallback, AvatarImage, Badge, Button } from '@design-system/react'

export default function Home() {
return (
Expand All @@ -21,6 +21,12 @@ export default function Home() {
<Badge variant="success">
Examples UI
</Badge>
<Avatar>
<AvatarImage src="https://raw.githubusercontent.com/castrogarciajs/castrogarciajs/master/public/sebastian.jpg" />
<AvatarFallback>
JS
</AvatarFallback>
</Avatar>
<AlertDialog>
<AlertDialogTrigger>Open</AlertDialogTrigger>
<AlertDialogContent>
Expand Down

0 comments on commit 0a8de5b

Please sign in to comment.