diff options
Diffstat (limited to 'app/helpers/icons_helper.rb')
-rw-r--r-- | app/helpers/icons_helper.rb | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index add15cc0d12..9957d5c6330 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -6,6 +6,8 @@ module IconsHelper extend self include FontAwesome::Rails::IconHelper + DEFAULT_ICON_SIZE = 16 + # Creates an icon tag given icon name(s) and possible icon modifiers. # # Right now this method simply delegates directly to `fa_icon` from the @@ -21,7 +23,7 @@ module IconsHelper options.include?(:base) ? fa_stacked_icon(names, options) : fa_icon(names, options) end - def custom_icon(icon_name, size: 16) + def custom_icon(icon_name, size: DEFAULT_ICON_SIZE) # We can't simply do the below, because there are some .erb SVGs. # File.read(Rails.root.join("app/views/shared/icons/_#{icon_name}.svg")).html_safe render "shared/icons/#{icon_name}.svg", size: size @@ -43,7 +45,7 @@ module IconsHelper ActionController::Base.helpers.image_path('file_icons.svg', host: sprite_base_url) end - def sprite_icon(icon_name, size: nil, css_class: nil) + def sprite_icon(icon_name, size: DEFAULT_ICON_SIZE, css_class: nil) if known_sprites&.exclude?(icon_name) exception = ArgumentError.new("#{icon_name} is not a known icon in @gitlab-org/gitlab-svg") Gitlab::ErrorTracking.track_and_raise_for_dev_exception(exception) @@ -52,7 +54,13 @@ module IconsHelper css_classes = [] css_classes << "s#{size}" if size css_classes << "#{css_class}" unless css_class.blank? - content_tag(:svg, content_tag(:use, "", { "xlink:href" => "#{sprite_icon_path}##{icon_name}" } ), class: css_classes.empty? ? nil : css_classes.join(' ')) + + content_tag( + :svg, + content_tag(:use, '', { 'xlink:href' => "#{sprite_icon_path}##{icon_name}" } ), + class: css_classes.empty? ? nil : css_classes.join(' '), + data: { testid: "#{icon_name}-icon" } + ) end def loading_icon(container: false, color: 'orange', size: 'sm', css_class: nil) @@ -94,11 +102,11 @@ module IconsHelper if value icon('circle', class: 'cgreen') else - icon('power-off', class: 'clgray') + sprite_icon('power', css_class: 'clgray') end end - def visibility_level_icon(level, fw: true, options: {}) + def visibility_level_icon(level, options: {}) name = case level when Gitlab::VisibilityLevel::PRIVATE @@ -106,13 +114,12 @@ module IconsHelper when Gitlab::VisibilityLevel::INTERNAL 'shield' else # Gitlab::VisibilityLevel::PUBLIC - 'globe' + 'earth' end - name = [name] - name << "fw" if fw + css_class = options.delete(:class) - icon(name.join(' '), options) + sprite_icon(name, size: DEFAULT_ICON_SIZE, css_class: css_class) end def file_type_icon_class(type, mode, name) |