Class: UI::PopoverTrigger

Inherits:
Phlex::HTML
  • Object
show all
Includes:
PopoverTriggerBehavior
Defined in:
app/components/ui/popover_trigger.rb

Overview

Trigger - Phlex implementation

Button or element that triggers the popover. Uses PopoverTriggerBehavior concern for shared styling logic.

Examples:

Basic usage

render UI::Trigger.new do
  button { "Click me" }
end

Instance Method Summary collapse

Methods included from PopoverTriggerBehavior

#popover_trigger_classes, #popover_trigger_html_attributes

Constructor Details

#initialize(as_child: false, classes: "", **attributes) ⇒ PopoverTrigger

Returns a new instance of PopoverTrigger.

Parameters:

  • as_child (Boolean) (defaults to: false)

    If true, adds data attributes to child without wrapper

  • classes (String) (defaults to: "")

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



18
19
20
21
22
# File 'app/components/ui/popover_trigger.rb', line 18

def initialize(as_child: false, classes: "", **attributes)
  @as_child = as_child
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/components/ui/popover_trigger.rb', line 24

def view_template(&block)
  trigger_attrs = popover_trigger_html_attributes.deep_merge(@attributes)

  if @as_child
    # asChild mode: yield attributes to block
    # The caller is responsible for rendering an element with these attributes
    yield(trigger_attrs) if block_given?
  else
    # Default mode: render as div
    div(**trigger_attrs, &block)
  end
end