Class: UI::SheetClose

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

Instance Method Summary collapse

Methods included from SharedAsChildBehavior

#merge_attributes

Constructor Details

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

Returns a new instance of SheetClose.

Parameters:

  • as_child (Boolean) (defaults to: false)

    When true, yields attributes to block instead of rendering button

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

    Button variant (passed to Button component when not using asChild)

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

    Button size (passed to Button component when not using asChild)

  • classes (String) (defaults to: nil)

    Additional CSS classes



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

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



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

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

  if @as_child
    # Yield attributes to block - child must accept and use them
    yield(close_attrs) if block_given?
  else
    # Default: render as Button component
    render UI::Button.new(
      variant: @variant,
      size: @size,
      classes: @classes,
      **close_attrs
    ) do
      yield if block_given?
    end
  end
end