Skip to content

Commit 769a8ee

Browse files
Update PST SCSS (#590)
* Update PST SCSS * Add overridden bootstrap variables * Comment out undefinted variable
1 parent 6199d83 commit 769a8ee

File tree

12 files changed

+348
-35
lines changed

12 files changed

+348
-35
lines changed

assets/theme-css/pst/abstracts/_links.scss

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ $link-hover-decoration-thickness: unquote("max(3px, .1875rem, .12em)") !default;
8686
color: var(--pst-color-link-hover);
8787
}
8888
}
89-
@include focus-indicator;
9089
}
9190

9291
// Text link styles
@@ -102,7 +101,6 @@ $link-hover-decoration-thickness: unquote("max(3px, .1875rem, .12em)") !default;
102101
@include link-decoration;
103102
@include link-decoration-hover;
104103
}
105-
@include focus-indicator;
106104
}
107105

108106
// Sidebar and TOC links
@@ -125,6 +123,12 @@ $link-hover-decoration-thickness: unquote("max(3px, .1875rem, .12em)") !default;
125123
&:active {
126124
color: var(--pst-color-link-hover);
127125
}
126+
127+
&:focus-visible {
128+
box-shadow: $focus-ring-box-shadow;
129+
outline: none;
130+
z-index: 10; // keep focus ring on top (prevent the link-sidebar-current notch from lying on top of the ring)
131+
}
128132
}
129133

130134
// Sidebar current page link styles
@@ -137,11 +141,16 @@ $link-hover-decoration-thickness: unquote("max(3px, .1875rem, .12em)") !default;
137141
font-weight: 600;
138142
color: var(--pst-color-primary);
139143
@if $link-hover-decoration-thickness {
140-
box-shadow: inset
144+
$notch-shadow: inset
141145
$link-hover-decoration-thickness
142146
0px
143147
0px
144148
var(--pst-color-primary);
149+
box-shadow: $notch-shadow;
150+
&:focus-visible {
151+
box-shadow: $notch-shadow, $focus-ring-box-shadow;
152+
outline: none;
153+
}
145154
}
146155
}
147156

@@ -176,9 +185,84 @@ $link-hover-decoration-thickness: unquote("max(3px, .1875rem, .12em)") !default;
176185
}
177186
}
178187

179-
// Focus indicator
180-
@mixin focus-indicator {
181-
&:focus-visible {
182-
outline: 2px solid var(--pst-color-accent);
188+
/*
189+
Mixin for links in the header (and the More dropdown toggle).
190+
191+
The mixin assumes it will be applied to some element X with a markup structure
192+
like: X > .nav-link, or X > .dropdown-toggle.
193+
194+
It also assumes X.current is how the app annotates which item in the header nav
195+
corresponds to the section in the docs that the user is currently reading.
196+
*/
197+
@mixin header-link {
198+
// Target the child and not the parent because we want the underline in the
199+
// mobile sidebar to only span the width of the text not the entire row/line.
200+
> .nav-link,
201+
> .dropdown-toggle {
202+
border-radius: 2px;
203+
color: var(--pst-color-text-muted);
204+
}
205+
206+
> .nav-link {
207+
// Set up pseudo-element for hover and current states below.
208+
position: relative;
209+
&::before {
210+
content: "";
211+
display: block;
212+
position: absolute;
213+
top: 0;
214+
right: 0;
215+
bottom: 0;
216+
left: 0;
217+
background-color: transparent;
218+
}
219+
220+
// Underline on hover.
221+
// - Don't use text-decoration because it will wrap across two lines if
222+
// the link text also wraps across two lines.
223+
// - Use pseudo-element in order to avoid the border-radius values
224+
// rounding the edges of the underline. (And since a header link can be
225+
// both focused and hovered at the same time and we want the focus ring
226+
// but not the underline to be rounded, we cannot use a box shadow or
227+
// bottom border link element to create the underline, or else it will
228+
// be rounded and if we apply border-radius 0 then the hovered focus
229+
// ring would go from rounded to sharp. So we have to use the
230+
// pseudo-element.)
231+
&:hover {
232+
color: var(--pst-color-secondary);
233+
text-decoration: none; // override the link-style-hover mixin
234+
&::before {
235+
border-bottom: 3px solid var(--pst-color-secondary);
236+
}
237+
}
238+
239+
&:focus-visible {
240+
box-shadow: none; // override Bootstrap
241+
outline: 3px solid var(--pst-color-accent);
242+
outline-offset: 3px;
243+
}
244+
}
245+
246+
> .dropdown-toggle {
247+
&:focus-visible {
248+
box-shadow: $focus-ring-box-shadow;
249+
}
250+
&:hover {
251+
text-decoration: none;
252+
box-shadow: 0 0 0 $focus-ring-width var(--pst-color-link-hover); // purple focus ring
253+
// Brighten the text on hover (muted -> base)
254+
color: var(--pst-color-text-base);
255+
}
256+
}
257+
258+
&.current {
259+
> .nav-link {
260+
color: var(--pst-color-primary);
261+
262+
// Underline the current navbar item
263+
&::before {
264+
border-bottom: 3px solid var(--pst-color-primary);
265+
}
266+
}
183267
}
184268
}

assets/theme-css/pst/base/_base.scss

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ body {
1515

1616
// hack to avoid the black background on some browser including Safari
1717
&::-webkit-scrollbar-track {
18-
background: var(--pst-color-background);
18+
background-color: var(--pst-color-background);
1919
}
2020
}
2121

@@ -167,16 +167,45 @@ pre {
167167
}
168168
}
169169

170-
// Needs bootstrap
171-
///// the back to top btn
172-
///#pst-back-to-top {
173-
/// z-index: $zindex-tooltip;
174-
/// position: fixed;
175-
/// display: none;
176-
/// top: 80vh;
177-
/// left: 50vw;
178-
/// transform: translate(-50%);
179-
/// color: var(--pst-color-secondary-text);
180-
/// background-color: var(--pst-color-secondary);
181-
/// border: none;
182-
///}
170+
// the back to top btn
171+
#pst-back-to-top {
172+
// z-index: $zindex-tooltip;
173+
position: fixed;
174+
display: none;
175+
top: 90vh;
176+
left: 50vw;
177+
transform: translate(-50%);
178+
color: var(--pst-color-secondary-text);
179+
background-color: var(--pst-color-secondary);
180+
border: none;
181+
182+
.fa-arrow-up {
183+
// Using margin instead of a space character prevents the space between the
184+
// icon and the text from being underlined when the button is hovered.
185+
margin-inline-end: 0.5em;
186+
}
187+
188+
@include link-style-hover;
189+
&:hover {
190+
text-decoration-thickness: 1px;
191+
background-color: var(--pst-violet-600);
192+
color: var(--pst-color-secondary-text);
193+
}
194+
195+
&:focus-visible {
196+
box-shadow: none;
197+
outline: $focus-ring-outline;
198+
outline-color: var(--pst-color-secondary);
199+
outline-offset: $focus-ring-width;
200+
}
201+
}
202+
203+
// Focus ring
204+
//
205+
// Note: The Bootstrap stylesheet provides the focus ring (customized by this
206+
// theme via Sass variables in _bootstrap.scss) in some cases. This rule covers
207+
// all other cases.
208+
:focus-visible {
209+
outline: $focus-ring-outline;
210+
box-shadow: none; // override Bootstrap
211+
}

assets/theme-css/pst/bootstrap.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "variables/bootstrap";

assets/theme-css/pst/content/_admonitions.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
* Admonitions CSS originally inspired by https://squidfunk.github.io/mkdocs-material/getting-started/
44
*/
55
$admonition-border-radius: 0.25rem;
6+
$admonition-left-border-width: 0.2rem;
67
div.admonition,
78
.admonition {
89
margin: 1.5625em auto;
910
padding: 0 0.6rem 0.8rem 0.6rem;
1011
overflow: hidden;
1112
page-break-inside: avoid;
12-
border-left: 0.2rem solid;
13+
border-left: $admonition-left-border-width solid;
1314
border-color: var(--pst-color-info);
1415
border-radius: $admonition-border-radius;
1516
background-color: var(--pst-color-on-background);
@@ -205,7 +206,7 @@ div.admonition,
205206
margin-top: 0;
206207

207208
// Undo the .sidebar directive border
208-
border-width: 0 0 0 0.2rem;
209+
border-width: 0 0 0 $admonition-left-border-width;
209210

210211
// TODO: these semantic-color-names border-color rules might no longer be
211212
// needed when we drop support for Sphinx 4 / docutils 0.17

assets/theme-css/pst/content/_figures.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ figure {
1515
color: var(--pst-color-text-muted);
1616
margin-left: auto;
1717
margin-right: auto;
18+
margin-top: 0.3rem;
19+
20+
& > p:last-child {
21+
// Don't add extra margin to already existing figure bottom margin
22+
margin-bottom: 0;
23+
}
1824

1925
table.table {
2026
width: fit-content;

assets/theme-css/pst/extensions/_sphinx_design.scss

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,22 @@ html[data-theme="light"] {
149149
.sd-card-body {
150150
background-color: var(--pst-color-panel-background);
151151
}
152+
153+
// Focus ring for link-cards
154+
.sd-stretched-link:focus-visible {
155+
// Don't put the focus ring on the <a> element (it has zero height in Sphinx Design cards)
156+
outline: none;
157+
158+
// Put the focus ring on the <a> element's ::after pseudo-element
159+
&:after {
160+
outline: $focus-ring-outline;
161+
border-radius: 0.25rem; // copied from Sphinx Design CSS for .sd-card
162+
}
163+
}
164+
165+
&.sd-card-hover:hover {
166+
border-color: var(--pst-color-link-hover);
167+
}
152168
}
153169
/*******************************************************************************
154170
* tabs
@@ -158,28 +174,53 @@ html[data-theme="light"] {
158174
> input {
159175
// Active tab label
160176
&:checked + label {
161-
border-color: transparent transparent var(--pst-color-primary); // top LR bottom
177+
border-style: solid solid none;
178+
border-color: var(--pst-color-primary) var(--pst-color-primary)
179+
transparent; // top LR bottom
180+
border-width: 0.125rem 0.125rem 0;
181+
border-radius: 0.125rem 0.125rem 0 0;
182+
background-color: var(--pst-color-on-background);
183+
transform: translateY(0.125rem);
162184
color: var(--pst-color-primary);
163185
}
164186

187+
&:focus-visible + label {
188+
border: 0.125rem solid var(--pst-color-accent);
189+
border-radius: 0.125rem;
190+
background-color: var(--pst-color-accent-bg);
191+
color: var(--pst-color-on-surface);
192+
}
193+
165194
// Hover label
166-
&:not(:checked) + label:hover {
167-
border-color: var(--pst-color-secondary);
195+
&:not(:checked):not(:focus-visible) + label:hover {
196+
border-color: transparent;
168197
color: var(--pst-color-secondary);
169198
}
170199
}
171200

172201
// Tab label
173202
> 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);
203+
color: var(--pst-color-on-surface);
204+
border: 0.125rem solid transparent;
205+
border-radius: 0.125rem 0.125rem 0px 0px;
206+
background-color: var(--pst-color-surface);
207+
padding: 0 0.75em;
208+
margin-inline-end: 0.25rem;
209+
line-height: 1.95;
210+
211+
html[data-theme="dark"] & {
212+
background-color: var(--pst-color-on-background);
181213
}
182214
}
215+
216+
// panel
217+
.sd-tab-content {
218+
border: 0.125rem solid var(--pst-color-primary);
219+
border-radius: 0.1875rem;
220+
box-shadow: unset;
221+
padding: 0.625rem;
222+
background-color: var(--pst-color-on-background);
223+
}
183224
}
184225

185226
/*******************************************************************************
@@ -255,5 +296,43 @@ details.sd-dropdown {
255296
.sd-summary-down {
256297
top: 0.7rem;
257298
}
299+
300+
// Focus ring
301+
&:focus-visible {
302+
outline: $focus-ring-outline;
303+
outline-offset: -$focus-ring-width;
304+
}
305+
}
306+
}
307+
308+
/*******************************************************************************
309+
* Buttons (which in Sphinx Design are actually links that look like buttons)
310+
* ref: https://sphinx-design.readthedocs.io/en/pydata-theme/badges_buttons.html#buttons
311+
*/
312+
html {
313+
.sd-btn {
314+
min-width: 2.25rem;
315+
padding: 0.3125rem 0.75rem 0.4375rem; // 5px 12px 7px
316+
317+
@include link-style-hover; // override Sphinx Design
318+
&:hover {
319+
text-decoration-thickness: 1px;
320+
}
321+
}
322+
323+
@each $name in $sd-semantic-color-names {
324+
.sd-btn-#{$name},
325+
.sd-btn-outline-#{$name} {
326+
&:focus-visible {
327+
// Override Sphinx Design's use of -highlight colors. The -highlight
328+
// colors are 15% darker, so this would create the effect of darkening
329+
// the button when focused but we just want the button to have a focus
330+
// ring of the same (non-highlight) color.
331+
background-color: var(--sd-color-#{$name}) !important;
332+
border-color: var(--sd-color-#{$name}) !important;
333+
outline: var(--sd-color-#{$name}) solid $focus-ring-width;
334+
outline-offset: $focus-ring-width;
335+
}
336+
}
258337
}
259338
}

0 commit comments

Comments
 (0)