Class: ShadcnPhlexcomponents::Slider
- Defined in:
- lib/shadcn_phlexcomponents/components/slider.rb
Constant Summary
Constants inherited from Base
Base::SANITIZER_ALLOWED_ATTRIBUTES, Base::SANITIZER_ALLOWED_TAGS, Base::TAILWIND_MERGER
Instance Method Summary collapse
- #default_attributes ⇒ Object
-
#initialize(name: nil, value: nil, id: nil, range: false, orientation: :horizontal, step: 1, min: 0, max: 100, disabled: false, options: false, **attributes) ⇒ Slider
constructor
A new instance of Slider.
- #view_template ⇒ Object
Methods inherited from Base
#before_template, #convert_collection_hash_to_struct, #find_as_child, #icon, #item_disabled?, #merge_default_attributes, #merged_as_child_attributes, #nokogiri_attributes_to_hash, #overlay, #sanitize_as_child
Constructor Details
#initialize(name: nil, value: nil, id: nil, range: false, orientation: :horizontal, step: 1, min: 0, max: 100, disabled: false, options: false, **attributes) ⇒ Slider
Returns a new instance of Slider.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/shadcn_phlexcomponents/components/slider.rb', line 5 def initialize(name: nil, value: nil, id: nil, range: false, orientation: :horizontal, step: 1, min: 0, max: 100, disabled: false, options: false, **attributes) if range if name && !name.is_a?(Array) raise ArgumentError, "Expected an array for \"name\", got #{name.class}" end if value && !value.is_a?(Array) raise ArgumentError, "Expected an array for \"value\", got #{value.class}" end end @range = range @name = range && name ? name[0] : name @end_name = range && name ? name[1] : nil @value = range && value ? value[0] : value @end_value = range && value ? value[1] : nil @id = id @orientation = orientation @step = step @min = min @max = max @disabled = disabled @options = super(**attributes) end |
Instance Method Details
#default_attributes ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shadcn_phlexcomponents/components/slider.rb', line 30 def default_attributes { data: { controller: "slider", range: @range.to_s, options: @options.to_json, value: @value, end_value: @end_value, orientation: @orientation, step: @step, min: @min, max: @max, disabled: @disabled.to_s, id: @id, }, } end |
#view_template ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/shadcn_phlexcomponents/components/slider.rb', line 48 def view_template div(class: "py-[6px]") do div(**@attributes) do input( type: :hidden, name: @name, value: @value, data: { slider_target: "hiddenInput" }, ) if @range input( type: :hidden, name: @end_name, value: @end_value, data: { slider_target: "endHiddenInput" }, ) end div(data: { slider_target: "slider" }) end end end |