2017-10-19 16:36:18 +03:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import styled from 'styled-components';
|
|
|
|
import { Popper as BasePopper, Arrow } from 'react-popper';
|
|
|
|
import rndId from 'rnd-id';
|
|
|
|
import remcalc from 'remcalc';
|
2017-11-23 14:18:38 +02:00
|
|
|
import is from 'styled-is';
|
2017-10-19 16:36:18 +03:00
|
|
|
|
|
|
|
import style from '../tooltip/style';
|
2017-11-23 14:18:38 +02:00
|
|
|
import { default as BaseTarget } from '../tooltip/target';
|
2017-10-19 16:36:18 +03:00
|
|
|
|
|
|
|
const arrowClassName = rndId();
|
|
|
|
|
|
|
|
const Popper = styled(BasePopper)`
|
|
|
|
box-shadow: 0 ${remcalc(2)} ${remcalc(6)} rgba(0, 0, 0, 0.1);
|
|
|
|
border: ${remcalc(1)} solid ${props => props.theme.grey};
|
|
|
|
|
2017-12-22 05:24:28 +02:00
|
|
|
padding: ${remcalc(15)} ${remcalc(18)} ${remcalc(3)} ${remcalc(18)};
|
2017-10-19 16:36:18 +03:00
|
|
|
|
|
|
|
${style({
|
|
|
|
background: 'white',
|
|
|
|
color: 'text',
|
|
|
|
border: 'grey',
|
|
|
|
arrow: arrowClassName
|
|
|
|
})};
|
|
|
|
`;
|
|
|
|
|
2017-11-23 14:18:38 +02:00
|
|
|
const StyledTarget = styled(BaseTarget)`
|
|
|
|
${is('box')`
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
|
2018-03-28 15:51:34 +03:00
|
|
|
display: flex !important;
|
2017-11-23 14:18:38 +02:00
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
`};
|
|
|
|
`;
|
|
|
|
|
2018-03-28 15:51:34 +03:00
|
|
|
export const Target = ({ children, box = false, ...rest }) => (
|
2017-11-23 14:18:38 +02:00
|
|
|
<StyledTarget box={box} tag={box ? 'div' : false} {...rest}>
|
|
|
|
{children}
|
|
|
|
</StyledTarget>
|
2018-03-28 15:51:34 +03:00
|
|
|
);
|
2017-11-23 14:18:38 +02:00
|
|
|
|
2017-10-19 16:36:18 +03:00
|
|
|
export default class Popover extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
ttpContMangr: PropTypes.object.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
render = () => {
|
|
|
|
const { children, placement = 'auto', ...rest } = this.props;
|
|
|
|
const { isOpen, setRef } = this.context.ttpContMangr;
|
|
|
|
|
|
|
|
return (
|
|
|
|
isOpen() && (
|
|
|
|
<Popper innerRef={setRef('popper')} placement={placement} {...rest}>
|
|
|
|
{children}
|
|
|
|
<Arrow>
|
|
|
|
<span className={arrowClassName} />
|
|
|
|
</Arrow>
|
|
|
|
</Popper>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export { default as Divider } from './divider';
|
|
|
|
export { default as Item } from './item';
|
|
|
|
export { default as Container } from '../tooltip/container';
|