Class: UI::DialogTrigger

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

Instance Method Summary collapse

Methods included from SharedAsChildBehavior

#merge_attributes

Constructor Details

#initialize(as_child: false, variant: :outline, size: :default, classes: nil, **attributes) ⇒ DialogTrigger

Returns a new instance of DialogTrigger.

Parameters:

  • as_child (Boolean) (defaults to: false)

    When true, yields attributes to block instead of rendering button

  • variant (Symbol) (defaults to: :outline)

    Button variant (when not using as_child)

  • size (Symbol) (defaults to: :default)

    Button size (when not using as_child)

  • classes (String) (defaults to: nil)

    Additional CSS classes

  • attributes (Hash)

    Additional HTML attributes



11
12
13
14
15
16
17
# File 'app/components/ui/dialog_trigger.rb', line 11

def initialize(as_child: false, variant: :outline, size: :default, classes: nil, **attributes)
  @as_child = as_child
  @variant = variant
  @size = size
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#view_template(&block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/ui/dialog_trigger.rb', line 19

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 component
    render UI::Button.new(
      variant: @variant,
      size: @size,
      classes: @classes,
      **trigger_attrs
    ), &block
  end
end