aboutsummaryrefslogtreecommitdiff
path: root/scss/_tooltip.scss
blob: b3a410146148f2b1f0353b9c056340688c4b0b09 (plain)
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
// Base class
.tooltip {
  // scss-docs-start tooltip-css-vars
  --#{$variable-prefix}tooltip-padding: #{$tooltip-padding-y} #{$tooltip-padding-x};
  --#{$variable-prefix}tooltip-font-size: #{$tooltip-font-size};
  --#{$variable-prefix}tooltip-color: #{$tooltip-color};
  --#{$variable-prefix}tooltip-bg: #{$tooltip-bg};
  --#{$variable-prefix}tooltip-border-radius: #{$tooltip-border-radius};
  --#{$variable-prefix}tooltip-opacity: #{$tooltip-opacity};
  --#{$variable-prefix}tooltip-arrow-width: #{$tooltip-arrow-width};
  --#{$variable-prefix}tooltip-arrow-height: #{$tooltip-arrow-height};
  // scss-docs-end tooltip-css-vars

  position: absolute;
  z-index: $zindex-tooltip;
  display: block;
  margin: $tooltip-margin;
  // Our parent element can be arbitrary since tooltips are by default inserted as a sibling of their target element.
  // So reset our font and text properties to avoid inheriting weird values.
  @include reset-text();
  @include font-size($tooltip-font-size);
  // Allow breaking very long words so they don't overflow the tooltip's bounds
  word-wrap: break-word;
  opacity: 0;

  &.show { opacity: var(--#{$variable-prefix}tooltip-opacity); }

  .tooltip-arrow {
    position: absolute;
    display: block;
    width: var(--#{$variable-prefix}tooltip-arrow-width);
    height: var(--#{$variable-prefix}tooltip-arrow-height);

    &::before {
      position: absolute;
      content: "";
      border-color: transparent;
      border-style: solid;
    }
  }
}

.bs-tooltip-top {
  padding: var(--#{$variable-prefix}tooltip-arrow-height) 0;

  .tooltip-arrow {
    bottom: 0;

    &::before {
      top: -1px;
      border-width: var(--#{$variable-prefix}tooltip-arrow-height) calc(var(--#{$variable-prefix}tooltip-arrow-width) * .5) 0; // stylelint-disable-line function-disallowed-list
      border-top-color: var(--#{$variable-prefix}tooltip-bg);
    }
  }
}

.bs-tooltip-end {
  padding: 0 var(--#{$variable-prefix}tooltip-arrow-height);

  .tooltip-arrow {
    left: 0;
    width: var(--#{$variable-prefix}tooltip-arrow-height);
    height: var(--#{$variable-prefix}tooltip-arrow-width);

    &::before {
      right: -1px;
      border-width: calc(var(--#{$variable-prefix}tooltip-arrow-width) * .5) var(--#{$variable-prefix}tooltip-arrow-height) calc(var(--#{$variable-prefix}tooltip-arrow-width) * .5) 0; // stylelint-disable-line function-disallowed-list
      border-right-color: var(--#{$variable-prefix}tooltip-bg);
    }
  }
}

.bs-tooltip-bottom {
  padding: var(--#{$variable-prefix}tooltip-arrow-height) 0;

  .tooltip-arrow {
    top: 0;

    &::before {
      bottom: -1px;
      border-width: 0 calc(var(--#{$variable-prefix}tooltip-arrow-width) * .5) var(--#{$variable-prefix}tooltip-arrow-height); // stylelint-disable-line function-disallowed-list
      border-bottom-color: var(--#{$variable-prefix}tooltip-bg);
    }
  }
}

.bs-tooltip-start {
  padding: 0 var(--#{$variable-prefix}tooltip-arrow-height);

  .tooltip-arrow {
    right: 0;
    width: var(--#{$variable-prefix}tooltip-arrow-height);
    height: var(--#{$variable-prefix}tooltip-arrow-width);

    &::before {
      left: -1px;
      border-width: calc(var(--#{$variable-prefix}tooltip-arrow-width) * .5) 0 calc(var(--#{$variable-prefix}tooltip-arrow-width) * .5) var(--#{$variable-prefix}tooltip-arrow-height); // stylelint-disable-line function-disallowed-list
      border-left-color: var(--#{$variable-prefix}tooltip-bg);
    }
  }
}

.bs-tooltip-auto {
  &[data-popper-placement^="top"] {
    @extend .bs-tooltip-top;
  }
  &[data-popper-placement^="right"] {
    @extend .bs-tooltip-end;
  }
  &[data-popper-placement^="bottom"] {
    @extend .bs-tooltip-bottom;
  }
  &[data-popper-placement^="left"] {
    @extend .bs-tooltip-start;
  }
}

// Wrapper for the tooltip content
.tooltip-inner {
  max-width: $tooltip-max-width;
  padding: var(--#{$variable-prefix}tooltip-padding);
  color: var(--#{$variable-prefix}tooltip-color);
  text-align: center;
  background-color: var(--#{$variable-prefix}tooltip-bg);
  border-radius: var(--#{$variable-prefix}tooltip-border-radius, 0); // stylelint-disable-line property-disallowed-list
}