Pattern Lab


Design systems, not pictures


http://patternlab.io/

https://github.com/pattern-lab/patternlab-php


Brad Frost

http://bradfrostweb.com/

Pattern Lab



  1. Atomic Design: A way of thinking about web development
  2. Pattern Lab: A PHP-based tool to build component-based prototypes

Atoms


In chemistry, atoms are the basic building blocks of matter. They have distinct properties and can't be broken down further without losing their meaning.

Translated to interfaces, atoms are basic tags, such as form labels, inputs or buttons. They also include more abstract elements like color palettes, fonts, and animations.

Atoms are abstract and aren't often terribly useful on their own, but they provide a useful reference and allow you to see all your global styles laid out at a glance.

Molecules


In chemistry, molecules are groups of atoms bonded together, which take on new properties as a result.

In interfaces, molecules are groups of elements that function together as a unit. For example, a form label, search input, and button atom can combine them together to form a search form molecule.

Building up from atoms to molecules encourages a “do one thing and do it well” mentality, and encourages creating reusable interface patterns.

Organisms


Organisms are groups of molecules (and possibly atoms) joined together to form distinct section of an interface.

Organisms can consist of similar and/or disparate molecule types. For example, a masthead organism might consist of a logo, navigation, and search form, while a “product grid” organism might consist of the same product info molecule repeated over and over.

Building up from molecules to organisms encourages creating standalone, portable, reusable components.

templates


With templates, we break our biochemistry analogy to get into language that makes more sense to clients and final output. Templates are comprised mostly of organisms combined together to form page-level objects.

Templates provide context for these relatively abstract molecules and organisms, which is helpful for designers and clients alike.

Templates mostly focus on content structure (such as character length, image size, etc) rather than the actual content.

Pages


Pages are specific instances of templates and swap out placeholder content with real representative content to give an accurate depiction of what a user will ultimately see.

Pages are essential for testing the effectiveness of the design system. This final form allows us to loop back to modify our molecules, organisms, and templates to better address the real context of the design.

Pages also provide a place to test variations in templates, such as testing an article containing a 40-character-length headline and other article with a 340-character-length headline. What does it look like when a user has one item in their shopping cart versus 10 items with a discount code applied? These specific page instances test the resiliency of the system, influencing how the underlying molecules, organisms, and templates are constructed.

Pattern Lab: Tools


  1. Generate for the first time:
    http://pattern-lab.info/docs/first-run.html
  2. We work in the "sources" directory.
  3. Pattern Lab renders all files to the "public" directory
  4. "public" directory is wiped out every time we generate.
  5. Partials written in mustache

Pattern Lab: Partials

Ta da! View public/index.html in a browser:

  1. sources/_patterns: self-explanatory
  2. All based on naming conventions:
    00-partial-name.mustache

Mustache 1

  1. A modern templating engine, similar to Twig, Handlebars
  2. Used to print data into templates and iterate over datasets

source/_patterns/01-molecules/00-text/00-byline-author-only.mustache


Where does "author" information come from?

source/_data/_data.json

Look for the "author" index. Notice json file names.

Mustache 2

Patterns can reference other patterns (entire point of PL)
source/_patterns/01-molecules/02-blocks/00-media-block.mustache
<div class="block block-thumb">
<a href="{{ url }}" class="b-inner">
<div class="b-thumb">
{{> atoms-square }}
</div>
<div class="b-text">
<h2 class="headline">{{ headline.short }}</h2>
<p>{{ excerpt.medium }}</p>
</div>
</a>
</div>

{{> atoms-square }} actually embeds:

source/_patterns/00-atoms/04-images/03-square.mustache

Mustache 3

Iterate:
source/_patterns/04-pages/00-homepage.mustache
...
<div class="g g-3up">
{{# touts}}
<div class="gi">
{{> molecules-inset-block }}
</div>
{{/ touts}}
</div>


Loops through "touts" object in source/_patterns/04-pages/00-homepages.json and passes each object to the source/_patterns/01-molecules/02-blocks/05-inset-block.mustache template


Annotations

  1. http://pattern-lab.info/docs/pattern-adding-annotations.html
  2. source/_data/annotations.js
  3. Essentially a json object with a jQuery selector and some notes.
{
    "el": ".logo",
    "title" : "Logo",
    "comment": "The logo image is an SVG file, which ensures blah."
} 

Sass

source/css/style.scss

Pattern Lab has almost NO opinions about how you should handle your Sass. A basic SMACSS structure is supplied. Go nuts.

** YOU COMPILE YOUR OWN Sass. Pattern Lab does not compile Sass.**

When Pattern Lab is recompiled, *.css files are moved from source/css to public/css.

Pattern Lab

By Christopher Bloom

Pattern Lab

Pattern Lab is pretty cool

  • 3,567