Skip to content

Commit cb1c691

Browse files
committed
MC-6270: Add docs for content type components
Completed first draft for review
1 parent 47170f4 commit cb1c691

File tree

6 files changed

+84
-91
lines changed

6 files changed

+84
-91
lines changed
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Option menu configurations
22

3-
{: .bs-callout .bs-callout-info }
4-
The development of this topic is currently **IN PROGRESS**.
3+
---
4+
5+
The development of this topic is currently **IN PROGRESS**.
6+
7+
---
8+

docs/create-basic-content-type/step-3-add-components.md

Lines changed: 78 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,34 @@ The development of this tutorial is currently **IN PROGRESS**.
55

66
***
77

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:
15+
16+
- Default preview component: `Magento_PageBuilder/js/content-type/preview`
17+
- Default master component: `Magento_PageBuilder/js/content-type/master`
18+
19+
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.]**
920

1021
## Component conventions
1122

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:
1324

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 content type.
25+
- Your preview component must be named `preview.js` and placed here in your module (`view/adminhtml/web/js/content-type/example-quote/`):
1526

16-
## Add component directories
27+
![Create config file](../images/step3-add-component.png)
1728

18-
The directory structure for your Quote components should look like this (`view/adminhtml/web/js/content-type/example-quote/`):
29+
- Your master component must be named `master.js` and placed here in your module (`view/frontend/web/js/content-type/example-quote/`):
1930

20-
![Create config file](../images/step3-add-component.png)
31+
![Create config file](../images/step3-add-master-component.png)
2132

22-
33+
We will not create a master component for our Quote example, but the location is given here if you need to include one for more complex content types.
34+
35+
Before continuing, add the preview component file (``preview.js`) to your `PageBuilderQuote` module within the directory structure noted.
2336

2437
## Component configuration
2538

@@ -38,158 +51,134 @@ In your configuration file, reference your Admin `preview_component` (`preview.j
3851
</config>
3952
```
4053

41-
The following table describes each component-related attribute from the Quote configuration.
54+
A description of each component-related attribute from the Quote configuration follows:
4255

4356
| Attribute | Description |
4457
| ------------------- | ------------------------------------------------------------ |
4558
| `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. |
4760
| `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. |
4861

4962
## Quote `preview_component`
5063

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.
5265

5366
```js
5467
define([
5568
'Magento_PageBuilder/js/content-type/preview',
56-
], function (PreviewBase) {
69+
], function (PreviewBase) {
5770
'use strict';
58-
5971
var $super;
6072

6173
function Preview(parent, config, stageId) {
6274
PreviewBase.call(this, parent, config, stageId);
6375
}
76+
6477
Preview.prototype = Object.create(PreviewBase.prototype);
6578
$super = PreviewBase.prototype;
6679

6780
Preview.prototype.retrieveOptions = function retrieveOptions() {
6881
var options = $super.retrieveOptions.call(this, arguments);
69-
console.log(options);
70-
71-
// Remove menu options
72-
// delete options.move;
73-
// delete options.duplicate;
74-
// delete options.edit;
75-
// delete options.remove;
82+
//console.log(options);
7683

77-
// options.edit.preview.config.icon = "<i class='icon-pagebuilder-copy'></i>";
78-
// options.edit.config.icon = "<i class='icon-pagebuilder-copy'></i>";
79-
// options.edit.icon._latestValue = "<i class='icon-pagebuilder-copy'></i>";
84+
// Change option menu title
85+
options.title.preview.config.label = "Quote Menu";
8086

8187
// Change option menu icons
82-
// options.edit.icon = "<i class='icon-pagebuilder-copy'></i>";
83-
84-
// Change option menu label
85-
// options.title.preview.config.label = "title.preview.config.label"; // works
86-
// options.title.title = "title.title"; // doesn't work
88+
options.remove.icon = "<i class='icon-admin-pagebuilder-error'></i>";
8789

8890
// Change tooltips
89-
options.move.title = "Drag";
90-
options.duplicate.title = "Copy";
91-
options.remove.title = "Delete";
9291
options.edit.title = "Open Editor";
92+
options.remove.title = "Delete";
93+
// options.move.title = "Move";
94+
// options.duplicate.title = "Duplicate";
95+
96+
// Remove menu options
97+
// delete options.move;
98+
// delete options.duplicate;
99+
// delete options.edit;
100+
// delete options.remove;
93101

94102
return options;
95103
};
96-
//
97-
// Preview.prototype.isContainer = function () {
98-
// return false;
99-
// };
100-
101104
return Preview;
102105
});
103106
```
104107

105-
### Extend from Page Builder preview.js
108+
### Extend from `Preview`
106109

107-
dasdasd
110+
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:
108111

109112
```js
110113
define([
111114
'Magento_PageBuilder/js/content-type/preview',
112-
], function (PreviewBase) {
115+
], function (PreviewBase) {
113116
'use strict';
114-
115117
var $super;
116118

117119
function Preview(parent, config, stageId) {
118120
PreviewBase.call(this, parent, config, stageId);
119121
}
122+
120123
Preview.prototype = Object.create(PreviewBase.prototype);
121124
$super = PreviewBase.prototype;
122125
```
123126
127+
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.
124128
129+
### Customize the options menu
125130
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:
127132
128-
sdfsdf
129-
130-
```js
131-
Preview.prototype.retrieveOptions = function retrieveOptions() {
132-
var options = $super.retrieveOptions.call(this, arguments);
133-
134-
return options;
135-
};
136-
```
133+
![Create config file](../images/options-menu-default.png)
137134
138-
139-
140-
#### Remove menu options
141-
142-
lsakd fjlsadfkj
135+
To do this, we need to override the protected `retrieveOptions()` function from the `Preview` class so we can change various options as shown here:
143136
144137
```js
145-
// Remove menu options
146-
delete options.move;
147-
delete options.duplicate;
148-
delete options.edit;
149-
delete options.remove;
150-
```
151-
152-
138+
Preview.prototype.retrieveOptions = function retrieveOptions() {
139+
var options = $super.retrieveOptions.call(this, arguments);
140+
//console.log(options);
153141

154-
#### Change option menu icons
155-
156-
sdfsdfsdf
157-
158-
```js
159-
// Change option menu icons
160-
options.edit.icon = "<i class='icon-pagebuilder-copy'></i>";
142+
// Change option menu title
143+
options.title.preview.config.label = "Quote Menu";
144+
145+
// Change option menu icons
146+
options.remove.icon = "<i class='icon-admin-pagebuilder-error'></i>";
147+
148+
// Change tooltips
149+
options.edit.title = "Open Editor";
150+
options.remove.title = "Delete";
151+
// options.move.title = "Move";
152+
// options.duplicate.title = "Duplicate";
153+
154+
// Remove menu options
155+
// delete options.move;
156+
// delete options.duplicate;
157+
// delete options.edit;
158+
// delete options.remove;
159+
160+
return options;
161+
};
161162
```
162163
164+
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 `delete options.move` and `delete options.duplicate` as shown commented out in the code.
163165
166+
![Create config file](../images/options-menu-custom.png)
164167
165-
#### Change option menu title
166-
167-
skdjflsdfjs
168-
169-
```js
170-
// Change option menu title
171-
options.title.preview.config.label = "title.preview.config.label";
172-
```
173-
168+
{: .bs-callout .bs-callout-info }
169+
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.
174170
171+
### Other changes
175172
176-
#### Change option menu tooltips
173+
Other changes and additions you can make to your preview component include:
177174
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]**
187176
188177
189178
190179
## Quote `master_component`
191180
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?]**
193182
194183
## Next
195184

docs/images/options-menu-custom.png

27.1 KB
Loading

docs/images/options-menu-default.png

26.9 KB
Loading

docs/images/step3-add-component.png

747 Bytes
Loading
17.6 KB
Loading

0 commit comments

Comments
 (0)