Fluid icon indicating copy to clipboard operation
Fluid copied to clipboard

Arguments for Named Slots

Open s2b opened this issue 5 months ago • 2 comments

As an addition to #1109, it should be possible to pass data from the component to the slot. This allows better separation between integration and component when components are nested and loop over arrays passed to the outer component. All mapping can happen outside of the component, but the component is still in charge of rendering.

Template:

<my:listComponent items="{items}">
    <f:fragment name="listItem" argumentsAs="item">
        <my:listItemComponent title="{item.title}" link="{item.url}" />
    </f:fragment>
</my:listComponent>

ListComponent.html:

<f:argument name="items" type="array" />

<ul>
    <f:for each="{items}" as="item" />
        <f:slot name="listItem" arguments="{item}" />
    </f:for>
</ul>

Syntax isn't final yet, there might be better ways to provide multiple arguments to the slot.

s2b avatar Jul 25 '25 09:07 s2b

Thinking this a bit further... It would be awsome to be able to define arguemnts in slots and not fall back to an "array" of typeless values.

<my:listComponent items="{items}">
    <f:fragment name="listItem">
        <my:listItemComponent title="{title}" link="{url}" />
    </f:fragment>
</my:listComponent>
<f:argument name="items" type="array" />

<ul>
    <f:for each="{items}" as="item" />
        <f:slot name="listItem" title="{item.title}" url="{item.url}">
             <f:argument name="title" type="string" />
             <f:argument name="url" type="string" />
        </f:slot>
    </f:for>
</ul>

sascha-egerer avatar Aug 07 '25 13:08 sascha-egerer

@sascha-egerer In general, I like the added type definitions there. However, I'm not sure about the arbitrary arguments to <f:slot /> mixing with name (and possible future built-in arguments?).

s2b avatar Aug 17 '25 17:08 s2b