Class: PhlexKit::SheetContent

Inherits:
BaseComponent show all
Defined in:
app/components/phlex_kit/sheet/sheet_content.rb

Constant Summary collapse

SIDES =
{ top: "top", right: "right", bottom: "bottom", left: "left" }.freeze

Instance Method Summary collapse

Methods inherited from BaseComponent

#on

Constructor Details

#initialize(side: :right, show_close_button: true, **attrs) ⇒ SheetContent

Returns a new instance of SheetContent.



5
6
7
8
9
# File 'app/components/phlex_kit/sheet/sheet_content.rb', line 5

def initialize(side: :right, show_close_button: true, **attrs)
  @side = side.to_sym
  @show_close_button = show_close_button
  @attrs = attrs
end

Instance Method Details

#view_template(&block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/components/phlex_kit/sheet/sheet_content.rb', line 10

def view_template(&block)
  template(data: { phlex_kit__sheet_target: "content" }) do
    div(data: { controller: "phlex-kit--sheet-content", action: "keydown->phlex-kit--sheet-content#keydown" }) do
      div(class: "pk-sheet-backdrop", data: { action: "click->phlex-kit--sheet-content#close" })
      div(**mix({ class: [ "pk-sheet-content", fetch_option(SIDES, @side, :side) ].join(" "), role: "dialog", aria: { modal: "true" }, tabindex: "-1", data: { phlex_kit__sheet_content_target: "panel" } }, @attrs)) do
        block&.call
        if @show_close_button
          button(type: "button", class: "pk-overlay-close", data: { action: "click->phlex-kit--sheet-content#close" }) do
            render Icon.new(:x, size: 15)
            span(class: "pk-sr-only") { "Close" }
          end
        end
      end
    end
  end
end