-
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
Showing
8 changed files
with
433 additions
and
243 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
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,9 @@ | ||
declare module '*.module.scss' { | ||
const content: { [className: string]: string }; | ||
export default content; | ||
} | ||
|
||
declare module '*.jpg' { | ||
const value: any; | ||
export default value; | ||
} |
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,37 @@ | ||
import { ComponentMeta, ComponentStory } from '@storybook/react' | ||
import React from 'react' | ||
|
||
import { Avatar } from '..' | ||
|
||
export default { | ||
title: 'Components/Utils/Avatar', | ||
component: Avatar, | ||
argTypes: { | ||
image: { | ||
control: { | ||
type: 'disabled' | ||
}, | ||
description: 'Imagen o Foto de perfil' | ||
}, | ||
label: { description: 'Texto alternativo del avatar' }, | ||
size: { description: 'Tamaño del avatar' }, | ||
shape: { description: 'Forma del avatar' } | ||
} | ||
} as ComponentMeta<typeof Avatar> | ||
|
||
const Template: ComponentStory<typeof Avatar> = (args) => ( | ||
<Avatar {...args} /> | ||
) | ||
|
||
export const DefaultAvatar = Template.bind({}) | ||
DefaultAvatar.args = { | ||
image: 'https://picsum.photos/300/300', | ||
size: 'md', | ||
shape: 'circle' | ||
} | ||
|
||
export const SquareAvatar = Template.bind({}) | ||
SquareAvatar.args = { | ||
image: 'https://picsum.photos/300/300', | ||
shape: 'square' | ||
} |
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,45 @@ | ||
/* eslint-disable no-undef */ | ||
import { render, screen } from '@testing-library/react' | ||
import React from 'react' | ||
import { Avatar } from '..' | ||
import { AvatarProps } from './Avatar' | ||
|
||
const userAvatar: AvatarProps = { | ||
image: 'https://picsum.photos/300/300', | ||
label: 'Maciel Castro' | ||
} | ||
|
||
const userWithoutLabelAvatar: AvatarProps = { | ||
image: 'https://picsum.photos/300/300', | ||
label: '' | ||
} | ||
|
||
const squareUserAvatar: AvatarProps = { | ||
image: 'https://picsum.photos/300/300', | ||
label: 'Maciel Castro', | ||
shape: 'square', | ||
size: 'xl' | ||
} | ||
|
||
describe('Avatar', () => { | ||
test('Should render avatar', () => { | ||
render(<Avatar {...userAvatar} />) | ||
|
||
const element = screen.getByAltText('Maciel Castro') | ||
expect(element).toBeInTheDocument() | ||
}) | ||
|
||
test('Should render avatar square', () => { | ||
render(<Avatar {...squareUserAvatar} />) | ||
|
||
const element = screen.getByAltText('Maciel Castro') | ||
expect(element).toHaveClass('square') | ||
}) | ||
|
||
test('Should render avatar with alternative text', () => { | ||
render(<Avatar {...userWithoutLabelAvatar} />) | ||
|
||
const element = screen.getByAltText('avatar') | ||
expect(element).toBeInTheDocument() | ||
}) | ||
}) |
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,5 +1,25 @@ | ||
import React from 'react' | ||
import React, { FC } from 'react' | ||
import './avatar.scss' | ||
|
||
const Avatar = () => <h1>Avatar component</h1> | ||
type ShapeType = | 'square' | 'circle' | ||
type SizeType = | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | ||
|
||
export interface AvatarProps { | ||
image: string | ||
label?: string | ||
shape?: ShapeType | ||
size?: SizeType | ||
} | ||
|
||
const Avatar: FC<AvatarProps> = ({ | ||
image, | ||
label, | ||
shape = 'circle', | ||
size = 'md' | ||
}) => ( | ||
<picture className={`rc-avatar size_${size}`}> | ||
<img src={image} alt={`${label || 'avatar'}`} className={`${shape}`} /> | ||
</picture> | ||
) | ||
|
||
export default Avatar |
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,36 @@ | ||
.rc-avatar { | ||
display: block; | ||
&.size { | ||
&_sm { | ||
width: 32px; | ||
height: 32px; | ||
} | ||
&_md { | ||
width: 64px; | ||
height: 64px; | ||
} | ||
&_lg { | ||
width: 96px; | ||
height: 96px; | ||
} | ||
&_xl { | ||
width: 128px; | ||
height: 128px; | ||
} | ||
&_xxl { | ||
width: 256px; | ||
height: 256px; | ||
} | ||
|
||
} | ||
|
||
img { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.circle { | ||
border-radius: 100%; | ||
} | ||
|
||
} |
Oops, something went wrong.