Skip to content

Commit

Permalink
Deprecate isinteger, fix and simplify spinbox and rangeslider (#138)
Browse files Browse the repository at this point in the history
* move input to widgets

* simplify

* fix js error

* bump widgets dependency
  • Loading branch information
piever authored Apr 3, 2019
1 parent 947025f commit dc6731a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ CSSUtil
Colors
JSON
Knockout 0.2.1
Widgets 0.6.0
Widgets 0.6.1
23 changes: 7 additions & 16 deletions src/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,17 @@ Create a widget to select numbers with placeholder `label`. An optional `range`
specifies maximum and minimum value accepted as well as the step.
"""
function spinbox(::WidgetTheme, label=""; value=nothing, placeholder=label, isinteger=nothing, kwargs...)
isinteger = something(isinteger, isa(_val(value), Integer))
T = isinteger ? Int : Float64
(value isa AbstractObservable) || (value = Observable{Union{T, Nothing}}(value))
isinteger === nothing || @warn "`isinteger` is deprecated"
if !isa(value, AbstractObservable)
T = something(isinteger, isa(value, Integer)) ? Int : Float64
value = Observable{Union{T, Nothing}}(value)
end
ui = input(value; isnumeric=true, placeholder=placeholder, typ="number", kwargs...)
Widget{:spinbox}(ui, output = value)
end

spinbox(T::WidgetTheme, vals::AbstractRange, args...; value=first(vals), isinteger=(eltype(vals) <: Integer), kwargs...) =
spinbox(T, args...; value=value, isinteger=isinteger, min=minimum(vals), max=maximum(vals), step=step(vals), kwargs...)
spinbox(T::WidgetTheme, vals::AbstractRange, args...; value=first(vals), kwargs...) =
spinbox(T, args...; value=value, min=minimum(vals), max=maximum(vals), step=step(vals), kwargs...)

"""
`autocomplete(options, label=""; value="")`
Expand Down Expand Up @@ -260,17 +262,6 @@ function input(::WidgetTheme; typ="text", kwargs...)
input(o; typ=typ, kwargs...)
end

function input(T::WidgetTheme, ::Type{S}, args...; isinteger=nothing, kwargs...) where {S<:Number}
(isinteger === nothing) && (isinteger = S<:Integer ? true : S<:AbstractFloat ? false : nothing)
spinbox(T, args...; isinteger=isinteger, kwargs...)
end

input(T::WidgetTheme, ::Type{<:Bool}, args...; kwargs...) = toggle(T, args...; kwargs...)
input(T::WidgetTheme, ::Type{<:AbstractString}, args...; kwargs...) = textbox(T, args...; kwargs...)
input(T::WidgetTheme, ::Type{<:Dates.Date}, args...; kwargs...) = datepicker(T, args...; kwargs...)
input(T::WidgetTheme, ::Type{<:Dates.Time}, args...; kwargs...) = timepicker(T, args...; kwargs...)
input(T::WidgetTheme, ::Type{<:Color}, args...; kwargs...) = colorpicker(T, args...; kwargs...)

"""
`button(content... = "Press me!"; value=0)`
Expand Down
3 changes: 1 addition & 2 deletions src/slider.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ function rangeslider(theme::WidgetTheme, vals::AbstractRange{<:Integer}, formatt
slap_design!(scp)
onjs(index, @js function (val)
if !$fromJS[]
new_val = Array.isArray(val) ? val : [val]
document.getElementById($id).noUiSlider.set(new_val)
document.getElementById($id).noUiSlider.set(Array.isArray(val) ? val : [val])
end
$fromJS[] = false
end)
Expand Down

0 comments on commit dc6731a

Please sign in to comment.