Sidebar: Enforce transition time and use pseudo-private properties #863
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sidebar transition minimum time
The main goal of this PR started out as enforcing a minimum transition time, but the pattern was useful and I decided to apply it everywhere.
Previously we set the sidebar transition duration like this:
But this has two major downsides:
The (sort-of) "public" property default can't be overwritten, instead we'd have to use
max(var(--bslib-sidebar-transition-duration, 500ms), 5m)every single time we want to use this value (annoying and obfuscating).The "public" CSS property is scoped to the
.bslib-sidebar-layoutclass, which is part of why we can't overwrite it. Users wanting to set the transition duration would end up clobbering our max default calculation.The new approach creates a pseudo-private property —
--_transition-duration– whose value inherits the public property –--bslib-sidebar-transition-duration.This means that we can store the default calculation in the psuedo-private variable, and internally reference the private variable directly.
Because
--bslib-sidebar-is already a lot for a prefix, I dropped it from the private properties. This makes the CSS easier to read where these properties are used. Also, because these are scoped to.bslib-sidebar-layout, the class acts as a prefix, so internally we can be more succint.All other properties
After doing this for the
--_transition-durationI decided to go all in and convert the rest of the properties. The end result is that it's now a lot easier to theme sidebar layouts using custom CSS properties on:root:Currently, users could globally use
.bslib-sidebar-layoutinstead of:root, but it's still tricker to get right than it could be. For example, currently the following doesn't work:In the above, the goal is to set the defaults for a region of the DOM, e.g. under the
#this-area. To make that work currently, you'd have to use#this-area .bslib-sidebar-layout. Also note that inline CSS properties set on a parent would similarly not be passed down, so the inline style on the parent div isn't used by the sidebar layout.With the pseudo-private properties, both approaches work. By using the private properties, we also have a layer of separation; properties that shouldn't inherit from the cascade don't consult the public CSS properties.