| 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:color"; |
| 10 |
@use "sass:map"; |
| 11 |
@use "sass:meta"; |
| 12 |
@use "sass:string"; |
| 13 |
|
| 14 |
/******************************************************************************* |
| 15 |
* Color and variables |
| 16 |
* |
| 17 |
* This is a list of the semantic color names from sphinx-design (we only |
| 18 |
* need to override variables that sphinx-design has actually defined). |
| 19 |
* https://github.com/executablebooks/sphinx-design/blob/9226a12a/style/_colors.scss#L31-L43 |
| 20 |
*/ |
| 21 |
$sd-semantic-color-names: ( |
| 22 |
"primary", |
| 23 |
"secondary", |
| 24 |
"success", |
| 25 |
"info", |
| 26 |
"warning", |
| 27 |
"danger", |
| 28 |
"light", |
| 29 |
"muted", |
| 30 |
"dark", |
| 31 |
"black", |
| 32 |
"white" |
| 33 |
); |
| 34 |
|
| 35 |
/** |
| 36 |
* Here we create some extra --pst-color-* variables and use |
| 37 |
* them to override the value of the corresponding sphinx-design variables. |
| 38 |
* This is easier than re-writing the sphinx-design rules. Even easier would be |
| 39 |
* directly assigning our values to the --sd-color-* variables, but then our |
| 40 |
* downstream users couldn't override *our* colors and have it affect buttons |
| 41 |
* and badges. |
| 42 |
* |
| 43 |
* First, define the extra keys needed to cover the full range of semantic |
| 44 |
* color names used in sphinx-design, then merge them with the names we |
| 45 |
* already define for our own needs. |
| 46 |
* see https://sphinx-design.readthedocs.io/en/latest/css_variables.html |
| 47 |
*/ |
| 48 |
$extra-semantic-colors: ( |
| 49 |
"white": $foundation-white, |
| 50 |
"light": ( |
| 51 |
light: $foundation-light-gray, |
| 52 |
bg-light: color.scale($foundation-light-gray, $lightness: 30%), |
| 53 |
dark: $foundation-light-gray, |
| 54 |
bg-dark: color.scale($foundation-light-gray, $lightness: -30%), |
| 55 |
), |
| 56 |
"muted": ( |
| 57 |
light: $foundation-muted-gray, |
| 58 |
bg-light: color.scale($foundation-muted-gray, $lightness: 30%), |
| 59 |
dark: $foundation-light-gray, |
| 60 |
bg-dark: color.scale($foundation-muted-gray, $lightness: -30%), |
| 61 |
), |
| 62 |
"dark": $foundation-dark-gray, |
| 63 |
"black": $foundation-black, |
| 64 |
); |
| 65 |
$all-colors: map.merge($pst-semantic-colors, $extra-semantic-colors); |
| 66 |
|
| 67 |
@mixin create-sd-colors($value, $name) { |
| 68 |
// define the pst variables, so that downstream user overrides will work |
| 69 |
--pst-color-#{$name}: #{$value}; |
| 70 |
|
| 71 |
// we are now using a11y-combination to calculate the text color - this is based |
| 72 |
// on the WCAG color contrast guidelines |
| 73 |
--pst-color-#{$name}-text: #{a11y-combination($value)}; |
| 74 |
|
| 75 |
// highlight is used for hover effects on buttons, here we make some fluid scaling |
| 76 |
// to avoid jarring effects -- we create a local variable that we can access |
| 77 |
// later to calculate the text color |
| 78 |
$highlight-color: color.scale($value, $lightness: -15%, $saturation: 5%); |
| 79 |
|
| 80 |
--pst-color-#{$name}-highlight: #{$highlight-color}; |
| 81 |
|
| 82 |
// override the sphinx-design variables |
| 83 |
--sd-color-#{$name}: var(--pst-color-#{$name}); |
| 84 |
--sd-color-#{$name}-text: var(--pst-color-#{$name}-text); |
| 85 |
--sd-color-#{$name}-highlight: var(--pst-color-#{$name}-highlight); |
| 86 |
|
| 87 |
// calculate the text color for the highlight color |
| 88 |
--pst-color-#{$name}-highlight-text: #{a11y-combination($highlight-color)}; |
| 89 |
} |
| 90 |
|
| 91 |
// Now we override the --sd-color-* variables. |
| 92 |
@each $mode in (light, dark) { |
| 93 |
@debug "Creating color variables for mode: #{$mode}"; |
| 94 |
html[data-theme="#{$mode}"] { |
| 95 |
// check if this color is defined differently for light/dark |
| 96 |
@each $name in $sd-semantic-color-names { |
| 97 |
$definition: map.get($all-colors, $name); |
| 98 |
|
| 99 |
@if meta.type-of($definition) == map { |
| 100 |
@each $key, $value in $definition { |
| 101 |
@if string.index($key, $mode) { |
| 102 |
// since now we define the bg colours in the semantic colours and not |
| 103 |
// by changing opacity, we need to check if the key contains bg and the |
| 104 |
// correct mode (light/dark) |
| 105 |
@if string.index($key, "bg") { |
| 106 |
--sd-color-#{$name}-bg: #{$value}; |
| 107 |
|
| 108 |
// create local variable -- needed to calculate the text color |
| 109 |
$value: check-color($value); |
| 110 |
|
| 111 |
--sd-color-#{$name}-bg-text: #{a11y-combination($value)}; |
| 112 |
} @else { |
| 113 |
$value: check-color($value); |
| 114 |
|
| 115 |
@include create-sd-colors($value, $name); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
} @else { |
| 120 |
$value: map.get($all-colors, $name); |
| 121 |
|
| 122 |
@include create-sd-colors($value, $name); |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
// Make sure the color border variables are set using our variables |
| 129 |
@each $mode in (light, dark) { |
| 130 |
html[data-theme="#{$mode}"] { |
| 131 |
--sd-color-card-border: var(--pst-color-border); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
/******************************************************************************* |
| 136 |
* shadows |
| 137 |
*/ |
| 138 |
html[data-theme="light"] { |
| 139 |
.sd-shadow-xs, |
| 140 |
.sd-shadow-sm, |
| 141 |
.sd-shadow-md, |
| 142 |
.sd-shadow-lg { |
| 143 |
@include box-shadow; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
/******************************************************************************* |
| 148 |
* cards |
| 149 |
*/ |
| 150 |
|
| 151 |
.bd-content .sd-card { |
| 152 |
border: 1px solid var(--pst-color-border); |
| 153 |
overflow: hidden; |
| 154 |
|
| 155 |
.sd-card-header { |
| 156 |
background-color: var(--pst-color-on-background); |
| 157 |
border-bottom: 1px solid var(--pst-color-border); |
| 158 |
} |
| 159 |
|
| 160 |
.sd-card-footer { |
| 161 |
background-color: var(--pst-color-on-background); |
| 162 |
border-top: 1px solid var(--pst-color-border); |
| 163 |
} |
| 164 |
|
| 165 |
.sd-card-body { |
| 166 |
background-color: var(--pst-color-on-background); |
| 167 |
} |
| 168 |
|
| 169 |
// Focus ring for link-cards |
| 170 |
.sd-stretched-link:focus-visible { |
| 171 |
// Don't put the focus ring on the <a> element (it has zero height in Sphinx Design cards) |
| 172 |
outline: none; |
| 173 |
|
| 174 |
// Put the focus ring on the <a> element's ::after pseudo-element |
| 175 |
&::after { |
| 176 |
outline: $focus-ring-outline; |
| 177 |
border-radius: 0.25rem; // copied from Sphinx Design CSS for .sd-card |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
&.sd-card-hover:hover { |
| 182 |
border-color: var(--pst-color-link-hover); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
/******************************************************************************* |
| 187 |
* tabs |
| 188 |
*/ |
| 189 |
|
| 190 |
.bd-content .sd-tab-set { |
| 191 |
> input { |
| 192 |
// Active tab label |
| 193 |
&:checked + label { |
| 194 |
border-style: solid solid none; |
| 195 |
border-color: var(--pst-color-primary) var(--pst-color-primary) |
| 196 |
transparent; // top LR bottom |
| 197 |
|
| 198 |
border-width: 0.125rem 0.125rem 0; |
| 199 |
border-radius: 0.125rem 0.125rem 0 0; |
| 200 |
background-color: var(--pst-color-on-background); |
| 201 |
transform: translateY(0.125rem); |
| 202 |
color: var(--pst-color-primary); |
| 203 |
} |
| 204 |
|
| 205 |
&:focus-visible + label { |
| 206 |
border: 0.125rem solid var(--pst-color-accent); |
| 207 |
border-radius: 0.125rem; |
| 208 |
background-color: var(--pst-color-accent-bg); |
| 209 |
color: var(--pst-color-on-surface); |
| 210 |
} |
| 211 |
|
| 212 |
// Hover label |
| 213 |
&:not(:checked, :focus-visible) + label:hover { |
| 214 |
border-color: transparent; |
| 215 |
color: var(--pst-color-secondary); |
| 216 |
text-decoration-line: underline; |
| 217 |
text-decoration-thickness: $link-hover-decoration-thickness; |
| 218 |
} |
| 219 |
} |
| 220 |
|
| 221 |
// Tab label |
| 222 |
> label { |
| 223 |
color: var(--pst-color-on-surface); |
| 224 |
border: 0.125rem solid transparent; |
| 225 |
border-radius: 0.125rem 0.125rem 0 0; |
| 226 |
background-color: var(--pst-color-surface); |
| 227 |
padding: 0 0.75em; |
| 228 |
margin-inline-end: 0.25rem; |
| 229 |
line-height: 1.95; |
| 230 |
|
| 231 |
html[data-theme="dark"] & { |
| 232 |
background-color: var(--pst-color-on-background); |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
// panel |
| 237 |
.sd-tab-content { |
| 238 |
border: 0.125rem solid var(--pst-color-primary); |
| 239 |
border-radius: 0.1875rem; |
| 240 |
box-shadow: unset; |
| 241 |
padding: 0.625rem; |
| 242 |
background-color: var(--pst-color-on-background); |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
/******************************************************************************* |
| 247 |
* Dropdowns |
| 248 |
*/ |
| 249 |
|
| 250 |
details.sd-dropdown { |
| 251 |
// Remove all borders to over-ride SD behavior, and we'll add our own later |
| 252 |
border: 0 !important; |
| 253 |
|
| 254 |
// Drop shadow should behave same as admonitions |
| 255 |
@include box-shadow; |
| 256 |
|
| 257 |
// Header is where the "clickable" box goes |
| 258 |
summary.sd-card-header { |
| 259 |
border: 0 !important; |
| 260 |
display: flex; |
| 261 |
align-items: center; |
| 262 |
position: relative; // So background color works |
| 263 |
font-weight: 600; |
| 264 |
padding-top: 0.5rem; |
| 265 |
padding-bottom: 0.5rem; |
| 266 |
|
| 267 |
// Set a variable that we can re-use for colors later |
| 268 |
// We must set this in the current and content sibling container |
| 269 |
// so that it is defined in both places |
| 270 |
--pst-sd-dropdown-color: var(--pst-gray-500); |
| 271 |
--pst-sd-dropdown-bg-color: var(--pst-color-surface); |
| 272 |
|
| 273 |
& + div.sd-summary-content { |
| 274 |
border: 0; |
| 275 |
|
| 276 |
--pst-sd-dropdown-color: var(--sd-color-card-border); |
| 277 |
} |
| 278 |
|
| 279 |
@each $name in $sd-semantic-color-names { |
| 280 |
&.sd-bg-#{$name} { |
| 281 |
--pst-sd-dropdown-color: var(--sd-color-#{$name}); |
| 282 |
--pst-sd-dropdown-bg-color: var(--sd-color-#{$name}-bg); |
| 283 |
|
| 284 |
// Otherwise it won't be defined in the sibling element |
| 285 |
& + div.sd-summary-content { |
| 286 |
--pst-sd-dropdown-color: var(--sd-color-#{$name}); |
| 287 |
--pst-sd-dropdown-bg-color: var(--sd-color-#{$name}-bg); |
| 288 |
} |
| 289 |
} |
| 290 |
&.sd-bg-text-#{$name} { |
| 291 |
// Use the WCAG conformant text color |
| 292 |
color: var(--sd-color-#{$name}-bg-text) !important; |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
@include legacy-backdrop-placeholder; |
| 297 |
|
| 298 |
background-color: var(--pst-sd-dropdown-bg-color) !important; |
| 299 |
|
| 300 |
// Add a left border with the same structure as our admonitions |
| 301 |
border-left: 0.2rem solid var(--pst-sd-dropdown-color) !important; |
| 302 |
|
| 303 |
// stylelint-disable-next-line no-duplicate-selectors |
| 304 |
& + div.sd-summary-content { |
| 305 |
border-left: 0.2rem solid var(--pst-sd-dropdown-color) !important; |
| 306 |
border-bottom-left-radius: calc(0.25rem - 1px); |
| 307 |
background-color: var(--pst-color-on-background); |
| 308 |
} |
| 309 |
|
| 310 |
span.sd-summary-icon { |
| 311 |
display: inline-flex; |
| 312 |
align-items: center; |
| 313 |
color: var(--pst-sd-dropdown-color) !important; |
| 314 |
|
| 315 |
svg { |
| 316 |
opacity: 1; |
| 317 |
} |
| 318 |
} |
| 319 |
|
| 320 |
// Positioning of the caret |
| 321 |
.sd-summary-up, |
| 322 |
.sd-summary-down { |
| 323 |
top: 0.7rem; |
| 324 |
} |
| 325 |
|
| 326 |
@include hover-darken-lighten; |
| 327 |
|
| 328 |
// Focus ring |
| 329 |
&:focus:focus-visible { |
| 330 |
outline: $focus-ring-outline; |
| 331 |
outline-offset: $focus-ring-offset; |
| 332 |
border-radius: $focus-ring-width; |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
&[open] summary.sd-card-header:focus:focus-visible { |
| 337 |
border-bottom-left-radius: 0; |
| 338 |
border-bottom-right-radius: 0; |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
/******************************************************************************* |
| 343 |
* Buttons (which in Sphinx Design are actually links that look like buttons) |
| 344 |
* ref: https://sphinx-design.readthedocs.io/en/pydata-theme/badges_buttons.html#buttons |
| 345 |
*/ |
| 346 |
html { |
| 347 |
.sd-btn { |
| 348 |
min-width: 2.25rem; |
| 349 |
padding: 0.3125rem 0.75rem 0.4375rem; // 5px 12px 7px |
| 350 |
|
| 351 |
&:hover { |
| 352 |
@include link-style-hover; // override Sphinx Design |
| 353 |
|
| 354 |
text-decoration-thickness: 1px; |
| 355 |
} |
| 356 |
} |
| 357 |
|
| 358 |
@each $name in $sd-semantic-color-names { |
| 359 |
.sd-btn-#{$name} { |
| 360 |
&:hover { |
| 361 |
color: var(--pst-color-#{$name}-highlight-text) !important; |
| 362 |
} |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
@each $name in $sd-semantic-color-names { |
| 367 |
.sd-btn-#{$name}, |
| 368 |
.sd-btn-outline-#{$name} { |
| 369 |
&:focus-visible { |
| 370 |
outline: var(--sd-color-#{$name}) solid $focus-ring-width; |
| 371 |
outline-offset: $focus-ring-offset; |
| 372 |
border-radius: $focus-ring-width; |
| 373 |
|
| 374 |
// Override Sphinx Design's use of -highlight colors. The -highlight |
| 375 |
// colors are 15% darker, so this would create the effect of darkening |
| 376 |
// the button when focused but we just want the button to have a focus |
| 377 |
// ring of the same (non-highlight) color. |
| 378 |
background-color: var(--sd-color-#{$name}) !important; |
| 379 |
border-color: var(--sd-color-#{$name}) !important; |
| 380 |
} |
| 381 |
} |
| 382 |
} |
| 383 |
} |