From 8c147e412793dc2408ea680175da7fc35e2910ea Mon Sep 17 00:00:00 2001 From: Alex Windett Date: Fri, 28 Oct 2016 10:35:22 +0100 Subject: [PATCH] Avatar Component - Creating Avatar component and adding to showcase - Creating a composer file and adding class to vertically align content centrally --- ui/src/components/avatar/index.js | 50 ++++++++++++++++++++++++++++++ ui/src/components/avatar/readme.md | 41 ++++++++++++++++++++++++ ui/src/components/avatar/style.css | 19 ++++++++++++ ui/src/docs.js | 1 + ui/src/index.js | 1 + ui/src/util/composers.css | 8 +++++ 6 files changed, 120 insertions(+) create mode 100644 ui/src/components/avatar/index.js create mode 100644 ui/src/components/avatar/readme.md create mode 100644 ui/src/components/avatar/style.css create mode 100644 ui/src/util/composers.css diff --git a/ui/src/components/avatar/index.js b/ui/src/components/avatar/index.js new file mode 100644 index 00000000..320a347e --- /dev/null +++ b/ui/src/components/avatar/index.js @@ -0,0 +1,50 @@ +// TODO: use a checkbox + +const classNames = require('classnames'); +const React = require('react'); +const styles = require('./style.css'); + +const Avatar = ({ + image, + name, + className, + style +}) => { + + const cn = classNames( + className, + styles.avatar + ); + + const fill = () => { + if ( image ) { + return ( + {name} + ); + } else { + const letter = name.split('')[0]; + return ( +

{letter}

+ ); + } + } + + return ( +
+ {fill()} +
+ ); +}; + +Avatar.propTypes = { + className: React.PropTypes.string, + image: React.PropTypes.string, + name: React.PropTypes.string, + style: React.PropTypes.object +}; + +module.exports = Avatar; diff --git a/ui/src/components/avatar/readme.md b/ui/src/components/avatar/readme.md new file mode 100644 index 00000000..c7520bdd --- /dev/null +++ b/ui/src/components/avatar/readme.md @@ -0,0 +1,41 @@ +# `` + +## demo + +```embed +const React = require('react'); +const ReactDOM = require('react-dom/server'); +const Base = require('../base'); +const Container = require('../container'); +const Row = require('../row'); +const Column = require('../column'); +const Avatar = require('./index.js'); +const styles = require('./style.css'); + +nmodule.exports = ReactDOM.renderToString( + + + + + + + + + + +); +``` + +## usage + +```js +const React = require('react'); +const Avatar = require('ui/avatar'); + +module.exports = () => { + return ( + + + ); +} +``` diff --git a/ui/src/components/avatar/style.css b/ui/src/components/avatar/style.css new file mode 100644 index 00000000..0816e095 --- /dev/null +++ b/ui/src/components/avatar/style.css @@ -0,0 +1,19 @@ +.avatar { + background: red; + border-radius: 50%; + height: remCalc(50); + overflow: hidden; + text-align: center; + width: remCalc(50); + position: relative; +} + +.letter { + font-size: 2rem; +} + +.picture { + max-width: 60%; + + composes: verticle_align_center from '../../util/composers.css'; +} diff --git a/ui/src/docs.js b/ui/src/docs.js index 1c70cc07..6fa79c6c 100644 --- a/ui/src/docs.js +++ b/ui/src/docs.js @@ -5,6 +5,7 @@ module.exports = { Layout: require('./guidelines/layout.md') }, Components: { + Avatar: require('./components/avatar/readme.md'), Base: require('./components/base/readme.md'), Container: require('./components/container/readme.md'), Row: require('./components/row/readme.md'), diff --git a/ui/src/index.js b/ui/src/index.js index 8f1d8a32..d8a0d049 100644 --- a/ui/src/index.js +++ b/ui/src/index.js @@ -1,4 +1,5 @@ module.exports = { + Avatar: require('./components/avatar'), Base: require('./components/base'), Button: require('./components/button'), Checkbox: require('./components/checkbox'), diff --git a/ui/src/util/composers.css b/ui/src/util/composers.css new file mode 100644 index 00000000..2388dd59 --- /dev/null +++ b/ui/src/util/composers.css @@ -0,0 +1,8 @@ +.verticle_align_center { + /* Need to palce position:relative on parent*/ + + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +}