|
| 1 | +/******************************************************************************* |
| 2 | + * Special-cases for the sphinx-design library, mainly to make it compatible |
| 3 | + * with the dark/light themes of pydata-sphinx-theme. |
| 4 | + * |
| 5 | + * NOTE: sphinx-design uses !important quite liberally, so here we must do the |
| 6 | + * same for our overrides to have any effect. |
| 7 | + */ |
| 8 | +@use "../variables/color" as pst-color; |
| 9 | +@use "sass:meta"; |
| 10 | +@use "sass:color"; |
| 11 | + |
| 12 | +/******************************************************************************* |
| 13 | + * Color and variables |
| 14 | + * |
| 15 | + * This is a list of the semantic color names from sphinx-design (we only |
| 16 | + * need to override variables that sphinx-design has actually defined). |
| 17 | + * https://github.com/executablebooks/sphinx-design/blob/9226a12a/style/_colors.scss#L31-L43 |
| 18 | + */ |
| 19 | +$sd-semantic-color-names: ( |
| 20 | + "primary", |
| 21 | + "secondary", |
| 22 | + "success", |
| 23 | + "info", |
| 24 | + "warning", |
| 25 | + "danger", |
| 26 | + "light", |
| 27 | + "muted", |
| 28 | + "dark", |
| 29 | + "black", |
| 30 | + "white" |
| 31 | +); |
| 32 | + |
| 33 | +/** |
| 34 | + * Here we create some extra --pst-color-* variables and use |
| 35 | + * them to override the value of the corresponding sphinx-design variables. |
| 36 | + * This is easier than re-writing the sphinx-design rules. Even easier would be |
| 37 | + * directly assigning our values to the --sd-color-* variables, but then our |
| 38 | + * downstream users couldn't override *our* colors and have it affect buttons |
| 39 | + * and badges. |
| 40 | + * |
| 41 | + * First, define the extra keys needed to cover the full range of semantic |
| 42 | + * color names used in sphinx-design, then merge them with the names we |
| 43 | + * already define for our own needs. |
| 44 | + * see https://sphinx-design.readthedocs.io/en/latest/css_variables.html |
| 45 | + */ |
| 46 | +$extra-semantic-colors: ( |
| 47 | + "white": $foundation-white, |
| 48 | + "light": ( |
| 49 | + light: $foundation-light-gray, |
| 50 | + bg-light: color.scale($foundation-light-gray, $lightness: 30%), |
| 51 | + dark: $foundation-light-gray, |
| 52 | + bg-dark: color.scale($foundation-light-gray, $lightness: -30%), |
| 53 | + ), |
| 54 | + "muted": ( |
| 55 | + light: $foundation-muted-gray, |
| 56 | + bg-light: color.scale($foundation-muted-gray, $lightness: 30%), |
| 57 | + dark: $foundation-light-gray, |
| 58 | + bg-dark: color.scale($foundation-muted-gray, $lightness: -30%), |
| 59 | + ), |
| 60 | + "dark": $foundation-dark-gray, |
| 61 | + "black": $foundation-black, |
| 62 | +); |
| 63 | + |
| 64 | +$all-colors: map-merge($pst-semantic-colors, $extra-semantic-colors); |
| 65 | + |
| 66 | +@mixin create-sd-colors($value, $name) { |
| 67 | + // define the pst variables, so that downstream user overrides will work |
| 68 | + --pst-color-#{$name}: #{$value}; |
| 69 | + // we are now using a11y-combination to calculate the text color - this is based |
| 70 | + // on the WCAG color contrast guidelines |
| 71 | + --pst-color-#{$name}-text: #{a11y-combination($value)}; |
| 72 | + //TODO: highlight seems to be used for buttons @trallard to fix on a11y follow-up work |
| 73 | + --pst-color-#{$name}-highlight: #{darken($value, 15%)}; |
| 74 | + // override the sphinx-design variables |
| 75 | + --sd-color-#{$name}: var(--pst-color-#{$name}); |
| 76 | + --sd-color-#{$name}-text: var(--pst-color-#{$name}-text); |
| 77 | + //TODO: highlight seems to be used for buttons @trallard to fix on a11y follow-up work |
| 78 | + --sd-color-#{$name}-highlight: var(--pst-color-#{$name}-highlight); |
| 79 | +} |
| 80 | + |
| 81 | +// Now we override the --sd-color-* variables. |
| 82 | +@each $mode in (light, dark) { |
| 83 | + html[data-theme="#{$mode}"] { |
| 84 | + // check if this color is defined differently for light/dark |
| 85 | + @each $name in $sd-semantic-color-names { |
| 86 | + $definition: map-get($all-colors, $name); |
| 87 | + @if type-of($definition) == map { |
| 88 | + @each $key, $value in $definition { |
| 89 | + @if str-index($key, $mode) != null { |
| 90 | + // since now we define the bg colours in the semantic colours and not |
| 91 | + // by changing opacity, we need to check if the key contains bg and the |
| 92 | + // correct mode (light/dark) |
| 93 | + @if str-index($key, "bg") != null { |
| 94 | + --sd-color-#{$name}-bg: #{$value}; |
| 95 | + // create local variable |
| 96 | + $bg-var: --sd-color-#{$name}-bg; |
| 97 | + $value: check-color($value); |
| 98 | + --sd-color-#{$name}-bg-text: #{a11y-combination($value)}; |
| 99 | + } @else { |
| 100 | + $value: check-color($value); |
| 101 | + @include create-sd-colors($value, $name); |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } @else { |
| 106 | + $value: map-get($all-colors, $name); |
| 107 | + @include create-sd-colors($value, $name); |
| 108 | + } |
| 109 | + } |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +// Make sure the color border variables are set using our variables |
| 114 | +@each $mode in (light, dark) { |
| 115 | + html[data-theme="#{$mode}"] { |
| 116 | + --sd-color-card-border: var(--pst-color-border); |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +/******************************************************************************* |
| 121 | + * shadows |
| 122 | + */ |
| 123 | +html[data-theme="light"] { |
| 124 | + .sd-shadow-xs, |
| 125 | + .sd-shadow-sm, |
| 126 | + .sd-shadow-md, |
| 127 | + .sd-shadow-lg { |
| 128 | + @include box-shadow(); |
| 129 | + } |
| 130 | +} |
| 131 | + |
| 132 | +/******************************************************************************* |
| 133 | + * cards |
| 134 | + */ |
| 135 | + |
| 136 | +.bd-content .sd-card { |
| 137 | + border: 1px solid var(--pst-color-border); |
| 138 | + |
| 139 | + // TODO - --pst-color-panel-background is not defined... where is this coming from? |
| 140 | + .sd-card-header { |
| 141 | + background-color: var(--pst-color-panel-background); |
| 142 | + border-bottom: 1px solid var(--pst-color-border); |
| 143 | + } |
| 144 | + .sd-card-footer { |
| 145 | + background-color: var(--pst-color-panel-background); |
| 146 | + border-top: 1px solid var(--pst-color-border); |
| 147 | + } |
| 148 | + |
| 149 | + .sd-card-body { |
| 150 | + background-color: var(--pst-color-panel-background); |
| 151 | + } |
| 152 | +} |
| 153 | +/******************************************************************************* |
| 154 | + * tabs |
| 155 | + */ |
| 156 | + |
| 157 | +.bd-content .sd-tab-set { |
| 158 | + > input { |
| 159 | + // Active tab label |
| 160 | + &:checked + label { |
| 161 | + border-color: transparent transparent var(--pst-color-primary); // top LR bottom |
| 162 | + color: var(--pst-color-primary); |
| 163 | + } |
| 164 | + |
| 165 | + // Hover label |
| 166 | + &:not(:checked) + label:hover { |
| 167 | + border-color: var(--pst-color-secondary); |
| 168 | + color: var(--pst-color-secondary); |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + // Tab label |
| 173 | + > label { |
| 174 | + color: var(--pst-color-text-muted); |
| 175 | + border-top: 0.125rem solid transparent; // so hover isn't just color change |
| 176 | + padding-top: 0.5em; // same as bottom padding, so hover overline looks OK |
| 177 | + // Hovered label |
| 178 | + html &:hover { |
| 179 | + color: var(--pst-color-secondary); |
| 180 | + border-color: var(--pst-color-secondary); |
| 181 | + } |
| 182 | + } |
| 183 | +} |
| 184 | + |
| 185 | +/******************************************************************************* |
| 186 | +* Dropdowns |
| 187 | +*/ |
| 188 | + |
| 189 | +details.sd-dropdown { |
| 190 | + // Remove all borders to over-ride SD behavior, and we'll add our own later |
| 191 | + border: 0px !important; |
| 192 | + summary.sd-card-header { |
| 193 | + border: 0 !important; |
| 194 | + & + div.sd-summary-content { |
| 195 | + border: 0; |
| 196 | + } |
| 197 | + } |
| 198 | + // Drop shadow should behave same as admonitions |
| 199 | + @include box-shadow(); |
| 200 | + |
| 201 | + // Header is where the "clickable" box goes |
| 202 | + summary.sd-card-header { |
| 203 | + display: flex; |
| 204 | + align-items: center; |
| 205 | + position: relative; // So background color works |
| 206 | + font-weight: 600; |
| 207 | + padding-top: 0.5rem; |
| 208 | + padding-bottom: 0.5rem; |
| 209 | + |
| 210 | + // Set a variable that we can re-use for colors later |
| 211 | + // We must set this in the current and content sibling container |
| 212 | + // so that it is defined in both places |
| 213 | + --pst-sd-dropdown-color: var(--pst-gray-500); |
| 214 | + --pst-sd-dropdown-bg-color: var(--pst-color-surface); |
| 215 | + & + div.sd-summary-content { |
| 216 | + --pst-sd-dropdown-color: var(--sd-color-card-border); |
| 217 | + } |
| 218 | + @each $name in $sd-semantic-color-names { |
| 219 | + &.sd-bg-#{$name} { |
| 220 | + --pst-sd-dropdown-color: var(--sd-color-#{$name}); |
| 221 | + --pst-sd-dropdown-bg-color: var(--sd-color-#{$name}-bg); |
| 222 | + // Otherwise it won't be defined in the sibling element |
| 223 | + & + div.sd-summary-content { |
| 224 | + --pst-sd-dropdown-color: var(--sd-color-#{$name}); |
| 225 | + --pst-sd-dropdown-bg-color: var(--sd-color-#{$name}-bg); |
| 226 | + } |
| 227 | + } |
| 228 | + &.sd-bg-text-#{$name} { |
| 229 | + // Use the WCAG conformant text color |
| 230 | + color: var(--sd-color-#{$name}-bg-text) !important; |
| 231 | + } |
| 232 | + } |
| 233 | + |
| 234 | + @include legacy-backdrop-placeholder; |
| 235 | + background-color: var(--pst-sd-dropdown-bg-color) !important; |
| 236 | + |
| 237 | + // Add a left border with the same structure as our admonitions |
| 238 | + border-left: 0.2rem solid var(--pst-sd-dropdown-color) !important; |
| 239 | + & + div.sd-summary-content { |
| 240 | + border-left: 0.2rem solid var(--pst-sd-dropdown-color) !important; |
| 241 | + border-bottom-left-radius: calc(0.25rem - 1px); |
| 242 | + background-color: var(--pst-color-on-background); |
| 243 | + } |
| 244 | + span.sd-summary-icon { |
| 245 | + display: inline-flex; |
| 246 | + align-items: center; |
| 247 | + color: var(--pst-sd-dropdown-color) !important; |
| 248 | + svg { |
| 249 | + opacity: 1; |
| 250 | + } |
| 251 | + } |
| 252 | + |
| 253 | + // Positioning of the caret |
| 254 | + .sd-summary-up, |
| 255 | + .sd-summary-down { |
| 256 | + top: 0.7rem; |
| 257 | + } |
| 258 | + } |
| 259 | +} |
0 commit comments