Class: UI::HoverCardContentComponent

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

Overview

ContentComponent - ViewComponent implementation

The content that appears on hover. Uses HoverCardContentBehavior for shared styling logic.

Examples:

Basic usage

<%= render UI::ContentComponent.new { "Hover card content" } %>

With custom alignment

<%= render UI::ContentComponent.new(align: "start", side_offset: 8) do %>
  Content here
<% end %>

Instance Method Summary collapse

Methods included from HoverCardContentBehavior

#content_classes, #content_data_attributes, #content_html_attributes

Constructor Details

#initialize(align: "center", side_offset: 4, classes: "", **attributes) ⇒ HoverCardContentComponent

Returns a new instance of HoverCardContentComponent.

Parameters:

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

    Alignment of the content (“start”, “center”, “end”)

  • side_offset (Integer) (defaults to: 4)

    Distance in pixels from the trigger

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



22
23
24
25
26
27
# File 'app/view_components/ui/hover_card_content_component.rb', line 22

def initialize(align: "center", side_offset: 4, classes: "", **attributes)
  @align = align
  @side_offset = side_offset
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



29
30
31
32
33
34
35
# File 'app/view_components/ui/hover_card_content_component.rb', line 29

def call
  attrs = content_html_attributes

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