I'm creating some sort of universal component to use it in React projects and in some old-fashioned Bootstrap + PHP ones.
So, I have a design like this.
As you can see it has repeated parts on the left and right sides. And I'm wondering to make it as much dynamically rendered as possible, kinda React's render props but which can be used in plain HTML + vanilla JS.
For example: in some cases there may no be an icon, in other - there may be a secondary text row and so on.
Previously I created a Data Grid component w/ dynamic render:
<campaign-table>
<campaign-head>
<campaign-cell numeric>ID</campaign-cell>
<campaign-cell>Name</campaign-cell>
<campaign-cell size="2">Description</campaign-cell>
</campaign-head>
<campaign-body>
<template>
{{#each items}}
<campaign-cell numeric>ID: {{ id }}</campaign-cell>
<campaign-cell> Name - <strong>{{ name }}</strong> </campaign-cell>
<campaign-cell>ℹ️ {{ description }}</campaign-cell>
{{/each}}
</template>
</campaign-body>
</campaign-table>
And CampaingBody component has method:
componentWillLoad() {
this.template = this.el.querySelector('template');
this.renderTemplate = hbs.compile(this.template.innerHTML);
}
Where hbs
is Handlebars package. But it seems that all those VDOM magic is broken when I'm using this trick.
So, I'm curious is there any way achieve this in "Stencil" way? If every slot knows necessary data it will be able to render it correctly.
How to pass data into Stenciljs slots?