Pluto.jl
Pluto.jl copied to clipboard
Add name to a Bond
Now we have the possibility of having the value next to a slider -- great! It would be useful to have the name of the variable too.
Yeah that's cool
Maybe just a label
field? I've been working around this with
begin
var_slider = @bind var Slider(LinRange(0, 20, 1001), default=10)
md"""
A descriptive label for `var` $var_slider
"""
end
What do you mean?
@bind var <binding> label="A descriptive label for `var`"
Aha, for that you can use:
md"A descriptive label for `var` $(@bind var Slider(LinRange(0, 20, 1001), default=10))"
I understand not wanting to add too much clutter to the @bind
interface, but label
is a common HTML tag with universal browser support; it also helps accessibility for screen readers.
Ah now I get it
You can use this:
# ╔═╡ 3027890b-196b-4a65-9f17-0180d21f6beb
using HypertextLiteral
# ╔═╡ 19da2136-a5e4-476e-95a9-853960e3a50f
macro label_bind(name::Symbol, ex::Expr)
quote
@htl("""
<div style='display: flex;'>
<code style='font-weight: bold'>$($(String(name)))</code>: $(@bind $(name) $(esc(ex)))
</div>
""")
end
end