1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-11-25 10:16:06 -05:00

add nice and soothing fade transition when dark/light mode is toggled

This commit is contained in:
2021-09-22 12:27:59 -04:00
parent 2ca02c81fd
commit 7353f0b95e
8 changed files with 64 additions and 13 deletions

View File

@@ -27,3 +27,8 @@ $responsive-width: 800px;
$link-underline-opacity: 40%;
$link-underline-size: 2px;
$link-opacity-color: #ffffff;
// Elements to fade on dark/light theme toggle:
$theme-transition-elements: ("color", "background-color", "border-color");
$theme-transition-duration: 0.15s;
$theme-transition-function: linear;

View File

@@ -1,14 +1,41 @@
@use "sass:map";
@use "sass:string";
@use "sass:list";
@use "../abstracts/functions" as *;
@use "settings";
@use "functions" as *;
// Takes a single CSS property and theme key (see abstracts/_themes) and sets
// both body.light and body.dark selectors.
@mixin themed($property, $key) {
// hack to allow root (body) theming
@mixin themed($property, $key, $moreTransitions: "") {
// allow root element (body) theming
$selectors: str-split("#{&}");
// fade colors on theme toggle
$transitions: ();
@each $element in settings.$theme-transition-elements {
$transitions: list.append(
$transitions,
string.unquote(
"#{$element} #{settings.$theme-transition-duration} #{settings.$theme-transition-function}"
)
);
}
@if $moreTransitions != "" {
// HACK: $moreTransitions is passed in and appended here because joining multiple transitions is hard :(
$transitions: list.append($transitions, string.unquote($moreTransitions));
}
@each $selector in $selectors {
@if $selector == "" {
// support root body element
$selector: "body";
}
@at-root #{$selector} {
transition: list.join($transitions, (), $separator: comma);
}
}
// set the actual light/dark properties
@each $theme, $map in $themes {
@each $selector in $selectors {
@at-root body.#{$theme} #{$selector} {