class UiBibz::Ui::Core::Forms::Numbers::SliderField

Create a SliderField

This element is an extend of UiBibz::Ui::Core::Component.

Attributes

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

Signatures

UiBibz::Ui::Core::Forms::Numbers::SliderField.new(content, options = {}, html_options = {}).render

UiBibz::Ui::Core::Forms::Numbers::SliderField.new(options = {}, html_options = {}) do
  content
end.render

Examples

UiBibz::Ui::Core::Forms::Numbers::SliderField.new(4, max: 20, min: 0, step: 2)

UiBibz::Ui::Core::Forms::Numbers::SliderField.new(max: 2, min: -3, step: 0.5) do
  5
end

Helper

ui_slider_field(content, options = {}, html_options = {})

ui_slider_field(options = {}, html_options = {}) do
 # content
end

Private Instance Methods

absolute_max() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 92
def absolute_max
  (max - thumb_max).abs
end
absolute_min() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 88
def absolute_min
  (min - thumb_min).abs
end
absolute_total() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 84
def absolute_total
  @absolute_total ||= min.abs + max.abs
end
component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 120
def component_html_classes
  ['slider', status, track_status, ('disabled' if disabled)]
end
disabled() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 124
def disabled
  'disabled' if options[:state] == :disabled || html_options[:disabled]
end
left_percentage() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 112
def left_percentage
  @left_percentage ||= not_on_hundred_percent? ? 100 * absolute_min / absolute_total : thumb_min
end
max() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 100
def max
  options[:max] || 100
end
min() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 96
def min
  options[:min] || 0
end
not_on_hundred_percent?() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 80
def not_on_hundred_percent?
  options[:max].present? && options[:max] != 100 || options[:min].present? && options[:min] != 0
end
pre_render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 58
def pre_render
  content_tag :div, html_options do
    concat slider_html
    concat range_field_tag(options[:input_name_min] || range_name('_min'), options[:thumb_min] || 0, range_html_options)
    concat range_field_tag(options[:input_name_max] || range_name('_max'), options[:thumb_max] || 100, range_html_options)
  end
end
range_html_options() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 76
def range_html_options
  { max: options[:max] || 100, min: options[:min] || 0, step: options[:step] || 1, disabled: disabled }
end
range_name(suffix) click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 136
def range_name(suffix)
  if content.end_with?(']')
    content.dup.insert(-2, suffix)
  else
    "#{content}#{suffix}"
  end
end
right_percentage() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 116
def right_percentage
  @right_percentage ||= not_on_hundred_percent? ? 100 - (100 * absolute_max / absolute_total) : thumb_max
end
slider_html() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 66
def slider_html
  content_tag :div do
    concat content_tag :div, '', class: 'slider-inverse-left', style: 'width: 100%'
    concat content_tag :div, '', class: 'slider-inverse-right', style: 'width: 100%'
    concat content_tag :div, '', class: 'slider-range', style: "left: #{left_percentage}%; right: #{100 - right_percentage}%"
    concat content_tag :div, '', class: 'slider-thumb slider-thumb-left', style: "left: #{left_percentage}%"
    concat content_tag :div, '', class: 'slider-thumb slider-thumb-right', style: "left: #{right_percentage}%"
  end
end
status() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 128
def status
  "slider-#{options[:status]}" if options[:status]
end
thumb_max() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 108
def thumb_max
  options[:thumb_max] || 100
end
thumb_min() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 104
def thumb_min
  options[:thumb_min] || 0
end
track_status() click to toggle source
# File lib/ui_bibz/ui/core/forms/numbers/slider_field.rb, line 132
def track_status
  "slider-track-#{options[:track_status]}" if options[:track_status]
end