Slider Field(ui_slider_field)
UiBibz::Ui::Core::Forms::Numbers::SliderField
Usage
This component is an extension of component element. A Ui Bibz component consists of 3 arguments:
# by variable
ui_range_field name, options, html_options
# or by block
ui_range_field options, html_options do
name
end
Examples
Some examples explain how to use the options present in the component.Slider Field
By default, ui_slider_field
generate 2 inputs with suffix names: _min and _max:
Eq. ui_slider_field "price"
will generate two inputs with price_min and price_max name.
You can override these inputs with the options: input_name_min
and input_name_max
.
ui_slider_field "price"
<div class="slider">
<div>
<div class="slider-inverse-left" style="width: 100%"></div>
<div class="slider-inverse-right" style="width: 100%"></div>
<div class="slider-range" style="left: 0%; right: 0%"></div>
<div class="slider-thumb slider-thumb-left" style="left: 0%"></div>
<div class="slider-thumb slider-thumb-right" style="left: 100%"></div>
</div>
<input type="range" name="price_min" id="price_min" value="0" max="100" min="0" step="1">
<input type="range" name="price_max" id="price_max" value="100" max="100" min="0" step="1">
</div>
Status
The
status
option has following symbols for argument:- :primary
- :secondary
- :success
- :danger
- :warning
- :info
- :light
- :dark
ui_slider_field :price, status: :primary, thumb_min: 0, thumb_max: 100, status: status
ui_slider_field :price, status: :secondary, thumb_min: 5, thumb_max: 95, status: status
ui_slider_field :price, status: :success, thumb_min: 10, thumb_max: 90, status: status
ui_slider_field :price, status: :danger, thumb_min: 15, thumb_max: 85, status: status
ui_slider_field :price, status: :warning, thumb_min: 20, thumb_max: 80, status: status
ui_slider_field :price, status: :info, thumb_min: 25, thumb_max: 75, status: status
ui_slider_field :price, status: :light, thumb_min: 30, thumb_max: 70, status: status
ui_slider_field :price, status: :dark, thumb_min: 35, thumb_max: 65, status: status
<div id="price-0" class="slider-primary slider">
<div>
<div class="slider-inverse-left" style="width: 100%"></div>
<div class="slider-inverse-right" style="width: 100%"></div>
<div class="slider-range" style="left: 0%; right: 0%"></div>
<div class="slider-thumb slider-thumb-left" style="left: 0%"></div>
<div class="slider-thumb slider-thumb-right" style="left: 100%"></div>
</div>
<input type="range" name="price_min" id="price_min" value="0" max="100" min="0" step="1">
<input type="range" name="price_max" id="price_max" value="100" max="100" min="0" step="1">
</div>
Track Status
The
status
option has following symbols for argument:- :primary
- :secondary
- :success
- :danger
- :warning
- :info
- :light
- :dark
ui_slider_field 'price', { thumb_min: 20, thumb_max: 70, track_status: :dark }, { id: "price-dark" }
ui_slider_field 'price', { thumb_min: 30, thumb_max: 60, status: :dark, track_status: :primary }, { id: "price-primary" }
""
Thumb min and max
ui_slider_header target: "price", thumb_min: 30, thumb_max: 70
ui_slider_field 'price', { thumb_min: 30, thumb_max: 70 }, { id: "price" }
<div data-target="price" class="slider-header">
<div class="slider-header-min">
<label>Min: </label>
<span>30</span>
</div>
<div class="slider-header-max">
<label>max: </label>
<span>70</span>
</div>
</div>
<div id="price" class="slider">
<div>
<div class="slider-inverse-left" style="width: 100%"></div>
<div class="slider-inverse-right" style="width: 100%"></div>
<div class="slider-range" style="left: 30%; right: 30%"></div>
<div class="slider-thumb slider-thumb-left" style="left: 30%"></div>
<div class="slider-thumb slider-thumb-right" style="left: 70%"></div>
</div>
<input type="range" name="price_min" id="price_min" value="30" max="100" min="0" step="1">
<input type="range" name="price_max" id="price_max" value="70" max="100" min="0" step="1">
</div>
Options
The ui_slider_header
options:
The ui_slider_header
can be customed with css like this:
.slider-header{ display: flex; justify-content: space-between; }
ui_slider_header target: "sensor", thumb_min: -60, thumb_max: 100, class: "slider-header-inline", label_min: "Price min.", label_max: "Price max."
ui_slider_field 'sensor', min: -120, thumb_min: -60, thumb_max: 100, max: 120, step: 20
<div data-target="sensor" class="slider-header-inline slider-header">
<div class="slider-header-min">
<label>Temp min.</label>
<span>-60</span>
</div>
<div class="slider-header-max">
<label>Temp max.</label>
<span>100</span>
</div>
</div>
<div id="sensor" class="slider" min="-120" max="120" step="20">
<div>
<div class="slider-inverse-left" style="width: 100%"></div>
<div class="slider-inverse-right" style="width: 100%"></div>
<div class="slider-range" style="left: 25%; right: 8%"></div>
<div class="slider-thumb slider-thumb-left" style="left: 25%"></div>
<div class="slider-thumb slider-thumb-right" style="left: 92%"></div>
</div>
<input type="range" name="sensor_min" id="sensor_min" value="-60" max="120" min="-120" step="20">
<input type="range" name="sensor_max" id="sensor_max" value="100" max="120" min="-120" step="20">
</div>
State
ui_slider_field 'age', state: :disabled
<div class="disabled slider">
<div>
<div class="slider-inverse-left" style="width: 100%"></div>
<div class="slider-inverse-right" style="width: 100%"></div>
<div class="slider-range" style="left: 30%; right: 30%"></div>
<div class="slider-thumb slider-thumb-left" style="left: 30%"></div>
<div class="slider-thumb slider-thumb-right" style="left: 70%"></div>
</div>
<input type="range" name="age_min" id="age_min" value="30" max="100" min="0" step="1" disabled="disabled">
<input type="range" name="age_max" id="age_max" value="70" max="100" min="0" step="1" disabled="disabled">
</div>
Simple form
Ui Bibz is compatible with simple form.
You can use defaults inputs of Simple Form and defaults inputs of Ui Bibz like ui_slider_field
. You can use Simple Form input options and Ui Bibz ui_slider_field options.
ui_slider_header target: "new_user", class: "slider-header-inline"
ui_form_for(@user) do |f|
...
f.input :name, as: :ui_number_field, label: false
...
end