Skip to content

Commit

Permalink
Merge pull request #1085 from gethinode/develop
Browse files Browse the repository at this point in the history
Reduce screen flickering when using color mode
  • Loading branch information
markdumay authored Aug 12, 2024
2 parents 54e0f72 + 145b2c2 commit 1dfce3d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
5 changes: 4 additions & 1 deletion assets/js/critical/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
})

window.addEventListener('DOMContentLoaded', () => {
setTheme(getTheme())
const light = (document.documentElement.getAttribute('data-bs-theme') === 'light')

document.querySelectorAll('.ball').forEach(ball => {
Expand All @@ -71,6 +70,7 @@
document.querySelectorAll('.navbar-mode-selector').forEach(chk => {
chk.checked = light
chk.addEventListener('change', function () {
document.documentElement.setAttribute('data-bs-theme-animate', 'true')
toggleTheme()
})
})
Expand All @@ -87,6 +87,9 @@
chk.checked = light
})
});

// initialize theme directly when script is invoked
setTheme(getTheme())
})()

{{- end -}}
2 changes: 1 addition & 1 deletion assets/scss/common/_styles.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@if $enable-dark-mode {
body {
[data-bs-theme-animate="true"] body {
transition: background-color 0.5s, color 0.5s;
}
}
Expand Down
8 changes: 7 additions & 1 deletion assets/scss/components/_navbar.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// stylelint-disable annotation-no-unknown

// Source: https://jsfiddle.net/njhgr40m/

@if $enable-dark-mode {
[data-bs-theme-animate="true"] .navbar {
transition: 0.5s ease-in-out;
}
}

.navbar {
--bs-navbar-expanded-color: var(--bs-body-bg);
--bs-navbar-toggler-color: var(--bs-navbar-hover-color);

transition: 0.5s ease-in-out;
background-color: transparent;

@each $state, $val in $theme-colors {
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
<!doctype html>
<html lang="{{ .Site.Language.Lang }}" class="no-js">
<head>
{{- partial "footer/scripts.html" (dict "filename" "js/critical.bundle.js" "match" "js/critical/**.js" "header" true "page" .) -}}
{{ block "head" . }}{{ end -}}
</head>

<body>
{{- partial "footer/scripts.html" (dict "filename" "js/critical.bundle.js" "match" "js/critical/**.js" "header" true "page" .) -}}
<div class="d-flex flex-column min-vh-100">
<div class="d-flex flex-column {{ if $fullCover }} fullscreen{{ end }}{{ if .IsHome }} {{ .Site.Params.home.style }}{{ end }}">
{{- partial "assets/navbar.html" (dict
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gethinode/hinode",
"version": "0.25.3",
"version": "0.25.4",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [
"hugo",
Expand Down

0 comments on commit 1dfce3d

Please sign in to comment.