mirror of
https://github.com/discourse/discourse.git
synced 2025-03-09 14:34:35 +00:00
UX: Prevent color flicker on dark themes (#17620)
Follow up to: #17619 Context: https://meta.discourse.org/t/introducing-discourse-splash-a-visual-preloader-displayed-while-site-assets-load/232003/17 We previously relied on the user's browser when deciding when to show the splash in light/dark mode. This worked well but can fail if the user manually selects a theme with a default "dark" scheme. This PR will now factor that in. If the user selects a theme with a default dark scheme, use that. If a user selects a theme with a "light" default scheme and also picks a secondary "dark" scheme, use the media detection we had before. This PR also removes the dark mode theme-color that was added in the previous PR. That will now go in a separate PR
This commit is contained in:
parent
43b8cfeae3
commit
3c558d2eb6
@ -9,6 +9,11 @@
|
|||||||
<style>
|
<style>
|
||||||
:root {
|
:root {
|
||||||
--animation-state: paused;
|
--animation-state: paused;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* user picked a theme where the "regular" scheme is dark */
|
||||||
|
<%- if dark_color_scheme? %>
|
||||||
|
:root {
|
||||||
--primary: #<%= ColorScheme.hex_for_name("primary", scheme_id) %>;
|
--primary: #<%= ColorScheme.hex_for_name("primary", scheme_id) %>;
|
||||||
--secondary: #<%= ColorScheme.hex_for_name("secondary", scheme_id) %>;
|
--secondary: #<%= ColorScheme.hex_for_name("secondary", scheme_id) %>;
|
||||||
--tertiary: #<%= ColorScheme.hex_for_name("tertiary", scheme_id) %>;
|
--tertiary: #<%= ColorScheme.hex_for_name("tertiary", scheme_id) %>;
|
||||||
@ -16,30 +21,33 @@
|
|||||||
--highlight: #<%= ColorScheme.hex_for_name("highlight", scheme_id) %>;
|
--highlight: #<%= ColorScheme.hex_for_name("highlight", scheme_id) %>;
|
||||||
--success: #<%= ColorScheme.hex_for_name("success", scheme_id) %>;
|
--success: #<%= ColorScheme.hex_for_name("success", scheme_id) %>;
|
||||||
}
|
}
|
||||||
|
<%- else %>
|
||||||
|
/* user picked a theme a light scheme and also enabled a dark scheme */
|
||||||
|
|
||||||
|
/* deal with light scheme first */
|
||||||
|
@media (prefers-color-scheme: light) {
|
||||||
|
:root {
|
||||||
|
--primary: #<%= ColorScheme.hex_for_name("primary", scheme_id) %>;
|
||||||
|
--secondary: #<%= ColorScheme.hex_for_name("secondary", scheme_id) %>;
|
||||||
|
--tertiary: #<%= ColorScheme.hex_for_name("tertiary", scheme_id) %>;
|
||||||
|
--quaternary: #<%= ColorScheme.hex_for_name("quaternary", scheme_id) %>;
|
||||||
|
--highlight: #<%= ColorScheme.hex_for_name("highlight", scheme_id) %>;
|
||||||
|
--success: #<%= ColorScheme.hex_for_name("success", scheme_id) %>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* then deal with dark scheme */
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
:root {
|
:root {
|
||||||
--animation-state: paused;
|
|
||||||
--primary: #<%= ColorScheme.hex_for_name("primary", dark_scheme_id) %>;
|
--primary: #<%= ColorScheme.hex_for_name("primary", dark_scheme_id) %>;
|
||||||
--secondary: #<%= ColorScheme.hex_for_name(
|
--secondary: #<%= ColorScheme.hex_for_name("secondary", dark_scheme_id) %>;
|
||||||
"secondary",
|
--tertiary: #<%= ColorScheme.hex_for_name("tertiary", dark_scheme_id) %>;
|
||||||
dark_scheme_id
|
--quaternary: #<%= ColorScheme.hex_for_name("quaternary", dark_scheme_id) %>;
|
||||||
) %>;
|
--highlight: #<%= ColorScheme.hex_for_name("highlight", dark_scheme_id) %>;
|
||||||
--tertiary: #<%= ColorScheme.hex_for_name(
|
|
||||||
"tertiary",
|
|
||||||
dark_scheme_id
|
|
||||||
) %>;
|
|
||||||
--quaternary: #<%= ColorScheme.hex_for_name(
|
|
||||||
"quaternary",
|
|
||||||
dark_scheme_id
|
|
||||||
) %>;
|
|
||||||
--highlight: #<%= ColorScheme.hex_for_name(
|
|
||||||
"highlight",
|
|
||||||
dark_scheme_id
|
|
||||||
) %>;
|
|
||||||
--success: #<%= ColorScheme.hex_for_name("success", dark_scheme_id) %>;
|
--success: #<%= ColorScheme.hex_for_name("success", dark_scheme_id) %>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
<%- end %>
|
||||||
|
|
||||||
/* these styles need to live here because the SVG has a different scope */
|
/* these styles need to live here because the SVG has a different scope */
|
||||||
.dots {
|
.dots {
|
||||||
@ -114,14 +122,47 @@
|
|||||||
<style>
|
<style>
|
||||||
html {
|
html {
|
||||||
overflow-y: hidden !important;
|
overflow-y: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* user picked a theme where the "regular" scheme is dark */
|
||||||
|
<%- if dark_color_scheme? %>
|
||||||
|
html {
|
||||||
background-color: #<%= ColorScheme.hex_for_name("secondary", scheme_id) %>;
|
background-color: #<%= ColorScheme.hex_for_name("secondary", scheme_id) %>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#d-splash .preloader-text-wrapper {
|
||||||
|
color: #<%= ColorScheme.hex_for_name("primary", scheme_id) %>;
|
||||||
|
}
|
||||||
|
<%- else %>
|
||||||
|
/* user picked a theme a light scheme and also enabled a dark scheme */
|
||||||
|
|
||||||
|
/* deal with light scheme first */
|
||||||
|
@media (prefers-color-scheme: light) {
|
||||||
|
html {
|
||||||
|
background-color: #<%= ColorScheme.hex_for_name("secondary", scheme_id) %>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#d-splash .preloader-text-wrapper {
|
||||||
|
color: #<%= ColorScheme.hex_for_name("primary", scheme_id) %>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* then deal with dark scheme */
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
html {
|
||||||
|
background-color: #<%= ColorScheme.hex_for_name("secondary", dark_scheme_id) %>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#d-splash .preloader-text-wrapper {
|
||||||
|
color: #<%= ColorScheme.hex_for_name("primary", dark_scheme_id) %>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
<%- end %>
|
||||||
|
|
||||||
#d-splash {
|
#d-splash {
|
||||||
display: grid;
|
display: grid;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
backface-visibility: hidden;
|
backface-visibility: hidden;
|
||||||
background-color: #<%= ColorScheme.hex_for_name("secondary", scheme_id) %>;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: 0;
|
top: 0;
|
||||||
@ -142,7 +183,6 @@
|
|||||||
animation-delay: 1s;
|
animation-delay: 1s;
|
||||||
animation-fill-mode: forwards;
|
animation-fill-mode: forwards;
|
||||||
animation-play-state: var(--animation-state);
|
animation-play-state: var(--animation-state);
|
||||||
color: #<%= ColorScheme.hex_for_name("primary", scheme_id) %>;
|
|
||||||
margin-bottom: -4em;
|
margin-bottom: -4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,18 +222,6 @@
|
|||||||
content: "...";
|
content: "...";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (prefers-color-scheme: dark) {
|
|
||||||
html {
|
|
||||||
background-color: #<%= ColorScheme.hex_for_name("secondary", dark_scheme_id) %>;
|
|
||||||
}
|
|
||||||
#d-splash {
|
|
||||||
background-color: #<%= ColorScheme.hex_for_name("secondary", dark_scheme_id) %>;
|
|
||||||
}
|
|
||||||
#d-splash .preloader-text-wrapper {
|
|
||||||
color: #<%= ColorScheme.hex_for_name("primary", dark_scheme_id) %>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<img
|
<img
|
||||||
|
@ -6,8 +6,7 @@
|
|||||||
<%- if site_apple_touch_icon_url.present? %>
|
<%- if site_apple_touch_icon_url.present? %>
|
||||||
<link rel="apple-touch-icon" type="image/png" href="<%= ::UrlHelper.absolute(site_apple_touch_icon_url) %>">
|
<link rel="apple-touch-icon" type="image/png" href="<%= ::UrlHelper.absolute(site_apple_touch_icon_url) %>">
|
||||||
<%- end %>
|
<%- end %>
|
||||||
<meta name="theme-color" content="#<%= ColorScheme.hex_for_name('header_background', scheme_id) %>" media="(prefers-color-scheme: light)">
|
<meta name="theme-color" content="#<%= ColorScheme.hex_for_name('header_background', scheme_id) %>">
|
||||||
<meta name="theme-color" content="#<%= ColorScheme.hex_for_name('header_background', dark_scheme_id) %>" media="(prefers-color-scheme: dark)">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=yes, viewport-fit=cover">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=yes, viewport-fit=cover">
|
||||||
<%- if Discourse.base_path.present? %>
|
<%- if Discourse.base_path.present? %>
|
||||||
<meta name="discourse-base-uri" content="<%= Discourse.base_path %>">
|
<meta name="discourse-base-uri" content="<%= Discourse.base_path %>">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user