Class: PhlexKit::DialogContent

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/dialog/dialog_content.rb

Overview

The

box. size: picks the width tier (md = shadcn's default max-w-sm); show_close_button: false drops the top-right ✕ (their showCloseButton). See dialog.rb.

Constant Summary collapse

SIZES =
{ xs: "xs", sm: "sm", md: nil, lg: "lg", xl: "xl", full: "full" }.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(size: :md, show_close_button: true, **attrs) ⇒ DialogContent

Returns a new instance of DialogContent.



8
9
10
11
12
# File 'app/components/phlex_kit/dialog/dialog_content.rb', line 8

def initialize(size: :md, show_close_button: true, **attrs)
  @size = size.to_sym
  @show_close_button = show_close_button
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/components/phlex_kit/dialog/dialog_content.rb', line 14

def view_template(&block)
  cls = [ "pk-dialog", SIZES.fetch(@size) ].compact.join(" ")
  dialog(**mix({ class: cls, data: { phlex_kit__dialog_target: "dialog", action: "click->phlex-kit--dialog#backdropClick" } }, @attrs)) do
    yield
    if @show_close_button
      button(type: "button", class: "pk-overlay-close", data: { action: "click->phlex-kit--dialog#dismiss" }) do
        render Icon.new(:x, size: 15)
        span(class: "pk-sr-only") { "Close" }
      end
    end
  end
end