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
Open

Add CSSWidgetWrapper #98

wants to merge 14 commits into from

Conversation

feanor12
Copy link
Contributor

@feanor12 feanor12 commented May 1, 2021

This widget wraps an existing widget to add CSS styles via JavaScript.

Features:

  • Redirect the value to a wrapper div element
  • Add widget.style lines based on the provided dictionary

Example:

@bind text CSSWidgetWrapper(TextField(default="hi"),
	Dict("backgroundColor"=>"green","color"=>"white"))

@fonsp
Copy link
Member

fonsp commented May 3, 2021

Thanks! The input event bubbles upwards, so you might not need to fire it again a second time. Can you remove that line and see if it still works?

@fonsp
Copy link
Member

fonsp commented May 3, 2021

The docs are unclear, the current description explains implementation details, but it doesn't actually say what the CSSWidgetWrapper does.

Can you follow the formatting conventions used here? Use Markdown syntax 👍 https://docs.julialang.org/en/v1/manual/documentation/

@fonsp
Copy link
Member

fonsp commented May 3, 2021

I think you might be able to achieve this without needing to create a wrapper element (which could affect layout styles), by generating code like this:

$widget

<script>
const widget = currentScript.previousElementSibling

</script>

@feanor12
Copy link
Contributor Author

feanor12 commented May 4, 2021

Thank you for the input. Using the first child of the bond and removing the wrapping div makes it a lot easier.
Also I removed the doc strings from the show and get method and modified the one on the struct.

I also realized I could make more general one for a general JavaScript injection.
This could then be used for the construction of style elements from a Dict.
https://github.com/feanor12/PlutoUI.jl/blob/jsinject/src/CSSWidgetWrapper.jl
Do you think this would be useful?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants