Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 10:33:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 10:33:21 +0300
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /app/helpers/lazy_image_tag_helper.rb
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'app/helpers/lazy_image_tag_helper.rb')
-rw-r--r--app/helpers/lazy_image_tag_helper.rb26
1 files changed, 25 insertions, 1 deletions
diff --git a/app/helpers/lazy_image_tag_helper.rb b/app/helpers/lazy_image_tag_helper.rb
index d0bdaaae5f8..10d603ef5d3 100644
--- a/app/helpers/lazy_image_tag_helper.rb
+++ b/app/helpers/lazy_image_tag_helper.rb
@@ -8,8 +8,11 @@ module LazyImageTagHelper
end
# Override the default ActionView `image_tag` helper to support lazy-loading
+ # accept :auto_dark boolean to enable automatic dark variant of the image
+ # (see: https://gitlab.com/gitlab-org/gitlab-ui/-/merge_requests/2698)
+ # accept :dark_variant path to be used as a source when dark mode is enabled
def image_tag(source, options = {})
- source = options[:dark_variant] if options[:dark_variant] && user_application_dark_mode?
+ source, options = prepare_dark_variant(source, options)
options = options.symbolize_keys
unless options.delete(:lazy) == false
@@ -29,4 +32,25 @@ module LazyImageTagHelper
# Required for Banzai::Filter::ImageLazyLoadFilter
module_function :placeholder_image # rubocop: disable Style/AccessModifierDeclarations
+
+ private
+
+ def prepare_dark_variant(source, options)
+ dark_variant = options.delete(:dark_variant)
+ auto_dark = options.delete(:auto_dark)
+
+ if dark_variant && auto_dark
+ raise ArgumentError, "dark_variant and auto_dark are mutually exclusive"
+ end
+
+ if (auto_dark || dark_variant) && user_application_dark_mode?
+ if auto_dark
+ options[:class] = 'gl-dark-invert-keep-hue'
+ elsif dark_variant
+ source = dark_variant
+ end
+ end
+
+ [source, options]
+ end
end