Class: UI::SheetTrigger

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

Instance Method Summary collapse

Methods included from SharedAsChildBehavior

#merge_attributes

Constructor Details

#initialize(as_child: false, **attributes) ⇒ SheetTrigger

Returns a new instance of SheetTrigger.

Parameters:

  • as_child (Boolean) (defaults to: false)

    When true, yields attributes to block instead of rendering button

  • attributes (Hash)

    Additional HTML attributes



8
9
10
11
# File 'app/components/ui/sheet_trigger.rb', line 8

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

Instance Method Details

#view_template(&block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/components/ui/sheet_trigger.rb', line 13

def view_template(&block)
  trigger_attrs = {
    data: {action: "click->ui--dialog#open"},
    **@attributes
  }

  if @as_child
    # Yield attributes to block - child must accept and use them
    yield(trigger_attrs) if block_given?
  else
    # Default: render as button
    button(**trigger_attrs, &block)
  end
end