Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Re-add the theme selection base on the Primer themes (Wip as not all colors are correctly overwritten yet)

Henriette Darge28a53f196547
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 692bc12bddf..a803fc381ea 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -315,6 +315,20 @@ module ApplicationHelper
.sort_by(&:last)
end
+ def theme_options_for_select
+ [
+ [t('themes.light'), 'light'],
+ [t('themes.light_high_contrast'), 'light_high_contrast'],
+ [t('themes.dark'), 'dark'],
+ [t('themes.dark_dimmed'), 'dark_dimmed'],
+ [t('themes.dark_high_contrast'), 'dark_high_contrast']
+ ]
+ end
+
+ def user_theme_data_attributes
+ mode, _theme_suffix = User.current.pref.theme.split("_", 2)
+ "data-color-mode=\"#{mode}\" data-#{mode}-theme=\"#{User.current.pref.theme}\"".html_safe
+ end
def highlight_default_language(lang_options)
lang_options.map do |(language_name, code)|
if code == Setting.default_language
diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb
index 1eca2b38a17..73508be3da9 100644
--- a/app/models/user_preference.rb
+++ b/app/models/user_preference.rb
@@ -123,6 +123,10 @@ class UserPreference < ApplicationRecord
settings[:comments_sorting] = to_boolean(value) ? 'desc' : 'asc'
end
+ def theme
+ super.presence || Setting.user_default_theme
+ end
+
def time_zone
super.presence || Setting.user_default_timezone.presence
end
diff --git a/app/views/custom_styles/_inline_css.erb b/app/views/custom_styles/_inline_css.erb
index 63ca363a8a2..eac3ebb0c59 100644
--- a/app/views/custom_styles/_inline_css.erb
+++ b/app/views/custom_styles/_inline_css.erb
@@ -28,45 +28,60 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<style type="text/css">
- :root {
- <% DesignColor.overwritten.each do |design_color| %>
- --<%= design_color.variable %>: <%= design_color.hexcode %>;
+ :root {
+ <% DesignColor.overwritten.each do |design_color| %>
+ --<%= design_color.variable %>: <%= design_color.hexcode %>;
<% if design_color.variable == "header-border-bottom-color" %>
- --header-border-bottom-width: 1px;
+ --header-border-bottom-width: 1px;
<% end %>
<% if design_color.variable == "main-menu-border-color" %>
- --main-menu-border-width: 1px;
+ --main-menu-border-width: 1px;
<% end %>
<% if design_color.variable == "alternative-color" %>
- --button--alt-highlight-background-hover-color: <%= design_color.darken 0.18 %>;
+ --button--alt-highlight-background-hover-color: <%= design_color.darken 0.18 %>;
<% end %>
<% if design_color.variable == "primary-color" %>
- --primary-color--minor1: <%= design_color.lighten 0.3 %>;
- --primary-color--minor2: <%= design_color.lighten 0.6 %>;
- --primary-color--minor3: <%= design_color.lighten 0.8 %>;
- --primary-color--major1: <%= design_color.darken 0.2 %>;
- --primary-color--major2: <%= design_color.darken 0.4 %>;
- --primary-color--major3: <%= design_color.darken 0.6 %>;
+ --primary-color--minor1: <%= design_color.lighten 0.3 %>;
+ --primary-color--minor2: <%= design_color.lighten 0.6 %>;
+ --primary-color--minor3: <%= design_color.lighten 0.8 %>;
+ --primary-color--major1: <%= design_color.darken 0.2 %>;
+ --primary-color--major2: <%= design_color.darken 0.4 %>;
+ --primary-color--major3: <%= design_color.darken 0.6 %>;
<% end %>
- <% end %>
- }
+ <% end %>
+ }
+
+ /* Overwrite Primer primitives */
+ [data-color-mode] {
+ <% DesignColor.overwritten.each do |design_color| %>
+ --body-background: var(--color-canvas-default);
+ --body-font-color: var(--color-fg-default);
+ <% if design_color.variable == "alternative-color" %>
+ --color-btn-primary-bg: <%= design_color.hexcode %> !important;
+ --color-btn-primary-hover-bg: <%= design_color.darken 0.18 %> !important;
+ <% end %>
+ <% if design_color.variable == "content-link-color" %>
+ --color-accent-fg: <%= design_color.hexcode %> !important;
+ <% end %>
+ <% end %>
+ }
- <%# Conditional styles %>
- <% if DesignColor.overwritten.map(&:variable).include?('header-border-bottom-color') %>
+ <%# Conditional styles %>
+ <% if DesignColor.overwritten.map(&:variable).include?('header-border-bottom-color') %>
<%# Remove top border of left menu to not have to borders adding to 2px %>
#main-menu #toggle-project-menu {
- border-top: 0px;
+ border-top: 0px;
}
<%# Trying to hit the query cache for the condition here: %>
<% if DesignColor.overwritten.map(&:variable).include?('header-bg-color') &&
DesignColor.overwritten.select { |design_color| design_color.variable == 'header-bg-color' }.try(:first).try(:hexcode) == '#FFFFFF' &&
DesignColor.overwritten.select { |design_color| design_color.variable == 'header-item-bg-hover-color' }.try(:first).try(:hexcode) == '#FFFFFF' %>
- <%# Disable hover background color to not overlap border %>
- .op-app-menu--item-action:hover,
- .top-menu-search.-collapsed .top-menu-search--button:hover {
+ <%# Disable hover background color to not overlap border %>
+ .op-app-menu--item-action:hover,
+ .top-menu-search.-collapsed .top-menu-search--button:hover {
background: transparent;
- }
+ }
+ <% end %>
<% end %>
- <% end %>
</style>
diff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erb
index a14039b2b7e..4da3e863b09 100644
--- a/app/views/layouts/base.html.erb
+++ b/app/views/layouts/base.html.erb
@@ -45,6 +45,7 @@ See COPYRIGHT and LICENSE files for more details.
data-overflowing-identifier=".__overflowing_body"
data-rendered-at="<%= Time.zone.now.iso8601 %>"
data-controller="application"
+ <%= user_theme_data_attributes %>
>
<%= render partial: 'warning_bar/warning_bar' %>
<noscript>
diff --git a/app/views/users/_preferences.html.erb b/app/views/users/_preferences.html.erb
index cb475eb1306..6c618bec3dc 100644
--- a/app/views/users/_preferences.html.erb
+++ b/app/views/users/_preferences.html.erb
@@ -33,6 +33,11 @@ See COPYRIGHT and LICENSE files for more details.
container_class: (defined? input_size) ? "-#{input_size}" : "-wide"
)
%>
+ <% if OpenProject::FeatureDecisions.personal_theme_selection_active? %>
+ <div class="form--field">
+ <%= pref_fields.select :theme, theme_options_for_select, container_class: '-middle' %>
+ </div>
+ <% end %>
<div class="form--field">
<%= pref_fields.select :comments_sorting,
[[t(:label_chronological_order), 'asc'],
diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rb
index b3c51671269..63e355b3fed 100644
--- a/config/constants/settings/definition.rb
+++ b/config/constants/settings/definition.rb
@@ -979,6 +979,13 @@ module Settings
users_deletable_by_admins: {
default: false
},
+ user_default_theme: {
+ default: 'light',
+ format: :string,
+ allowed: -> do
+ UserPreferences::Schema.schema.dig('definitions', 'UserPreferences', 'properties', 'theme', 'enum')
+ end
+ },
users_deletable_by_self: {
default: false
},
diff --git a/config/initializers/feature_decisions.rb b/config/initializers/feature_decisions.rb
index 0e883273360..94369abf41f 100644
--- a/config/initializers/feature_decisions.rb
+++ b/config/initializers/feature_decisions.rb
@@ -41,3 +41,4 @@ require_relative '../../lib_static/open_project/feature_decisions'
OpenProject::FeatureDecisions.add :show_changes
OpenProject::FeatureDecisions.add :more_global_index_pages
+OpenProject::FeatureDecisions.add :personal_theme_selection
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 5077258d746..438b7cf0835 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -369,6 +369,13 @@ en:
no_results_title_text: There are currently no work package statuses.
no_results_content_text: Add a new status
+ themes:
+ light: "Light"
+ light_high_contrast: "Light high contrast"
+ dark: "Dark"
+ dark_dimmed: "Dark dimmed"
+ dark_high_contrast: "Dark high contrast"
+
types:
index:
no_results_title_text: There are currently no types.
diff --git a/config/schemas/user_preferences.schema.json b/config/schemas/user_preferences.schema.json
index aa9d71eab74..ad99f137df8 100644
--- a/config/schemas/user_preferences.schema.json
+++ b/config/schemas/user_preferences.schema.json
@@ -12,6 +12,10 @@
"time_zone": {
"type": ["string", "null"]
},
+ "theme": {
+ "type": "string",
+ "enum": ["light", "light_high_contrast", "dark", "dark_dimmed", "dark_high_contrast"]
+ },
"warn_on_leaving_unsaved": {
"type": "boolean"
},
diff --git a/frontend/src/global_styles/content/_grid.sass b/frontend/src/global_styles/content/_grid.sass
index 1bed7da3a02..e9920737009 100644
--- a/frontend/src/global_styles/content/_grid.sass
+++ b/frontend/src/global_styles/content/_grid.sass
@@ -8,11 +8,6 @@ $grid--widget-padding: 20px 20px 20px 20px
@mixin grid--commons
display: grid
-body.widget-grid-layout
- #content-wrapper,
- #content
- background-color: var(--grid-background-color)
-
.grid--container
@include grid--commons
diff --git a/frontend/src/global_styles/content/_table.sass b/frontend/src/global_styles/content/_table.sass
index 188f4751542..b3cc806817b 100644
--- a/frontend/src/global_styles/content/_table.sass
+++ b/frontend/src/global_styles/content/_table.sass
@@ -237,7 +237,7 @@ table.generic-table
thead.-sticky th
position: sticky
top: 0
- background: white
+ background: var(--body-background)
.generic-table--footer-outer
diff --git a/frontend/src/global_styles/content/modules/_auth_plugins.sass b/frontend/src/global_styles/content/modules/_auth_plugins.sass
index dcb7488a4e9..aa8a4423308 100644
--- a/frontend/src/global_styles/content/modules/_auth_plugins.sass
+++ b/frontend/src/global_styles/content/modules/_auth_plugins.sass
@@ -24,7 +24,7 @@
background-size: 18px 18px
background-position-x: 8px
background-position-y: center
- background-color: #FFF
+ background-color: var(--body-background)
&.auth-provider--imaged
padding-left: 2rem
diff --git a/frontend/src/global_styles/layout/_base.sass b/frontend/src/global_styles/layout/_base.sass
index f37946a538c..da016666169 100644
--- a/frontend/src/global_styles/layout/_base.sass
+++ b/frontend/src/global_styles/layout/_base.sass
@@ -53,7 +53,7 @@
height: calc(100vh - var(--header-height))
overflow-y: auto
overflow-x: hidden
- background-color: #fff
+ background-color: var(--body-background)
position: relative
&.nosidebar
diff --git a/frontend/src/global_styles/openproject/_mixins.sass b/frontend/src/global_styles/openproject/_mixins.sass
index fa2736180a9..effa7cd5151 100644
--- a/frontend/src/global_styles/openproject/_mixins.sass
+++ b/frontend/src/global_styles/openproject/_mixins.sass
@@ -81,7 +81,6 @@
text-decoration: none
@mixin widget-box--style
- background: var(--widget-box-block-bg-color)
margin: 10px
box-shadow: 0px 1px 5px 0px rgba(0,0,0,0.1)