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
#template
Class Method Summary
collapse
Instance Method Summary
collapse
#initialize, #theme
#set_slots, #slot_block_for, #slot_kwargs_for, #slot_renderable?
#labelled_aria
#merge_html_options
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
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
|
#render ⇒ Object
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: , 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: , **kwargs, &block
)
end
end
|