Class: UI::SheetComponent

Inherits:
ViewComponent::Base
  • Object
show all
Includes:
SheetBehavior
Defined in:
app/view_components/ui/sheet_component.rb

Overview

Sheet container component (ViewComponent) A panel that slides in from the edge of the screen

Examples:

Basic usage

<%= render UI::SheetComponent.new do %>
  <%= render UI::TriggerComponent.new { "Open Sheet" } %>
  <%= render UI::OverlayComponent.new do %>
    <%= render UI::ContentComponent.new do %>
      <%= render UI::HeaderComponent.new do %>
        <%= render UI::TitleComponent.new { "Sheet Title" } %>
        <%= render UI::DescriptionComponent.new { "Sheet description" } %>
      <% end %>
      <!-- Content -->
      <%= render UI::FooterComponent.new do %>
        <%= render UI::CloseComponent.new { "Cancel" } %>
      <% end %>
    <% end %>
  <% end %>
<% end %>

Instance Method Summary collapse

Methods included from SheetBehavior

#merged_sheet_data_attributes, #sheet_base_classes, #sheet_classes, #sheet_data_attributes, #sheet_html_attributes

Constructor Details

#initialize(open: false, close_on_escape: true, close_on_overlay_click: true, classes: "", **attributes) ⇒ SheetComponent

Returns a new instance of SheetComponent.

Parameters:

  • open (Boolean) (defaults to: false)

    whether the sheet is open

  • close_on_escape (Boolean) (defaults to: true)

    close on Escape key press

  • close_on_overlay_click (Boolean) (defaults to: true)

    close on overlay click

  • classes (String) (defaults to: "")

    additional CSS classes

  • attributes (Hash)

    additional HTML attributes



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/view_components/ui/sheet_component.rb', line 30

def initialize(
  open: false,
  close_on_escape: true,
  close_on_overlay_click: true,
  classes: "",
  **attributes
)
  @open = open
  @close_on_escape = close_on_escape
  @close_on_overlay_click = close_on_overlay_click
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



44
45
46
47
48
49
# File 'app/view_components/ui/sheet_component.rb', line 44

def call
  attrs = sheet_html_attributes
  attrs[:data] = attrs[:data].merge(@attributes.fetch(:data, {}))

   :div, content, **attrs.merge(@attributes.except(:data))
end