From 11b83206eba05f089077f8c3a6940414b19d1034 Mon Sep 17 00:00:00 2001 From: Brian Durand Date: Sun, 29 Sep 2024 14:48:43 -0700 Subject: [PATCH 1/6] add support for dark mode --- CHANGELOG.md | 6 ++++++ README.md | 6 ++++++ VERSION | 2 +- app/application.css | 17 +++++++++-------- app/application_vars.css.erb | 31 +++++++++++++++++++++++++++++++ app/layout.css | 8 +++++--- app/layout.html.erb | 1 + app/layout_vars.css.erb | 19 +++++++++++++++++++ config.ru | 2 +- lib/ultra_settings/rack_app.rb | 5 +++-- lib/ultra_settings/web_view.rb | 21 ++++++++++++++++++--- 11 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 app/application_vars.css.erb create mode 100644 app/layout_vars.css.erb diff --git a/CHANGELOG.md b/CHANGELOG.md index c34828e..b902185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 2.0.1 + +### Added + +- Added option to specify the color scheme for the web UI when mounting the rack app to support dark mode. + ## 2.0.0 ### Fixed diff --git a/README.md b/README.md index 632c439..a14e7e6 100644 --- a/README.md +++ b/README.md @@ -346,6 +346,12 @@ mount Rack::Builder.new do end, at: "/ultra_settings" ``` +You can specify the color scheme by setting by providing the `color_scheme` option to the `UltraSettings::RackApp` class. The default color scheme is `:light`. You can also set the scheme to `:dark` or `:system`. + +```ruby +UltraSettings::RackApp.new(color_scheme: :dark) +``` + #### Embedding the Settings View in Admin Tools If you prefer to embed the settings view directly into your own admin tools or dashboard, you can use the `UltraSettings::ApplicationView` class to render the settings interface within your existing views: diff --git a/VERSION b/VERSION index 227cea2..38f77a6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.0 +2.0.1 diff --git a/app/application.css b/app/application.css index c5790b8..db11284 100644 --- a/app/application.css +++ b/app/application.css @@ -15,29 +15,30 @@ .ultra-settings-table thead th { vertical-align: bottom; - border-bottom: 2px solid #dee2e6; + border-bottom: 2px solid var(--table-border-color); + background-color: var(--table-header-bg-color); } .ultra-settings-table td, .ultra-settings-table th { padding: 0.75rem; vertical-align: top; - border-top: 1px solid #dee2e6; + border-top: 1px solid var(--table-border-color); } .ultra-settings-table tbody tr:nth-of-type(odd) { - background-color: rgba(0, 0, 0, .03); + background-color: var(--alt-row-color); } .ultra-settings-table code { font-family: monospace; font-size: 0.9rem; display: inline; - color: darkred; + color: var(--code-color); font-weight: 600; } .ultra-settings-table em { - color: gray; + color: var(--em-color); font-style: italic; font-size: 0.9rem; } @@ -49,13 +50,13 @@ font-size: 1rem; font-weight: 400; line-height: 1.5; - color: #212529; - background-color: #fff; + color: var(--form-control-color); + background-color: var(--form-control-bg-color); background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: right .75rem center; background-size: 16px 12px; - border: 1px solid #ced4da; + border: 1px solid var(--form-control-border-color); border-radius: .25rem; transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out; -webkit-appearance: none; diff --git a/app/application_vars.css.erb b/app/application_vars.css.erb new file mode 100644 index 0000000..66e6151 --- /dev/null +++ b/app/application_vars.css.erb @@ -0,0 +1,31 @@ +<% unless color_scheme == :dark %> + .ultra-settings-configuration { + --table-header-bg-color: #fff; + --table-border-color: #dee2e6; + --alt-row-color: rgba(0, 0, 0, .05); + --form-control-color: #495057; + --form-control-bg-color: #fff; + --form-control-border-color: #ced4da; + --code-color: darkred; + --em-color: gray; + } +<% end %> + +<% if color_scheme == :system %> + @media (prefers-color-scheme: dark) { +<% end %> +<% if color_scheme == :system || color_scheme == :dark %> + .ultra-settings-configuration { + --table-header-bg-color: #333; + --table-border-color: #555; + --alt-row-color: rgba(0, 0, 0, .30); + --form-control-color: #eee; + --form-control-bg-color: #666; + --form-control-border-color: #555; + --code-color: pink; + --em-color: #999; + } +<% end %> +<% if color_scheme == :system %> + } +<% end %> diff --git a/app/layout.css b/app/layout.css index 5035f86..a56a8e3 100644 --- a/app/layout.css +++ b/app/layout.css @@ -1,12 +1,14 @@ -* {box-sizing:border-box;} +* { + box-sizing:border-box; +} body { font-family: sans-serif; font-size: 1rem; line-height: 1.5; text-align: left; - color: #212529; - background-color: #ffffff; + color: var(--text-color); + background-color: var(--background-color); margin: 0; padding: 0; } diff --git a/app/layout.html.erb b/app/layout.html.erb index 4a38e90..b65d952 100644 --- a/app/layout.html.erb +++ b/app/layout.html.erb @@ -5,6 +5,7 @@ Application Configuration +