Add auto/manual color scheme stylesheets depending on user preferences

This commit is contained in:
Anton Khorev 2024-11-16 17:51:50 +03:00
parent 8a020b3ec7
commit 2ca74ab3ef
10 changed files with 28 additions and 7 deletions

View file

@ -20,4 +20,3 @@ $table-border-factor: .1;
$list-group-hover-bg: rgba(var(--bs-emphasis-color-rgb), .075);
$enable-negative-margins: true;
$color-mode-type: media-query;

View file

@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: media-query
);

View file

@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: media-query
);

View file

@ -1 +0,0 @@
@import "common";

View file

@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: data
);

View file

@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: data
);

View file

@ -1 +0,0 @@
@import "common";

View file

@ -281,7 +281,15 @@ class ApplicationController < ActionController::Base
end
end
helper_method :preferred_editor
def preferred_site_color_scheme
if current_user
current_user.preferences.find_by(:k => "site.color_scheme")&.v || "auto"
else
"auto"
end
end
helper_method :preferred_editor, :preferred_site_color_scheme
def update_totp
if Settings.key?(:totp_key)

View file

@ -5,7 +5,11 @@
<%= javascript_include_tag "turbo", :type => "module" %>
<%= javascript_include_tag "application" %>
<%= javascript_include_tag "i18n/#{I18n.locale}" %>
<%= stylesheet_link_tag "screen-#{dir}", :media => "screen" %>
<% if preferred_site_color_scheme == "auto" %>
<%= stylesheet_link_tag "screen-auto-#{dir}", :media => "screen" %>
<% else %>
<%= stylesheet_link_tag "screen-manual-#{dir}", :media => "screen" %>
<% end %>
<%= stylesheet_link_tag "print-#{dir}", :media => "print" %>
<%= stylesheet_link_tag "leaflet-all", :media => "screen, print" %>
<%= render :partial => "layouts/meta" %>

View file

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html lang="<%= I18n.locale %>" dir="<%= dir %>">
<%= tag.html :lang => I18n.locale, :dir => dir, :data => { :bs_theme => (preferred_site_color_scheme if preferred_site_color_scheme != "auto") } do %>
<%= render :partial => "layouts/head" %>
<body class="<%= body_class %>">
<%= render :partial => "layouts/header" %>
@ -8,4 +8,4 @@
<noscript><p><img src="<%= request.protocol %><%= Settings.matomo["location"] %>/matomo.php?idsite=<%= Settings.matomo["site"] %>" class="matomo" alt="" /></p></noscript>
<% end -%>
</body>
</html>
<% end %>