Class: UI::ScrollAreaComponent

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

Overview

ScrollAreaComponent - ViewComponent implementation

Augments native scroll functionality for custom, cross-browser styling. Root container with Stimulus controller.

Examples:

Basic usage

<%= render UI::ScrollAreaComponent.new(classes: "h-[200px] w-[350px] rounded-md border p-4") do %>
  <div class="space-y-4">
    <h3 class="text-sm font-semibold">Tags</h3>
    <!-- Content here -->
  </div>
<% end %>

Instance Method Summary collapse

Methods included from ScrollAreaBehavior

#scroll_area_classes, #scroll_area_html_attributes

Constructor Details

#initialize(type: "hover", scroll_hide_delay: 600, classes: "", **attributes) ⇒ ScrollAreaComponent

Returns a new instance of ScrollAreaComponent.

Parameters:

  • type (String) (defaults to: "hover")

    Scrollbar visibility behavior (“hover”, “scroll”, “auto”, “always”)

  • scroll_hide_delay (Integer) (defaults to: 600)

    Delay in ms before hiding scrollbar on hover

  • 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/scroll_area_component.rb', line 22

def initialize(type: "hover", scroll_hide_delay: 600, classes: "", **attributes)
  @type = type
  @scroll_hide_delay = scroll_hide_delay
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/view_components/ui/scroll_area_component.rb', line 29

def call
  root_attrs = scroll_area_html_attributes.deep_merge(@attributes)

  # Add Stimulus controller and values
  root_attrs[:data] ||= {}
  root_attrs[:data][:controller] = "ui--scroll-area"
  root_attrs[:data][:ui__scroll_area_type_value] = @type
  root_attrs[:data][:ui__scroll_area_scroll_hide_delay_value] = @scroll_hide_delay

   :div, **root_attrs do
    safe_join([
      render(UI::ViewportComponent.new) { content },
      render(UI::ScrollbarComponent.new(orientation: "vertical")),
      render(UI::CornerComponent.new)
    ])
  end
end