Framework Interoperable Component Libraries Using Lit Web Components.
Tags: webcomponents, lit, shoelace, webdev
Published: 2023-10-08 04:08:32

> **TLDR:** This post is made to rave about repo I found called [json-schema-form-element](https://github.com/json-schema-form-element/core) a lit-based component library for form generation that works with all major front-end / metaframeworks, but also to show how I'm betting on Lit for the future of the web._

[Lit](https://lit.dev/) is having a moment, one would say it's on fire 🔥🤣. It's being used everywhere from the [web version of Photoshop](https://medium.com/@addyosmani/photoshop-is-now-on-the-web-38d70954365a) to [Microsoft's new windows app store](https://www.theverge.com/2023/10/6/23906082/microsoft-windows-app-store-web-version-launch). I think something clicked for me recently as to why lit is the major choice when it comes to the future of the web, and web components overall. 

Component libraries, love them or hate them it's how web developers quickly cobble together bits of code to form a semi-usable website. From [Bootstrap](https://getbootstrap.com/2.0.2/) to things like [Material UI](https://v4.mui.com/) and more recently [Radix UI](https://www.radix-ui.com/) and [Tailwind](https://tailwindcss.com/). With the way that front-end frameworks have been proliferating there are a lot of frameworks out there React, Angular, Solid, Vue, Astro and Lit. How are we able to write framework agnostic component libraries? That way you don't need to re-learn and find alternatives to the things you love to use if you want to build an app in a different framework.

Enter [Shoelace](https://shoelace.style/) an undoubtedly witty pin on "Bootstrap", that aims at bringing back direct usable components but by offering web-components by default, but it also offers web-components wrapped in a [react component as well](https://github.com/shoelace-style/shoelace/blob/next/scripts/make-react.js#L59C9-L59C16). This is at the core of building a framework interoperable component library, 1) use web-components, 2) wrap them in that specific language's syntax.

While I haven't used `Shoelace` directly yet, they tout that it's possible to fully customize the components styles, unlike bootstrap which was expected to be used as is. The overuse of bootstrap ultimately led to the homogenization of web-design, making websites feel "bootstrap". With things like CSS Variables and custom styles I'm hoping `Shoelace` doesn't fall into this trap.

I've been very passionate about a project called `react-jsonschema-form` ([github](https://github.com/rjsf-team/react-jsonschema-form), [editor](https://rjsf-team.github.io/react-jsonschema-form/)). I personally hate writing forms, and love the idea of serializable components, schema, validation all in one. I've always wanted an alternative to this project that offered an alternative to react, and possibly the ability to render a schema form to static HTML (like ssg). 

I've thought about this a lot while using other frameworks like [Deno Fresh](https://fresh.deno.dev/) which uses [Preact](https://preactjs.com/) under the hood, mainly for JSX templating, but also for islands functionality. Within that framework you can't really use React component libraries. You start to think more about generating static HTML like this example from the Deno blog [A Whole Website in a Single JavaScript File, cont'd](https://deno.com/blog/a-whole-website-in-a-single-js-file-continued, which shows building a simple webpage with routes all in one typescript file, a site that serves no Javascript to the browser.

The other day I stumbled upon my dream project the other day `json-schema-form-element` ([github](https://github.com/json-schema-form-element/core), [editor](https://jsfe.js.org/AllFeatures)) which is heavily inspired by the react counterpart. It's exactly what I wanted to make. This project, `json-schema-form-element` is a masterclass in how to make a modern web-component-first / "authored" library which is also interoperable with all other frameworks.

The example repo uses Astro which allows the author to demo all of the usages for the library, check it out here: [index.astro](https://github.com/json-schema-form-element/examples/blob/main/src/pages/index.astro#L70-L85). Using Astro for this is just another thing the author got right here.

I'm really excited about all this, and it makes me have some faith in the web again. I think that Lit is a step in the right direction especially the ability to do SSR / SSG and hydrate a web page. Hopefully 🤞 Shoelace can get SSR running, [which is currently one hurdle](https://github.com/shoelace-style/shoelace/issues/778), but I think it is achievable.

Anyway, what do you think of Lit? What do you think of the approach that `json-schema-form-element` takes at making an interoperable component library? Comment below 👇 and let me know!

Follow me on Mastodon for more thoughts on the future of web-development, web components, and typescript stuff [@indieweb.social@thomasreggi](https://indieweb.social/@thomasreggi).

[![Thomas Reggi's Mastodon Profile Image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yykf8is1q8viw7ss97w7.png)](https://indieweb.social/@thomasreggi)