Mozilla Brick

UI components for modern web apps

Soledad Penadés

Hold on

What is a "component"?

"a constituent part; element; ingredient."


Photo by apeofjungle


Photo by oskay


Photo by Neosnaps

And a web component...?

It's the same




Sample by LanDub

So, web components

The key is custom

Although the spec calls them widgets

Why Web Components?

Can't we just use divs?

<div class="widget calendar ui theme-winter">
  <div class="component-wrapper">
    <div class="inner-content">
      (ad nauseaum)

Why Web Components?

Or maybe some jQuery UI plugin?

$( "#datepicker" ).datepicker( $.datepicker.regional[ "fr" ] );
$( "#locale" ).change(function() {
  $( "#datepicker" ).datepicker( "option",
    $.datepicker.regional[ $( this ).val() ] );


With web components...

Ingredients for successful Web Components

So... not ready yet?

X-Tag to the rescue

X-Tag Shims all the things!!!11

(where appropriate)

X-Tag Shims all the things!!!11

(where appropriate)

How does mark-up with Brick look like?

Minimum app

      Spiffy header!
  Marvelous content!
    Magnificent footer!


See it in action

Why the hyphen?

The spec says:

"The custom element type identifies a custom element interface and is a sequence of alphanumeric ASCII characters that must match the NCName production and contain a U+002D HYPHEN-MINUS character"

i.e. "the name of a custom element must contain a hyphen"

the spec

So we took the X from X-Tag

And added a hyphen.

The imperative way

Creating bricks out of nowhere

It's magic!

var cal = document.createElement('x-calendar');

See it in action

The Brick line up


Get all the bricks

  1. Download the built files (brick.css & brick.js)
  2. Include the css file in your <head>:
    <link rel="stylesheet" type="text/css" href="css/brick.css" />
  3. Include the js file at the end of your <body>:
    <script src="js/brick.js"></script>
  4. Instead of window.onload, listen for DOMElementsLoaded

See it in action


Your bricks, the way you like them!

Customising the appearance

Give them a new layer of paint with CSS

  1. Include the brick.css file first
  2. Include your css file afterwards

Your CSS file overwrites some of Brick's default styles.

Customising the appearance


x-appbar {
  background-image: linear-gradient(-180deg, #f0f 0%, 
    #f00 30%, #ff0 50%, #0f0 75%, #00f 100%);
  color: #fff;
  text-shadow: 1px 1px 1px #000;
  padding: 1rem;
  font-size: 2rem;

See it in action

Customising the bundle

Or when you know what you're doing: no bundling

  1. clone the brick repo and run make
  2. include dist/core/core.min.js
  3. include the components you need, e.g. dist/calendar/calendar.min.js

Bake your own bricks

The moment you've been waiting for

Three simple steps

At the very minimum

  1. Include dist/core/core.min.js
  2. Write and include your-brick.js
  3. Write and include your-brick.css (optional)

What's in your-brick.js?

(function() {
  xtag.register('your-brick', {
    lifecycle: {
      created: function() {
        this.innerHTML = 'I am a brick';

See it in action

Adding events

(function() {
  xtag.register('your-brick', {
    // ...
    events: {
      'tap': function(e) { = 
          '#' + Math.round(0xFFFFFF * Math.random())

See it in action

Something more advanced

Let's build a complete app

Pocket Cutesy

We're still in beta

Brick 1.0 ß7

Expect bumps

Brick roadmap

Q1 2014

Brick 1.0

Brick roadmap

H1 2014

Brick roadmap

H2 2014

Not in the Brick roadmap

Unicorns and rainbows



Ask me questions!



Ask me questions!


Slides & code at

Slide notes