-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TAIK-2326] - Add boring avatars on avatar component (#58)
* Add boring-avatars lib * Update avatar component with boring-avatars * Update stories * Update tests * Update avatar story with size arg * Update table component styling * Add square prop to the avatar component * Fix avatar on tables in small devices
- Loading branch information
Henrique Macedo
authored
Jul 22, 2021
1 parent
6ab231e
commit 4400f4d
Showing
16 changed files
with
13,388 additions
and
12,932 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
36 changes: 36 additions & 0 deletions
36
src/atoms/avatar-image/__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,36 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Avatar renders 1`] = ` | ||
<DocumentFragment> | ||
.c0 { | ||
position: relative; | ||
border: 1px solid hsl(0,0%,16%); | ||
border-radius: 999px; | ||
width: 30px; | ||
height: 30px; | ||
overflow: hidden; | ||
z-index: 0; | ||
} | ||
.c0 > * { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
z-index: -1; | ||
} | ||
.c0 img { | ||
object-fit: cover; | ||
} | ||
<div | ||
class="c0 avatar-img" | ||
size="30" | ||
> | ||
<img | ||
alt="avatar alt" | ||
src="/dummy.png" | ||
/> | ||
</div> | ||
</DocumentFragment> | ||
`; |
6 changes: 3 additions & 3 deletions
6
src/atoms/avatar/__tests__/avatar.test.tsx → ...ms/avatar-image/__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
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 @@ | ||
import React, { CSSProperties } from 'react'; | ||
import Avatar from 'boring-avatars'; | ||
import * as Styles from './styles'; | ||
|
||
export interface AvatarProps { | ||
style?: CSSProperties; | ||
className?: string; | ||
size?: number; | ||
url?: string; | ||
alt: string; | ||
boring?: boolean; | ||
boringType?: 'marble' | 'beam' | 'pixel' | 'sunset' | 'ring' | 'bauhaus'; | ||
square?: boolean; | ||
} | ||
|
||
const AvatarImage = (props: AvatarProps) => { | ||
const { | ||
style, | ||
className = 'avatar-img', | ||
size = 30, | ||
url, | ||
alt, | ||
boring = true, | ||
boringType = 'pixel', | ||
square = false, | ||
} = props; | ||
|
||
return ( | ||
<Styles.Wrapper className={className} size={size} square={square}> | ||
{boring && !url ? ( | ||
<Avatar | ||
size={size} | ||
name={alt} | ||
variant={boringType} | ||
square={square} | ||
colors={['#55cad7', '#5031a9', '#f9c543', '#ef5766', '#7a7a7a']} | ||
/> | ||
) : ( | ||
<img style={style} src={url} alt={alt} /> | ||
)} | ||
</Styles.Wrapper> | ||
); | ||
}; | ||
|
||
export default AvatarImage; |
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,49 @@ | ||
import React from 'react'; | ||
import AvatarImage, { AvatarProps } from '..'; | ||
|
||
export default { | ||
title: 'Design System/Atoms/Avatar Image', | ||
component: AvatarImage, | ||
argTypes: { | ||
boringType: { | ||
control: { | ||
type: 'select', | ||
options: ['marble', 'beam', 'pixel', 'sunset', 'ring', 'bauhaus'], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const PNG = (args: AvatarProps) => <AvatarImage {...args} />; | ||
|
||
PNG.args = { | ||
size: 100, | ||
boring: false, | ||
boringType: 'pixel', | ||
square: false, | ||
alt: 'Maria Rincon', | ||
url: | ||
'https://taikai.azureedge.net/O4f7yrc0ecq0JUEirIk1sZ2XItEpJ-xrIr2W03kRrJs/rs:fit:400:400:0/g:no/aHR0cHM6Ly9zdG9yYWdlLmdvb2dsZWFwaXMuY29tL3RhaWthaS1zdG9yYWdlL2ltYWdlcy90YWlrYWkvbWFyaWFfNDAwXzQwMC5qcGc.jpg', | ||
}; | ||
|
||
export const SVG = (args: AvatarProps) => <AvatarImage {...args} />; | ||
|
||
SVG.args = { | ||
size: 100, | ||
boring: false, | ||
boringType: 'pixel', | ||
square: false, | ||
alt: 'Default Avatar', | ||
url: './images/default-avatar.svg', | ||
}; | ||
|
||
export const BoringAvatar = (args: AvatarProps) => <AvatarImage {...args} />; | ||
|
||
BoringAvatar.args = { | ||
size: 100, | ||
boring: true, | ||
boringType: 'pixel', | ||
square: false, | ||
alt: 'Maria Rincon', | ||
url: '', | ||
}; |
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,30 @@ | ||
import styled from 'styled-components/macro'; | ||
import { colors } from '../../ions/variables'; | ||
|
||
const { normal } = colors; | ||
|
||
interface AvatarProps { | ||
size?: number; | ||
square?: boolean; | ||
} | ||
|
||
export const Wrapper = styled.div<AvatarProps>` | ||
position: relative; | ||
border: 1px solid ${normal}; | ||
border-radius: ${props => (props.square ? 0 : '999px')}; | ||
width: ${props => props.size}px; | ||
height: ${props => props.size}px; | ||
overflow: hidden; | ||
z-index: 0; | ||
> * { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
z-index: -1; | ||
} | ||
img { | ||
object-fit: cover; | ||
} | ||
`; |
20 changes: 0 additions & 20 deletions
20
src/atoms/avatar/__tests__/__snapshots__/avatar.test.tsx.snap
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.