/
hint-position.scss
139 lines (116 loc) · 2.71 KB
/
hint-position.scss
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/**
* source: hint-position.scss
*
* Defines the positoning logic for the tooltips.
*
* Classes added:
* 1) hint--top
* 2) hint--bottom
* 3) hint--left
* 4) hint--right
*/
@mixin vertical-positioned-tooltip($propertyY, $transitionDirection, $xDirection:0) {
&:before {
// bring arrow inside so that it animates to normal position when shown.
// HACK: +1px to avoid the 1 px white space between arrow and body during transition.
margin-#{$propertyY}: -2 * $hintArrowBorderWidth + 1px;
}
&:before, &:after {
#{$propertyY}: 100%;
left: 50%; // get top-left corner in center
}
&:before {
left: calc(50% - #{$hintArrowBorderWidth}); // get arrow center aligned with content
}
$translateX: -50%;
@if $xDirection == -1 {
$translateX: -100%;
}
@elseif $xDirection == 1 {
$translateX: 0;
}
&:after {
@include vendor('transform', translateX($translateX));
}
&:after {
@if $xDirection != 0 {
// bring back the tooltip by some offset so that arrow doesn't stick at end
margin-left: -$xDirection * $hintArrowOffsetX;
}
}
&:hover, &:focus {
@include set-margin('translateY', $transitionDirection, $translateX);
}
}
@mixin horizontal-positioned-tooltip($propertyX, $transitionDirection) {
&:before {
// bring arrow inside so that it animates to normal position when shown
// HACK: +1px to avoid the 1 px white space between arrow and body during transition.
margin-#{$propertyX}: -2 * $hintArrowBorderWidth + 1px;
// bring back to center vertically
margin-bottom: -1 * $hintArrowBorderWidth;
}
&:after {
// bring back to center
margin-bottom: -1 * floor($hintTooltipHeight / 2);
}
&:before, &:after {
#{$propertyX}: 100%;
bottom: 50%;
}
&:hover, &:focus {
@include set-margin('translateX', $transitionDirection);
}
}
/**
* set default color for tooltip arrows
*/
@include arrow-border-color($hintDefaultColor);
/**
* top tooltip
*/
.#{$hintPrefix}top {
@include vertical-positioned-tooltip('bottom', -1);
}
/**
* bottom tooltip
*/
.#{$hintPrefix}bottom {
@include vertical-positioned-tooltip('top', 1);
}
/**
* right tooltip
*/
.#{$hintPrefix}right {
@include horizontal-positioned-tooltip('left', 1);
}
/**
* left tooltip
*/
.#{$hintPrefix}left {
@include horizontal-positioned-tooltip('right', -1);
}
/**
* top-left tooltip
*/
.#{$hintPrefix}top-left {
@include vertical-positioned-tooltip('bottom', -1, -1);
}
/**
* top-right tooltip
*/
.#{$hintPrefix}top-right {
@include vertical-positioned-tooltip('bottom', -1, 1);
}
/**
* bottom-left tooltip
*/
.#{$hintPrefix}bottom-left {
@include vertical-positioned-tooltip('top', 1, -1);
}
/**
* bottom-right tooltip
*/
.#{$hintPrefix}bottom-right {
@include vertical-positioned-tooltip('top', 1, 1);
}