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
Copy file name to clipboardExpand all lines: docs/create-basic-content-type/step-3-add-components.md
+78-89Lines changed: 78 additions & 89 deletions
Original file line number
Diff line number
Diff line change
@@ -5,21 +5,34 @@ The development of this tutorial is currently **IN PROGRESS**.
5
5
6
6
***
7
7
8
-
Components are the JavaScript files that define the behaviors of your content type when they appear on the stage in the Admin UI (using the `preview.js` component) and in the storefront (using the `master.js` component). As such, they are complementary to the templates you added previously in Step 2, acting as the view models to the template's views.
8
+
In this step, we will create a preview component in order to show you how to customize the Quote options menu.
9
+
10
+
## About components
11
+
12
+
Components are the JavaScript files that define the behaviors of your content type when they appear on the stage in the Admin UI (using the `preview.js` component) and in the storefront (using the `master.js` component). As such, they are complementary to the templates you added previously in Step 2, acting as the view models to the template's views.
13
+
14
+
Custom component files are completely optional. If they are not added to your content type, Page Builder will use these defaults:
Reasons for adding your own preview component include customizing options menus and adding user-interactivity that your content type needs to fulfill its function when displayed on the Admin stage. Adding your own master component is necessary if you want to... **[Reviewer: please give some examples of when custom master components might be necessary.]**
9
20
10
21
## Component conventions
11
22
12
-
Discuss the naming convention of the preview.js and master.js files, similar to the naming convention for the preview.html and master.html template files.
23
+
The conventions for naming your components and adding them to your module are as follows:
13
24
14
-
These component files are completely optional. Among the reasons for adding your own component is to customize the options menu in the Admin preview. That's what we will do for our Quote contenttype.
25
+
- Your preview component must be named `preview.js` and placed here in your module (`view/adminhtml/web/js/content-type/example-quote/`):
|`component`| There are two component types to choose from: `content-type` and `content-type-collection`. Use `Magento_PageBuilder/js/content-type` for static content types that do not have children (like our Quote). Use `Magento_PageBuilder/js/content-type-collection` for content types that can contain children (container content types). |
46
-
|`preview_component`| Optional. The `preview.js` file provides rendering logic to the Admin preview template. If your content type does not require any changes to the standard option menu (shown on mouseover) for a content type or other user-interactivity in the Admin, you can omit this attribute from the the `type` element. When you omit the attribute, Page Builder will use `Magento_PageBuilder/js/content-type/preview` by default. |
59
+
|`preview_component`| Optional. The `preview.js` file provides rendering logic to the Admin preview template. If your content type does not require any changes to Page Builder's standard rendering logic, you can omit this attribute from the the `type` element. When you omit the attribute, Page Builder will use `Magento_PageBuilder/js/content-type/preview` by default.<br /><br />However, if you want to make changes to the option menu for your content type, or other customize other user-interactivity in the Admin, you need to create your own preview component as we have done for the Quote content type. |
47
60
|`master_component`| Optional. The `master.js` file provides rendering logic to the master format storefront template. As with the `preview_component`, if your content type does not require any specific user-interactivity or other behavior when it's displayed in the storefront, you can simply omit this attribute from the the `type` element. When you omit the attribute, Page Builder will use `Magento_PageBuilder/js/content-type/master` by default. <br /><br />In the Quote configuration, the `master_component` attribute is only included for discussion. It simply points to the Page Builder default `master.js` component that would be used the attribute was omitted. |
48
61
49
62
## Quote `preview_component`
50
63
51
-
The Quote `preview_component` (`preview.js`) is shown here in full, followed by an explanation of how the component is used in the Quote.
64
+
The Quote `preview_component` (`preview.js`) example is shown here in full for you to copy into your `preview.js` file, followed by an explanation of its key parts.
The first thing we do in our preview component is extend Page Builder's `Preview` class (`magento2-page-builder/app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/preview.ts`) by declaring it as a dependency and calling it from the preview component's constructor as follows:
You don't have to extend `Preview` this way, but if you do, you get access to both its public and protected functions. In our Quote example, we need access to one protected function, discussed next.
124
128
129
+
### Customize the options menu
125
130
126
-
### Manipulate the options menu
131
+
Our goal for the Quote preview component is to customize the default Page Builder options menu for a content type, as shown here:
In the preceding code, we made changes to the options menu title, icons, and tooltips. You can also remove options from the menu. For example, if you don't want end-users to move or duplicate your content type, you can remove those options from your menu using `deleteoptions.move` and `deleteoptions.duplicate` as shown commented out in the code.
Even though you can change the base option menu properties as described, we suggest you stick the the default options as much as possible to provide end-users with a consistent experience across Magento's content types and other third-party content types that are included as time goes on.
174
170
171
+
### Other changes
175
172
176
-
#### Change option menu tooltips
173
+
Other changes and additions you can make to your preview component include:
177
174
178
-
lsdfkjsdklfj
179
-
180
-
```js
181
-
// Change tooltips
182
-
options.move.title="Drag";
183
-
options.duplicate.title="Copy";
184
-
options.remove.title="Delete";
185
-
options.edit.title="Open Editor";
186
-
```
175
+
**[Reviewer: Please include a list of other changes or additions that developers might make in their own preview component]**
187
176
188
177
189
178
190
179
## Quote `master_component`
191
180
192
-
As mentioned previously, our Quote content type has no need for a master.js component file. Instead, we are using Page Builder's default master component file: `Magento_PageBuilder/js/content-type/master`.
181
+
As mentioned previously, our Quote content type has no need for a master.js component file. Instead, we are using Page Builder's default master component file: `Magento_PageBuilder/js/content-type/master`. More information on master components and their usage can be found **[where?]**
0 commit comments