rails_heroicon 2.0.2 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@ require "action_view"
2
2
 
3
3
  module RailsHeroicon
4
4
  module Helper
5
+ include ActionView::Helpers::TagHelper
5
6
  # To add a heroicon, call <tt><%= heroicon "icon_name" %></tt> on your erb template.
6
7
  # Head over to https://heroicons.com to view all the icons.
7
8
  #
@@ -9,7 +10,7 @@ module RailsHeroicon
9
10
  # The helper method accepts mutiple arguments such as:
10
11
  #
11
12
  # === Variant
12
- # There are two types of variants: 'outline' and 'solid', the default being the 'outline'.
13
+ # There are three types of variants: 'outline', 'solid' and 'mini', the default being the 'outline'.
13
14
  # To specify the solid variant, call <tt><%= heroicon "icon_name", variant: "solid" %></tt>
14
15
  #
15
16
  # === HTML attributes
@@ -25,9 +26,9 @@ module RailsHeroicon
25
26
  #
26
27
  # This will set the <tt>height</tt> and <tt>width</tt> attribute on the svg.
27
28
  #
28
- # If the variant is set as <tt>outline</tt>, size automatically defaults to 24, and if the variant is set as
29
- # <tt>solid</tt>, size automatically defaults to 20. However, this can be over-written with the <tt>size</tt>
30
- # attribute.
29
+ # If the variant is set as <tt>outline</tt> or <tt>solid</tt>, size automatically defaults to 24,
30
+ # and if the variant is set as <tt>mini</tt>, size automatically defaults to 20.
31
+ # However, this can be over-written with the <tt>size</tt> attribute.
31
32
  #
32
33
  # == Accessibility
33
34
  # The helper method automatically sets <tt>aria-hidden=true</tt> if <tt>aria-label</tt> is not set, and
@@ -11,11 +11,9 @@ module RailsHeroicon
11
11
 
12
12
  @icon = icon.to_s
13
13
  @variant = variant.to_s
14
- @options = options
14
+ @options = options.dup
15
15
  @size = icon_size_with(size)
16
-
17
- @options.merge!(a11y)
18
- @options.merge!(misc)
16
+ @options.merge!(svg_properties)
19
17
  end
20
18
 
21
19
  # Finds the svg icon with respect to variant.
@@ -28,30 +26,24 @@ module RailsHeroicon
28
26
 
29
27
  private
30
28
 
31
- def a11y
32
- accessible = {}
29
+ def svg_properties
30
+ properties = {}
31
+
32
+ properties[:viewBox] = mini? ? "0 0 20 20" : "0 0 24 24"
33
+ properties[:height] = @size
34
+ properties[:width] = @size
35
+ properties[:version] = "1.1"
36
+ properties[:fill] = outline? ? "none" : "currentColor"
37
+ properties[:stroke] = outline? ? "currentColor" : "none"
38
+ properties[:"stroke-width"] = "1.5" if outline?
33
39
 
34
- if @options[:"aria-label"].nil? && @options["aria-label"].nil? && @options.dig(:aria, :label).nil?
35
- accessible[:"aria-hidden"] = "true"
40
+ if options[:"aria-label"].nil? && options["aria-label"].nil? && options.dig(:aria, :label).nil?
41
+ properties[:"aria-hidden"] = "true"
36
42
  else
37
- accessible[:role] = "img"
43
+ properties[:role] = "img"
38
44
  end
39
45
 
40
- accessible
41
- end
42
-
43
- def misc
44
- hash = {}
45
-
46
- hash[:viewBox] = mini? ? "0 0 20 20" : "0 0 24 24"
47
- hash[:height] = @size
48
- hash[:width] = @size
49
- hash[:version] = "1.1"
50
- hash[:fill] = outline? ? "none" : "currentColor"
51
- hash[:stroke] = outline? ? "currentColor" : "none"
52
- hash[:"stroke-width"] = "1.5" if outline?
53
-
54
- hash
46
+ properties
55
47
  end
56
48
 
57
49
  # If the user has explicitly stated the size attribute, then use that. If size attribute is not passed
@@ -1,3 +1,3 @@
1
1
  module RailsHeroicon
2
- VERSION = "2.0.2".freeze
2
+ VERSION = "2.1.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_heroicon
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - abeidahmed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-04 00:00:00.000000000 Z
11
+ date: 2022-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview