Class: HeroiconsHelper::Icon

Inherits:
Object
  • Object
show all
Defined in:
lib/heroicons_helper/icon.rb

Overview

Icon to show heroicons by name and variant.

Constant Summary collapse

VARIANT_OUTLINE =
"outline"
VARIANT_SOLID =
"solid"
VARIANT_MINI =
"mini"
VARIANT_MICRO =
"micro"
VALID_VARIANTS =
Set.new([VARIANT_OUTLINE, VARIANT_SOLID, VARIANT_MINI, VARIANT_MICRO]).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, variant, size: nil, attributes: {}) ⇒ Icon

Returns a new instance of Icon.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/heroicons_helper/icon.rb', line 17

def initialize(name, variant, size: nil, attributes: {})
  @name = name.to_s
  @variant = variant.to_s

  heroicon = get_heroicon(@name, @variant)

  @inner = heroicon["inner"]
  @width = size || heroicon["width"]
  @height = size || heroicon["height"]
  @keywords = heroicon["keywords"]
  @attributes = attributes.merge(heroicon["attributes"])
  @attributes.merge!({
    "class" => classes,
    "viewBox" => viewbox,
    "version" => "1.1",
  })
    .merge!(a11y)
    .compact!
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



9
10
11
# File 'lib/heroicons_helper/icon.rb', line 9

def attributes
  @attributes
end

#heightObject (readonly)

Returns the value of attribute height.



9
10
11
# File 'lib/heroicons_helper/icon.rb', line 9

def height
  @height
end

#innerObject (readonly)

Returns the value of attribute inner.



9
10
11
# File 'lib/heroicons_helper/icon.rb', line 9

def inner
  @inner
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



9
10
11
# File 'lib/heroicons_helper/icon.rb', line 9

def keywords
  @keywords
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/heroicons_helper/icon.rb', line 9

def name
  @name
end

#variantObject (readonly)

Returns the value of attribute variant.



9
10
11
# File 'lib/heroicons_helper/icon.rb', line 9

def variant
  @variant
end

#widthObject (readonly)

Returns the value of attribute width.



9
10
11
# File 'lib/heroicons_helper/icon.rb', line 9

def width
  @width
end

Instance Method Details

#to_svgObject

Returns an string representing a <svg> tag



38
39
40
# File 'lib/heroicons_helper/icon.rb', line 38

def to_svg
  "<svg #{html_attributes}>#{@inner}</svg>"
end