-
Notifications
You must be signed in to change notification settings - Fork 258
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
7 changed files
with
331 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { MarkGithubIcon } from '@primer/octicons-react'; | ||
import { render } from '@testing-library/react'; | ||
import { Avatar, type IAvatar } from './Avatar'; | ||
|
||
describe('components/Avatar.tsx', () => { | ||
it('should render small avatar', () => { | ||
const props: IAvatar = { | ||
defaultIcon: MarkGithubIcon, | ||
title: 'test', | ||
url: 'https://avatars.githubusercontent.com/u/583231?v=4', | ||
size: 'small', | ||
}; | ||
const tree = render(<Avatar {...props} />); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render medium avatar', () => { | ||
const props: IAvatar = { | ||
defaultIcon: MarkGithubIcon, | ||
title: 'test', | ||
url: 'https://avatars.githubusercontent.com/u/583231?v=4', | ||
size: 'medium', | ||
}; | ||
const tree = render(<Avatar {...props} />); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('should render default icon when no url', () => { | ||
const props: IAvatar = { | ||
defaultIcon: MarkGithubIcon, | ||
title: 'test', | ||
url: null, | ||
size: 'small', | ||
}; | ||
const tree = render(<Avatar {...props} />); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
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,32 @@ | ||
import type { Icon } from '@primer/octicons-react'; | ||
import type { FC } from 'react'; | ||
import { cn } from '../utils/cn'; | ||
|
||
export interface IAvatar { | ||
title: string; | ||
url: string | null; | ||
size: 'small' | 'medium'; | ||
defaultIcon: Icon; | ||
} | ||
|
||
export const Avatar: FC<IAvatar> = (props: IAvatar) => { | ||
if (props.url) { | ||
return ( | ||
<img | ||
className={cn( | ||
'cursor-pointer rounded-full object-cover', | ||
props.size === 'small' ? 'size-4' : 'size-5', | ||
)} | ||
src={props.url} | ||
alt={`${props.title}'s avatar`} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<props.defaultIcon | ||
size={props.size === 'small' ? 14 : 18} | ||
className="text-gray-500 dark:text-gray-300" | ||
/> | ||
); | ||
}; |
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
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.
Oops, something went wrong.