Skip to content

Commit

Permalink
Apply more styles/logic to toggle icon's container (not the icon itself)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Oct 16, 2023
1 parent 31cf806 commit cf72028
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
27 changes: 11 additions & 16 deletions inst/components/scss/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,6 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--bslib-sidebar-icon-size)),
> .collapse-toggle {
grid-row: 1 / 2;
grid-column: 1 / 2;
display: inline-flex;
align-items: center;
position: absolute;
right: calc(var(--bslib-sidebar-icon-size));
top: calc(var(--bslib-sidebar-icon-size, 1rem) / 2);
Expand All @@ -147,29 +145,26 @@ $bslib-sidebar-column-sidebar: Min(calc(100% - var(--bslib-sidebar-icon-size)),
justify-content: center;
padding: 0;
color: var(--bslib-sidebar-fg);
background-color: unset; // don't take `button` background color
transform: rotateY(var(--bslib-collapse-toggle-transform));
transition:
color var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
top var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
// N.B. In order to properly add/remove the .transitioning class (in JS),
// we assume on this `right` property will fire a transitionend event
right var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
left var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration);
top var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
left var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
color var(--bslib-sidebar-transition-easing-x) var(--bslib-sidebar-transition-duration),
transform var(--bslib-sidebar-toggle-transition-easing) var(--bslib-sidebar-transition-duration);

opacity: 0.8;
background-color: unset; // don't take `button` background color
&:hover {
opacity: 1;
background-color: var(--bslib-sidebar-toggle-bg);
}

> * {
opacity: 0.8;
> * {
width: var(--bslib-sidebar-icon-size);
height: var(--bslib-sidebar-icon-size);
transform: rotateY(var(--bslib-collapse-toggle-transform));
// N.B. since mobile view won't trigger a transition of grid-template-columns,
// we transition this toggle to ensure _some_ transition event always happens.
transition: transform var(--bslib-sidebar-toggle-transition-easing) var(--bslib-sidebar-transition-duration);
}

&:hover > * {
opacity: 1;
}
}

Expand Down
15 changes: 8 additions & 7 deletions srcts/src/components/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,14 @@ class Sidebar {
this.toggle("toggle");
});

// Remove the transitioning class when the transition ends. We watch the
// collapse toggle icon because it's guaranteed to transition, whereas the
// sidebar doesn't animate on mobile (or in browsers where animating
// grid-template-columns is not supported).
toggle.firstElementChild?.addEventListener("transitionend", () =>
this._finalizeState()
);
// When the toggle's done transitioning, finalize the sidebar state
// (e.g., remove the transitioning class).
// N.B. assumes the toggle's right property is transitioned...
toggle.addEventListener("transitionend", (e) => {
if (e.target !== toggle) return;
if (e.propertyName !== "right") return;
this._finalizeState();
});
}

/**
Expand Down

0 comments on commit cf72028

Please sign in to comment.