1
0
mirror of https://github.com/yldio/copilot.git synced 2024-09-21 13:53:51 +03:00

implimenting tooltip component

This commit is contained in:
Alex Windett 2016-12-20 12:02:47 +00:00
parent 5513f58335
commit 172cc3d447
7 changed files with 172 additions and 4 deletions

View File

@ -30,12 +30,13 @@ const Letter = styled.p`
`; `;
const Avatar = styled.div` const Avatar = styled.div`
border-radius: 50%; border-radius: 100%;
height: ${remcalc(50)}; height: ${remcalc(42)};
display: inline-block;
overflow: hidden; overflow: hidden;
position: relative; position: relative;
text-align: center; text-align: center;
width: ${remcalc(50)}; width: ${remcalc(42)};
`; `;
module.exports = ({ module.exports = ({

View File

@ -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 (
<StyledList
arrowPosition={arrowPosition}
className={className}
>
{children}
</StyledList>
);
};
module.exports.propTypes = {
arrowPosition: React.PropTypes.object,
children: React.PropTypes.node,
className: React.PropTypes.string,
style: React.PropTypes.object
};

View File

@ -0,0 +1,41 @@
# `<Tooltip>`
## 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(
<Base>
<Row>
<Column>
<Tooltip color='#35a8c0' name='Alex' />
</Column>
<Column>
<Tooltip color='#ef6176' name='Alex' src='https://openclipart.org/image/2400px/svg_to_png/177482/ProfilePlaceholderSuit.png' />
</Column>
</Row>
</Base>
);
```
## usage
```js
const React = require('react');
const Tooltip = require('ui/avatar');
module.exports = () => {
return (
<Tooltip color='#35a8c0' name='Alex' />
<Tooltip color='#ef6176' name='Alex' src='path/to/image.png' />
);
}
```

View File

@ -18,5 +18,6 @@ module.exports = {
Select: require('./components/select'), Select: require('./components/select'),
Widget: require('./components/widget'), Widget: require('./components/widget'),
Pagination: require('./components/pagination'), Pagination: require('./components/pagination'),
Modal: require('./components/modal') Modal: require('./components/modal'),
Tooltip: require('./components/tooltip')
}; };

View File

@ -48,4 +48,7 @@ module.exports = {
bottom: ${positions.bottom || 'auto'}; bottom: ${positions.bottom || 'auto'};
left: ${positions.left || 'auto'}; left: ${positions.left || 'auto'};
` `
// {
// debugger
// }
}; };

View File

@ -22,6 +22,7 @@ const {
Tabs, Tabs,
Tab, Tab,
Toggle, Toggle,
Tooltip,
Widget, Widget,
Radio, Radio,
RadioGroup RadioGroup
@ -265,6 +266,28 @@ storiesOf('Toggle', module)
<Toggle /> <Toggle />
)); ));
storiesOf('Tooltip', module)
.add('default', () => (
<Tooltip>
<li>One</li>
<li>Two</li>
<li>Three</li>
</Tooltip>
))
.add('custom position', () => {
const arrowPosition = {
left: '90%',
bottom: '100%'
};
return (
<Tooltip arrowPosition={arrowPosition}>
<li>One</li>
<li>Two</li>
<li>Three</li>
</Tooltip>
);
});
storiesOf('Widget', module) storiesOf('Widget', module)
.add('single', () => ( .add('single', () => (
<Widget <Widget

View File

@ -119,3 +119,9 @@ test('renders <Notification> without exploding', (t) => {
const wrapper = shallow(<Pagination />); const wrapper = shallow(<Pagination />);
t.deepEqual(wrapper.length, 1); t.deepEqual(wrapper.length, 1);
}); });
test('renders <Tooltip> without exploding', (t) => {
const Tooltip = require('../src/components/tooltip');
const wrapper = shallow(<Tooltip />);
t.deepEqual(wrapper.length, 1);
});