Bootstrap 5 Web Components
I like web components.
Bootstrap is great, and I use it for pretty much everything. However, the fact that there's a lot of copy-and-paste that happens with it means that it can be tedious to maintain and update. Also, it's just sometimes a pain to read. This repo is a collection of web components that I've created to make Bootstrap easier to use and faster to write. (This page is written using them--check the source!)
Every component that starts with bs- is a web component that wraps Bootstrap's
functionality for that component. Every component is stylable by passing classes into the
web component; the classes will be applied as expected to the Bootstrap component underneath.
Any other component is a custom component that involves Bootstrap in some way, but also
includes additional functionality. These components include things like a button that
automatically handles its own loading spinner and a main element that
prevents the Flash of Unstyled Content (FOUC) common when using web components.
Usage
Start by laying out your normal Bootstrap HTML structure, like this:
Once you have your basic template, copy the *.js files into your project that you want and include them at the bottom of your html file. With the script tags in place, you can use the web components in your html just like you would use Bootstrap's components.
Flashes of Unstyled Content (FOUC)
One of the major pitfalls of web components (besides their relative verbosity) is that
they take time to load. The HTML content will load in, but the browser won't know what
to do with it until the web component is upgraded. This can cause a flash of unstyled
content (FOUC) when the page loads. To prevent this, you can use the main-container
component, which will prevent FOUC by preventing the page from rendering until all web
components are upgraded.
This provides a nice loading screen (that loads in first) for your users while the web components load in. In practice, this takes very little time, but it hides the FOUC from your users and feels pretty slick.
main-container component is loaded in above the content so
that it gives time for the other components to load and initialize.