Merge pull request #9727 from colinux/fix-dark-theme-blinkblink

Fix thème sombre: ne clignote pas avec le thème clair au moment du render
This commit is contained in:
Colin Darie 2023-11-20 19:42:05 +00:00 committed by GitHub
commit 6c4f6a52cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View file

@ -0,0 +1,9 @@
:javascript
function setDarkBeforeRender() {
const localScheme = localStorage.getItem('scheme')
if (localScheme == 'dark' || (localScheme == 'system' && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.setAttribute('data-fr-theme', 'dark');
}
}
setDarkBeforeRender();

View file

@ -35,6 +35,7 @@
= stylesheet_link_tag 'application', media: 'all'
= yield(:invisible_captcha_styles)
= render partial: 'layouts/setup_theme'
%body{ { id: content_for(:page_id), class: browser.platform.ios? ? 'ios' : nil, data: { controller: 'turbo number-input' } }.compact }
= render partial: 'layouts/skiplinks'

View file

@ -1,5 +1,5 @@
!!! 5
%html{ lang: html_lang, class: yield(:root_class) }
%html{ lang: html_lang, data: { fr_scheme: 'system' }, class: yield(:root_class) }
%head
%meta{ "http-equiv": "Content-Type", content: "text/html; charset=UTF-8" }
%meta{ "http-equiv": "X-UA-Compatible", content: "IE=edge" }
@ -23,6 +23,8 @@
= vite_stylesheet_tag 'main', media: 'all'
= stylesheet_link_tag 'application', media: 'all'
= render partial: 'layouts/setup_theme'
%body{ class: browser.platform.ios? ? 'ios' : nil, data: { controller: 'turbo' } }
.page-wrapper
%main.m-6