-
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
2a90a64
commit bf00f3e
Showing
8 changed files
with
106 additions
and
4 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
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,23 @@ | ||
import { ComponentPropsWithRef } from 'react'; | ||
|
||
/** Avatar component properties */ | ||
export interface IAvatarProps extends ComponentPropsWithRef<'img'> { | ||
/** Alternative information text */ | ||
alt: string; | ||
|
||
/** Image path */ | ||
src: string; | ||
} | ||
|
||
/** | ||
* Display user avatar photo | ||
* | ||
* @param props - Component props | ||
* | ||
* @returns Avatar component | ||
*/ | ||
export function Avatar(props: IAvatarProps) { | ||
const { alt, className = 'h-8 w-8', src, ...rest } = props; | ||
|
||
return <img {...{ alt, className, src }} {...rest} />; | ||
} |
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
27 changes: 27 additions & 0 deletions
27
packages/project-tailwind/src/components/__tests__/Avatar.test.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,27 @@ | ||
import { render } from '@testing-library/react'; | ||
import { Avatar } from '../Avatar'; | ||
|
||
describe('Avatar', () => { | ||
it('should correctly render component when no styles are set', () => { | ||
const { asFragment } = render( | ||
<Avatar | ||
alt="Alt text" | ||
src="https://www.gravatar.com/avatar/8801091e665fdac669daa63d32167b7b" | ||
/>, | ||
); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
|
||
it('should correctly render component when custom styles are set', () => { | ||
const { asFragment } = render( | ||
<Avatar | ||
className="h-auto w-auto" | ||
alt="Alt text" | ||
src="https://www.gravatar.com/avatar/8801091e665fdac669daa63d32167b7b" | ||
/>, | ||
); | ||
|
||
expect(asFragment()).toMatchSnapshot(); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/project-tailwind/src/components/__tests__/__snapshots__/Avatar.test.tsx.snap
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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Avatar should correctly render component when custom styles are set 1`] = ` | ||
<DocumentFragment> | ||
<img | ||
alt="Alt text" | ||
class="h-auto w-auto" | ||
src="https://www.gravatar.com/avatar/8801091e665fdac669daa63d32167b7b" | ||
/> | ||
</DocumentFragment> | ||
`; | ||
|
||
exports[`Avatar should correctly render component when no styles are set 1`] = ` | ||
<DocumentFragment> | ||
<img | ||
alt="Alt text" | ||
class="h-8 w-8" | ||
src="https://www.gravatar.com/avatar/8801091e665fdac669daa63d32167b7b" | ||
/> | ||
</DocumentFragment> | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import './styles/tailwind.css'; | ||
|
||
/** Components */ | ||
export * from './components/Alert'; | ||
export * from './components/Avatar'; | ||
export * from './components/Logo'; |
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,17 @@ | ||
import { ComponentMeta, ComponentStory } from '@storybook/react'; | ||
import { Avatar } from '../components/Avatar'; | ||
|
||
export default { | ||
args: { | ||
alt: 'My avatar', | ||
className: 'h-40 w-40', | ||
src: 'https://www.gravatar.com/avatar/8801091e665fdac669daa63d32167b7b', | ||
}, | ||
component: Avatar, | ||
} as ComponentMeta<typeof Avatar>; | ||
|
||
const Template: ComponentStory<typeof Avatar> = (props) => ( | ||
<Avatar {...props} /> | ||
); | ||
|
||
export const AvatarComponent = Template.bind({}); |