denisismagilov - Fotolia
Code reuse is indubitably valuable. With reusable application modules, developers can take it a step further into web apps and UIs.
Web Components are modular elements of a UI that developers can assemble, reuse and port among browsers and sometimes even app environments. Developers create UIs from Web Components similarly to how they compose applications from services or microservices. As with service- or microservices-based programming, the Web Component model has rules, tips and drawbacks.
Let's explain how to use Web Components and the pieces that comprise them.
What constitutes Web Components?
Web Components standards and related processes consist of four pieces:
- Custom Elements, which design or define Web Components;
- the Shadow DOM that frames Custom Elements in a way that makes them portable;
- HTML Templates that describe how to instantiate Web Components.
The specifications for Web Components enable developers to use Custom Elements, an extension of the browser API set, to define a particular piece for the browser to parse. Each Web Component is embedded in its Shadow DOM, which stands for Document Object Model, the representation of a webpage. Each Component can then function as a self-contained element of the larger page.
To use Web Components, developers must install, import and then reference them; the site webcomponents.org details this process, and it hosts Web Component samples and a community of web developers.
How to use Web Components to build a UI
Components are objects. Think of a Web Component as a subpage that a constructor must invoke to be visible and active. Each Component has a constructor that runs when it's activated, which makes the Component visible and defines its initial state. Thus, object-oriented thinking is important when you construct a UI for Web Component implementation.
UI design tools, languages and frameworks
For the lowest barrier to entry with Web Components, use UI design tools. These tools can help design a UI that matches Web Component capabilities. Most web design tools follow the precepts of the Material Design system; and Google, which originally designed it, offers a Material Components framework, as well as a broader set of tools and practices associated with building a modular UI that's suitable with Web Components.
Material Design is the most widely used design language on the internet, but there are other options for UI designers who prefer customized looks. Materialize is a superset of Material Design that offers, according to many web designers, better creative support. MUI and Flat Remix are lightweight design languages that constitute subsets of Material Design.
Ant and Grommet are design languages that represent total departures from Material Design in principles and use.
Design + Web Components = the UI. The better control a software team has over its designs and the more it relies on standardized structures, the more it will get out of Web Component use.
What to make of the proliferation of progressive web apps
Why enterprises need to prioritize UX research