Class: Rolemodel::Optics::IconBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/rolemodel/optics/icon_builder.rb

Constant Summary collapse

DEFAULT_SIZE =
'medium'
DEFAULT_WEIGHT =
'normal'
DEFAULT_EMPHASIS =
'normal'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, filled: false, size: DEFAULT_SIZE, weight: DEFAULT_WEIGHT, emphasis: DEFAULT_EMPHASIS, duotone: false, additional_classes: '', color: '', hover_text: name) ⇒ IconBuilder

TODO: consider Data.define a custom options object if all of these parameters are indeed necessary.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rolemodel/optics/icon_builder.rb', line 14

def initialize( # rubocop:disable Metrics/ParameterLists
  name,
  filled: false,
  size: DEFAULT_SIZE,
  weight: DEFAULT_WEIGHT,
  emphasis: DEFAULT_EMPHASIS,
  duotone: false,
  additional_classes: '',
  color: '',
  hover_text: name
)
  @name = name
  @filled = filled
  @size = size
  @weight = weight
  @emphasis = emphasis
  @duotone = duotone
  @additional_classes = additional_classes
  @color = color
  @hover_text = hover_text
end

Instance Attribute Details

#additional_classesObject (readonly)

Returns the value of attribute additional_classes.



6
7
8
# File 'lib/rolemodel/optics/icon_builder.rb', line 6

def additional_classes
  @additional_classes
end

#colorObject (readonly)

Returns the value of attribute color.



6
7
8
# File 'lib/rolemodel/optics/icon_builder.rb', line 6

def color
  @color
end

#duotoneObject (readonly)

Returns the value of attribute duotone.



6
7
8
# File 'lib/rolemodel/optics/icon_builder.rb', line 6

def duotone
  @duotone
end

#emphasisObject (readonly)

Returns the value of attribute emphasis.



6
7
8
# File 'lib/rolemodel/optics/icon_builder.rb', line 6

def emphasis
  @emphasis
end

#filledObject (readonly)

Returns the value of attribute filled.



6
7
8
# File 'lib/rolemodel/optics/icon_builder.rb', line 6

def filled
  @filled
end

#hover_textObject (readonly) Also known as: title

Returns the value of attribute hover_text.



6
7
8
# File 'lib/rolemodel/optics/icon_builder.rb', line 6

def hover_text
  @hover_text
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rolemodel/optics/icon_builder.rb', line 6

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/rolemodel/optics/icon_builder.rb', line 6

def size
  @size
end

#weightObject (readonly)

Returns the value of attribute weight.



6
7
8
# File 'lib/rolemodel/optics/icon_builder.rb', line 6

def weight
  @weight
end

Class Method Details

.flash_icon(type) ⇒ Object



36
37
38
# File 'lib/rolemodel/optics/icon_builder.rb', line 36

def self.flash_icon(type, **)
  new(flash_icons[type.to_sym], **)
end

.flash_iconsObject

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/rolemodel/optics/icon_builder.rb', line 40

def self.flash_icons
  raise NotImplementedError
end

Instance Method Details

#buildObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/rolemodel/optics/icon_builder.rb', line 44

def build
  options = {
    class: tag_classes.compact_blank.join(' '),
    title: hover_text,
    # color: primary, neutral, alerts-notice, alerts-warning, alerts-danger, alerts-info
    style: ("#{color_attribute}: var(--op-color-#{color}-base);" if color.present?)
  }.compact_blank

  tag.public_send(tag_method, tag_contents, **options)
end