Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tooltip component #738

Merged
merged 12 commits into from
May 1, 2020
5 changes: 4 additions & 1 deletion src/components/Tooltip/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { Tooltip } from './Tooltip'
storiesOf('Tooltip', module).add('all', () => (
<List>
<li>
<Tooltip message="Pablo Diego José Francisco de Paula Juan Nepomuceno Cipriano de la Santísima Trinidad Ruiz Picasso">
<Tooltip
message="Pablo Diego José Francisco de Paula Juan Nepomuceno Cipriano de la Santísima Trinidad Ruiz Picasso"
balloonType="dark"
>
Default: Pablo Diego José Francisco de Paula Juan Nepomuceno Cipriano de la Santísima
Trinidad Ruiz Picasso
</Tooltip>
Expand Down
8 changes: 6 additions & 2 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react'
import styled, { css } from 'styled-components'
import { LightBalloon } from '../Balloon'
import { LightBalloon, DarkBalloon } from '../Balloon'
import { useTheme, Theme } from '../../hooks/useTheme'

interface Prop {
Expand All @@ -9,6 +9,7 @@ interface Prop {
triggerType?: 'icon' | 'text'
multiLine?: boolean
ellipsisOnly?: boolean
balloonType?: 'light' | 'dark'
}

export const Tooltip: React.FC<Prop> = ({
Expand All @@ -17,6 +18,7 @@ export const Tooltip: React.FC<Prop> = ({
triggerType,
multiLine,
ellipsisOnly = false,
balloonType = 'light',
}) => {
const theme = useTheme()
const [isVisible, setIsVisible] = useState(false)
Expand Down Expand Up @@ -46,6 +48,7 @@ export const Tooltip: React.FC<Prop> = ({
const outAction = () => {
setIsVisible(false)
}
const StyledBalloon = balloonType === 'light' ? StyledLightBalloon : StyledDarkBallon
AtsushiM marked this conversation as resolved.
Show resolved Hide resolved

return (
<Wrapper
Expand All @@ -71,7 +74,7 @@ const Wrapper = styled.span`
max-width: 100%;
`

const StyledBalloon = styled(LightBalloon)`
const StyledLightBalloon = styled(LightBalloon)`
position: absolute;
left: 0;
bottom: calc(100% + 10px);
Expand All @@ -85,6 +88,7 @@ const StyledBalloon = styled(LightBalloon)`
left: calc(-100% - 5px);
}
`
const StyledDarkBallon = StyledLightBalloon.withComponent(DarkBalloon)
AtsushiM marked this conversation as resolved.
Show resolved Hide resolved

const StyledBalloonText = styled.p<{ themes: Theme }>`
margin: 0;
Expand Down