|
| 1 | +/** |
| 2 | + * Consistent styling for links |
| 3 | + **/ |
| 4 | + |
| 5 | +// Define some useful variables for links styling consistency |
| 6 | +// |
| 7 | +// Thickness of the underline for links |
| 8 | +// the default will be either: |
| 9 | +// - 1px |
| 10 | +// - 0.0625rem if it's thicker than 1px because the user has changed the text |
| 11 | +// size in their browser |
| 12 | +$link-underline-thickness: unquote("max(1px, .0625rem)") !default; |
| 13 | +// Offset of link underlines from text baseline |
| 14 | +// The default is 3px expressed as ems, as calculated against the default body |
| 15 | +// font size (on desktop). |
| 16 | +$link-underline-offset: 0.1578em !default; |
| 17 | +// Thickness of link underlines in hover state |
| 18 | +// The default for each link will be the thickest of the following: |
| 19 | +// - 3px |
| 20 | +// - 0.1875rem, if it's thicker than 3px because the user has changed the text |
| 21 | +// size in their browser |
| 22 | +// - 0.12em (relative to the link's text size) |
| 23 | +$link-hover-decoration-thickness: unquote("max(3px, .1875rem, .12em)") !default; |
| 24 | + |
| 25 | +// Ensures links have an underline decoration by default - needed to meet |
| 26 | +// WCAG SC 1.4.1 |
| 27 | +@mixin link-decoration { |
| 28 | + text-decoration: underline; |
| 29 | + |
| 30 | + @if $link-underline-thickness { |
| 31 | + text-decoration-thickness: $link-underline-thickness; |
| 32 | + } |
| 33 | + |
| 34 | + @if $link-underline-offset { |
| 35 | + text-underline-offset: $link-underline-offset; |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +// Ensures links have an underline decoration on hover - distinct from the |
| 40 | +// default behaviour |
| 41 | +@mixin link-decoration-hover { |
| 42 | + @if $link-hover-decoration-thickness { |
| 43 | + text-decoration-thickness: $link-hover-decoration-thickness; |
| 44 | + // Disable ink skipping on underlines on hover. Browsers haven't |
| 45 | + // standardised on this part of the spec yet, so set both properties |
| 46 | + text-decoration-skip-ink: none; // Chromium, Firefox |
| 47 | + text-decoration-skip: none; // Safari |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +// Simple hover style - can be used alone or in conjunction with other mixins |
| 52 | +// Add the text underline and change in thickness on hover |
| 53 | +@mixin link-style-hover { |
| 54 | + &:hover { |
| 55 | + @include link-decoration; |
| 56 | + @include link-decoration-hover; |
| 57 | + color: var(--pst-color-link-hover); |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +// Default link styles |
| 62 | +// |
| 63 | +// Defines: default unvisited, visited, hover, and active. |
| 64 | +// TODO: @trallard to improve focus styles in subsequent PR |
| 65 | +@mixin link-style-default { |
| 66 | + // So that really long links don't spill out of their container |
| 67 | + word-wrap: break-word; |
| 68 | + |
| 69 | + color: var(--pst-color-link); |
| 70 | + @include link-decoration; |
| 71 | + |
| 72 | + &:hover { |
| 73 | + color: var(--pst-color-link-hover); |
| 74 | + @include link-decoration-hover; |
| 75 | + } |
| 76 | + |
| 77 | + // TODO: @trallard to add active styles in subsequent PR |
| 78 | + &:active { |
| 79 | + color: var(--pst-color-link); |
| 80 | + } |
| 81 | + |
| 82 | + // Visited should still be hoverable |
| 83 | + &:visited { |
| 84 | + color: var(--pst-color-link); |
| 85 | + &:hover { |
| 86 | + color: var(--pst-color-link-hover); |
| 87 | + } |
| 88 | + } |
| 89 | + @include focus-indicator; |
| 90 | +} |
| 91 | + |
| 92 | +// Text link styles |
| 93 | +// |
| 94 | +// Makes links use the muted text colour and removes the underline. |
| 95 | +// Use this mixin for navigation bar links. |
| 96 | +@mixin link-style-text { |
| 97 | + color: var(--pst-color-text-muted); |
| 98 | + text-decoration: none; |
| 99 | + |
| 100 | + &:hover { |
| 101 | + color: var(--pst-color-link-hover); |
| 102 | + @include link-decoration; |
| 103 | + @include link-decoration-hover; |
| 104 | + } |
| 105 | + @include focus-indicator; |
| 106 | +} |
| 107 | + |
| 108 | +// Sidebar and TOC links |
| 109 | +// |
| 110 | +// Makes links use the muted text colour and removes the underline. |
| 111 | +// Use this mixin for navigation the primary sidebar and table of contents. |
| 112 | +// Active and hover should work together rather than one overriding the other. |
| 113 | +@mixin link-sidebar { |
| 114 | + color: var(--pst-color-text-muted); |
| 115 | + text-decoration: none; |
| 116 | + |
| 117 | + &:hover { |
| 118 | + text-decoration: underline; |
| 119 | + background-color: transparent; |
| 120 | + color: var(--pst-color-link-hover); |
| 121 | + @include link-decoration-hover; |
| 122 | + } |
| 123 | + |
| 124 | + // TODO: @trallard to update active styles in subsequent PR |
| 125 | + &:active { |
| 126 | + color: var(--pst-color-link-hover); |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | +// Sidebar current page link styles |
| 131 | +// |
| 132 | +// Adds a vertical line on the left hand side of the link to indicate that |
| 133 | +// it's the current page. Note this is distinct from an active state. |
| 134 | +// Used on the primary sidebar and the TOC. |
| 135 | +// We want the side box shadow to have the same thickness as the hover underline |
| 136 | +@mixin link-sidebar-current { |
| 137 | + font-weight: 600; |
| 138 | + color: var(--pst-color-primary); |
| 139 | + @if $link-hover-decoration-thickness { |
| 140 | + box-shadow: inset |
| 141 | + $link-hover-decoration-thickness |
| 142 | + 0px |
| 143 | + 0px |
| 144 | + var(--pst-color-primary); |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +// Navigation bar current page link styles |
| 149 | +// |
| 150 | +// Adds a bottom underline, this leaves enough space for the hover state without |
| 151 | +// cluttering the navbar. |
| 152 | +// We want the side box shadow to have the same thickness as the hover underline |
| 153 | +@mixin link-navbar-current { |
| 154 | + font-weight: 600; |
| 155 | + color: var(--pst-color-primary); |
| 156 | + @if $link-hover-decoration-thickness { |
| 157 | + border-bottom: $link-hover-decoration-thickness |
| 158 | + solid |
| 159 | + var(--pst-color-primary); |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +// Navigation bar icon links hover styles |
| 164 | +// |
| 165 | +// Adds a bottom box-shadow - since there is no text we cannot use text-decoration |
| 166 | +// We want the side box shadow to have the same thickness as the hover underline |
| 167 | +@mixin icon-navbar-hover { |
| 168 | + &:hover { |
| 169 | + color: var(--pst-color-link-hover); |
| 170 | + @if $link-hover-decoration-thickness { |
| 171 | + box-shadow: 0px |
| 172 | + $link-hover-decoration-thickness |
| 173 | + 0px |
| 174 | + var(--pst-color-link-hover); |
| 175 | + } |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +// Focus indicator |
| 180 | +@mixin focus-indicator { |
| 181 | + &:focus-visible { |
| 182 | + outline: 2px solid var(--pst-color-accent); |
| 183 | + } |
| 184 | +} |
0 commit comments