Skip to content

Commit

Permalink
Merge pull request #118 from GenieFramework/hh-radios
Browse files Browse the repository at this point in the history
Handle boolean values for val keyword correctly
  • Loading branch information
hhaensel authored Nov 9, 2023
2 parents ad67664 + 650cf47 commit 0d4073d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/Menus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module Menus
using Genie, Stipple, StippleUI, StippleUI.API
import Genie.Renderer.Html: HTMLString, normal_element, register_normal_element

export menu
export qmenu

register_normal_element("q__menu", context = @__MODULE__)

"""
menu(fieldname::Union{Symbol,Nothing} = nothing, args...; content::Union{String,Vector} = "", kwargs...)
menu(fieldname::Union{Symbol,Nothing}, args...; content::Union{String,Vector} = "", kwargs...)
The `menu` component is a convenient way to show menus. Goes very well with `list` as dropdown content, but it’s by no means limited to it.
Expand All @@ -19,7 +19,7 @@ The `menu` component is a convenient way to show menus. Goes very well with `lis
### View
```julia-repl
julia> btn("Basic Menu", color="primary", [StippleUI.menu( [p("Hello")])
julia> btn("Basic Menu", color="primary", [StippleUI.menu(nothing, [p("Hello")])])
```
-----------
Expand All @@ -46,7 +46,7 @@ julia> btn("Basic Menu", color="primary", [StippleUI.menu( [p("Hello")])
* `maxwidth::String` - The maximum width of the menu; Size in CSS units, including unit name ex. `16px` `2rem`
"""
function menu(
fieldname::Union{Symbol,Nothing} = nothing,
fieldname::Symbol,
args...;
content::Union{String,Vector} = "",
kwargs...)
Expand All @@ -56,11 +56,22 @@ function menu(
end
end

function menu(
args...;
content::Union{String,Vector} = "",
kwargs...)

q__menu(args...; kw(kwargs)...) do
join(content)
end
end

function menu(content::Function,
fieldname::Union{Symbol,Nothing} = nothing,
args...;
kwargs...)
menu(label, fieldname, args...; content = content(), kwargs...)
menu(args...; content = content(), kwargs...)
end

const qmenu = menu

end
7 changes: 6 additions & 1 deletion src/Radios.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ julia> radio("Polygon", :shape, val="polygon")
* `keep-color::Bool` - Should the color (if specified any) be kept when checkbox is unticked?
2. General
* `tabindex::Union{Int, String}` - Tabindex HTML attribute value
3. Model
* `fieldname::Symbol` - Name of the variable to bind to.
4. Label
* `label::AbstractString` - Label
* `leftlabel::Bool` - Label (if any specified) should be displayed on the left side of the checkbox
5. State
* `disable::Bool` - Put component in disabled mode
Expand All @@ -54,8 +57,10 @@ julia> radio("Polygon", :shape, val="polygon")
function radio( label::AbstractString = "",
fieldname::Union{Symbol,Nothing} = nothing,
args...;
val = nothing,
kwargs...)
q__radio(args...; kw([:label => label, :fieldname => fieldname, kwargs...])...)
kw_val = val === nothing ? Dict() : Dict(:val => (val isa Bool ? js_attr(val) : val))
q__radio(args...; kw([:label => label, :fieldname => fieldname, kw_val..., kwargs...])...)
end

end

0 comments on commit 0d4073d

Please sign in to comment.