|
| 1 | +@use '../../../compiled/tokens/scss/size'; |
| 2 | +@use '../../../compiled/tokens/scss/color'; |
| 3 | +@use '../../../compiled/tokens/scss/ease'; |
| 4 | +@use '../../../compiled/tokens/scss/transition'; |
| 5 | +@use '../../../compiled/tokens/scss/z-index'; |
| 6 | +@use 'sass:color' as sass-color; |
| 7 | +@use '../../../mixins/ms'; |
| 8 | + |
| 9 | +/// |
| 10 | +/// Tooltip styles |
| 11 | +/// |
| 12 | +/// These Tooltip styles will be inlined in a Gutenberg Custom HTML block |
| 13 | +/// |
| 14 | +/// TODO Consider making a Tooltip patterns component in the future |
| 15 | +/// |
| 16 | + |
| 17 | +$tooltip-color-background: var(--theme-color-background-secondary); |
| 18 | +$tooltip-color-border: #{sass-color.change( |
| 19 | + color.$brand-primary-darker, |
| 20 | + $alpha: 0.4 |
| 21 | + )}; |
| 22 | +$tooltip-color-shadow: #{sass-color.change( |
| 23 | + color.$brand-primary-darker, |
| 24 | + $alpha: 0.2 |
| 25 | + )}; |
| 26 | + |
| 27 | +/// |
| 28 | +/// 1. Positions tooltip vertically (below button) |
| 29 | +/// 2. Horizontally centers tooltip |
| 30 | +/// |
| 31 | + |
| 32 | +._c-tooltip { |
| 33 | + background: $tooltip-color-background; |
| 34 | + border-radius: size.$border-radius-medium; |
| 35 | + box-shadow: 0 0 0 size.$edge-medium $tooltip-color-border, |
| 36 | + size.$edge-large size.$edge-large 0 size.$edge-medium $tooltip-color-shadow; |
| 37 | + color: var(--theme-color-text-emphasis); |
| 38 | + inset-block-start: 100%; // 1 |
| 39 | + inset-inline-start: 50%; // 2 |
| 40 | + opacity: 0; |
| 41 | + padding: ms.step(-4); |
| 42 | + position: absolute; // 2 |
| 43 | + transform: translateX(-50%); // 2 |
| 44 | + white-space: nowrap; |
| 45 | + z-index: z-index.$alert; |
| 46 | + |
| 47 | + /// |
| 48 | + /// Tooltip arrow |
| 49 | + /// |
| 50 | + /// The tooltip arrow is made up of two arrows, the first a background arrow |
| 51 | + /// that visually acts as the border and a second that sits on top as the |
| 52 | + /// actual (lighter colored) arrow that visually connects with the tooltip body. |
| 53 | + /// |
| 54 | + /// 1. Magic number, design-based decision |
| 55 | + /// 2. Bottom-align the arrows on top of each other |
| 56 | + /// 3. The translateX value horizontally centers the arrows |
| 57 | + /// 4. The translateY value vertically aligns the arrows to top of tooltip body |
| 58 | + /// |
| 59 | + |
| 60 | + &::before, |
| 61 | + &::after { |
| 62 | + border-color: transparent transparent |
| 63 | + var(--arrow-color, $tooltip-color-border); |
| 64 | + border-style: solid; |
| 65 | + border-width: var(--arrow-size, 0.64em); // 1 |
| 66 | + content: ''; |
| 67 | + inset-block-end: var(--arrow-offset, 0); // 2 |
| 68 | + inset-inline-start: 50%; // 3 |
| 69 | + position: absolute; // 3 |
| 70 | + transform: translate(-50%, -2.4em); // 3, 4 |
| 71 | + } |
| 72 | + |
| 73 | + /// |
| 74 | + /// Foreground tooltip arrow |
| 75 | + /// |
| 76 | + /// Updates the values for the arrow that is overlaid on top of the background |
| 77 | + /// arrow. Together, they form a bordered tooltip arrow. |
| 78 | + /// |
| 79 | + /// 1. Magic number, design-based decision. I eye-balled the size of the |
| 80 | + /// overlaid arrow so that the visual border appeared the same width as the |
| 81 | + /// tooltip body border. |
| 82 | + /// 2. There was a 1px gap at some viewport sizes, this removed the gap |
| 83 | + /// |
| 84 | + |
| 85 | + &::after { |
| 86 | + --arrow-color: #{$tooltip-color-background}; |
| 87 | + --arrow-size: 0.6em; // 1 |
| 88 | + --arrow-offset: -0.125em; // 2 |
| 89 | + } |
| 90 | + |
| 91 | + /// |
| 92 | + /// Shared animation state properties |
| 93 | + /// |
| 94 | + |
| 95 | + &.is-animating-intro, |
| 96 | + &.is-animating-outro { |
| 97 | + animation-duration: transition.$slow; |
| 98 | + animation-fill-mode: both; |
| 99 | + } |
| 100 | + |
| 101 | + /// |
| 102 | + /// Tooltip intro animation config |
| 103 | + /// |
| 104 | + |
| 105 | + &.is-animating-intro { |
| 106 | + animation-name: tooltipIntro; |
| 107 | + animation-timing-function: ease.$out_sine; |
| 108 | + |
| 109 | + @media (prefers-reduced-motion: no-preference) { |
| 110 | + animation-name: tooltipIntroIncreasedMotion; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + /// |
| 115 | + /// Tooltip outro animation config |
| 116 | + /// |
| 117 | + |
| 118 | + &.is-animating-outro { |
| 119 | + animation-name: tooltipOutro; |
| 120 | + animation-timing-function: ease.$out_sine; |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +/// |
| 125 | +/// Tooltip intro animation (default) |
| 126 | +/// |
| 127 | + |
| 128 | +@keyframes tooltipIntro { |
| 129 | + to { |
| 130 | + opacity: 1; |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +/// |
| 135 | +/// Tooltip intro animation (increased motion) |
| 136 | +/// |
| 137 | +/// 1. Only the Y value is changing. Before the animation, the horizontal |
| 138 | +/// translation is set to `-50%` to center the tooltip. We don't want to |
| 139 | +/// overwrite the X transformation when we add the Y transformation. Since |
| 140 | +/// there can only be a single `transform` property, we need to include the |
| 141 | +/// X value alongside the Y value. |
| 142 | +/// |
| 143 | + |
| 144 | +@keyframes tooltipIntroIncreasedMotion { |
| 145 | + from { |
| 146 | + animation-timing-function: ease.$out_sine; |
| 147 | + } |
| 148 | + |
| 149 | + 50% { |
| 150 | + animation-timing-function: ease.$in_out_sine; |
| 151 | + transform: translate(-50%, 15%); // 1 |
| 152 | + } |
| 153 | + |
| 154 | + to { |
| 155 | + opacity: 1; |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | +/// |
| 160 | +/// Tooltip outro animation |
| 161 | +/// |
| 162 | + |
| 163 | +@keyframes tooltipOutro { |
| 164 | + from { |
| 165 | + opacity: 1; |
| 166 | + } |
| 167 | +} |
0 commit comments