Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make hover effect on dropdown admonitions more prominent #1986

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ details.sd-dropdown {
font-weight: 600;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
transition: box-shadow 0.15s ease-in-out;

@media (prefers-reduced-motion) {
transition: none;
}

// Set a variable that we can re-use for colors later
// We must set this in the current and content sibling container
Expand Down Expand Up @@ -323,8 +328,18 @@ details.sd-dropdown {
top: 0.7rem;
}

// Hover ring
&:hover {
$box-shadow-offset: 2px;

box-shadow:
0 0 0 $box-shadow-offset var(--pst-color-background),
0 0 0 calc($box-shadow-offset + $focus-ring-width)
var(--pst-color-link-hover);
}

// Focus ring
&:focus-visible {
&:focus:focus-visible {
outline: $focus-ring-outline;
outline-offset: -$focus-ring-width;
}
Expand Down
86 changes: 75 additions & 11 deletions src/pydata_sphinx_theme/assets/styles/extensions/_togglebutton.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* Sphinx togglebutton
*
* https://sphinx-togglebutton.readthedocs.io/en/latest/index.html
*/

.bd-content {
Expand All @@ -17,8 +19,59 @@
}
}

// 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;
}
}

@mixin ring-base {
content: "";
transform: translateX(
-$admonition-left-border-width
); // align left edges of admonition and ring

width: calc(100% + $admonition-left-border-width); // align right edges
height: 100%;
}

// Collapsible admonition, implemented as <div> + <button>
.dropdown.admonition.toggle {
overflow: visible;

.admonition-title {
@include icon-hover-effects;

&::before {
transition:
border-radius 0.15s ease-in-out,
box-shadow 0.15s ease-in-out;

@media (prefers-reduced-motion) {
transition: none;
}
}

&:hover::before {
@include ring-base;

$box-shadow-offset: 2px;

border-radius: $focus-ring-width;
box-shadow:
0 0 0 $box-shadow-offset var(--pst-color-background),
0 0 0 calc($box-shadow-offset + $focus-ring-width)
var(--pst-color-link-hover);
}
}

button.toggle-button {
color: inherit;

Expand Down Expand Up @@ -50,14 +103,9 @@
// the left border on the container's children). This makes it complicated
// to get the focus ring to simultaneously cover the left border in the
// header and align perfectly on the right with the body.
.admonition-title:focus-within::before {
content: "";
transform: translateX(
-$admonition-left-border-width
); // align left edges of admonition and ring

width: calc(100% + $admonition-left-border-width); // align right edges
height: 100%;
.admonition-title:focus-within:has(:focus-visible)::before {
@include ring-base;

border: $focus-ring-outline;
border-radius: $focus-ring-width;
}
Expand All @@ -70,13 +118,29 @@
}
}

// Details buttons
// Collapsible anything, implemented as <details> + <summary>
details.toggle-details {
// Over-ride border color to re-use our primary color
summary {
border-left: 3px solid var(--pst-color-primary);

@include chevron-down;
@include icon-hover-effects;

transition: box-shadow 0.15s ease-in-out;

@media (prefers-reduced-motion) {
box-shadow: none;
}

&:hover {
$box-shadow-offset: 2px;

box-shadow:
0 0 0 $box-shadow-offset var(--pst-color-background),
0 0 0 calc($box-shadow-offset + $focus-ring-width)
var(--pst-color-link-hover);
}
}

// When expanded, sharpen the bottom left and right corners of the focus ring
Expand Down
Loading