Class: Button::Component

Inherits:
Lookbook::BaseComponent
  • Object
show all
Defined in:
app/components/lookbook/button/component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, icon: nil, **html_attrs) ⇒ Component

Returns a new instance of Component.



7
8
9
10
11
# File 'app/components/lookbook/button/component.rb', line 7

def initialize(id: nil, icon: nil, **html_attrs)
  @id = id
  @icon = icon
  @button_attrs = html_attrs
end

Instance Attribute Details

#button_attrsObject (readonly)

Returns the value of attribute button_attrs.



5
6
7
# File 'app/components/lookbook/button/component.rb', line 5

def button_attrs
  @button_attrs
end

#iconObject (readonly)

Returns the value of attribute icon.



5
6
7
# File 'app/components/lookbook/button/component.rb', line 5

def icon
  @icon
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'app/components/lookbook/button/component.rb', line 5

def id
  @id
end

Instance Method Details

#before_renderObject



25
26
27
28
29
# File 'app/components/lookbook/button/component.rb', line 25

def before_render
  if dropdown? && id.nil?
    raise "Dropdown buttons must be given an ID"
  end
end

#button_componentObject



31
32
33
# File 'app/components/lookbook/button/component.rb', line 31

def button_component
  icon_button? ? IconButton::Component : TextButton::Component
end

Returns:

  • (Boolean)


13
14
15
# File 'app/components/lookbook/button/component.rb', line 13

def dropdown?
  dropdown.present?
end

#icon_button?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'app/components/lookbook/button/component.rb', line 21

def icon_button?
  !text_button? && icon
end

#text_button?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'app/components/lookbook/button/component.rb', line 17

def text_button?
  content.present?
end