Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Nov 6, 2022
2 parents d1949f8 + 6520c88 commit 010c239
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StippleUI"
uuid = "a3c5d34a-b254-4859-a8fa-b86abb7e84a3"
authors = ["Adrian Salceanu <[email protected]>"]
version = "0.20.2"
version = "0.21.0"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Expand Down
2 changes: 1 addition & 1 deletion src/Badges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...] )...
)
Expand Down
2 changes: 1 addition & 1 deletion src/FormInputs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 27 additions & 7 deletions src/Ranges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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.
----------
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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

Expand Down

0 comments on commit 010c239

Please sign in to comment.