-
Notifications
You must be signed in to change notification settings - Fork 69
/
tooltip.js
104 lines (99 loc) · 2.43 KB
/
tooltip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import styled, { css } from 'styled-components';
// THIS FILE IS AN ABSOLUTE MESS
// IM TOO TIRED TO FIX IT
// :)
function triangleForSide(side) {
if (side === 'left') {
return css`
top: calc(50% - 10px);
left: -10px;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-right: 10px solid #333;
`;
}
if (side === 'top') {
return css`
top: -10px;
left: calc(50% - 10px);
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #333;
`;
}
if (side === 'bottom') {
return css`
bottom: -10px;
left: calc(50% - 10px);
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-top: 10px solid #333;
`;
}
if (side === 'right') {
return css`
top: calc(50% - 10px);
right: -10px;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid #333;
`;
}
}
const triangleCommon = css`
position: absolute;
content: ' ';
font-size: 0;
line-height: 0;
width: 0;
`;
export default styled.div`
display: inline-block;
border-radius: 6px;
background: #333;
opacity: 0.8;
position: relative;
padding: 0.25em;
${props =>
props.side
? css`
margin-${props => props.side}: 10px;
&:after {
position: absolute;
content: ' ';
font-size: 0;
line-height: 0;
width: 0;
${props => triangleForSide(props.side)};
}`
: css`
.tether-target-attached-right &:after {
${() => triangleForSide('left')};
${triangleCommon};
}
.tether-target-attached-right & {
margin-left: 10px;
}
.tether-target-attached-left &:after {
${() => triangleForSide('right')};
${triangleCommon};
}
.tether-target-attached-left & {
margin-right: 10px;
}
.tether-target-attached-bottom &:after {
${() => triangleForSide('top')};
${triangleCommon};
}
.tether-target-attached-bottom & {
margin-top: 10px;
}
.tether-target-attached-top &:after {
${() => triangleForSide('bottom')};
${triangleCommon};
}
.tether-target-attached-top & {
margin-bottom: 10px;
}
`};
`;