Class: Button::BaseComponent

Inherits:
SparkComponents::Component
  • Object
show all
Defined in:
app/components/spark/button/base_component.rb

Direct Known Subclasses

IconComponent, PrimaryComponent, TextComponent

Constant Summary collapse

COLORS =
i(blue green yellow red)
SIZES =
i(small base medium large)

Instance Method Summary collapse

Instance Method Details

#before_renderObject



15
16
17
18
19
20
21
# File 'app/components/spark/button/base_component.rb', line 15

def before_render
  add_class("size-#{size}") if size
  add_class("color-#{color}") if color
  if (href && (data_attr[:remote] || data_attr[:method]))
    root_attr rel: "nofollow"
  end
end

#button_contentObject



33
34
35
36
37
38
# File 'app/components/spark/button/base_component.rb', line 33

def button_content
  capture {
    concat component("ui/icon", name: icon) if icon
    concat tag.span(text || @yield, class: join_class(:label))
  }
end

#renderObject



23
24
25
26
27
28
29
30
31
# File 'app/components/spark/button/base_component.rb', line 23

def render
  (:div, class: join_class("wrapper")) do
    if href
      link_to(button_content, href, tag_attrs)
    else
      tag.button(button_content, tag_attrs)
    end
  end
end