This repository has been archived by the owner on Nov 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from jamesplease/avatars
adding Avatar component and docs
- Loading branch information
Showing
12 changed files
with
125 additions
and
3 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
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,7 @@ | ||
class AvatarExample extends Component { | ||
render() { | ||
return <Avatar image="https://randomuser.me/api/portraits/women/50.jpg" />; | ||
} | ||
} | ||
|
||
return <AvatarExample />; |
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,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 | |
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
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; | ||
} |
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,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; |
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,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')} /> | ||
)); |