Class: UI::ScrollAreaScrollbar

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

Overview

Scrollbar - Phlex implementation

Custom scrollbar track that contains the draggable thumb.

Examples:

Vertical scrollbar (default)

render UI::Scrollbar.new(orientation: "vertical")

Horizontal scrollbar

render UI::Scrollbar.new(orientation: "horizontal")

Instance Method Summary collapse

Methods included from SharedAsChildBehavior

#merge_attributes

Methods included from ScrollAreaScrollbarBehavior

#scroll_area_scrollbar_classes, #scroll_area_scrollbar_html_attributes

Constructor Details

#initialize(as_child: false, orientation: "vertical", classes: "", **attributes) ⇒ ScrollAreaScrollbar

Returns a new instance of ScrollAreaScrollbar.

Parameters:

  • as_child (Boolean) (defaults to: false)

    When true, yields attributes to block instead of rendering div

  • orientation (String) (defaults to: "vertical")

    “vertical” or “horizontal”

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



20
21
22
23
24
25
# File 'app/components/ui/scroll_area_scrollbar.rb', line 20

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

Instance Method Details

#view_template(&block) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/components/ui/scroll_area_scrollbar.rb', line 27

def view_template(&block)
  scrollbar_attrs = scroll_area_scrollbar_html_attributes.deep_merge(@attributes)

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

  if @as_child && block_given?
    # asChild mode: yield attributes to block, but also render thumb if not provided
    yield(scrollbar_attrs)
    render UI::Thumb.new unless block_given?
  else
    # Default mode: render as div with thumb
    div(**scrollbar_attrs) do
      render UI::Thumb.new
    end
  end
end