Class: Primrose::Components::Button

Inherits:
Rose
  • Object
show all
Defined in:
lib/primrose/components/button.rb

Constant Summary collapse

TEMPLATE =
<<~ERB
  <button
    onclick="<%= @action %>"
    class="<%= @style %>"
    <%= 'disabled' if @disabled %>
    <%= 'loading' if @loading %>
    >
      <%= @label %>
  </button>
ERB

Instance Attribute Summary

Attributes inherited from Rose

#children, #event_handlers, #state

Instance Method Summary collapse

Methods inherited from Rose

#add_child, #get_binding, #handle_error, #lifecycle, #on, #render_children, #trigger

Constructor Details

#initialize(label:, action:, style: nil, disabled: false, loading: false) ⇒ Button

Returns a new instance of Button.



17
18
19
20
21
22
23
24
# File 'lib/primrose/components/button.rb', line 17

def initialize(label:, action:, style: nil, disabled: false, loading: false)
  @label = label
  @action = action
  @style = style
  @disabled = disabled
  @loading = loading
  super()
end

Instance Method Details

#renderObject



26
27
28
# File 'lib/primrose/components/button.rb', line 26

def render
  Prim.render(TEMPLATE, self)
end

#set_disabled(value) ⇒ Object



30
31
32
# File 'lib/primrose/components/button.rb', line 30

def set_disabled(value)
  @state.alter({ disabled: value })
end

#set_loading(value) ⇒ Object



34
35
36
# File 'lib/primrose/components/button.rb', line 34

def set_loading(value)
  @state.alter({ loading: value })
end