Progressive Web Components (arielsalminen.com)

70 points by hosteur 15 hours ago

Kuyawa an hour ago

I like web components, the simpler the better, so I like what I see but having a strong OCD about syntax I just want to propose the use of <Button ... instead of <elena-button ...

It's just a matter of using a regex [1] and making your syntax more palatable

Regardless, kudos for the release

* const componentRegex = /<%[ ]+([A-Z][a-zA-Z0-9])([^%]?)%>/g;

sheept 35 minutes ago

HTML is case insensitive, so <Button> is the same as <button>, and custom element names must have a hyphen.

Your component regex represents a JSX limitation, but web components do not need React. Plus, if you capitalize the first letter, JSX would treat it as a React component rather than a web component (i.e. custom native HTML elements)

socketcluster 32 minutes ago

Web Components are great for doing multi-pass rendering with template placeholder substitution happening at multiple levels in the component hierarchy. The entire element HTML hierarchy can be declared in one place. It's extremely versatile.

React cannot do this. It's difficult to explain without writing a whole essay but the benefits are very clear once you try this approach.

hyperhello 3 hours ago

One fun thing I did once is use the custom elements API to make a custom tag <element-template>. When the page sees <element-template tag=what-name></element-template>, it looks inside, finds any <template></template> <script></script> and <style></style> tags, and builds a new custom element with that tag name and all the powers. Cool but not incredibly simple.

Another amazing trick is to put a mutation observer on the page to detect <template> tags as they're created. (template tags parse the HTML within but don't actually create it on the page). Once the observer finds a template tag it can upgrade them to have new powers, like replacing the contents of other tags. There are ways to tame web components and make them very easy to use.

thex10 an hour ago

This article I came across last month on “Framework-agnostic design systems” happens to use this Elena library and I think explains its use case well: https://piccalil.li/blog/framework-agnostic-design-systems-p...

zelphirkalt 3 hours ago

The HTML + CSS first approach and JS only for enrichment sounds great, and like what should be done anyway. I wonder though, how it will play out in reality. Will web developers using this library make the effort to keep essential functionality JS free, if possible, and provide additional views using whatever web framework they use, or will they implement essential functionality as "JS enrichment", requiring JS for things that do not actually need to be done in JS at all?

microflash 2 hours ago

In reality, building anything complex is a huge pain using web components, particularly because it is hard to author them with appropriate level of styling API and accessibility support. In my experience, web components are fantastic for consumers but terrible for the authors.

Still, the advantages are clear: they don’t need any special runtime and can be used with other JS frameworks.

Another thing in favor of web components is support for custom registries which make gradual migration from one version to another trivial. AFAIK, no JS framework has an equivalent of custom registries.

claytongulick 8 minutes ago

Try keeping them in the light dom.

Everything works like normal html + css, but you get all the benefits of reusability and encapsulated script logic.

Lit-html (the library, not the framework) gives this approach super rendering speed too.

strix_varius 3 hours ago

Hm, the page is unreadable on brave on dark mode.

shevy-java 3 hours ago

Ok but ... why? With that I mean, why do we need it? What can be created with PWC specifically? Is there a gallery of web games? That would at the least make understanding the use case easier.

Joeri 3 hours ago

It’s on the page: https://elenajs.com/#why-should-i-use-elena

You can create anything and everything. Web components are about extending html to make it do more, progressive web components are about rendering that on the server and progressively enhancing with interactivity in the browser. Elena solves the major pain points in doing that. Components built this way can be used in any framework.