11ty / webc

Single File Web Components
MIT License
1.3k stars 36 forks source link

Allow for webc:nokeep in the component itself #158

Closed cfjedimaster closed 1 year ago

cfjedimaster commented 1 year ago

I've got a component where I never want it to show up in the HTML. To do this, I have to add code to the calling template, like so:

<myawesomecomponent webc:nokeep></myawesomecomponent>

That works, but it would be nice if the component could set this itself, perhaps in front matter. Imagine a webc component I'm sharing with others. I want it to be as simple to use as possible. Being able to set this myself means less typing for the user.

zachleat commented 1 year ago

https://www.11ty.dev/docs/languages/webc/#override-the-host-component-tag does most of this, I think!

cfjedimaster commented 1 year ago

This is not quite what I mean. So my component is named lightbox. When I leave it in the DOM, I end up with:


<html>
<body>
<!--StartFragment-->

<lightbox images="[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"><div class="lightbox_images">
stuff here
</div></lightbox>
</body>
</html>
``

Using webc:nokeep on the calling doc completely removes it. If I use override, I can *replace* it with my top level div, but I still have images=object etc. 

I'm only bugged about this as I need to use a :attribute as my data is complex, not a string. (FYI, this is not a blocker for me. I'm using scoped css so I'll need a top level tag anyway, but still curious.)
cfjedimaster commented 1 year ago

Ehh - forgot about :@ to make it private. Disregard again, 0 for 2 today, but learned stuff. :)