RangeSlider
variant canvas · classic × color (7) × size sm/md/lg · filled · show_value · value_format · marks · steppers · two-handle range · vertical
Pick a value (or a range) by dragging. canvas (default): a 4px track and a round white knob.
Dragging
<div class="grid grid-cols-2 gap-[16px]"><.range id="rs-disc" label="Desconto" show_value value_format="até %{value}%" color="primary" loop value={50} /><.range id="rs-price" label="Faixa de preço" show_value value_format="R$ 0 – 1.000" color="secondary" loop value={50} marks={[0, 250, 500, 750, {1000, "1.000"}]} /></div>
color × variant
<div class="grid grid-cols-[100px_repeat(2,_minmax(0,1fr))] gap-y-[10px] gap-x-[12px] items-center"><span></span><span class="text-xs text-muted font-mono text-center">canvas</span><span class="text-xs text-muted font-mono text-center">classic</span><span class="text-xs text-muted font-mono">neutral</span><div class="flex justify-center min-w-0"><.range id="r-neutral-1" color="neutral" value={30} /></div><div class="flex justify-center min-w-0"><.range id="r-neutral-2" color="neutral" variant="classic" value={30} /></div><span class="text-xs text-muted font-mono">primary</span><div class="flex justify-center min-w-0"><.range id="r-primary-1" color="primary" value={38} /></div><div class="flex justify-center min-w-0"><.range id="r-primary-2" color="primary" variant="classic" value={38} /></div><span class="text-xs text-muted font-mono">secondary</span><div class="flex justify-center min-w-0"><.range id="r-secondary-1" color="secondary" value={46} /></div><div class="flex justify-center min-w-0"><.range id="r-secondary-2" color="secondary" variant="classic" value={46} /></div><span class="text-xs text-muted font-mono">info</span><div class="flex justify-center min-w-0"><.range id="r-info-1" color="info" value={54} /></div><div class="flex justify-center min-w-0"><.range id="r-info-2" color="info" variant="classic" value={54} /></div><span class="text-xs text-muted font-mono">success</span><div class="flex justify-center min-w-0"><.range id="r-success-1" color="success" value={62} /></div><div class="flex justify-center min-w-0"><.range id="r-success-2" color="success" variant="classic" value={62} /></div><span class="text-xs text-muted font-mono">warning</span><div class="flex justify-center min-w-0"><.range id="r-warning-1" color="warning" value={70} /></div><div class="flex justify-center min-w-0"><.range id="r-warning-2" color="warning" variant="classic" value={70} /></div><span class="text-xs text-muted font-mono">error</span><div class="flex justify-center min-w-0"><.range id="r-error-1" color="error" value={78} /></div><div class="flex justify-center min-w-0"><.range id="r-error-2" color="error" variant="classic" value={78} /></div></div>
size · filled
<div class="grid grid-cols-4 gap-[16px]"><.range id="r-sm" label="size=sm" show_value color="primary" size="sm" value={60} /><.range id="r-md" label="size=md" show_value color="primary" value={60} /><.range id="r-lg" label="size=lg" show_value color="primary" size="lg" value={60} /><.range id="r-nf" label="sem filled" show_value color="primary" filled={false} value={60} /></div>
show_value · marks · steppers · range · vertical
<div class="grid grid-cols-2 gap-[16px]"><.range id="r-com" label="Comissão" show_value value_format="%{value}%" color="primary" value={35} marks={[{0, "0%"}, {25, "25%"}, {50, "50%"}, {75, "75%"}, {100, "100%"}]} /><.range id="r-qty" label="Quantidade" show_value value_format="%{value} un" color="primary" max={10} value={4} steppers /><.range id="r-per" label="Período" show_value value_format="jun – out" color="primary" value={{25, 75}} marks={[{0, "jan"}, {25, "abr"}, {50, "jul"}, {75, "out"}, {100, "dez"}]} /><div class="flex flex-wrap items-center gap-[28px] justify-center"><.range id="r-v1" color="primary" orientation="vertical" value={70} /><.range id="r-v2" color="success" orientation="vertical" value={35} /><.range id="r-v3" color="warning" orientation="vertical" value={55} /></div></div>
API values that complete the parity
<div class="grid grid-cols-3 gap-[14px]"><div class="flex flex-col items-start gap-1.5"><.range id="r-or" style="width:200px" value={60} /><span class="font-mono text-[11px] text-muted">orientation=horizontal</span></div></div>
Usage
<.range field={@form[:discount]} min={0} max={50} filled show_value value_format="%{value}%" /> <.range start_field={@form[:min]} end_field={@form[:max]} marks={[0, 250, 500, 1000]} /> <.range field={@form[:vol]} orientation="vertical" height="8rem" />
Rules
- Dragging: the knob gets a ring in the color; the value next to it follows.
- Two-handle range: the stretch between the knobs is painted.
- Clickable
marksbelow;steppersadd − and +.
API reference
Todos os function components, atributos, valores e slots que este componente cobre.
Range slider: a rounded track with a round thumb, one value or a range of two.
<.range name="volume" value={50} color="primary" />
<.range field={@form[:level]} label="Level" min={0} max={10} size="lg" show_value />
<.range name="discount" label="Desconto" value={12} max={30} show_value value_format="%{value}%" />
<.range start_name="from" end_name="to" value={{40, 280}} min={0} max={500} />
<.range name="weight" orientation="vertical" value={40} />
The slider is a track, a fill and one or two thumbs, positioned by the custom properties
--lu-sp (the value, in %) and --lu-rlo (the lower value of a pair). The
LedgerUI.Range hook (priv/static/ledger_ui/hooks/range.js) drags the thumbs, takes the
arrow keys, Home, End and Page Up/Down (it adds role="slider" and the ARIA values to the
thumbs), keeps the value text, the fill and the marks in step, and writes the value to hidden
inputs named like the field, firing a bubbling input event so phx-change runs.
Deviations from the README: color has no default (no c-* class, the neutral look) and
filled defaults to true (filled={false} is the design's "sem filled"); the value is not a
native <input type="range"> but hidden inputs.
<.range>
Renders a range slider.
| Attr | Type | Default | Values / notes |
|---|---|---|---|
id |
:string |
nil |
|
name |
:string |
nil |
|
value |
:any |
||
field |
{:struct, Phoenix.HTML.FormField} |
nil |
|
min |
:any |
0 |
|
max |
:any |
100 |
|
step |
:any |
1 |
|
color |
:string |
nil |
nil, neutral, primary, secondary, info, success, warning, error |
size |
:string |
"md" |
sm, md, lg |
fill |
:string |
nil |
|
variant |
:string |
"canvas" |
canvas, classic |
start_field |
{:struct, Phoenix.HTML.FormField} |
nil |
|
end_field |
{:struct, Phoenix.HTML.FormField} |
nil |
|
start_name |
:string |
nil |
|
end_name |
:string |
nil |
|
orientation |
:string |
"horizontal" |
horizontal, vertical |
height |
:string |
nil |
Height of a vertical slider (112px, the design's 8rem, by default). |
filled |
:boolean |
true |
|
loop |
:boolean |
false |
The canvas demo animation: the value runs along the track (--lu-sp over 5s) and the thumb "grabs" it. The value in the hidden input stays. |
show_value |
:boolean |
false |
|
value_format |
:string |
"%{value}" |
|
marks |
:list |
[] |
|
steppers |
:boolean |
false |
|
decrease_label |
:string |
"Decrease" |
|
increase_label |
:string |
"Increase" |
|
label |
:string |
nil |
|
label_class |
:any |
nil |
|
help |
:string |
nil |
|
errors |
:list |
[] |
|
disabled |
:boolean |
false |
|
wrapper_class |
:any |
nil |
|
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element.
<.range_slider>
Same as range/1 (same attributes and slots), under the name the design vitrine uses.
| Attr | Type | Default | Values / notes |
|---|---|---|---|
id |
:string |
nil |
|
name |
:string |
nil |
|
value |
:any |
||
field |
{:struct, Phoenix.HTML.FormField} |
nil |
|
min |
:any |
0 |
|
max |
:any |
100 |
|
step |
:any |
1 |
|
color |
:string |
nil |
nil, neutral, primary, secondary, info, success, warning, error |
size |
:string |
"md" |
sm, md, lg |
fill |
:string |
nil |
|
variant |
:string |
"canvas" |
canvas, classic |
start_field |
{:struct, Phoenix.HTML.FormField} |
nil |
|
end_field |
{:struct, Phoenix.HTML.FormField} |
nil |
|
start_name |
:string |
nil |
|
end_name |
:string |
nil |
|
orientation |
:string |
"horizontal" |
horizontal, vertical |
height |
:string |
nil |
|
filled |
:boolean |
true |
|
loop |
:boolean |
false |
|
show_value |
:boolean |
false |
|
value_format |
:string |
"%{value}" |
|
marks |
:list |
[] |
|
steppers |
:boolean |
false |
|
decrease_label |
:string |
"Decrease" |
|
increase_label |
:string |
"Increase" |
|
label |
:string |
nil |
|
label_class |
:any |
nil |
|
help |
:string |
nil |
|
errors |
:list |
[] |
|
disabled |
:boolean |
false |
|
wrapper_class |
:any |
nil |
|
class |
:any |
nil |
Any other HTML/phx attribute goes to the root element.