Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color mode preference #5337

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/assets/stylesheets/parameters.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions app/assets/stylesheets/screen-auto-ltr.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: media-query
);
3 changes: 3 additions & 0 deletions app/assets/stylesheets/screen-auto-rtl.rtlcss.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: media-query
);
3 changes: 3 additions & 0 deletions app/assets/stylesheets/screen-light-ltr.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: data
);
3 changes: 3 additions & 0 deletions app/assets/stylesheets/screen-light-rtl.rtlcss.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "common" with (
$color-mode-type: data
);
1 change: 0 additions & 1 deletion app/assets/stylesheets/screen-ltr.scss

This file was deleted.

1 change: 0 additions & 1 deletion app/assets/stylesheets/screen-rtl.rtlcss.scss

This file was deleted.

6 changes: 6 additions & 0 deletions app/controllers/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ def update
else
params[:user][:preferred_editor]
end

cookies["_osm_color_scheme"] = {
:value => params[:color_scheme],
:expires => 10.years.from_now
}

if current_user.save
# Use a partial so that it is rendered during the next page load in the correct language.
flash[:notice] = { :partial => "preferences/update_success_flash" }
Expand Down
6 changes: 5 additions & 1 deletion app/views/layouts/_head.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 request.cookies["_osm_color_scheme"] == "light" %>
<%= stylesheet_link_tag "screen-light-#{dir}", :media => "screen" %>
<% else %>
<%= stylesheet_link_tag "screen-auto-#{dir}", :media => "screen" %>
<% end %>
<%= stylesheet_link_tag "print-#{dir}", :media => "print" %>
<%= stylesheet_link_tag "leaflet-all", :media => "screen, print" %>
<%= render :partial => "layouts/meta" %>
Expand Down
8 changes: 8 additions & 0 deletions app/views/preferences/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

<%= f.text_field :languages %>

<div class="mb-3">
<%= label_tag "color_scheme", t("preferences.show.preferred_color_scheme"), :class => "form-label" %>
<%= select_tag "color_scheme",
options_for_select([[t("preferences.show.color_schemes.auto"), "auto"],
[t("preferences.show.color_schemes.light"), "light"]], request.cookies["_osm_color_scheme"]),
:class => "form-select" %>
</div>

<%= f.primary t(".save") %>
<%= link_to t(".cancel"), preferences_path, :class => "btn btn-link" %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/preferences/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@
<li><%= locale %></li>
<% end %>
</ul>
</dd>

<dt class="col-sm-4"><%= t ".preferred_color_scheme" %></dt>
<dd class="col-sm-8">
<% if request.cookies["_osm_color_scheme"] == "light" %>
<%= t ".color_schemes.light" %>
<% else %>
<%= t ".color_schemes.auto" %>
<% end %>
</dd>
</dl>

Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,10 @@ en:
title: My Preferences
preferred_editor: Preferred Editor
preferred_languages: Preferred Languages
preferred_color_scheme: Preferred Color Scheme
color_schemes:
auto: Auto
light: Light
edit_preferences: Edit Preferences
edit:
title: Edit Preferences
Expand Down