Skip to content

Commit bc63476

Browse files
authored
Allow styling rangeslider (#136)
* load bulma on slider * allow className in rangeslider
1 parent 027547c commit bc63476

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/slider.jl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ function rangeslider(vals::AbstractArray;
7979
Creates a slider widget which can take on the values in `vals` and accepts several "handles".
8080
Pass a vector to `value` with two values if you want to select a range.
8181
"""
82-
function rangeslider(::WidgetTheme, vals::AbstractRange{<:Integer}, formatted_vals = format.(vals);
83-
style = Dict(), label = nothing, value = medianelement(vals), orientation = "horizontal", readout = true)
82+
function rangeslider(theme::WidgetTheme, vals::AbstractRange{<:Integer}, formatted_vals = format.(vals);
83+
style = Dict(), label = nothing, value = medianelement(vals), orientation = "horizontal", readout = true,
84+
className = "is-primary")
8485

8586
T = Observables._val(value) isa Vector ? Vector{eltype(vals)} : eltype(vals)
8687
value isa AbstractObservable || (value = Observable{T}(value))
@@ -89,7 +90,7 @@ function rangeslider(::WidgetTheme, vals::AbstractRange{<:Integer}, formatted_va
8990
orientation = string(orientation)
9091
preprocess = T<:Vector ? js"unencoded.map(Math.round)" : js"Math.round(unencoded[0])"
9192

92-
scp = Scope(imports = [nouislider_min_js, nouislider_min_css])
93+
scp = Scope(imports = vcat([nouislider_min_js, nouislider_min_css], libraries(theme)))
9394
setobservable!(scp, "index", index)
9495
fromJS = Observable(scp, "fromJS", false)
9596
changes = Observable(scp, "changes", 0)
@@ -158,12 +159,12 @@ function rangeslider(::WidgetTheme, vals::AbstractRange{<:Integer}, formatted_va
158159
sld = t.scope
159160
sld = label !== nothing ? flex_row(label, sld) : sld
160161
sld = readout ? vbox(vskip(3em), sld) : sld
161-
sld = div(sld, className = "field rangeslider rangeslider-horizontal interact-widget")
162+
sld = div(sld, className = "field rangeslider rangeslider-horizontal interact-widget $className")
162163
else
163164
sld = t.scope
164165
sld = readout ? hbox(hskip(6em), sld) : sld
165166
sld = label !== nothing ? vbox(label, sld) : sld
166-
sld = div(sld, className = "field rangeslider rangeslider-vertical interact-widget")
167+
sld = div(sld, className = "field rangeslider rangeslider-vertical interact-widget $className")
167168
end
168169
sld
169170
end
@@ -180,7 +181,7 @@ function rangepicker(vals::AbstractArray;
180181
181182
A multihandle slider with a set of spinboxes, one per handle.
182183
"""
183-
function rangepicker(::WidgetTheme, vals::AbstractRange{S}; value = [extrema(vals)...], readout = false) where {S}
184+
function rangepicker(::WidgetTheme, vals::AbstractRange{S}; value = [extrema(vals)...], readout = false, className = "is-primary") where {S}
184185
T = Observables._val(value) isa Vector ? Vector{eltype(vals)} : eltype(vals)
185186
value isa AbstractObservable || (value = Observable{T}(value))
186187
wdg = Widget{:rangepicker}(output = value)
@@ -200,7 +201,7 @@ function rangepicker(::WidgetTheme, vals::AbstractRange{S}; value = [extrema(val
200201
end
201202
inputs = t -> (val for (key, val) in components(t) if occursin(r"slider|input", string(key)))
202203
wdg.layout = t -> div(inputs(t)..., className = "interact-widget")
203-
wdg["slider"] = rangeslider(vals, value = value, readout = readout)
204+
wdg["slider"] = rangeslider(vals, value = value, readout = readout, className = className)
204205
wdg["changes"] = map(+, (val["changes"] for val in inputs(wdg))...)
205206
return wdg
206207
end

0 commit comments

Comments
 (0)