UNPKG

4.23 kBSCSSView Raw
1@use '../internal' as *;
2
3$generate-utility: should-generate-classes($TOOLTIPS);
4
5@if $generate-utility {
6 /* TOOLTIPS */
7 .tooltip {
8 position: relative; /* let's the pseudoelement that we are displaying relative to the button. */
9 overflow: visible; /* Allows the pseudoelement to be shown */
10 white-space: nowrap; /* Keeps the button text from wrapping and getting too large */
11
12 /* This is the psuedoelement that creates the tooltip */
13 &::after {
14 position: absolute;
15 color: #fff;
16 font-size: 0.6rem;
17 background-color: $tooltip-primary-bg;
18 content: attr(
19 data-tooltip
20 ); /* Retrieves the data specified in this element property and displays it as text */
21 display: block;
22 line-height: 1rem;
23 text-transform: none;
24 overflow: hidden;
25 padding: 0.4rem 0.8rem;
26 opacity: 0; /* Hide the element */
27 text-overflow: ellipsis;
28 max-width: 15rem;
29 transform: translate(-50%, 0);
30 transition: all var(--animation-duration) ease;
31 z-index: 200;
32 pointer-events: none;
33 bottom: 100%; /* Pushes the tooltip above the button */
34 left: 50%; /* Horizontally center it */
35 border-radius: 0.2rem;
36 }
37
38 /* Handles the on hover event of the button and then modifies the associated tooltip accordingly. */
39 &:focus::after,
40 &:hover::after {
41 opacity: 1;
42 transform: translate(-50%, -0.5rem);
43 transition: all var(--animation-duration) ease;
44 }
45
46 /* Tooltip top left */
47 &.tooltip--top-left::after {
48 transform: translate(-50%, 0);
49 }
50
51 &.tooltip--top-left:hover::after,
52 &.tooltip--top-left:focus::after {
53 left: 0;
54 transform: translate(-100%, -0.5rem);
55 }
56
57 /* Tooltip top right */
58 &.tooltip--top-right::after {
59 left: auto;
60 transform: translate(15%, 0);
61 }
62
63 &.tooltip--top-right:hover::after,
64 &.tooltip--top-right:focus::after {
65 right: 0;
66 transform: translate(100%, -0.5rem);
67 }
68
69 /* Tooltip bottom */
70 &.tooltip--bottom::after {
71 top: 100%;
72 transform: translate(-50%, -1rem); /* Moves tooltip to the center horizontally and shifts tooltip down */
73 bottom: auto;
74 }
75
76 &.tooltip--bottom:hover::after,
77 &.tooltip--bottom:focus::after {
78 transform: translate(-50%, 0.5rem);
79 bottom: auto;
80 }
81
82 /* Tooltip bottom left */
83 &.tooltip--bottom-left::after {
84 top: 100%;
85 transform: translate(-65%, -1rem);
86 bottom: auto;
87 }
88
89 &.tooltip--bottom-left:hover::after,
90 &.tooltip--bottom-left:focus::after {
91 left: 0;
92 transform: translate(-100%, 0.5rem);
93 }
94
95 /* Tooltip bottom right */
96 &.tooltip--bottom-right::after {
97 left: auto;
98 top: 100%;
99 transform: translate(0%, -1rem);
100 bottom: auto;
101 }
102
103 &.tooltip--bottom-right:hover::after,
104 &.tooltip--bottom-right:focus::after {
105 right: 0;
106 transform: translate(100%, 0.5rem);
107 }
108
109 /* Tooltip right */
110 &.tooltip--right::after {
111 left: 100%;
112 bottom: 50%;
113 transform: translate(-1rem, 50%);
114 }
115
116 &.tooltip--right:hover::after,
117 &.tooltip--right:focus::after {
118 transform: translate(0.5rem, 50%);
119 }
120
121 /* Tooltip Left */
122 &.tooltip--left::after {
123 right: 100%;
124 bottom: 50%;
125 left: auto; /* Needed to work */
126 transform: translate(1rem, 50%);
127 }
128
129 &.tooltip--left:hover::after,
130 &.tooltip--left:focus::after {
131 transform: translate(-0.5rem, 50%);
132 }
133 }
134}