Class: Primrose::Components::Modal

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

Constant Summary collapse

TEMPLATE =
<<~ERB
  <% if @is_open %>
    <label for="modal-<%= @name %>"><%= @label %></label>
    <div class="modal <%= @style_class %>">
      <div class="modal-content">
        <%= @content %>
      </div>
    </div>
  <% end %>
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(content:, is_open: false, name: nil, label: nil, style_class: nil) ⇒ Modal

Returns a new instance of Modal.



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

def initialize(content:, is_open: false, name: nil, label: nil, style_class: nil)
  @content = content
  @is_open = is_open
  @name = name
  @label = label
  @style_class = style_class
  super()
end

Instance Method Details

#closeObject



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

def close
  @is_open = false
end

#openObject



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

def open
  @is_open = true
end

#renderObject



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

def render
  Prim.render(TEMPLATE, self)
end