Pluto.jl icon indicating copy to clipboard operation
Pluto.jl copied to clipboard

Add name to a Bond

Open dpsanders opened this issue 3 years ago • 8 comments

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.

dpsanders avatar Aug 29 '20 14:08 dpsanders

Yeah that's cool

fonsp avatar Aug 30 '20 12:08 fonsp

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

image

stillyslalom avatar Sep 02 '20 20:09 stillyslalom

What do you mean?

fonsp avatar Sep 02 '20 22:09 fonsp

@bind var <binding> label="A descriptive label for `var`"

stillyslalom avatar Sep 02 '20 22:09 stillyslalom

Aha, for that you can use:

md"A descriptive label for `var` $(@bind var Slider(LinRange(0, 20, 1001), default=10))"

fonsp avatar Sep 02 '20 23:09 fonsp

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.

stillyslalom avatar Sep 03 '20 00:09 stillyslalom

Ah now I get it

fonsp avatar Sep 03 '20 00:09 fonsp

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

image-1652964737328

fonsp avatar May 19 '22 12:05 fonsp