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
Implement Component Slots #8
Comments
In Vue terminology, this breaks down into "named slots" and "scoped slots". Essentially named slots are static named pieces of DOM whereas scoped slots have data passed back in from the component to the caller's DOM generation code as an arg (for example, a slot that is called to generate each row of a dynamic data table). I think we'll just have one mechanism in Vugu which can optionally have args. Calling a component with slots: <div>
<!-- call data table with a slice of Item -->
<somelib:data-table :items="c.Items">
<!-- "named slot" approach with just static data -->
<h1 vg-slot="top">My Top Section</h1>
<!-- called for each row -->
<td vg-slot="row" vg-slot-args="item Item">
<span vg-html="item.Name"></span>
</td>
</somelib:data-table>
</div> Actually, using as the tag name makes it so that slots can easily contain things like just text or multiple tags: <div>
<!-- call data table with a slice of Item -->
<somelib:data-table :items="c.Items">
<!-- "named slot" approach with just static data -->
<vg-slot name="top">My Top Section</vg-slot>
<!-- called for each row -->
<vg-slot name="row" args="item Item">
<td><span vg-html="item.Name"></span></td>
</vg-slot>
</somelib:data-table>
</div> |
More notes on this. It looks like these are going to end up being just functions. So "DefaultSlot" is literally I don't think we need to distinguish between "named" and "scoped" slots - they are both just callback functions - and they can have whatever params are appropriate or no params at all. Note sure on the syntax, more ideas (for the slot definition part):
To call a slot from within pkg:Comp, probably something like:
... where DefaultSlot is the name of the function to call and the args are the args, translates to: Need to figure out what syntax makes the most sense and feels consistent, but I think the idea is sound and will be straightforward to implement. "name" might be better than "id" - since functions and fields have "name"s. I think using "params" and "args" and "call" are good because they correspond to the code they output and are reasonably intuitive. The developer will also have to define these fields of type func on their struct (i.e. example at top of this comment), but I don't thats an issue - it's a bit more typing than Vue, but type safe - like many idea are when translated from JS to Go. |
This is working now: https://www.vugu.org/doc/components#slots |
Need to figure out the syntax but basically you should be able to:
This is a common technique in UI component libraries and lets you tell a UI component "do all your usual fancy stuff but in the section where you have X, this is what you put in there". Fancy data tables, dialog boxes, etc. use this approach.
The text was updated successfully, but these errors were encountered: