Class: IconButton::Component

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

Constant Summary collapse

ICON_SIZES =
{
  xs: 3,
  sm: 3.5,
  md: 4,
  lg: 6
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, icon: nil, tooltip: nil, disabled: false, size: :md, href: nil, **html_attrs) ⇒ Component

Returns a new instance of Component.



14
15
16
17
18
19
20
21
22
# File 'app/components/lookbook/icon_button/component.rb', line 14

def initialize(id: nil, icon: nil, tooltip: nil, disabled: false, size: :md, href: nil, **html_attrs)
  @id = id
  @icon = icon
  @tooltip = tooltip
  @disabled = disabled
  @size = size
  @href = href
  super(**html_attrs)
end

Instance Attribute Details

#disabledObject (readonly)

Returns the value of attribute disabled.



12
13
14
# File 'app/components/lookbook/icon_button/component.rb', line 12

def disabled
  @disabled
end

#hrefObject (readonly)

Returns the value of attribute href.



12
13
14
# File 'app/components/lookbook/icon_button/component.rb', line 12

def href
  @href
end

#iconObject (readonly)

Returns the value of attribute icon.



12
13
14
# File 'app/components/lookbook/icon_button/component.rb', line 12

def icon
  @icon
end

#sizeObject (readonly)

Returns the value of attribute size.



12
13
14
# File 'app/components/lookbook/icon_button/component.rb', line 12

def size
  @size
end

#tooltipObject (readonly)

Returns the value of attribute tooltip.



12
13
14
# File 'app/components/lookbook/icon_button/component.rb', line 12

def tooltip
  @tooltip
end

Instance Method Details

#icon_sizeObject



28
29
30
# File 'app/components/lookbook/icon_button/component.rb', line 28

def icon_size
  ICON_SIZES[size]
end

#idObject



24
25
26
# File 'app/components/lookbook/icon_button/component.rb', line 24

def id
  @id ||= Utils.temp_id(prefix: "button")
end

#paddingObject



32
33
34
# File 'app/components/lookbook/icon_button/component.rb', line 32

def padding
  [:xs, :sm].include?(size) ? "p-1" : "p-2"
end

#tag_nameObject



36
37
38
# File 'app/components/lookbook/icon_button/component.rb', line 36

def tag_name
  href.present? ? :a : :button
end