diff --git a/web/src/components/ui/avatar/Avatar.stories.tsx b/web/src/components/ui/avatar/Avatar.stories.tsx index 13b18b14b..c7d1589f7 100644 --- a/web/src/components/ui/avatar/Avatar.stories.tsx +++ b/web/src/components/ui/avatar/Avatar.stories.tsx @@ -1,8 +1,9 @@ import type { Meta, StoryObj } from '@storybook/react'; import { Avatar } from './Avatar'; +import { faker } from '@faker-js/faker'; const meta = { - title: 'UI/Avatar', + title: 'UI/Avatar/Avatar', component: Avatar, parameters: { layout: 'centered' @@ -22,7 +23,13 @@ export const Default: Story = { export const WithImage: Story = { args: { name: 'John Doe', - image: 'https://github.com/shadcn.png' + image: faker.image.avatar() + } +}; + +export const WithImageAndNoName: Story = { + args: { + image: faker.image.avatar() } }; diff --git a/web/src/components/ui/avatar/Avatar.tsx b/web/src/components/ui/avatar/Avatar.tsx index 95424696e..e4fc65aaf 100644 --- a/web/src/components/ui/avatar/Avatar.tsx +++ b/web/src/components/ui/avatar/Avatar.tsx @@ -17,7 +17,7 @@ export interface AvatarProps { export const Avatar: React.FC = React.memo( ({ image, name, className, useToolTip, size, fallbackClassName }) => { const hasName = !!name; - const nameLetters = hasName ? createNameLetters(name, image) : ''; + const nameLetters = createNameLetters(name); return ( @@ -28,10 +28,11 @@ export const Avatar: React.FC = React.memo( height: size }}> {image && } - - {nameLetters || } - + {hasName ? ( + + ) : ( + + )} ); @@ -39,20 +40,28 @@ export const Avatar: React.FC = React.memo( ); Avatar.displayName = 'Avatar'; -const BusterAvatarFallback: React.FC = () => { +const NameLettersFallback: React.FC<{ fallbackClassName?: string; nameLetters: string }> = ({ + fallbackClassName, + nameLetters +}) => { + return {nameLetters}; +}; + +const BusterAvatarFallback: React.FC<{ fallbackClassName?: string }> = ({ fallbackClassName }) => { return ( -
- -
+ +
+ +
+
); }; -const createNameLetters = (name?: string | null, image?: string | null | React.ReactNode) => { - if (name && !image) { +const createNameLetters = (name?: string | null) => { + if (name) { const firstTwoLetters = getFirstTwoCapitalizedLetters(name); if (firstTwoLetters.length == 2) return firstTwoLetters; - //Get First Name Initial const _name = name.split(' ') as [string, string]; const returnName = `${_name[0][0]}`.toUpperCase().replace('@', ''); diff --git a/web/src/components/ui/avatar/AvatarBase.tsx b/web/src/components/ui/avatar/AvatarBase.tsx index 81917eea9..e7869aa77 100644 --- a/web/src/components/ui/avatar/AvatarBase.tsx +++ b/web/src/components/ui/avatar/AvatarBase.tsx @@ -35,7 +35,7 @@ const AvatarFallback = React.forwardRef<