Enhancing Drupal front end performance through Pattern LabVinit Kumar27 Apr, 2021

Component-driven theming is becoming widely popular today because of various reasons. The most significant being reusability and portability of components. Pattern lab is a front-end framework that uses an atomic design architecture to implement a component-based design. In this article, we will discuss more about Pattern Lab and how you can enhance your Drupal frontend performance with it.

Pattern Lab

What is Pattern Lab?

Think of Pattern Lab as an application that can help you organize your UI components in a pattern-driven approach. It is basically a static site generator that binds together all the UI components together. Pattern lab uses atomic design to accelerate the process of creating modular designs. It starts out really basic and gets more complex as you move up the ladder.

Pattern Driven Approach

Credit: Pattern Lab

Let’s breakdown these visual building blocks:

Atoms: They are the most basic building blocks of your design. For example, UI elements like buttons, search fields, form elements, labels.

Molecules: They are groups of atoms that work together to perform a particular action. For example, a search navigation that involves a combination of atoms like a search button, a search field and a label.

Organisms: Organisms are molecules and atoms grouped together to define sections of the application. They’re more complex and have more interactions. For example, a header, a footer or a related blog post section.

Templates: Groups of Organisms form Templates. They are placeholders for organisms. For example, a blog page template, login page template or a shopping cart page template.

Pages: When you combine a template with real content, you get a page.

Page Template

Credit: Pattern Lab

Why should you use Pattern Lab?

Patten Lab makes frontend developers work an absolute pleasure. This is because it allows rapid design prototyping with demonstrable interface and interactivity.

It allows developers to maintain code consistency, implement and leverage reusable components and allows multiple developers to work at the same time. All of these benefits help in easy maintenance of the code.

In terms of Drupal, frontend developers can start their work independently without the dependency on Drupal development. We can work faster and with more consistency than ever before.

Patten Lab with Drupal

Integrating Pattern Lab with Drupal has many benefits and can improve and fasten frontend development. Thanks to the Drupal community, we now have a contributed theme Emulsify Drupal that comes with inbuilt the Pattern Lab architecture. This reduces the extra development effort of achieving a Pattern Lab integration.

Creating a Heading atom in Pattern Lab

For a better understanding of implementing Pattern Lab in Drupal, let’s take an example of creating a Heading atom and integrating it in Drupal Twig template.

Heading atom directory

Heading atom directory

In the atom directory we will have 3 required files.

_heading.twig : The heading markup will go in this file
_hading.scss : This is for heading style
heading.yml : This is for static data to be passed in twig

Heading atom Twig

Heading Twig

_heading.twig

In Heading twig, we can add the element markup with all the required attributes as variable. We can pass data from yml file or drupal field data with these variables.

Heading.yml / Heading.json

Heading json

heading.json

This is an example of a json file containing static data for the variable available in the _heading.twig file.

Integrating Heading atom in Drupal template with field values

Here, we will be overriding the page template and integrating it with the heading atom.

Barkit Page

Default bartik page-title.html.twig

Heading atom integrated with Page Title

Pattern Lab Heading atom integrated in page-title.html.twig

Here, in page-title.html.twig, instead of the default H1 element we are importing the heading atom as reusable element and adding Drupal field value to the defined variable in the heading atom - heading_level and heading.

Using the same pattern, we can create engaging Drupal websites using Pattern Lab.

Shefali ShettyApr 05, 2017