Skip to content

Instantly share code, notes, and snippets.

@aaronmcadam
Created March 30, 2017 09:24
Show Gist options
  • Save aaronmcadam/bb5743cf51f648b1303b80b399968303 to your computer and use it in GitHub Desktop.
Save aaronmcadam/bb5743cf51f648b1303b80b399968303 to your computer and use it in GitHub Desktop.
import React, { PropTypes } from 'react';
import styled from 'styled-components';
import { base as baseTheme } from '../../../cl-themes/src';
import { sizes, userRoles } from '../constants';
import Image from '../Image';
const getUserRoleColour = ({ user, theme }) => {
if (user.role === 'staff') {
return theme.palette.role.staff;
}
return theme.palette.role.participant;
};
const Wrapper = ({ user, ...props }) => (
<Image
bordered
src={user.avatar}
{...props}
data-role="avatar"
alt="avatar"
/>
);
const Avatar = styled(Wrapper)`
border-radius: 50%;
border-color: ${getUserRoleColour};
border-width: 2px;
box-sizing: border-box;
`;
Avatar.propTypes = {
/** An avatar may appear at different sizes. */
size: PropTypes.oneOf(sizes.labels),
/** Specifies the user. */
user: PropTypes.shape({
/** Specifies the URL of the avatar. */
avatar: PropTypes.string.isRequired,
/** Specifies the user role */
role: PropTypes.oneOf(userRoles),
}),
/** Specifies the theme. */
theme: PropTypes.shape({
palette: PropTypes.object.isRequired,
}).isRequired,
};
Avatar.defaultProps = {
size: 'tiny',
theme: baseTheme,
};
export default Avatar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment