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
module LazyImageTagHelper
include PreferencesHelper
def placeholder_image
"data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
end
# Override the default ActionView `image_tag` helper to support lazy-loading
def image_tag(source, options = {})
source = options[:dark_variant] if options[:dark_variant] && user_application_dark_mode?
options = options.symbolize_keys
unless options.delete(:lazy) == false
......
......@@ -62,6 +62,10 @@ module PreferencesHelper
@user_application_theme ||= Gitlab::Themes.for_user(current_user).css_class
end
def user_application_dark_mode?
user_application_theme == 'gl-dark'
end
def user_application_theme_css_filename
@user_application_theme_css_filename ||= Gitlab::Themes.for_user(current_user).css_filename
end
......
......@@ -96,6 +96,30 @@ RSpec.describe PreferencesHelper do
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
context 'with a user' 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