From 85aba79501bfe0cb749a30b2acc7a36ffcfc7717 Mon Sep 17 00:00:00 2001 From: gabalafou Date: Fri, 6 Dec 2024 09:49:40 -0600 Subject: [PATCH] Match Sphinx toggle button and Sphinx Design hover and focus styles (#2061) This PR makes the hover and focus styles more consistent for the various collapsible admonitions we support (Sphinx Design and Sphinx Toggle Button). It also makes the focus rings better match the [design system](https://www.figma.com/design/SnLFWtSKEBLYrtLHbs4TSE/PyData-Sphinx-Theme-Design-System-(Community)?node-id=1233-8360&node-type=frame&t=4kx1rhhCuQNUGldF-0). Screenshot of the admonition focus rings from the design system: ![](https://github.com/user-attachments/assets/6725942d-85e9-41da-bce9-eabe3f39a57e) Screenshots from my local git branch, for comparison: ![image](https://github.com/user-attachments/assets/797e298c-d755-455e-b470-9690ea41b353) ![image](https://github.com/user-attachments/assets/7ac58e27-edcf-4baf-8783-da886eab0802) --- .../assets/styles/abstracts/_links.scss | 2 +- .../assets/styles/abstracts/_mixins.scss | 12 +++ .../styles/extensions/_sphinx_design.scss | 16 ++- .../styles/extensions/_togglebutton.scss | 101 +++++++++++++----- .../assets/styles/variables/_bootstrap.scss | 5 + 5 files changed, 108 insertions(+), 28 deletions(-) diff --git a/src/pydata_sphinx_theme/assets/styles/abstracts/_links.scss b/src/pydata_sphinx_theme/assets/styles/abstracts/_links.scss index c3e9d31c0..212170efd 100644 --- a/src/pydata_sphinx_theme/assets/styles/abstracts/_links.scss +++ b/src/pydata_sphinx_theme/assets/styles/abstracts/_links.scss @@ -217,6 +217,6 @@ $link-hover-decoration-thickness: string.unquote( &:focus-visible { box-shadow: none; // override Bootstrap outline: 3px solid var(--pst-color-accent); - outline-offset: 3px; + outline-offset: $focus-ring-width; } } diff --git a/src/pydata_sphinx_theme/assets/styles/abstracts/_mixins.scss b/src/pydata_sphinx_theme/assets/styles/abstracts/_mixins.scss index ffbd79c75..a4e41bf19 100644 --- a/src/pydata_sphinx_theme/assets/styles/abstracts/_mixins.scss +++ b/src/pydata_sphinx_theme/assets/styles/abstracts/_mixins.scss @@ -64,3 +64,15 @@ min-width: 24px; min-height: 24px; } + +// Meant to darken the element on hover in light mode, or +// lighten on hover in dark mode. +@mixin hover-darken-lighten { + &:hover { + filter: brightness(0.9); + + html[data-theme="dark"] & { + filter: brightness(1.1); + } + } +} diff --git a/src/pydata_sphinx_theme/assets/styles/extensions/_sphinx_design.scss b/src/pydata_sphinx_theme/assets/styles/extensions/_sphinx_design.scss index 7c86cdd3d..dc403321f 100644 --- a/src/pydata_sphinx_theme/assets/styles/extensions/_sphinx_design.scss +++ b/src/pydata_sphinx_theme/assets/styles/extensions/_sphinx_design.scss @@ -322,12 +322,20 @@ details.sd-dropdown { top: 0.7rem; } + @include hover-darken-lighten; + // Focus ring &:focus:focus-visible { outline: $focus-ring-outline; - outline-offset: -$focus-ring-width; + outline-offset: $focus-ring-offset; + border-radius: $focus-ring-width; } } + + &[open] summary.sd-card-header:focus:focus-visible { + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; + } } /******************************************************************************* @@ -358,14 +366,16 @@ html { .sd-btn-#{$name}, .sd-btn-outline-#{$name} { &:focus-visible { + outline: var(--sd-color-#{$name}) solid $focus-ring-width; + outline-offset: $focus-ring-offset; + border-radius: $focus-ring-width; + // Override Sphinx Design's use of -highlight colors. The -highlight // colors are 15% darker, so this would create the effect of darkening // the button when focused but we just want the button to have a focus // ring of the same (non-highlight) color. background-color: var(--sd-color-#{$name}) !important; border-color: var(--sd-color-#{$name}) !important; - outline: var(--sd-color-#{$name}) solid $focus-ring-width; - outline-offset: $focus-ring-width; } } } diff --git a/src/pydata_sphinx_theme/assets/styles/extensions/_togglebutton.scss b/src/pydata_sphinx_theme/assets/styles/extensions/_togglebutton.scss index 1d0f87cc4..2d5ca3e5a 100644 --- a/src/pydata_sphinx_theme/assets/styles/extensions/_togglebutton.scss +++ b/src/pydata_sphinx_theme/assets/styles/extensions/_togglebutton.scss @@ -1,5 +1,9 @@ /** * Sphinx togglebutton + * + * The rules in this style sheet are meant to tweak the + * [sphinx-togglebutton](https://sphinx-togglebutton.readthedocs.io/en/latest/index.html) + * extension so that it matches the look and feel of this theme. */ .bd-content { @@ -17,8 +21,31 @@ } } - // Admonition toggles - .admonition { + // Apply this mixin to the element that will be hovered. These styles are + // intended to match what sphinx-design does for its dropdown admonitions. + @mixin icon-hover-effects { + &:hover .tb-icon { + opacity: 1; + scale: 1.1; + } + + .tb-icon { + opacity: 0.6; + } + } + + // Collapsible admonition, implemented as
+