UX: improve experimental sidebar transitions (#17358)

This commit is contained in:
Kris 2022-07-06 13:31:06 -04:00 committed by GitHub
parent 63562e8b14
commit fbc89dd41a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 15 deletions

View File

@ -39,9 +39,7 @@ export default Controller.extend({
}, },
_mainOutletAnimate() { _mainOutletAnimate() {
document document.querySelector("body").classList.remove("sidebar-animate");
.querySelector("#main-outlet")
.classList.remove("main-outlet-animate");
}, },
@action @action
@ -49,9 +47,6 @@ export default Controller.extend({
// enables CSS transitions, but not on did-insert // enables CSS transitions, but not on did-insert
document.querySelector("body").classList.add("sidebar-animate"); document.querySelector("body").classList.add("sidebar-animate");
// reduces CSS transition jank
document.querySelector("#main-outlet").classList.add("main-outlet-animate");
discourseDebounce(this, this._mainOutletAnimate, 250); discourseDebounce(this, this._mainOutletAnimate, 250);
this.toggleProperty("showSidebar"); this.toggleProperty("showSidebar");

View File

@ -683,11 +683,8 @@ table {
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
display: grid; display: grid;
// we can CSS transition the sidebar grid width change
// as long as we keep the column count consistent
// grid transitions are only supported in Firefox at the moment, but coming summer 2022 to Chrome
grid-template-areas: "sidebar content"; grid-template-areas: "sidebar content";
grid-template-columns: min-content minmax(0, 1fr); grid-template-columns: 0 minmax(0, 1fr); // 0 column width needs to be set for CSS transitions
gap: 0; gap: 0;
#main-outlet { #main-outlet {

View File

@ -1,22 +1,31 @@
:root { :root {
--d-sidebar-width: 240px; --d-sidebar-width: 16em;
--d-sidebar-animation-time: 0.25s;
--d-sidebar-animation-ease: ease-in-out;
} }
.header-sidebar-toggle { .header-sidebar-toggle {
margin-right: 1em; --toggle-padding: 0.5em;
margin-right: 0.75em;
@media screen and (min-width: 1300px) { @media screen and (min-width: 1300px) {
// extending the toggle beyond the page when space allows // extending the toggle beyond the page when space allows
// for better logo alignment with content // for better logo alignment with content
body:not(.has-sidebar-page) & { body:not(.has-sidebar-page) & {
margin-left: -3.7em; margin-left: -3.7em;
transition: margin var(--d-sidebar-animation-speed)
var(--d-sidebar-animation-ease);
} }
} }
.mobile-view & {
margin-left: calc(var(--toggle-padding) * -1);
}
button { button {
position: relative; position: relative;
font-size: var(--font-up-2); font-size: var(--font-up-2);
padding: 0.5em; padding: var(--toggle-padding);
.discourse-no-touch & { .discourse-no-touch & {
&:hover { &:hover {

View File

@ -187,6 +187,15 @@ input {
} }
} }
#main-outlet-wrapper {
// grid-template-columns transition supported in Firefox, Chrome support coming summer 2022
transition: grid-template-columns var(--d-sidebar-animation-time);
}
.d-header-wrap .wrap {
transition: max-width var(--d-sidebar-animation-time);
}
body.has-sidebar-page { body.has-sidebar-page {
.wrap { .wrap {
// increase page max-width to accommodate sidebar width // increase page max-width to accommodate sidebar width
@ -203,8 +212,7 @@ body.has-sidebar-page {
} }
body.sidebar-animate { body.sidebar-animate {
.d-header .wrap,
#main-outlet-wrapper { #main-outlet-wrapper {
transition: ease-in-out 0.5s; transition: all var(--d-sidebar-animation-time);
} }
} }