As the web design niche evolves, developers frequently face the necessity of using a more systemized approach to the creation of websites, instead of stamping web pages one after another in a non-specific order. A specific example of such a systematized approach is so-called atomic design, based on the atoms of web development: HTML tags that define input fields, forms, buttons, and other elementary components of the web interface (font types, colors, etc.). Atomic design allows developers to convert abstractions into unique, complex systems that are easily scalable and composed in one consistent style. This method makes the web development process more construction-based (we are building a site brick by brick, like Legos).

To implement features of atomic design, Drupal 8 features Pattern Lab, a static website generator. Let’s talk about it.

Pattern Lab: what is it?

Pattern Lab, as we mentioned above, is a static website generator that employs the atomic design methodology, helps to annotate patterns, and provides a basic set of tools to work with the patterns.

The Pattern Lab working principle is based on the idea that atoms, which are included in the composition of larger molecules, form larger units, hence creating whole pages. When UI is designed with this principle, developers aren’t obliged to make a multitude of customizations if changes need to be made to some of the patterns (basically, the update takes place automatically in all the places this pattern was used).

Why use Pattern Lab?

Well, to answer that question, let’s take a look at the main advantages of creating component-based themes with Pattern Lab:

Pattern Lab helps to fully decouple design from an application on Drupal.

Developers and designers save time on making corrections in projects.

Despite an ever-increasing number of components (an unavoidable process during scaling), Pattern Lab allows users to adhere to one specific frontend style.

The product built with the help of component-based Drupal theming is much more accessible when it comes to testing, as modules comprising the frontend won’t depend in any way on the contents of the connected DBMS.

Which tasks can Pattern Lab solve?

Now we will discuss some particular tasks and cases where Pattern Lab can be exceptionally helpful.

Optimization of dynamic data manipulation

An important attribute of Pattern Lab is its ability to optimize dynamic data manipulation. In order to understand whether the created user interface patterns will fit the dynamically-updated content or not, Pattern Lab uses JSON/YAML/Markdown/etc. data. This alternative allows it to separate the pattern structure from its contents. This, in turn, explicitly demonstrates the DRY principle, according to which developers should focus all their effort on creating universal patterns that fit any content. Moreover, if you need to make corrections within the pattern itself, it won’t require you to update each and every implementation (all this happens automatically). Pattern Lab's capabilities also mean you won’t have to additionally load a separate CMS to simply demonstrate several frontend variations to a client.

The creation of pseudo-templates

The next useful thing Pattern Lab is capable of is the creation of pseudo-templates. If web developers previously had to generate every possible frontend option in a static way (which took a lot of time, i.e. more client money), with Pattern Lab, you can forget about these cumbersome processes. Demonstrate all the possible content variations while saving time and money.

Decoupling

Pattern Lab helps backend developers, too. In particular, the developers get frontend access (without interfering with the designer’s work), through which they can simply define which elements are dynamic (and need to be exported to the server).

In this manner, we can conclude that Pattern Lab separates the structure and data. This allows everyone possessing a sufficient server development competency to manage any module in the system with the content attached without risk, while backend developers can focus on the system’s architecture design.

An ability to ‘jump into’ code

Pattern Lab allows users to view the basic HTML code of the pattern, as well as the pattern code used for the generation of HTML. It also allows users to display the CSS and JavaScript code. This supports the formation of a single coding style during interface creation for all patterns. In order to configure some of the components, you only need code to enable a certain pattern from a library.

Tools for adaptive web design creation

Pattern Lab has a very interesting tool, Ish., which allows you to view interfaces and their consistent patterns in several different resolutions. This is an irreplaceable assistant for web designers that strive to thoroughly test each created interface on as many gadgets as possible.

Annotations

Last but not least, Pattern Lab helps to describe patterns (in particular, it provides multiple ways to add pattern description and design system annotations). To add a description, you will need a Markdown file with a name corresponding with the name of the pattern.

The role of Twig in working with Drupal 8 and Pattern Lab

Generally speaking, Pattern Lab can’t work with Drupal 8 independently. In order to employ all of the advantages of Drupal Pattern Lab and start theming using the atomic methodology, you’ll also need Twig - a fast and secure solution for the building of templates created by the Sensio Lab team (although we should note that an original version of Twig also required Mustache Templates). With the help of this PHP template creating tool, you get the ability to work with a single project (via Twig instructions) instead of two, as was characteristic in the previous version of Drupal

How to connect Pattern Lab to the project on Drupal 8

As a matter of fact, there are a multitude of ways to connect Pattern Lab to Drupal you can choose from. We prefer the one called Emulsify. Here are several ways you can use it to connect the website generator (particularly, employ Node Version Manager, the streaming build system Gulp, dependency manager Composer and, optionally - the dependency management tool Yarn):