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



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

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

Instance Method Details

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

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
# File 'lib/stimulus_plumbers/components/popover.rb', line 18

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])
end

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



45
46
47
# File 'lib/stimulus_plumbers/components/popover.rb', line 45

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

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



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

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

#renderObject



14
15
16
# File 'lib/stimulus_plumbers/components/popover.rb', line 14

def render(...)
  render_popover(...)
end

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/stimulus_plumbers/components/popover.rb', line 26

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