| 1 |
/** |
| 2 |
* Sphinx togglebutton |
| 3 |
* |
| 4 |
* The rules in this style sheet are meant to tweak the |
| 5 |
* [sphinx-togglebutton](https://sphinx-togglebutton.readthedocs.io/en/latest/index.html) |
| 6 |
* extension so that it matches the look and feel of this theme. |
| 7 |
*/ |
| 8 |
|
| 9 |
.bd-content { |
| 10 |
@mixin chevron-down { |
| 11 |
.toggle-chevron-right { |
| 12 |
transform: rotate(90deg); // point chevron down |
| 13 |
transition: none; // match non-animated behavior of other chevrons on site |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
@mixin chevron-up { |
| 18 |
.toggle-chevron-right { |
| 19 |
transform: rotate(-90deg); // point chevron up |
| 20 |
transition: none; // match non-animated behavior of other chevrons on site |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
// Apply this mixin to the element that will be hovered. These styles are |
| 25 |
// intended to match what sphinx-design does for its dropdown admonitions. |
| 26 |
@mixin icon-hover-effects { |
| 27 |
&:hover .tb-icon { |
| 28 |
opacity: 1; |
| 29 |
scale: 1.1; |
| 30 |
} |
| 31 |
|
| 32 |
.tb-icon { |
| 33 |
opacity: 0.6; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
// Collapsible admonition, implemented as <div> + <button> |
| 38 |
.dropdown.admonition.toggle { |
| 39 |
// The title is visible when the admonition is collapsed and expanded |
| 40 |
.admonition-title { |
| 41 |
@include icon-hover-effects; |
| 42 |
@include hover-darken-lighten; |
| 43 |
|
| 44 |
&:hover { |
| 45 |
box-shadow: none; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
button.toggle-button { |
| 50 |
color: inherit; |
| 51 |
|
| 52 |
// When disclosure widget is closed |
| 53 |
&.toggle-button-hidden { |
| 54 |
@include chevron-down; |
| 55 |
} |
| 56 |
|
| 57 |
// When open |
| 58 |
@include chevron-up; |
| 59 |
} |
| 60 |
|
| 61 |
// Focus ring |
| 62 |
// ---------- |
| 63 |
// Sphinx-togglebutton makes the entire admonition header clickable, but |
| 64 |
// only the button within the header is focusable. But we want the entire |
| 65 |
// header and not just the button inside the header to be surrounded by a |
| 66 |
// a focus ring. |
| 67 |
&:has(:focus-visible) { |
| 68 |
/* Override Sphinx Toggle Button. Make the overflow visible, otherwise the |
| 69 |
focus ring is hidden. */ |
| 70 |
overflow: visible; |
| 71 |
|
| 72 |
/* |
| 73 |
Why not just do the following? |
| 74 |
|
| 75 |
``` |
| 76 |
.admonition-title { |
| 77 |
outline: $focus-ring-outline; |
| 78 |
} |
| 79 |
``` |
| 80 |
|
| 81 |
Why use ::before? If we put the focus ring on the ::before pseudo-element, |
| 82 |
we can reposition the focus ring by repositioning the pseudo-element. |
| 83 |
|
| 84 |
Why reposition? The left edge of the admonition title box does not align |
| 85 |
with the left edge of the overall admonition box. There is a left border |
| 86 |
that belongs to the overall box. The border is outside of the admonition |
| 87 |
title, which means it is also outside of a focus ring around the title. We |
| 88 |
can make the focus ring bigger, with `outline-offset`, but this will |
| 89 |
result in a ring that looks off-centered. So we have to pull the ring left |
| 90 |
and stretch it right. That's what the pseudo-element allows us to do. |
| 91 |
|
| 92 |
Note: we do not have to do this for collapsible admonitions made with |
| 93 |
Sphinx Design (as opposed to sphinx-togglebutton). |
| 94 |
*/ |
| 95 |
.admonition-title::before { |
| 96 |
content: ""; |
| 97 |
|
| 98 |
// pull the focus ring left and expand it right to be perfectly centered |
| 99 |
// between the left border and the right edge of the admonition title |
| 100 |
left: -$admonition-left-border-width; |
| 101 |
width: calc(100% + $admonition-left-border-width); |
| 102 |
height: 100%; |
| 103 |
outline: $focus-ring-outline; |
| 104 |
outline-offset: $focus-ring-offset; |
| 105 |
border-radius: $focus-ring-width; |
| 106 |
} |
| 107 |
|
| 108 |
// When expanded, sharpen the bottom left and right corners of the focus ring |
| 109 |
&:not(.toggle-hidden) .admonition-title::before { |
| 110 |
border-bottom-left-radius: 0; |
| 111 |
border-bottom-right-radius: 0; |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
// Collapsible component, implemented as <details> + <summary> |
| 117 |
details.toggle-details { |
| 118 |
// Over-ride border color to re-use our primary color |
| 119 |
summary { |
| 120 |
border-left: 3px solid var(--pst-color-primary); |
| 121 |
|
| 122 |
@include chevron-down; |
| 123 |
@include icon-hover-effects; |
| 124 |
@include hover-darken-lighten; |
| 125 |
|
| 126 |
&:hover { |
| 127 |
box-shadow: none; |
| 128 |
} |
| 129 |
|
| 130 |
&:focus-visible { |
| 131 |
outline-offset: $focus-ring-offset; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
// When expanded, sharpen the bottom left and right corners of the focus ring |
| 136 |
&[open] { |
| 137 |
@include chevron-up; |
| 138 |
|
| 139 |
:focus-visible { |
| 140 |
border-bottom-left-radius: 0; |
| 141 |
border-bottom-right-radius: 0; |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
} |