Class: StimulusPlumbers::Components::Popover

Inherits:
Plumber::Base show all
Defined in:
lib/stimulus_plumbers/components/popover.rb,
lib/stimulus_plumbers/components/popover/panel.rb,
lib/stimulus_plumbers/components/popover/trigger.rb

Defined Under Namespace

Classes: Panel, Trigger

Constant Summary collapse

STIMULUS_CONTROLLER =
"popover"

Instance Attribute Summary

Attributes inherited from Plumber::Base

#template

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Plumber::Base

#initialize, #theme

Methods included from Plumber::Renderer

#set_slots, #slot_block_for, #slot_kwargs_for, #slot_renderable?

Methods included from Plumber::Options::Aria

#labelled_aria

Methods included from Plumber::Options::Html

#merge_html_options

Constructor Details

This class inherits a constructor from StimulusPlumbers::Plumber::Base

Class Method Details

.panel_id_for(trigger_id) ⇒ Object



8
9
10
# File 'lib/stimulus_plumbers/components/popover.rb', line 8

def self.panel_id_for(trigger_id)
  [trigger_id, "popover"].compact.join("_")
end

Instance Method Details

#build(panel_id: nil) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



14
15
16
17
18
19
20
# File 'lib/stimulus_plumbers/components/popover.rb', line 14

def build(panel_id: nil, &block)
  @panel_id     = panel_id || self.class.panel_id_for(template.sp_dom_id)
  @trigger_html = nil
  @panel_html   = nil
  yield self
  template.safe_join([@trigger_html, @panel_html].compact)
end

#build_panel(**kwargs, &block) ⇒ Object



41
42
43
# File 'lib/stimulus_plumbers/components/popover.rb', line 41

def build_panel(**kwargs, &block)
  @panel_html = Popover::Panel.new(template).build(panel_id: @panel_id, **kwargs, &block)
end

#panel(**kwargs, &block) ⇒ Object



37
38
39
# File 'lib/stimulus_plumbers/components/popover.rb', line 37

def panel(**kwargs, &block)
  @panel_html = Popover::Panel.new(template).render(panel_id: @panel_id, **kwargs, &block)
end

#renderObject



12
# File 'lib/stimulus_plumbers/components/popover.rb', line 12

def render(...) = render_popover(...)

#trigger(haspopup: "dialog", controls: @panel_id, **kwargs, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/stimulus_plumbers/components/popover.rb', line 22

def trigger(haspopup: "dialog", controls: @panel_id, **kwargs, &block)
  if block_given? && block.arity == 1
    attrs = {
      panel_id: @panel_id,
      aria:     { haspopup: haspopup, expanded: "false", controls: controls },
      data:     { popover_target: "trigger", action: Popover::Trigger::STIMULUS_ACTION }
    }
    @trigger_html = template.capture(attrs, &block)
  else
    @trigger_html = Popover::Trigger.new(template).render(
      panel_id: @panel_id, haspopup: haspopup, **kwargs, &block
    )
  end
end