Class: LightningUiKit::SliderComponent
- Inherits:
-
BaseComponent
- Object
- BaseComponent
- LightningUiKit::SliderComponent
- Defined in:
- app/components/lightning_ui_kit/slider_component.rb
Instance Attribute Summary collapse
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#step ⇒ Object
readonly
Returns the value of attribute step.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #classes ⇒ Object
- #data ⇒ Object
- #fill_style ⇒ Object
-
#initialize(name: nil, min: 0, max: 100, step: 1, value: nil, disabled: false, form: nil, **options) ⇒ SliderComponent
constructor
A new instance of SliderComponent.
- #input_name ⇒ Object
- #percent ⇒ Object
- #thumb_style ⇒ Object
Constructor Details
#initialize(name: nil, min: 0, max: 100, step: 1, value: nil, disabled: false, form: nil, **options) ⇒ SliderComponent
Returns a new instance of SliderComponent.
2 3 4 5 6 7 8 9 10 11 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 2 def initialize(name: nil, min: 0, max: 100, step: 1, value: nil, disabled: false, form: nil, **) @name = name @min = min @max = max @step = step @value = value.nil? ? min : value @disabled = disabled @form = form @options = end |
Instance Attribute Details
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
13 14 15 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 13 def disabled @disabled end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
13 14 15 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 13 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
13 14 15 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 13 def min @min end |
#step ⇒ Object (readonly)
Returns the value of attribute step.
13 14 15 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 13 def step @step end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
13 14 15 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 13 def value @value end |
Instance Method Details
#classes ⇒ Object
28 29 30 31 32 33 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 28 def classes merge_classes([ "lui:relative lui:flex lui:h-5 lui:w-full lui:touch-none lui:select-none lui:items-center", @options[:class] ].compact.join(" ")) end |
#data ⇒ Object
43 44 45 46 47 48 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 43 def data { controller: "lui-slider", action: "input->lui-slider#update" }.merge(@options[:data] || {}) end |
#fill_style ⇒ Object
35 36 37 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 35 def fill_style "width: #{formatted_percent}%;" end |
#input_name ⇒ Object
22 23 24 25 26 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 22 def input_name return @name unless @form && @name "#{@form.object_name}[#{@name}]" end |
#percent ⇒ Object
15 16 17 18 19 20 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 15 def percent range = (@max - @min).to_f return 0 if range <= 0 (((@value - @min) / range) * 100).clamp(0, 100) end |
#thumb_style ⇒ Object
39 40 41 |
# File 'app/components/lightning_ui_kit/slider_component.rb', line 39 def thumb_style "left: #{formatted_percent}%;" end |