Commit 36e79a9d authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'slashmanov/add-dark-mode-support-to-image-tag' into 'master'

Add Dark Mode support to the image_tag helper

See merge request gitlab-org/gitlab!81219
parents 4ee9f1dd c6fde03a
# frozen_string_literal: true # frozen_string_literal: true
module LazyImageTagHelper module LazyImageTagHelper
include PreferencesHelper
def placeholder_image def placeholder_image
"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
end end
# Override the default ActionView `image_tag` helper to support lazy-loading # Override the default ActionView `image_tag` helper to support lazy-loading
def image_tag(source, options = {}) def image_tag(source, options = {})
source = options[:dark_variant] if options[:dark_variant] && user_application_dark_mode?
options = options.symbolize_keys options = options.symbolize_keys
unless options.delete(:lazy) == false unless options.delete(:lazy) == false
......
...@@ -62,6 +62,10 @@ module PreferencesHelper ...@@ -62,6 +62,10 @@ module PreferencesHelper
@user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class @user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class
end end
def user_application_dark_mode?
user_application_theme == 'gl-dark'
end
def user_application_theme_css_filename def user_application_theme_css_filename
@user_application_theme_css_filename ||= Gitlab::Themes.for_user(current_user).css_filename @user_application_theme_css_filename ||= Gitlab::Themes.for_user(current_user).css_filename
end end
......
...@@ -96,6 +96,30 @@ RSpec.describe PreferencesHelper do ...@@ -96,6 +96,30 @@ RSpec.describe PreferencesHelper do
end end
end end
describe '#user_application_dark_mode?' do
context 'with a user' do
it "returns true if user's selected dark theme" do
stub_user(theme_id: 11)
expect(helper.user_application_dark_mode?).to eq true
end
it "returns false if user's selected any light theme" do
stub_user(theme_id: 1)
expect(helper.user_application_dark_mode?).to eq false
end
end
context 'without a user' do
it 'returns false' do
stub_user
expect(helper.user_application_dark_mode?).to eq false
end
end
end
describe '#user_color_scheme' do describe '#user_color_scheme' do
context 'with a user' do context 'with a user' do
it "returns user's scheme's css_class" do it "returns user's scheme's css_class" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment