Class: UI::SliderThumbComponent

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

Overview

Slider Thumb component (ViewComponent) Draggable handle that controls the slider value

Examples:

Basic usage (single thumb)

<%= render UI::SliderThumbComponent.new %>

Multiple thumbs (range)

<%= render UI::SliderThumbComponent.new %>
<%= render UI::SliderThumbComponent.new %>

Instance Method Summary collapse

Methods included from SliderThumbBehavior

#slider_thumb_html_attributes

Constructor Details

#initialize(disabled: false, classes: "", attributes: {}) ⇒ SliderThumbComponent

Returns a new instance of SliderThumbComponent.

Parameters:

  • disabled (Boolean) (defaults to: false)

    whether thumb is disabled

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

    additional CSS classes

  • attributes (Hash) (defaults to: {})

    additional HTML attributes



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

def initialize(disabled: false, classes: "", attributes: {})
  @disabled = disabled
  @classes = classes
  @attributes = attributes
end

Instance Method Details

#callObject



24
25
26
27
28
29
# File 'app/view_components/ui/slider_thumb_component.rb', line 24

def call
  attrs = slider_thumb_html_attributes
  attrs[:data] = attrs[:data].merge(@attributes.fetch(:data, {}))

   :div, "", **attrs.merge(@attributes.except(:data))
end