Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional label kwarg to confirm #294

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/Confirm.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
### A Pluto.jl notebook ###
# v0.19.12
# v0.19.38

using Markdown
using InteractiveUtils
Expand Down Expand Up @@ -114,16 +114,18 @@ begin
Base.@kwdef struct ConfirmBond
element::Any
secret_key::String=String(rand('a':'z', 10))
label::Union{String, Nothing}=nothing
end

function Base.show(io::IO, m::MIME"text/html", cb::ConfirmBond)
if !AbstractPlutoDingetjes.is_supported_by_display(io, Bonds.transform_value)
return Base.show(io, m, HTML("<span>❌ You need to update Pluto to use this PlutoUI element.</span>"))
end
output = @htl(
"""<span style='display: contents;'>$(
cb.element
)<input type=submit id=$(cb.secret_key)><script id=$(cb.secret_key)>
"""<span style='display: contents;'>
$(cb.element)
<input type=submit $((id=cb.secret_key, value=cb.label))>
<script id=$(cb.secret_key)>

let key = $(cb.secret_key)

Expand Down Expand Up @@ -210,7 +212,7 @@ end
# ╔═╡ a20da18f-7a74-43ca-9b66-1f3b82efa0c3
"""
```julia
confirm(element::Any)
confirm(element::Any; label::Union{String, Nothing}=nothing)
```

Normally, when you move a [`Slider`](@ref) or type in a [`TextField`](@ref), all intermediate values are sent back to `@bind`.
Expand All @@ -219,6 +221,8 @@ By wrapping an input element in `confirm`, you get a button to manually control

One case where this is useful is a notebook that does a long computation based on a `@bind` input.

`label` specifies a custom label for the confirm button.

# Examples

```julia
Expand Down Expand Up @@ -258,9 +262,10 @@ You can combine this with [`PlutoUI.combine`](@ref)!
> ![screenshot of running the code above in pluto](https://user-images.githubusercontent.com/6933510/145614965-7a1e8630-4766-4589-8a84-b022bdfb09fc.gif)

"""
function confirm(element::Any)
function confirm(element::Any; label::Union{String, Nothing}=nothing)
ConfirmBond(;
element=element,
label=label,
)
end

Expand Down Expand Up @@ -291,7 +296,7 @@ x(234)
# ╔═╡ fc92b3fc-6143-477c-a413-84dcd1b4cfc0
# ╠═╡ skip_as_script = true
#=╠═╡
@bind t confirm(html"<input>")
@bind t confirm(html"<input>"; label="Submit your text")
╠═╡ =#

# ╔═╡ 363a65ec-218c-43a2-b740-8061fac25011
Expand Down
Loading