Class: UI::ScrollAreaViewport

Inherits:
Phlex::HTML
  • Object
show all
Includes:
ScrollAreaViewportBehavior, SharedAsChildBehavior
Defined in:
app/components/ui/scroll_area_viewport.rb

Overview

Viewport - Phlex implementation

Scrollable content container with hidden native scrollbar.

Examples:

Basic usage (automatically used by ScrollArea)

render UI::Viewport.new do
  # Content here
end

Instance Method Summary collapse

Methods included from SharedAsChildBehavior

#merge_attributes

Methods included from ScrollAreaViewportBehavior

#scroll_area_viewport_classes, #scroll_area_viewport_html_attributes

Constructor Details

#initialize(as_child: false, classes: "", **attributes) ⇒ ScrollAreaViewport

Returns a new instance of ScrollAreaViewport.

Parameters:

  • as_child (Boolean) (defaults to: false)

    When true, yields attributes to block instead of rendering div

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



18
19
20
21
22
# File 'app/components/ui/scroll_area_viewport.rb', line 18

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

Instance Method Details

#view_template(&block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/components/ui/scroll_area_viewport.rb', line 24

def view_template(&block)
  viewport_attrs = scroll_area_viewport_html_attributes.deep_merge(@attributes)

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

  if @as_child && block_given?
    # asChild mode: yield attributes to block
    yield(viewport_attrs)
  else
    # Default mode: render as div with inner table div
    div(**viewport_attrs) do
      div(style: "min-width: 100%; display: table;", &block)
    end
  end
end