Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add user and group icons #10

Merged
merged 2 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/components/Avatar.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,49 @@
import React from 'react'
import PropTypes from 'prop-types'
import styled from '@emotion/styled'
import { Icon } from './Icon'
import { color } from './shared/styles'

const SIZES = {
big: 60,
medium: 40,
small: 24,
medium: 40,
big: 60,
}

const StyledAvatar = styled.div`
background: ${props =>
!props.src || props.isLoading ? color.metalGrey : 'transparent'};
border: 2px solid ${color.paperWhite};
border-radius: 50%;
display: inline-block;
vertical-align: top;
overflow: hidden;
height: ${props => SIZES[props.size]}px;
width: ${props => SIZES[props.size]}px;
line-height: ${props => SIZES[props.size] - 6}px;
text-align: center;

img {
width: 100%;
height: auto;
display: block;
}
`

export const Avatar = ({ src, name, ...props }) => {
export const Avatar = ({ src, size, name, isLoading, ...props }) => {
let avatarFigure = <Icon size={size} icon="user" />
const a11yProps = {}

if (isLoading) {
a11yProps['aria-busy'] = true
a11yProps['aria-label'] = 'Loading avatar ...'
} else if (src) {
avatarFigure = <img src={src} alt={name} />
}

return (
<StyledAvatar {...props}>
<img src={src} alt={name} />
<StyledAvatar size={size} {...a11yProps} {...props}>
{avatarFigure}
</StyledAvatar>
)
}
Expand Down
19 changes: 13 additions & 6 deletions src/components/Avatar.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react'
import styled from '@emotion/styled'
import { Avatar } from './Avatar'
import { color, spacing } from './shared/styles'

export default {
title: 'Design System|Avatar',
Expand All @@ -8,35 +10,40 @@ export default {
},
}

const Background = styled.div`
background: ${color.moonGrey};
padding: ${spacing.padding.medium}px;
`

export const big = () => (
<div>
<Background>
<Avatar
size="big"
name="Tair Assimov"
src="https://avatars2.githubusercontent.com/u/5113"
/>
<Avatar isLoading size="big" />
</div>
</Background>
)

export const medium = () => (
<div>
<Background>
<Avatar
size="medium"
name="Tair Assimov"
src="https://avatars2.githubusercontent.com/u/6704740"
/>
<Avatar isLoading size="medium" />
</div>
</Background>
)

export const small = () => (
<div>
<Background>
<Avatar
size="small"
name="Tair Assimov"
src="https://avatars2.githubusercontent.com/u/211478"
/>
<Avatar isLoading size="small" />
</div>
</Background>
)
2 changes: 1 addition & 1 deletion src/components/Icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { color } from './shared/styles'
const SIZES = {
small: 16,
medium: 24,
large: 32,
big: 32,
}

const Svg = styled.svg`
Expand Down
2 changes: 2 additions & 0 deletions src/components/shared/icons.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.