Class: UI::SheetOverlayComponent

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

Overview

Sheet overlay component (ViewComponent) Container and backdrop for sheet

Examples:

<%= render UI::OverlayComponent.new do %>
  <%= render UI::ContentComponent.new do %>
    <!-- Content -->
  <% end %>
<% end %>

Instance Method Summary collapse

Methods included from SheetOverlayBehavior

#merged_sheet_overlay_container_data_attributes, #sheet_overlay_base_classes, #sheet_overlay_classes, #sheet_overlay_container_base_classes, #sheet_overlay_container_classes, #sheet_overlay_container_data_attributes, #sheet_overlay_container_html_attributes, #sheet_overlay_data_attributes, #sheet_overlay_html_attributes

Constructor Details

#initialize(open: false, classes: "", **attributes) ⇒ SheetOverlayComponent

Returns a new instance of SheetOverlayComponent.

Parameters:

  • open (Boolean) (defaults to: false)

    whether the sheet is open

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

    additional CSS classes

  • attributes (Hash)

    additional HTML attributes



18
19
20
21
22
# File 'app/view_components/ui/sheet_overlay_component.rb', line 18

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

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/view_components/ui/sheet_overlay_component.rb', line 24

def call
  container_attrs = sheet_overlay_container_html_attributes
  container_attrs[:data] = container_attrs[:data].merge(@attributes.fetch(:data, {}))
  overlay_attrs = sheet_overlay_html_attributes

   :div, **container_attrs.merge(@attributes.except(:data)) do
    safe_join([
      (:div, "", **overlay_attrs),
      content
    ])
  end
end