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" 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/FormInputs.jl b/src/FormInputs.jl index 4ae45452..d6b036d3 100644 --- a/src/FormInputs.jl +++ b/src/FormInputs.jl @@ -117,7 +117,7 @@ function numberfield( label::Union{String, Symbol} = "", q__input( [isa(content, Function) ? content() : join(content)], args...; kw( - [:label => label, :fieldname => fieldname, kwargs...], + [:label => label, :fieldname => fieldname, :type => "number", kwargs...], Dict("fieldname" => "v-model.number"))... ) end diff --git a/src/Ranges.jl b/src/Ranges.jl index 6879151d..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 @@ -85,7 +105,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, @@ -101,7 +121,7 @@ function Base.range( end """ - 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. ---------- @@ -138,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 @@ -150,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, @@ -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