Class: UI::SelectContent

Inherits:
Phlex::HTML
  • Object
show all
Includes:
SelectContentBehavior
Defined in:
app/components/ui/select_content.rb

Overview

Select Content - Phlex implementation

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

Examples:

Basic usage

render UI::Content.new do
  render UI::Item.new(value: "apple") { "Apple" }
  render UI::Item.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) ⇒ SelectContent

Returns a new instance of SelectContent.

Parameters:

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

    Additional CSS classes to merge

  • attributes (Hash)

    Additional HTML attributes



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

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

Instance Method Details

#view_template(&block) ⇒ Object



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

def view_template(&block)
  div(**select_content_html_attributes.deep_merge(@attributes)) do
    # Scroll up button
    render UI::SelectScrollUpButton.new

    # Viewport with scrollable content
    div(
      data_radix_select_viewport: true,
      data_ui__select_target: "viewport",
      data_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;"
    ) do
      yield if block_given?
    end

    # Scroll down button
    render UI::SelectScrollDownButton.new
  end
end