Class: UI::PopoverContentComponent

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

Overview

ContentComponent - ViewComponent implementation

The floating content panel. Uses PopoverContentBehavior concern for shared styling logic.

Examples:

Basic usage

<%= render UI::ContentComponent.new do %>
  Popover content here
<% end %>

With custom styling

<%= render UI::ContentComponent.new(classes: "w-80 p-6") do %>
  Content
<% end %>

Instance Method Summary collapse

Methods included from PopoverContentBehavior

#popover_content_classes, #popover_content_data_attributes, #popover_content_html_attributes

Constructor Details

#initialize(side: "bottom", align: "center", classes: "", **attributes) ⇒ PopoverContentComponent

Returns a new instance of PopoverContentComponent.

Parameters:

  • side (String) (defaults to: "bottom")

    Side of the trigger to show the content (“top”, “bottom”, “left”, “right”)

  • align (String) (defaults to: "center")

    Alignment relative to the trigger (“start”, “center”, “end”)

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



24
25
26
27
28
29
# File 'app/view_components/ui/popover_content_component.rb', line 24

def initialize(side: "bottom", align: "center", classes: "", **attributes)
  @side = side
  @align = align
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



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

def call
  content_attrs = popover_content_html_attributes

  # Merge data attributes properly
  if @attributes[:data]
    content_attrs[:data] = content_attrs[:data].merge(@attributes[:data])
  end

   :div, **content_attrs.deep_merge(@attributes.except(:data)) do
    content
  end
end