Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Merge pull request #91 from jamesplease/avatars
Browse files Browse the repository at this point in the history
adding Avatar component and docs
  • Loading branch information
jamesplease authored May 24, 2018
2 parents 0c9156d + 9f3d5f8 commit b155a6c
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### v0.4.0 (2018/5/24)

* Introduces the Avatar component

### v0.3.1 (2018/5/23)

* Update the way that the Switch focus state is rendered
Expand Down
8 changes: 8 additions & 0 deletions docs/components.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export default [
{
name: 'Avatar',
url: 'avatar',
componentKey: 'avatar',
description:
'An Avatar is an image that repesents the user. If no image is present it will show the initials.',
component: 'src/components/component-doc',
},
{
name: 'Button',
url: 'button',
Expand Down
7 changes: 7 additions & 0 deletions docs/examples/avatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AvatarExample extends Component {
render() {
return <Avatar image="https://randomuser.me/api/portraits/women/50.jpg" />;
}
}

return <AvatarExample />;
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"codemirror": "^5.36.0",
"fetch-dedupe": "^3.0.0",
"highlight.js": "^9.12.0",
"materialish": "0.3.1",
"materialish": "0.4.0",
"no-scroll": "^2.1.1",
"prop-types": "^15.6.1",
"react": "^16.0.0",
Expand Down
24 changes: 24 additions & 0 deletions docs/readmes/avatar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Usage

```jsx
import { Avatar } from 'materialish';
import 'materialish/avatar.css';
```

## Props

| Prop Name | Default Value | Required | Description |
| --------- | ------------- | -------- | -------------------------------------------------------- |
| className | | No | Additional class name(s) to add to the Avatar |
| image | | No | The URL for the user's picture |
| initials | | No | The user's initials |
| ...rest | | No | Other props are placed on the root element of the Avatar |

## CSS Variables

| Variable | Default Value | Description |
| --------------------------- | ------------- | ---------------------------------------------------------------------- |
| --mt-baseFontSize | 1rem | The text size and dimensions of the avatar are based off of this value |
| --mt-fontFamily | 'Roboto' | The font family to use for text |
| --mt-avatar-backgroundColor | #ccc | The background color of the avatar |
| --mt-avatar-color | #333 | The text color of the avatar |
1 change: 1 addition & 0 deletions docs/src/common/utils/load-materialish-styles.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import '../../styles/npm-package-styles/avatar.css';
import '../../styles/npm-package-styles/button.css';
import '../../styles/npm-package-styles/ripple.css';
import '../../styles/npm-package-styles/checkbox.css';
Expand Down
2 changes: 2 additions & 0 deletions docs/static.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ const homeMarkdown = fs.readFileSync('./src/home/index.md', {
});

const readmes = {
avatar: fs.readFileSync('./readmes/avatar.md', { encoding: 'utf-8' }),
button: fs.readFileSync('./readmes/button.md', { encoding: 'utf-8' }),
checkbox: fs.readFileSync('./readmes/checkbox.md', { encoding: 'utf-8' }),
switch: fs.readFileSync('./readmes/switch.md', { encoding: 'utf-8' }),
};

const examples = {
avatar: fs.readFileSync('./examples/avatar.js', { encoding: 'utf-8' }),
button: fs.readFileSync('./examples/button.js', { encoding: 'utf-8' }),
checkbox: fs.readFileSync('./examples/checkbox.js', { encoding: 'utf-8' }),
switch: fs.readFileSync('./examples/switch.js', { encoding: 'utf-8' }),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "materialish",
"version": "0.3.1",
"version": "0.4.0",
"description": "React components that loosely follow Material Design",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
34 changes: 34 additions & 0 deletions src/avatar/avatar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
.mt-avatar {
/*
This (ugly) set of variables defines the variable fallback implementation.
1. If `mt-avatar-backgroundColor` is set, then that will be applied
2. Otherwise, `#ccc` will be applied
*/
--_mt-avatar-backgroundColor: var(--mt-avatar-backgroundColor, #ccc);
--_mt-avatar-color: var(--mt-avatar-color, #333);

font-size: var(--mt-baseFontSize, 1rem);
font-family: var(--mt-fontFamily, 'Roboto');
width: 5em;
height: 5em;
overflow: hidden;
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
background-color: var(--_mt-avatar-backgroundColor);
color: var(--_mt-avatar-color);
vertical-align: middle;
}

.mt-avatar_image {
width: 100%;
height: 100%;
}

.mt-avatar_initials {
font-size: 3em;
width: 100%;
text-align: center;
}
19 changes: 19 additions & 0 deletions src/avatar/avatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { Component } from 'react';

class Avatar extends Component {
render() {
const { className = '', image, initials = '', ...props } = this.props;

return (
<div className={`mt-avatar ${className}`} {...props}>
{image ? (
<img className="mt-avatar_image" src={image} alt="" />
) : (
<div className="mt-avatar_initials">{initials}</div>
)}
</div>
);
}
}

export default Avatar;
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import Ripple from './ripple/ripple';
import Button from './button/button';
import Checkbox from './checkbox/checkbox';
import Switch from './switch/switch';
import Avatar from './avatar/avatar';

export { Button, Checkbox, Ripple, Switch };
export { Avatar, Button, Checkbox, Ripple, Switch };
22 changes: 22 additions & 0 deletions stories/avatar.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';
import { setOptions } from '@storybook/addon-options';
import '../src/avatar/avatar.css';
import { Avatar } from '../src/index';

setOptions({
name: 'Materialish',
addonPanelInRight: true,
});

storiesOf('Avatar', module)
.add('Regular', () => (
<Avatar
image="https://randomuser.me/api/portraits/women/50.jpg"
onClick={action('clicked')}
/>
))
.add('With Initials', () => (
<Avatar initials="JP" onClick={action('clicked')} />
));

0 comments on commit b155a6c

Please sign in to comment.