-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add theme support to the SolidusAdmin UI with dark and dimmed variants
- Save the user preference alongside the system preference so that when the system switches the UI will follow along. - Use the session to store preferences so that we start the page with the correct theme(s). - Keep the current theme in the select tag up to date at page load and whenever the system changes. Add dark and dimmed theme variants dark: Full black background with no alteration on images. dimmed: Dark gray background with dimmed images, easier on the eyes but less accurate colors.
- Loading branch information
Showing
8 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* = require solidus_admin/tailwind.css | ||
*/ | ||
|
||
html { | ||
-webkit-filter: invert(100%); | ||
filter: invert(100%) hue-rotate(180deg); | ||
} | ||
|
||
main img { | ||
filter: invert(100%) hue-rotate(-180deg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* = require solidus_admin/tailwind.css | ||
*/ | ||
|
||
html { | ||
filter: invert(91%) hue-rotate(180deg); | ||
} | ||
|
||
main img { | ||
filter: invert(91%) brightness(1.5) contrast(1.5) hue-rotate(-180deg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
admin/app/controllers/solidus_admin/controller_helpers/theme.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin::ControllerHelpers::Theme | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
before_action :update_user_theme | ||
end | ||
|
||
private | ||
|
||
def update_user_theme | ||
requested_theme = params[:switch_to_theme].presence or return | ||
|
||
# Avoid interpolating user content into the session key | ||
system_theme = params[:system_theme].presence == "dark" ? "dark" : "light" | ||
session_key = :"admin_#{system_theme}_theme" | ||
|
||
if theme_is_available?(requested_theme) && requested_theme.to_sym != session[session_key] | ||
session[session_key] = requested_theme | ||
|
||
flash[:notice] = t('spree.theme_changed') | ||
redirect_back_or_to(params.except(:switch_to_theme, :system_theme).permit!.to_h.merge(account_menu_open: true)) | ||
end | ||
end | ||
|
||
def theme_is_available?(theme) | ||
theme && SolidusAdmin::Config.themes.key?(theme.to_sym) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters