From 1b1516f0007832ef68100e3c8f353d282e06d14d Mon Sep 17 00:00:00 2001 From: jeremie Date: Thu, 13 Oct 2022 00:47:33 -0400 Subject: [PATCH 1/5] add type number to numberfield --- src/FormInputs.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FormInputs.jl b/src/FormInputs.jl index d48822be..c4f07d6d 100644 --- a/src/FormInputs.jl +++ b/src/FormInputs.jl @@ -118,7 +118,7 @@ function numberfield( label::String = "", args...; kw( [:label => label, :fieldname => fieldname, kwargs...], - Dict("fieldname" => "v-model.number"))... + Dict("fieldname" => "v-model.number", "type" => "number"))... ) end From 169481489c132a3143601a62e15142187d8767ba Mon Sep 17 00:00:00 2001 From: jeremie Date: Thu, 13 Oct 2022 02:00:54 -0400 Subject: [PATCH 2/5] add type number to numberfield --- src/FormInputs.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FormInputs.jl b/src/FormInputs.jl index c4f07d6d..b6e06fdb 100644 --- a/src/FormInputs.jl +++ b/src/FormInputs.jl @@ -117,8 +117,8 @@ function numberfield( label::String = "", q__input( [isa(content, Function) ? content() : join(content)], args...; kw( - [:label => label, :fieldname => fieldname, kwargs...], - Dict("fieldname" => "v-model.number", "type" => "number"))... + [:label => label, :fieldname => fieldname, :type => "number", kwargs...], + Dict("fieldname" => "v-model.number"))... ) end From 2f86d92b11b0c054fb7667fc6d2ff09a270cbafc Mon Sep 17 00:00:00 2001 From: hhaensel Date: Tue, 18 Oct 2022 23:45:14 +0200 Subject: [PATCH 3/5] support symbols and strings in range(), small fixes --- src/Badges.jl | 2 +- src/Ranges.jl | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Badges.jl b/src/Badges.jl index 81ae96b5..7013e395 100644 --- a/src/Badges.jl +++ b/src/Badges.jl @@ -48,7 +48,7 @@ julia> Html.div("Badge", class="text-h6", [ * `rounded::Bool` - Makes a rounded shaped badge """ function badge( fieldname::Union{Symbol,String,Nothing} = nothing, - args...; kwargs...) where {T<:Stipple.ReactiveModel} + args...; kwargs...) q__badge(args...; kw( [(isa(fieldname, String) ? :label : :fieldname) => fieldname, kwargs...] )... ) diff --git a/src/Ranges.jl b/src/Ranges.jl index 6879151d..f1044b48 100644 --- a/src/Ranges.jl +++ b/src/Ranges.jl @@ -85,7 +85,7 @@ julia> range(18:1:90, * `dense::Bool` - Dense mode; occupies less space """ function Base.range( - range::AbstractRange{T} where T <: Real, + range::AbstractRange{<:QRangeType}, fieldname::Union{Symbol,Nothing} = nothing, args...; lazy = false, @@ -100,6 +100,26 @@ function Base.range( ])...) end +const QRangeType = Union{Symbol, String, Real} +struct QRange <: AbstractRange{QRangeType} + min::QRangeType + step::QRangeType + max::QRangeType +end + +Base.length(qr::QRange) = (qr.min isa Real && qr.step isa Real && qr.max isa Real) ? length(qr.min:qr.step:qr.max) : nothing +Base.step(qr::QRange) = qr.step +Base.first(qr::QRange) = qr.min +Base.last(qr::QRange) = qr.max + +QRange(min::QRangeType, max::QRangeType) = QRange(min, 1, max) + +Base.:(:)(start::Union{Symbol, String}, step::QRangeType, stop::QRangeType) = QRange(start, step, stop) +Base.:(:)(start::Real, step::Union{Symbol, String}, stop::QRangeType) = QRange(start, step, stop) +Base.:(:)(start::Real, step::Real, stop::Union{Symbol, String}) = QRange(start, step, stop) +Base.:(:)(start::Union{Symbol, String}, stop::QRangeType) = QRange(start, 1, stop) +Base.:(:)(start::Real, stop::Union{Symbol, String}) = QRange(start, 1, stop) + """ slider(range::AbstractRange{T} where T <: Real, fieldname::Union{Symbol,Nothing} = nothing, args...; lazy = false, kwargs...) @@ -165,7 +185,7 @@ function slider(range::AbstractRange{T} where T <: Real, ])...) end -function Stipple.render(rd::RangeData{T}, fieldname::Union{Symbol,Nothing} = nothing) where {T,R} +function Stipple.render(rd::RangeData{T}, fieldname::Union{Symbol,Nothing} = nothing) where {T} Dict(:min => rd.range.start, :max => rd.range.stop) end From e63101d25d4b119948ee007f95114e95f7eff7e2 Mon Sep 17 00:00:00 2001 From: hhaensel Date: Wed, 19 Oct 2022 00:14:16 +0200 Subject: [PATCH 4/5] apply changes to slider, fix order of definitions, update docs --- src/Ranges.jl | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/Ranges.jl b/src/Ranges.jl index f1044b48..5d046295 100644 --- a/src/Ranges.jl +++ b/src/Ranges.jl @@ -18,8 +18,28 @@ Base.@kwdef mutable struct RangeData{T} range::UnitRange{T} end +const QRangeType = Union{Symbol, String, Real} +struct QRange <: AbstractRange{QRangeType} + min::QRangeType + step::QRangeType + max::QRangeType +end + +Base.length(qr::QRange) = (qr.min isa Real && qr.step isa Real && qr.max isa Real) ? length(qr.min:qr.step:qr.max) : nothing +Base.step(qr::QRange) = qr.step +Base.first(qr::QRange) = qr.min +Base.last(qr::QRange) = qr.max + +QRange(min::QRangeType, max::QRangeType) = QRange(min, 1, max) + +Base.:(:)(start::Union{Symbol, String}, step::QRangeType, stop::QRangeType) = QRange(start, step, stop) +Base.:(:)(start::Real, step::Union{Symbol, String}, stop::QRangeType) = QRange(start, step, stop) +Base.:(:)(start::Real, step::Real, stop::Union{Symbol, String}) = QRange(start, step, stop) +Base.:(:)(start::Union{Symbol, String}, stop::QRangeType) = QRange(start, 1, stop) +Base.:(:)(start::Real, stop::Union{Symbol, String}) = QRange(start, 1, stop) + """ - range(range::AbstractRange{T} where T <: Real, fieldname::Union{Symbol,Nothing} = nothing, args...; lazy = false, kwargs...) + range(range::AbstractRange{<:Union{Symbol, String, Real}}, fieldname::Union{Symbol,Nothing} = nothing, args...; lazy = false, kwargs...) The `range` component is a great way to offer the user the selection of a sub-range of values between a minimum and maximum value, with optional steps to select those values. An example use case for the Range component would be to offer a price range selection @@ -72,7 +92,7 @@ julia> range(18:1:90, * `labelvalueleft::Union{String, Int}` - Override default label for min value ex. `labelvalueleft="model.min + 'px'"` * `labelvalueright::Union{String, Int}` - Override default label for max value ex. `labelvalueright="model.max + 'px'"` 5. Model - * `range::AbstractRange{T}` - The range of values to select from min:step:max + * `range::AbstractRange{T}` - The range of values to select from min:step:max, symbols or strings can be used to reference model fields, e.g. `range("min":2:"max", :myvalue)` * `lazy::Bool` - If true, update the value of the model field only upon release of the slider 6. State * `disable::Bool` - Put component in disabled mode @@ -100,28 +120,8 @@ function Base.range( ])...) end -const QRangeType = Union{Symbol, String, Real} -struct QRange <: AbstractRange{QRangeType} - min::QRangeType - step::QRangeType - max::QRangeType -end - -Base.length(qr::QRange) = (qr.min isa Real && qr.step isa Real && qr.max isa Real) ? length(qr.min:qr.step:qr.max) : nothing -Base.step(qr::QRange) = qr.step -Base.first(qr::QRange) = qr.min -Base.last(qr::QRange) = qr.max - -QRange(min::QRangeType, max::QRangeType) = QRange(min, 1, max) - -Base.:(:)(start::Union{Symbol, String}, step::QRangeType, stop::QRangeType) = QRange(start, step, stop) -Base.:(:)(start::Real, step::Union{Symbol, String}, stop::QRangeType) = QRange(start, step, stop) -Base.:(:)(start::Real, step::Real, stop::Union{Symbol, String}) = QRange(start, step, stop) -Base.:(:)(start::Union{Symbol, String}, stop::QRangeType) = QRange(start, 1, stop) -Base.:(:)(start::Real, stop::Union{Symbol, String}) = QRange(start, 1, stop) - """ - slider(range::AbstractRange{T} where T <: Real, fieldname::Union{Symbol,Nothing} = nothing, args...; lazy = false, kwargs...) + slider(range::AbstractRange{<:Union{Symbol, String, Real}}, fieldname::Union{Symbol,Nothing} = nothing, args...; lazy = false, kwargs...) The `slider` is a great way for the user to specify a number value between a minimum and maximum value, with optional steps between valid values. The slider also has a focus indicator (highlighted slider button), which allows for keyboard adjustments of the slider. ---------- @@ -158,7 +158,7 @@ julia> slider(1:5:100) * `labelvalueleft::Union{String, Int}` - Override default label for min value ex. `labelvalueleft="model.min + 'px'"` * `labelvalueright::Union{String, Int}` - Override default label for max value ex. `labelvalueright="model.max + 'px'"` 5. Model - * `range::AbstractRange{T}` - The range of values to select from min:step:max + * `range::AbstractRange{T}` - The range of values to select from min:step:max, symbols or strings can be used to reference model fields, e.g. `range("min":2:"max", :myvalue)` * `lazy::Bool` - If true, update the value of the model field only upon release of the slider 6. State * `disable::Bool` - Put component in disabled mode @@ -170,7 +170,7 @@ julia> slider(1:5:100) * `dark::Bool` - Notify the component that the background is a dark color * `dense::Bool` - Dense mode; occupies less space """ -function slider(range::AbstractRange{T} where T <: Real, +function slider(range::AbstractRange{<:QRangeType}, fieldname::Union{Symbol, Nothing} = nothing, args...; lazy = false, From 6520c88d80aac09ee1189a6b47f635e335f8a5a4 Mon Sep 17 00:00:00 2001 From: hhaensel Date: Wed, 19 Oct 2022 09:53:11 +0200 Subject: [PATCH 5/5] set version v0.21.0 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 873751a4..2b928cd7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "StippleUI" uuid = "a3c5d34a-b254-4859-a8fa-b86abb7e84a3" authors = ["Adrian Salceanu "] -version = "0.20.2" +version = "0.21.0" [deps] Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"