Class: UI::ScrollAreaViewportComponent

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

Overview

ViewportComponent - ViewComponent implementation

Scrollable content container with hidden native scrollbar.

Examples:

Basic usage (automatically used by ScrollAreaComponent)

<%= render UI::ViewportComponent.new do %>
  <!-- Content here -->
<% end %>

Instance Method Summary collapse

Methods included from ScrollAreaViewportBehavior

#scroll_area_viewport_classes, #scroll_area_viewport_html_attributes

Constructor Details

#initialize(classes: "", **attributes) ⇒ ScrollAreaViewportComponent

Returns a new instance of ScrollAreaViewportComponent.

Parameters:

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



16
17
18
19
# File 'app/view_components/ui/scroll_area_viewport_component.rb', line 16

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

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
# File 'app/view_components/ui/scroll_area_viewport_component.rb', line 21

def call
  viewport_attrs = scroll_area_viewport_html_attributes.deep_merge(@attributes)

  # Add Stimulus target
  viewport_attrs[:data] ||= {}
  viewport_attrs[:data][:"ui--scroll-area-target"] = "viewport"

   :div, **viewport_attrs do
     :div, content, style: "min-width: 100%; display: table;"
  end
end