Warning
You're browsing the documentation for an old version of Webiny. Consider upgrading your project to Webiny 5.40.x.
What You’ll Learn
  • how elements are used in Page Builder theme
  • how to update elements in Page Builder theme

Overview
anchor

Another way Webiny Page Builder ensures that visual styles follow your design system is by having certain style presets for some of the elements like the Button element as shown below:

Webiny theme elementsWebiny theme elements
(click to enlarge)

Elements Definition
anchor

Elements are defined in the elements section of the pb-theme plugin. It defines certain attributes for Page Builder elements that you can insert into your page content. For example:

apps/theme/pageBuilder/index.ts

Currently, only the following elements support this, for example:

  • button
  • heading
  • paragraph
  • list
  • quote

But the point is that if you create a custom component for Page Builder, you can reference the same mechanism and add this functionality to your custom elements.

The definition takes two keys:

  • className: Name of the CSS class that gets appended to that element.
  • label: This is what’s shown in the dropdown when a user is selecting a style.
Webiny theme elementsWebiny theme elements
(click to enlarge)

Button Element
anchor

In the case of the button element, the types attribute contains available button types. Each type references a specific class name that gets added to the button component when that type is selected.

By default, Webiny uses BEM namingexternal link. The default button class is webiny-pb-element-button, so when the user selects the primary button type, it adds a modifier of primary to the base class, meaning the resulting class name becomes webiny-pb-element-button--primary.

Extend Button Element Types
anchor

We achieve this in two steps:

  1. Add a new item in button types
  2. Add styles corresponding to that type

Add New Item in Button Types
anchor

Make the following change in apps/theme/pageBuilder/index.tsexternal link file:

apps/theme/pageBuilder/index.ts

Add Styles
anchor

Make the following changes in apps/theme/pageBuilder/styles/elements/button.scssexternal link file:

apps/theme/pageBuilder/styles/elements/button.scss

With these changes in place, the button element gets a new type available to use in the Page Builder editor as shown below:

Webiny theme new button element typeWebiny theme new button element type
(click to enlarge)