From 172cc3d447697c06b3d4b35d7e06c8d87efcce34 Mon Sep 17 00:00:00 2001 From: Alex Windett Date: Tue, 20 Dec 2016 12:02:47 +0000 Subject: [PATCH] implimenting tooltip component --- ui/src/components/avatar/index.js | 7 ++- ui/src/components/tooltip/index.js | 93 +++++++++++++++++++++++++++++ ui/src/components/tooltip/readme.md | 41 +++++++++++++ ui/src/index.js | 3 +- ui/src/shared/composers.js | 3 + ui/stories/index.js | 23 +++++++ ui/test/index.js | 6 ++ 7 files changed, 172 insertions(+), 4 deletions(-) create mode 100644 ui/src/components/tooltip/index.js create mode 100644 ui/src/components/tooltip/readme.md diff --git a/ui/src/components/avatar/index.js b/ui/src/components/avatar/index.js index 568a59b8..dc5b24c2 100644 --- a/ui/src/components/avatar/index.js +++ b/ui/src/components/avatar/index.js @@ -30,12 +30,13 @@ const Letter = styled.p` `; const Avatar = styled.div` - border-radius: 50%; - height: ${remcalc(50)}; + border-radius: 100%; + height: ${remcalc(42)}; + display: inline-block; overflow: hidden; position: relative; text-align: center; - width: ${remcalc(50)}; + width: ${remcalc(42)}; `; module.exports = ({ diff --git a/ui/src/components/tooltip/index.js b/ui/src/components/tooltip/index.js new file mode 100644 index 00000000..7d0c40bd --- /dev/null +++ b/ui/src/components/tooltip/index.js @@ -0,0 +1,93 @@ +// TODO: use a checkbox + +const React = require('react'); +const composers = require('../../shared/composers'); +const fns = require('../../shared/functions'); +const Styled = require('styled-components'); + +const { + baseBox, + pseudoEl, +} = composers; + +const { + remcalc +} = fns; + +const { + default: styled +} = Styled; + +const ItemPadder = 9; +const WrapperPadder = 24; +const ulPadder = `${WrapperPadder - ItemPadder} 0`; + + +const StyledList = styled.ul` + position: relative; + background: #fff; + color: #646464; + display: inline-block; + font-family: sans-serif; + list-style-type: none; + margin: 0; + padding: ${remcalc(ulPadder)}; + min-width: ${remcalc(200)}; + + ${baseBox()} + + & > * { + + padding: ${remcalc(ItemPadder)} ${remcalc(WrapperPadder)}; + + &:hover { + background: red; + } + } + + &:after, &:before { + border: solid transparent; + height: 0; + width: 0; + + ${ props => pseudoEl(props.arrowPosition) } + } + + &:after { + border-color: rgba(255, 255, 255, 0); + border-bottom-color: #fff; + border-width: 10px; + margin-left: -10px; + } + &:before { + border-color: rgba(216, 216, 216, 0); + border-bottom-color: #d8d8d8; + border-width: 12px; + margin-left: -12px; + } +`; +module.exports = ({ + children, + className, + style, + arrowPosition = { + bottom: '100%', + left: '10%' + } +}) => { + return ( + + {children} + + ); +}; + +module.exports.propTypes = { + arrowPosition: React.PropTypes.object, + children: React.PropTypes.node, + className: React.PropTypes.string, + style: React.PropTypes.object +}; diff --git a/ui/src/components/tooltip/readme.md b/ui/src/components/tooltip/readme.md new file mode 100644 index 00000000..a006a17e --- /dev/null +++ b/ui/src/components/tooltip/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 Tooltip = require('./index.js'); +const styles = require('./style.css'); + +nmodule.exports = ReactDOM.renderToString( + + + + + + + + + + +); +``` + +## usage + +```js +const React = require('react'); +const Tooltip = require('ui/avatar'); + +module.exports = () => { + return ( + + + ); +} +``` diff --git a/ui/src/index.js b/ui/src/index.js index 7de04210..941401ff 100644 --- a/ui/src/index.js +++ b/ui/src/index.js @@ -18,5 +18,6 @@ module.exports = { Select: require('./components/select'), Widget: require('./components/widget'), Pagination: require('./components/pagination'), - Modal: require('./components/modal') + Modal: require('./components/modal'), + Tooltip: require('./components/tooltip') }; diff --git a/ui/src/shared/composers.js b/ui/src/shared/composers.js index 517b2eeb..3d0c5d30 100644 --- a/ui/src/shared/composers.js +++ b/ui/src/shared/composers.js @@ -48,4 +48,7 @@ module.exports = { bottom: ${positions.bottom || 'auto'}; left: ${positions.left || 'auto'}; ` + // { + // debugger + // } }; diff --git a/ui/stories/index.js b/ui/stories/index.js index 22806a2f..05a5b00b 100644 --- a/ui/stories/index.js +++ b/ui/stories/index.js @@ -22,6 +22,7 @@ const { Tabs, Tab, Toggle, + Tooltip, Widget, Radio, RadioGroup @@ -265,6 +266,28 @@ storiesOf('Toggle', module) )); +storiesOf('Tooltip', module) + .add('default', () => ( + +
  • One
  • +
  • Two
  • +
  • Three
  • +
    + )) + .add('custom position', () => { + const arrowPosition = { + left: '90%', + bottom: '100%' + }; + return ( + +
  • One
  • +
  • Two
  • +
  • Three
  • +
    + ); + }); + storiesOf('Widget', module) .add('single', () => ( without exploding', (t) => { const wrapper = shallow(); t.deepEqual(wrapper.length, 1); }); + +test('renders without exploding', (t) => { + const Tooltip = require('../src/components/tooltip'); + const wrapper = shallow(); + t.deepEqual(wrapper.length, 1); +});