Skip to content

Commit

Permalink
Add dark color theme.
Browse files Browse the repository at this point in the history
Users' profile provides a way to select a color theme
  • Loading branch information
Moises Deniz committed Jan 12, 2024
1 parent 3313d46 commit 2a73056
Show file tree
Hide file tree
Showing 29 changed files with 112 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/api/app/assets/javascripts/webui/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// FIXME remove jquery-ui file when we upgrade jquery-ui gem
//= require webui/jquery-ui.min.js
//= require bootstrap
//= require webui/color_themes.js
//= require cocoon
//= require jquery.flot
//= require jquery.flot.resize
Expand Down
27 changes: 27 additions & 0 deletions src/api/app/assets/javascripts/webui/color_themes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*!
* Color mode toggler for Bootstrap's docs (https://getbootstrap.com/)
* Copyright 2011-2023 The Bootstrap Authors
* Licensed under the Creative Commons Attribution 3.0 Unported License.
*/

(() => {
'use strict'

const getPreferredTheme = () => {
const userTheme = document.documentElement.getAttribute('data-bs-theme-from-user')
if (userTheme == "system") {
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}
return userTheme
}

const setTheme = theme => {
document.documentElement.setAttribute('data-bs-theme', theme)
}

setTheme(getPreferredTheme())

window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
setTheme(getPreferredTheme())
})
})()
3 changes: 2 additions & 1 deletion src/api/app/assets/stylesheets/webui/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@import 'bootstrap_variables/sizes';
@import 'bootstrap_variables/options';
@import 'bootstrap';
@import 'colors';
@import 'bootstrap-modal';
@import 'font-awesome';
@import 'tokenfield';
Expand Down Expand Up @@ -73,7 +74,7 @@
@import 'request_show_redesign/build_results';
@import 'accordion-reviews-component';
@import 'tokens';
@import 'colors';
@import 'subscriptions';

html {
overflow-y: scroll !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ ol.breadcrumb {
font-size: 0.9rem;

&.active {
color: $gray-700;
color: $breadcrumbs-item-text-color;
font-weight: bold;
}

& a {
color: $gray-700;
color: $breadcrumbs-item-text-color;
}
}
}
}
8 changes: 7 additions & 1 deletion src/api/app/assets/stylesheets/webui/build-results.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
}
}

.buildresult_repo_header {
background-color: var(--bs-secondary-bg);
}

.custom-label {
cursor: pointer;
color: $link-color;
Expand All @@ -43,7 +47,7 @@
@extend .d-flex;
@extend .flex-column;
position: relative;
background-color: #eeeeee;
background-color: var(--bs-secondary-bg);
max-height: 100vh;
width: 100%;
font-size: 90%;
Expand All @@ -66,6 +70,8 @@
.build-info-content {
@extend .py-2;
@extend .px-3;
padding-top: 0.4rem !important;
padding-bottom: 0.4rem !important;
overflow-y: hidden;
}

Expand Down
6 changes: 5 additions & 1 deletion src/api/app/assets/stylesheets/webui/cm2/bootstrap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
&.CodeMirror {
font-family: $font-family-monospace, monospace;
background: $card-bg;
color: $body-color;
color: var(--bs-body-color);
line-height: 1.2;
}

Expand Down Expand Up @@ -71,3 +71,7 @@
}

.editable .cm-s-bootstrap .CodeMirror-cursor { border-left: 1px solid $body-color; }

.editor-bg {
background-color: var(--bs-secondary-bg);
}
2 changes: 1 addition & 1 deletion src/api/app/assets/stylesheets/webui/coderay.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.CodeRay, .CodeRay .change {
background: $card-bg;
color: $body-color;
color: var(--bs-body-color);
}
.CodeRay pre { margin: 0 }
span.CodeRay { white-space: pre }
Expand Down
14 changes: 10 additions & 4 deletions src/api/app/assets/stylesheets/webui/colors.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
.bg-gray-800 {
background-color: $gray-800;
}

.text-bg-dismissed {
color: $white;
background-color: $gray-500;
}

$navbar-themed-bg: $gray-800;
$breadcrumbs-item-text-color: $gray-700;

// Dark theme overrides
@include color-mode(dark) {
$breadcrumbs-item-text-color: $gray-400;
$navbar-themed-bg: #121212;
}

12 changes: 12 additions & 0 deletions src/api/app/assets/stylesheets/webui/editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

[data-bs-theme="light"] {
.editor-bg {
background-color: var(--bs-light);
}
}

[data-bs-theme="dark"] {
.editor-bg {
background-color: var(--bs-dark-bg-subtle);
}
}
2 changes: 1 addition & 1 deletion src/api/app/assets/stylesheets/webui/image_templates.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

&.active{
@extend .card;
background: #ebfdc7;
background: var(--bs-tertiary-bg);
}
}
3 changes: 1 addition & 2 deletions src/api/app/assets/stylesheets/webui/modals.scss
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
.modal {
font-size: var(--bs-body-font-size);
color: $body-color;
color: var(--bs-body-color);

.modal-header h5 {
color: $body-color;
overflow-x: hidden;
overflow-wrap: break-word;
}
Expand Down
5 changes: 5 additions & 0 deletions src/api/app/assets/stylesheets/webui/navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
}
}

.navbar-themed-colors {
@extend .border-gray-500;
background-color: $navbar-themed-bg;
}

@include media-breakpoint-up(md) {
.navbar-dark.navbar-collapse {
&.watchlist-collapse, &.places-collapse, &.actions-collapse {
Expand Down
10 changes: 10 additions & 0 deletions src/api/app/assets/stylesheets/webui/repositories.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ details[open].repository-path {
}
}
}

.flags_repo_header {
@extend .table-light;
}

@include color-mode(dark) {
.flags_repo_header {
--bs-table-bg: var(--bs-dark-bg-subtle);
}
}
3 changes: 3 additions & 0 deletions src/api/app/assets/stylesheets/webui/subscriptions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.subscriptions-card-bg {
background-color: var(--bs-secondary-bg);
}
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def account_edit_link
end

def assign_common_user_attributes
@displayed_user.assign_attributes(params[:user].slice(:biography).permit!)
@displayed_user.assign_attributes(params[:user].slice(:biography, :color_theme).permit!)
@displayed_user.assign_attributes(params[:user].slice(:realname, :email).permit!) unless @account_edit_link
@displayed_user.toggle(:in_beta) if params[:user][:in_beta]
end
Expand Down
1 change: 1 addition & 0 deletions src/api/app/models/unregistered_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def self.register(opts)
# id :integer not null, primary key
# adminnote :text(65535)
# biography :string(255) default("")
# color_theme :integer default("system"), not null
# deprecated_password :string(255) indexed
# deprecated_password_hash_type :string(255)
# deprecated_password_salt :string(255)
Expand Down
5 changes: 5 additions & 0 deletions src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class User < ApplicationRecord
NOBODY_LOGIN = '_nobody_'.freeze
MAX_BIOGRAPHY_LENGTH_ALLOWED = 250

COLOR_THEMES = ['system', 'light', 'dark'].freeze
enum :color_theme, COLOR_THEMES

# disable validations because there can be users which don't have a bcrypt
# password yet. this is for backwards compatibility
has_secure_password validations: false
Expand Down Expand Up @@ -121,6 +124,7 @@ class User < ApplicationRecord
validates :password, confirmation: true, allow_blank: true
validates :biography, length: { maximum: MAX_BIOGRAPHY_LENGTH_ALLOWED }
validates :rss_secret, uniqueness: true, length: { maximum: 200 }, allow_blank: true
validates :color_theme, inclusion: { in: COLOR_THEMES }

after_create :create_home_project, :measure_create
after_update :measure_delete
Expand Down Expand Up @@ -952,6 +956,7 @@ def hash_string(value)
# id :integer not null, primary key
# adminnote :text(65535)
# biography :string(255) default("")
# color_theme :integer default("system"), not null
# deprecated_password :string(255) indexed
# deprecated_password_hash_type :string(255)
# deprecated_password_salt :string(255)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%nav.navbar.fixed-bottom.navbar-dark.bg-gray-800.border-top.border-gray-500.p-0
%nav.navbar.fixed-bottom.navbar-dark.navbar-themed-colors.border-top.p-0
%ul.nav.justify-content-center.w-100.nav-justified
- if User.session
%li.nav-item
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.navbar-collapse.navbar-dark.bg-gray-800{ class: "#{collapse_type}-collapse" }
.navbar-collapse.navbar-dark.navbar-themed-colors{ class: "#{collapse_type}-collapse" }
.navbar-nav
.nav.justify-content-end.py-2
%button.navbar-toggler{ type: 'button', 'data-toggle': collapse_type, aria: { expanded: 'false', label: "Toggle #{collapse_type}" } }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.navbar-dark.bg-gray-800.border-top.border-gray-500#toggle-sidebar-button
.navbar-dark.border-top.navbar-themed-colors#toggle-sidebar-button
%ul.nav.flex-column.ms-auto.pt-0.text-nowrap.menu-options
%li.nav-item
%a.nav-link{ type: 'button' }
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/layouts/webui/_top_navigation.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%nav.navbar.navbar-dark.bg-gray-800.fixed-top
%nav.navbar.navbar-dark.navbar-themed-colors.fixed-top
.container-fluid.d-flex.flex-nowrap.justify-content-between.w-100
= link_to(root_path, class: 'navbar-brand', alt: 'Logo') do
= image_tag('obs-logo_small.svg')
Expand Down
6 changes: 3 additions & 3 deletions src/api/app/views/layouts/webui/webui.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
!!!
%html{ lang: 'en' }
%html{ lang: 'en', "data-bs-theme-from-user": User.session&.color_theme || "system" }
%head
%meta{ content: 'charset=utf-8' }/
%meta{ name: 'viewport', content: 'width=device-width, initial-scale=1, shrink-to-fit=no' }
Expand Down Expand Up @@ -42,7 +42,7 @@
#grid
#top-navigation-area
= render partial: 'layouts/webui/top_navigation'
.navbar-dark.bg-gray-800#left-navigation-area{ class: "#{'collapsed' if sidebar_collapsed?}" }
.navbar-dark.navbar-themed-colors#left-navigation-area{ class: "#{'collapsed' if sidebar_collapsed?}" }
= render partial: 'layouts/webui/left_navigation', locals: { spider_bot: @spider_bot }
= render partial: 'layouts/webui/left_navigation_collapse_button'
.d-flex.flex-column#content-area
Expand Down Expand Up @@ -77,7 +77,7 @@

-# Collapsible menu shared between top and bottom navigation
- if User.session
.navbar-dark.bg-gray-800.navbar-collapse.watchlist-collapse
.navbar-dark.navbar-collapse.navbar-themed-colors.watchlist-collapse
= render WatchlistComponent.new(user: User.session!,
bs_request: @bs_request,
package: @package,
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/package/_buildstatus.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
repository_name = result.repository.tr('.', '_')
expanded = repository_expanded?(collapsed_repositories, repository_name, package_name)
- if result.repository != previous_repo
.d-flex.flex-row.py-1.bg-light.ps-1.ps-sm-2
.d-flex.flex-row.py-1.buildresult_repo_header.ps-1.ps-sm-2
= link_to(word_break(result.repository, 22),
project_package_repository_binaries_path(project_name: project, package_name: package, repository_name: result.repository),
title: "Binaries for #{result.repository}")
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/views/webui/project/_buildstatus.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- repository_name = repository.tr('.', '_')
- expanded = repository_expanded?(collapsed_repositories, repository_name)
.d-flex.flex-column
.d-flex.flex-row.py-1.bg-light.ps-1.ps-sm-2
.d-flex.flex-row.py-1.buildresult_repo_header.ps-1.ps-sm-2
= link_to(word_break(repository, 12),
project_repository_state_path(project: project.name, repository: repository),
title: "Repository #{repository}")
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/views/webui/shared/_editor.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

%div{ class: "card #{'editable' unless style[:read_only]}" }
- unless style[:read_only]
.sticky-top.bg-light{ id: "top_#{uid}" }
.sticky-top.editor-bg{ id: "top_#{uid}" }
.card-header
.d-flex.justify-content-between
.btn-group.ps-2
Expand All @@ -32,7 +32,7 @@
= text_area_tag("editor_#{uid}", text, cols: '0', rows: '0', data: data, class: 'form-control')

- unless style[:read_only]
.bg-light{ id: "bottom_#{uid}" }
.editor-bg{ id: "bottom_#{uid}" }
.card-footer
.d-flex.justify-content-end
%p
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.table-responsive
%table.table.table-hover.table-sm{ id: table_id }
%thead.table-light
%thead.flags_repo_header
%tr
%th.w-auto Repository
%th.w-auto.text-center All
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- i = 0
- subscriptions_form.subscriptions_by_event.each do |subscription|
.card.bg-light.mb-2
.card.subscriptions-card-bg.mb-2
.card-body
%h5.card-title= subscription.event_class.description
%p.card-text= Event::Base::EXPLANATION_FOR_NOTIFICATIONS[subscription.event_class.to_s]
Expand Down
3 changes: 3 additions & 0 deletions src/api/app/views/webui/user/_edit_account_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
%small.form-text#bio-chars-counter
.mb-3
= f.text_field(:email, required: true, email: true, placeholder: 'Email', readonly: behind_proxy, class: 'form-control')
.mb-3
= f.label :color_theme, "Theme"
= f.select(:color_theme, options_for_select(User::COLOR_THEMES), {}, class: 'form-select')
.mb-3
- if behind_proxy
%p
Expand Down
2 changes: 1 addition & 1 deletion src/api/vendor/assets/stylesheets/tokenfield.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
-ms-flex-wrap: wrap;
flex-wrap: wrap;
box-sizing: border-box;
background: #fff;
background: var(--bs-body-bg);
font-family: sans-serif;
font-size: 14px;
line-height: 20px;
Expand Down

0 comments on commit 2a73056

Please sign in to comment.