-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
cf8c637
commit 32af921
Showing
4 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
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
85 changes: 85 additions & 0 deletions
85
components/AvatarWithOnlineBadge/AvatarWithOnlineBadge.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 type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import AvatarWithOnlineBadge from './AvatarWithOnlineBadge'; | ||
import AvatarPic1 from '../../public/assets/avatar.jpg'; | ||
|
||
const meta: Meta<typeof AvatarWithOnlineBadge> = { | ||
title: 'Components/AvatarWithOnlineBadge', | ||
component: AvatarWithOnlineBadge, | ||
tags: ['autodocs'], | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof AvatarWithOnlineBadge>; | ||
|
||
export const Online: Story = { | ||
args: { | ||
size: 'medium', | ||
imageUrl: AvatarPic1, | ||
userName: 'Batman', | ||
isOnline: true, | ||
}, | ||
}; | ||
|
||
export const Offline: Story = { | ||
args: { | ||
size: 'medium', | ||
imageUrl: AvatarPic1, | ||
userName: 'Batman', | ||
isOnline: false, | ||
}, | ||
}; | ||
|
||
export const Small: Story = { | ||
args: { | ||
size: 'small', | ||
imageUrl: AvatarPic1, | ||
userName: 'Batman', | ||
isOnline: true, | ||
}, | ||
}; | ||
|
||
export const Medium: Story = { | ||
args: { | ||
size: 'medium', | ||
imageUrl: AvatarPic1, | ||
userName: 'Batman', | ||
isOnline: true, | ||
}, | ||
}; | ||
|
||
export const Large: Story = { | ||
args: { | ||
size: 'large', | ||
imageUrl: AvatarPic1, | ||
userName: 'Batman', | ||
isOnline: true, | ||
}, | ||
}; | ||
|
||
export const NoImageUrlSmall: Story = { | ||
args: { | ||
size: 'small', | ||
userName: 'Batman', | ||
isOnline: true, | ||
}, | ||
}; | ||
|
||
export const NoImageUrlMedium: Story = { | ||
args: { | ||
size: 'medium', | ||
userName: 'Batman', | ||
isOnline: true, | ||
}, | ||
}; | ||
|
||
export const NoImageUrlLarge: Story = { | ||
args: { | ||
size: 'large', | ||
userName: 'Batman', | ||
isOnline: true, | ||
}, | ||
}; |
40 changes: 40 additions & 0 deletions
40
components/AvatarWithOnlineBadge/AvatarWithOnlineBadge.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,40 @@ | ||
import React from 'react'; | ||
import Avatar from '../Avatar/Avatar'; | ||
|
||
type AvatarWithOnlineBadgeProps = { | ||
/** | ||
* size of the Avatar | ||
*/ | ||
size?: 'small' | 'medium' | 'large'; | ||
/** | ||
* sets the user avatar image | ||
*/ | ||
imageUrl?: string | null; | ||
/** | ||
* user name that will be used to get the 1st Letter for Avatar Fallback | ||
*/ | ||
userName: string; | ||
/** | ||
* indicator if user is Online | ||
*/ | ||
isOnline: boolean; | ||
}; | ||
|
||
const AvatarWithOnlineBadge = (props: AvatarWithOnlineBadgeProps) => { | ||
const { size = 'medium', imageUrl, userName, isOnline } = props; | ||
|
||
return ( | ||
<div className="relative w-fit"> | ||
<Avatar size={size} imageUrl={imageUrl} userName={userName} /> | ||
|
||
{/* badge */} | ||
{isOnline && ( | ||
<div className="absolute right-[-2px] bottom-[-2px] grid place-content-center w-3 h-3 min-w-3 rounded-full bg-white"> | ||
<div className="bg-green-600 w-2 h-2 min-w-2 rounded-full" /> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default AvatarWithOnlineBadge; |
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 @@ | ||
export { default } from './AvatarWithOnlineBadge'; |