Class: SdrViewComponents::Elements::IconButtonComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/sdr_view_components/elements/icon_button_component.rb

Overview

Component for a button which is an icon

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

#args_for, #merge_actions, #merge_classes

Constructor Details

#initialize(icon:, label:, classes: [], **options) ⇒ IconButtonComponent

Returns a new instance of IconButtonComponent.



7
8
9
10
11
12
13
# File 'app/components/sdr_view_components/elements/icon_button_component.rb', line 7

def initialize(icon:, label:, classes: [], **options)
  @icon = icon
  @label = label
  @classes = classes
  @options = options
  super()
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



19
20
21
# File 'app/components/sdr_view_components/elements/icon_button_component.rb', line 19

def label
  @label
end

#optionsObject (readonly)

Returns the value of attribute options.



19
20
21
# File 'app/components/sdr_view_components/elements/icon_button_component.rb', line 19

def options
  @options
end

Instance Method Details

#before_renderObject



15
16
17
# File 'app/components/sdr_view_components/elements/icon_button_component.rb', line 15

def before_render
  raise SdrViewComponents::Error::UnknownComponentIcon, "Unknown icon type: #{@icon}" unless button_icon?
end

#button_iconObject



25
26
27
# File 'app/components/sdr_view_components/elements/icon_button_component.rb', line 25

def button_icon
  helpers.public_send(:"#{@icon}_icon")
end

#classesObject



21
22
23
# File 'app/components/sdr_view_components/elements/icon_button_component.rb', line 21

def classes
  merge_classes(%w[border border-0], @classes)
end