You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document outlines how to implement the inline editing toolbar for any content type. This feature is used within the heading to allow for easy modification of the heading type and alignment. It can be used within your content types to quickly change common things without needing to open the full editor.
3
+
This topic shows you how to implement an inline toolbar for your content type. You can see an example of a toolbar in Page Builder's Heading content type, as shown here:
6
4
7
5

8
6
9
-
## Overview
10
-
11
-
To add a custom toolbar to a Page Builder content block:
7
+
Toolbars provide end-users with a quick way to change common properties of your content type (such as text alignment and heading types) without needing to open the full editor. The toolbar does not replace the need for form fields in the editor; it simply extends those fields.
12
8
13
-
1.[Add a toolbar configuration](#toolbarConfig)
14
-
2.[Add a toolbar template](#toolbarTpl)
9
+
## How the Toolbar works
15
10
16
-
## Add a toolbar configuration {#toolbarConfig}
11
+
The diagram below shows the basic steps for adding a toolbar to your content type. It also shows how the various parts connect and work together.
17
12
18
-
To add a Toolbar configuration to your content block, you need to create a new instance of the `Toolbar` class, then add configuration options to it.
13
+

19
14
20
-
An example implementation can be found in the Heading content block:
In the Heading example, the `Toolbar` constructor requires its parent preview and the toolbar options you want to include as follows:
24
16
25
-
```javascript
26
-
newToolbar(this, this.getToolbarOptions());
27
-
```
17
+
## Step 1: Add toolbar options
28
18
29
-
where `this.getToolbarOptions()`returns the toolbar options. For example, the Heading toolbar's three text-alignment options are defined as follows:
19
+
Toolbar options are the clickable items in a toolbar that represent the property values of a form field. For example, the Heading content type adds toolbar options for the `text_align` field from `pagebuilder_base_form.xml`. The Heading adds the values of the `text_align` field (`left`, `center`, and `right`) as items on the toolbar, represented with the images provided by the icon CSS classes as shown here:
30
20
31
21
```typescript
32
22
{
@@ -52,28 +42,79 @@ where `this.getToolbarOptions()`returns the toolbar options. For example, the He
52
42
},
53
43
```
54
44
55
-
Option property descriptions:
45
+
The `OptionInterface` and `ValueInterface` define the structure of toolbar options. You can find these interfaces in `magento2-page-builder/app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type-toolbar.types.ts`. Descriptions of the elements follow:
|`key`| The field `name` you are binding to. For example: `<field name="quote_css"...>`|
50
+
|`type`| The `formElement` of the key field. For example: `<field ... formElement="select">`|
51
+
|`values`| Array of field option values. |
52
+
|`value`| Field option value, such as a CSS class (as shown in the code example). |
53
+
|`label`| Field option label, such as a label for a select option (as shown in the code example) |
54
+
|`icon`| CSS class name for the icon to display in the toolbar to represent the field's option. If you don't include a CSS class, the toolbar will display the label instead. |
-**Call the toolbar constructor.** The `Toolbar` constructor requires you to pass your `Preview` component and the array of toolbar options you created in step 1 (`this.toolbar = new Toolbar(this, this.getToolbarOptions());`). You can find Page Builder's `Toolbar` class in `magento2-page-builder/app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type-toolbar.ts`.
Within your `preview.html` template, use a `div` element (with CSS class and events) to wrap whichever element in your template you want the toolbar to act on. For example, the custom Quote content type wraps its `<blockquote>` element within a `div` with the toolbar's CSS class and event binding, as shown here:
0 commit comments