-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: switch to simple Tooltip (🗜 yet another 83kB to bundle size)
- Loading branch information
1 parent
213f85b
commit e1b2065
Showing
5 changed files
with
74 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import * as React from 'react'; | ||
|
||
import styled from '../styled-components'; | ||
|
||
const Wrapper = styled.div` | ||
position: relative; | ||
`; | ||
|
||
const Tip = styled.div` | ||
position: absolute; | ||
min-width: 80px; | ||
max-width: 500px; | ||
background: #fff; | ||
bottom: 100%; | ||
left: 50%; | ||
margin-bottom: 10px; | ||
transform: translateX(-50%); | ||
border-radius: 4px; | ||
padding: 0.3em 0.6em; | ||
text-align: center; | ||
`; | ||
|
||
const Content = styled.div` | ||
background: #fff; | ||
color: #000; | ||
display: inline; | ||
font-size: 0.85em; | ||
white-space: nowrap; | ||
`; | ||
|
||
const Arrow = styled.div` | ||
position: absolute; | ||
width: 0; | ||
height: 0; | ||
bottom: -5px; | ||
left: 50%; | ||
margin-left: -5px; | ||
border-left: solid transparent 5px; | ||
border-right: solid transparent 5px; | ||
border-top: solid #fff 5px; | ||
`; | ||
|
||
const Gap = styled.div` | ||
position: absolute; | ||
width: 100%; | ||
height: 20px; | ||
bottom: -20px; | ||
`; | ||
|
||
export interface TooltipProps { | ||
open: boolean; | ||
title: string; | ||
} | ||
|
||
export class Tooltip extends React.Component<TooltipProps> { | ||
render() { | ||
const { open, title, children } = this.props; | ||
return ( | ||
<Wrapper> | ||
{children} | ||
{open && ( | ||
<Tip> | ||
<Content>{title}</Content> | ||
<Arrow /> | ||
<Gap /> | ||
</Tip> | ||
)} | ||
</Wrapper> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters