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 CSSWidgetWrapper #98

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
35 changes: 35 additions & 0 deletions src/CSSWidgetWrapper.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export CSSWidgetWrapper

"""
CSSWidgetWrapper(widget, style::Dict{String,String})

Modify the style properties of the first HTML node for the given widget.

# Examples
Generate a text field with a red background and white text.
```
@bind text CSSWidgetWrapper(TextField(),Dict("backgroundColor"=>"red","color"=>"white"))
```
Generate a text field with 1px wide solid red border.
```
@bind text CSSWidgetWrapper(TextField(),Dict("border"=>"1px solid red"))
```
"""
struct CSSWidgetWrapper
widget
style::Dict{String,String}
end

function show(io::IO, m::MIME"text/html", w::CSSWidgetWrapper)
style = join(["widget.style.$k = '$v';" for (k,v) in w.style],"\n")
script = """
<script>
var widget = currentScript.parentElement.firstElementChild
$style
</script>
"""
show(io,m,w.widget)
print(io,script)
end

Base.get(w::CSSWidgetWrapper) = get(w.widget)
1 change: 1 addition & 0 deletions src/PlutoUI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include("./Resource.jl")
include("./Terminal.jl")
include("./RangeSlider.jl")
include("./DisplayTricks.jl")
include("./CSSWidgetWrapper.jl")

@reexport module MultiCheckBoxNotebook
include("./MultiCheckBox.jl")
Expand Down