-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
228 additions
and
4 deletions.
There are no files selected for viewing
Empty file.
85 changes: 85 additions & 0 deletions
85
apps/nt-headless-ui/components/ui/avatar/avatar.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import React from 'react' | ||
|
||
import { Avatar, AvatarFallback, AvatarImage } from './avatar' | ||
|
||
const URL_IMAGE = | ||
'https://gratisography.com/wp-content/uploads/2024/11/gratisography-augmented-reality-800x525.jpg' | ||
|
||
const meta: Meta = { | ||
title: 'Components/Avatar', | ||
component: Avatar, | ||
subcomponents: { AvatarImage, AvatarFallback }, | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: | ||
'A flexible Avatar component using Radix UI.', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof Avatar> | ||
|
||
export const Default: Story = { | ||
render: (args) => ( | ||
<Avatar {...args}> | ||
<AvatarImage src={URL_IMAGE} alt="User Avatar" /> | ||
<AvatarFallback> | ||
<div className="bg-slate-500" /> | ||
</AvatarFallback> | ||
</Avatar> | ||
), | ||
args: { | ||
className: '', | ||
}, | ||
parameters: { | ||
docs: { | ||
description: { | ||
story: 'Default Avatar with an image and fallback text.', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export const WithFallbackOnly: Story = { | ||
render: (args) => ( | ||
<Avatar {...args}> | ||
<AvatarFallback> | ||
<div className="bg-slate-500" /> | ||
</AvatarFallback> | ||
</Avatar> | ||
), | ||
args: { | ||
className: '', | ||
}, | ||
parameters: { | ||
docs: { | ||
description: { | ||
story: 'Avatar displaying only fallback text.', | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export const CustomSize: Story = { | ||
render: (args) => ( | ||
<Avatar {...args}> | ||
<AvatarImage src={URL_IMAGE} alt="User Avatar" /> | ||
<AvatarFallback>loading..</AvatarFallback> | ||
</Avatar> | ||
), | ||
args: { | ||
className: 'h-16 w-16', | ||
}, | ||
parameters: { | ||
docs: { | ||
description: { | ||
story: 'Avatar with a custom size.', | ||
}, | ||
}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { cn } from '@/lib/utils' | ||
import * as AvatarPrimitive from '@radix-ui/react-avatar' | ||
import * as React from 'react' | ||
|
||
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 | ||
|
||
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 bg-muted border', | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName | ||
|
||
export { Avatar, AvatarImage, AvatarFallback } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.