Complete implementation for Avatar

old
Javi Velasco 2015-11-26 01:53:42 +01:00
parent c9061e27e1
commit 2106d0ee41
8 changed files with 85 additions and 54 deletions

View File

@ -1,49 +1,28 @@
import React, { PropTypes, Component } from 'react';
import React from 'react';
import ClassNames from 'classnames';
import FontIcon from '../font_icon'; // ewww! :P @TODO
import FontIcon from '../font_icon';
import style from './style';
class Avatar extends Component {
const Avatar = ({children, className, icon, image, title, ...other}) => {
const classes = ClassNames(style.avatar, [], className);
const avatarStyle = {backgroundImage: typeof image === 'string' ? `url(${image})` : null};
static propTypes = {
accent: PropTypes.bool,
children: PropTypes.oneOfType([
PropTypes.string,
PropTypes.node
]),
className: PropTypes.string,
icon: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element
]),
image: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element
]),
primary: PropTypes.bool
}
return (
<div className={classes} {...other}>
{typeof icon === 'string' ? <FontIcon className={style.letter} value={icon} /> : icon}
{typeof image === 'string' && title ? <span className={style.letter}>{title[0]}</span> : null}
{typeof image === 'string' ? <span className={style.image} style={avatarStyle} /> : null}
{children}
</div>
);
};
static defaultProps = {
size: 40
}
render () {
let component;
const { accent, children, className, icon, primary, image, ...other } = this.props;
const classes = ClassNames(style.avatar, [
primary ? style.primary : accent ? style.accent : null
], className);
if (typeof image === 'string') {
component = <img className={style.avatarImg} src={image} />;
} else if (typeof image === 'string') {
component = <img className={style.avatarImg} src={image} />;
} else if (typeof icon === 'string') {
component = <FontIcon value="icon" />;
}
return <div className={classes}>{component ? component : children}</div>;
}
}
Avatar.propTypes = {
children: React.PropTypes.node,
className: React.PropTypes.string,
icon: React.PropTypes.string,
image: React.PropTypes.string,
title: React.PropTypes.string
};
export default Avatar;

View File

@ -0,0 +1,4 @@
$avatar-color: $color-white !default;
$avatar-background: $palette-grey-500 !default;
$avatar-size: 4 * $unit !default;
$avatar-font-size: 2.4 * $unit !default;

View File

@ -1 +1,3 @@
export Avatar from './Avatar';
import Avatar from './Avatar.jsx';
export { Avatar };
export default Avatar;

View File

@ -1,11 +1,36 @@
@import "../base";
@import "./config";
.avatar {
width: 40px;
height: 40px;
width: $avatar-size;
background-color: $avatar-background;
height: $avatar-size;
overflow: hidden;
border-radius: 50%;
position: relative;
color: $avatar-color;
text-align: center;
font-size: $avatar-font-size;
> svg {
width: 1em;
height: $avatar-size;
fill: currentColor;
}
}
.image {
position: absolute;
display: block;
width: 100%;
height: 100%;
background-color: transparent;
background-position: center;
background-size: cover;
border-radius: 50%;
}
.avatarImg {
max-width: 100%;
height: auto;
.letter {
display: block;
width: 100%;
line-height: $avatar-size;
}

View File

@ -0,0 +1,15 @@
import React from 'react';
import Avatar from '../../components/avatar';
import GithubIcon from './github_icon';
const AvatarTest = () => (
<section>
<h5>Avatars</h5>
<Avatar image={"https://placeimg.com/80/80/animals"} />
<Avatar title="Javier Velasco" image={"https://javivelasco.com/avatar404"} />
<Avatar icon="folder" />
<Avatar><GithubIcon /></Avatar>
</section>
);
export default AvatarTest;

View File

@ -1,12 +1,7 @@
import React from 'react';
import GithubIcon from './github_icon';
import { Button, IconButton } from '../../components/button';
const GithubIcon = () => (
<svg viewBox="0 0 284 277">
<g><path d="M141.888675,0.0234927555 C63.5359948,0.0234927555 0,63.5477395 0,141.912168 C0,204.6023 40.6554239,257.788232 97.0321356,276.549924 C104.12328,277.86336 106.726656,273.471926 106.726656,269.724287 C106.726656,266.340838 106.595077,255.16371 106.533987,243.307542 C67.0604204,251.890693 58.7310279,226.56652 58.7310279,226.56652 C52.2766299,210.166193 42.9768456,205.805304 42.9768456,205.805304 C30.1032937,196.998939 43.9472374,197.17986 43.9472374,197.17986 C58.1953153,198.180797 65.6976425,211.801527 65.6976425,211.801527 C78.35268,233.493192 98.8906827,227.222064 106.987463,223.596605 C108.260955,214.426049 111.938106,208.166669 115.995895,204.623447 C84.4804813,201.035582 51.3508808,188.869264 51.3508808,134.501475 C51.3508808,119.01045 56.8936274,106.353063 65.9701981,96.4165325 C64.4969882,92.842765 59.6403297,78.411417 67.3447241,58.8673023 C67.3447241,58.8673023 79.2596322,55.0538738 106.374213,73.4114319 C117.692318,70.2676443 129.83044,68.6910512 141.888675,68.63701 C153.94691,68.6910512 166.09443,70.2676443 177.433682,73.4114319 C204.515368,55.0538738 216.413829,58.8673023 216.413829,58.8673023 C224.13702,78.411417 219.278012,92.842765 217.804802,96.4165325 C226.902519,106.353063 232.407672,119.01045 232.407672,134.501475 C232.407672,188.998493 199.214632,200.997988 167.619331,204.510665 C172.708602,208.913848 177.243363,217.54869 177.243363,230.786433 C177.243363,249.771339 177.078889,265.050898 177.078889,269.724287 C177.078889,273.500121 179.632923,277.92445 186.825101,276.531127 C243.171268,257.748288 283.775,204.581154 283.775,141.912168 C283.775,63.5477395 220.248404,0.0234927555 141.888675,0.0234927555" /></g>
</svg>
);
const ButtonTest = () => (
<section>
<h5>Buttons</h5>

View File

@ -0,0 +1,9 @@
import React from 'react';
const GithubIcon = () => (
<svg viewBox="0 0 284 277">
<g><path d="M141.888675,0.0234927555 C63.5359948,0.0234927555 0,63.5477395 0,141.912168 C0,204.6023 40.6554239,257.788232 97.0321356,276.549924 C104.12328,277.86336 106.726656,273.471926 106.726656,269.724287 C106.726656,266.340838 106.595077,255.16371 106.533987,243.307542 C67.0604204,251.890693 58.7310279,226.56652 58.7310279,226.56652 C52.2766299,210.166193 42.9768456,205.805304 42.9768456,205.805304 C30.1032937,196.998939 43.9472374,197.17986 43.9472374,197.17986 C58.1953153,198.180797 65.6976425,211.801527 65.6976425,211.801527 C78.35268,233.493192 98.8906827,227.222064 106.987463,223.596605 C108.260955,214.426049 111.938106,208.166669 115.995895,204.623447 C84.4804813,201.035582 51.3508808,188.869264 51.3508808,134.501475 C51.3508808,119.01045 56.8936274,106.353063 65.9701981,96.4165325 C64.4969882,92.842765 59.6403297,78.411417 67.3447241,58.8673023 C67.3447241,58.8673023 79.2596322,55.0538738 106.374213,73.4114319 C117.692318,70.2676443 129.83044,68.6910512 141.888675,68.63701 C153.94691,68.6910512 166.09443,70.2676443 177.433682,73.4114319 C204.515368,55.0538738 216.413829,58.8673023 216.413829,58.8673023 C224.13702,78.411417 219.278012,92.842765 217.804802,96.4165325 C226.902519,106.353063 232.407672,119.01045 232.407672,134.501475 C232.407672,188.998493 199.214632,200.997988 167.619331,204.510665 C172.708602,208.913848 177.243363,217.54869 177.243363,230.786433 C177.243363,249.771339 177.078889,265.050898 177.078889,269.724287 C177.078889,273.500121 179.632923,277.92445 186.825101,276.531127 C243.171268,257.748288 283.775,204.581154 283.775,141.912168 C283.775,63.5477395 220.248404,0.0234927555 141.888675,0.0234927555" /></g>
</svg>
);
export default GithubIcon;

View File

@ -2,6 +2,7 @@
import React from 'react';
import App from '../components/app';
import AppBarToolbox from '../components/app_bar';
import Avatar from './components/avatar';
import ButtonToolbox from '../components/button';
import Autocomplete from './components/autocomplete';
import Button from './components/button';
@ -43,6 +44,7 @@ const Root = () => (
</AppBarToolbox>
<Autocomplete />
<Avatar />
<Button />
<Card />
<Checkbox />