Class: Shadcn::Slider::Thumb::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/slider/thumb/component.rb

Overview

The handle, and the only focusable thing in the component: role="slider" with its own aria-valuenow, so a two-thumb range is two controls rather than one with two numbers.

Positioning lives on a wrapper the root renders, not here — Radix does the same, and it is what lets the thumb keep transition-[color,box-shadow] without the position transitioning too.

Constant Summary

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#call, #css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(orientation: :horizontal, value: 0, min: 0, max: 100, disabled: false, index: 0, **attributes) ⇒ Component

Returns a new instance of Component.



28
29
30
31
32
33
34
35
36
37
# File 'app/components/shadcn/slider/thumb/component.rb', line 28

def initialize(orientation: :horizontal, value: 0, min: 0, max: 100,
               disabled: false, index: 0, **attributes)
  @orientation = orientation
  @value = value
  @min = min
  @max = max
  @disabled = disabled
  @index = index
  super(**attributes)
end

Instance Attribute Details

#disabledObject (readonly)

Returns the value of attribute disabled.



26
27
28
# File 'app/components/shadcn/slider/thumb/component.rb', line 26

def disabled
  @disabled
end

#indexObject (readonly)

Returns the value of attribute index.



26
27
28
# File 'app/components/shadcn/slider/thumb/component.rb', line 26

def index
  @index
end

#maxObject (readonly)

Returns the value of attribute max.



26
27
28
# File 'app/components/shadcn/slider/thumb/component.rb', line 26

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



26
27
28
# File 'app/components/shadcn/slider/thumb/component.rb', line 26

def min
  @min
end

#orientationObject (readonly)

Returns the value of attribute orientation.



26
27
28
# File 'app/components/shadcn/slider/thumb/component.rb', line 26

def orientation
  @orientation
end

#valueObject (readonly)

Returns the value of attribute value.



26
27
28
# File 'app/components/shadcn/slider/thumb/component.rb', line 26

def value
  @value
end

Instance Method Details

#element_attributes(**defaults) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/components/shadcn/slider/thumb/component.rb', line 39

def element_attributes(**defaults)
  super(**{
    role: "slider",
    tabindex: disabled ? -1 : 0,
    "aria-valuemin" => min,
    "aria-valuemax" => max,
    "aria-valuenow" => value,
    "aria-orientation" => orientation,
    "aria-disabled" => (disabled.presence && "true"),
    "data-orientation" => orientation,
    "data-index" => index,
    "data-shadcn--slider-target" => "thumb",
    "data-action" => "keydown->shadcn--slider#keydown " \
                     "pointerdown->shadcn--slider#thumbDown"
  }.compact.merge(defaults))
end