Class: UI::SelectContentComponent

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

Overview

ContentComponent - ViewComponent implementation

Dropdown container that holds items and groups. Includes scroll buttons and viewport.

Examples:

Basic usage

<%= render UI::ContentComponent.new do %>
  <%= render UI::ItemComponent.new(value: "apple") { "Apple" } %>
  <%= render UI::ItemComponent.new(value: "banana") { "Banana" } %>
<% end %>

Instance Method Summary collapse

Methods included from SelectContentBehavior

#select_content_classes, #select_content_html_attributes

Constructor Details

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

Returns a new instance of SelectContentComponent.

Parameters:

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



18
19
20
21
# File 'app/view_components/ui/select_content_component.rb', line 18

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

Instance Method Details

#callObject



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

def call
   :div, **select_content_html_attributes.deep_merge(@attributes) do
    safe_join([
      render(UI::SelectScrollUpButtonComponent.new),
      (:div,
        content,
        data: {
          radix_select_viewport: true,
          ui__select_target: "viewport",
          action: "scroll->ui--select#handleScroll"
        },
        class: "size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:outline-1 focus-visible:ring-ring/50 p-1",
        style: "overflow-y: auto; overflow-x: hidden;"),
      render(UI::SelectScrollDownButtonComponent.new)
    ])
  end
end