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:
Diffstat (limited to 'app/helpers/badges_helper.rb')
-rw-r--r--app/helpers/badges_helper.rb66
1 files changed, 8 insertions, 58 deletions
diff --git a/app/helpers/badges_helper.rb b/app/helpers/badges_helper.rb
index d48eae26a90..069c15433a5 100644
--- a/app/helpers/badges_helper.rb
+++ b/app/helpers/badges_helper.rb
@@ -1,25 +1,6 @@
# frozen_string_literal: true
module BadgesHelper
- VARIANT_CLASSES = {
- muted: "badge-muted",
- neutral: "badge-neutral",
- info: "badge-info",
- success: "badge-success",
- warning: "badge-warning",
- danger: "badge-danger"
- }.tap { |hash| hash.default = hash.fetch(:muted) }.freeze
-
- SIZE_CLASSES = {
- sm: "sm",
- md: "md",
- lg: "lg"
- }.tap { |hash| hash.default = hash.fetch(:md) }.freeze
-
- GL_BADGE_CLASSES = %w[gl-badge badge badge-pill].freeze
-
- GL_ICON_CLASSES = %w[gl-icon gl-badge-icon].freeze
-
# Creates a GitLab UI badge.
#
# Examples:
@@ -53,47 +34,16 @@ module BadgesHelper
#
# See also https://gitlab-org.gitlab.io/gitlab-ui/?path=/story/base-badge--default.
def gl_badge_tag(*args, &block)
+ # Merge the options and html_options hashes if both are present,
+ # because the badge component wants a flat list of keyword args.
+ args.compact!
+ hashes, params = args.partition { |a| a.is_a? Hash }
+ options_hash = hashes.reduce({}, :merge)
+
if block
- build_gl_badge_tag(capture(&block), *args)
+ render Pajamas::BadgeComponent.new(**options_hash), &block
else
- build_gl_badge_tag(*args)
+ render Pajamas::BadgeComponent.new(*params, **options_hash)
end
end
-
- private
-
- def build_gl_badge_tag(content, options = nil, html_options = nil)
- options ||= {}
- html_options ||= {}
-
- icon_only = options[:icon_only]
- variant_class = VARIANT_CLASSES[options.fetch(:variant, :muted)]
- size_class = SIZE_CLASSES[options.fetch(:size, :md)]
- icon_classes = GL_ICON_CLASSES.dup << options.fetch(:icon_classes, nil)
-
- html_options = html_options.merge(
- class: [
- *GL_BADGE_CLASSES,
- variant_class,
- size_class,
- *html_options[:class]
- ]
- )
-
- if icon_only
- html_options['aria-label'] = content
- html_options['role'] = 'img'
- end
-
- if options[:icon]
- icon_classes << "gl-mr-2" unless icon_only
- icon = sprite_icon(options[:icon], css_class: icon_classes.join(' '))
-
- content = icon_only ? icon : icon + content
- end
-
- tag = html_options[:href].nil? ? :span : :a
-
- content_tag(tag, content, html_options)
- end
end