Skip to content

Commit

Permalink
feat(Tooltip): Applying theme props
Browse files Browse the repository at this point in the history
  • Loading branch information
allyssonsantos committed May 24, 2019
1 parent a33fb1a commit bef5f86
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions components/Tooltip/Tooltip.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import Colors from '../Colors';
import placementConfig from './options';
import { colors, spacing } from '../shared/theme';

const Tip = styled.div`
background-color: ${Colors.BLACK[700]};
border-color: ${Colors.BLACK[700]};
border-radius: 4px;
color: ${Colors.WHITE};
font-size: 16px;
font-weight: bold;
opacity: ${({ visible }) => (visible ? '1' : '0')};
padding: 4px 8px;
position: absolute;
line-height: 0;
text-align: center;
transition: opacity 0.2s ease-in-out, visibility 0.2s ease-in-out;
z-index: 100;
${({
theme: {
colors: { neutral },
spacing: { xxsmall, xsmall },
},
}) => `
background-color: ${neutral[700]};
border-color: ${neutral[700]};
color: ${neutral[100]};
padding: ${xxsmall}px ${xsmall}px;
`}
${({ placement }) => placementConfig.tipPosition[placement]};
&:before {
Expand Down Expand Up @@ -55,6 +63,7 @@ class Tooltip extends Component {
placement,
text,
visible: visibleProp,
theme,
...rest
} = this.props;
const { visible: visibleState } = this.state;
Expand All @@ -65,7 +74,11 @@ class Tooltip extends Component {
onMouseLeave={() => this.isVisible(false)}
{...rest}
>
<Tip placement={placement} visible={visibleProp || visibleState}>
<Tip
placement={placement}
visible={visibleProp || visibleState}
theme={theme}
>
<TipText>{text}</TipText>
</Tip>
{children}
Expand All @@ -86,11 +99,19 @@ Tooltip.propTypes = {
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]).isRequired,
theme: PropTypes.shape({
spacing: PropTypes.object,
colors: PropTypes.object,
}),
};

Tooltip.defaultProps = {
placement: 'top',
visible: false,
theme: {
spacing,
colors,
},
};

export default Tooltip;

0 comments on commit bef5f86

Please sign in to comment.