JuliaPluto / PlutoUI.jl

https://featured.plutojl.org/basic/plutoui.jl
The Unlicense
299 stars 54 forks source link

Add `details` #288

Closed genericallyterrible closed 4 months ago

genericallyterrible commented 4 months ago

Adds new function details to automatically create a well formed Details disclosure element (<details>).

Currently scoped as:

using PlutoUI.ExperimentalLayout: details

using PlutoUI #: details

Example usage of new details function

Since this new function creates normal HTML <details> elements, collapsed details elements will omit their contents from any print/export. If this behavior is undesirable, it seems a JS fix could be applied as discussed here on SO though I'm unsure where it would slot in.

I couldn't get @bind to behave properly in the Layout.jl notebook to fully test it internally. UI elements would render, but bound variables would never update. When using details in the binder environment automatically created by github-actions it behaves as expected.

Example usage of new details function with bound variables

github-actions[bot] commented 4 months ago

Try this Pull Request!

Open Julia and type:

  julia> import Pkg
julia> Pkg.activate(temp=true)
julia> Pkg.add(url="https://github.com/genericallyterrible/PlutoUI.jl", rev="summary-details")
julia> using PlutoUI

Or run this code in your browser: Run with binder

fonsp commented 4 months ago

Super nice!! And really well implemented, happy to see that you are using HypertextLiteral!! I would say that this is not "experimental", and it can go directly into PlutoUI. What do you think?

genericallyterrible commented 4 months ago

Sounds good to me! Wasn't super sure where details should end up, and honestly stumbled my way into Layout.jl. If it should live in some other file so it's not submoduled under ExperimentalLayout, the only reliance it has on the other code in Layout.jl is the 5 lines implementing embed_display (and the variable p for example purposes).

I can move details into its own notebook and copy over the functionality of embed_display if that's appropriate, or perhaps there's some other path you had in mind?

genericallyterrible commented 4 months ago

details has been moved to Details.jl and is now reexported from PlutoUI.jl

Edit: Running on the binder image:

Demonstration of this pull request running on binder

genericallyterrible commented 4 months ago

Thanks so much for the tweaks and tests!

I'd be happy to PR the CSS over to Pluto once this is accepted, everyone deserves pretty <details>. 😊

I have a bit of clarification on one of your changes and its impacts on the assumptions I made about how details should format its contents, but I'll leave that comment as a response to the change itself.

fonsp commented 4 months ago

Thanks so much for the PR! Let me know what you would like to work on next :)