Skip to content

Commit 4879680

Browse files
committed
MC-6270: Add docs for content type components
WIP code sample
1 parent fc9c407 commit 4879680

File tree

2 files changed

+66
-10
lines changed

2 files changed

+66
-10
lines changed

docs/create-basic-content-type/step-2-add-templates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ The `css` attribute applies CSS classes entered by users on the form to a templa
154154

155155
### class
156156

157-
Just as with any other html template, you can add your own classes to your template elements. However, you should **always add the `pagebuilder-content-type` as the first class in the top node in your `preview.html` template** as shown for the Quote. Page Builder uses the `pagebuilder-content-type` class to visual indicators and mouseover effects to the Admin preview template, such as correctly positioning the options menu. Defining custom LESS/CSS classes for your content type is discussed in [Step 5: Add styles](step-5-add-styles.md).
157+
Just as with any other html template, you can add your own classes to your template elements. However, you should **always add the `pagebuilder-content-type` as the first class in the top node in your `preview.html` template** as shown for the Quote. Page Builder uses the `pagebuilder-content-type` class to add visual indicators and mouseover effects to the Admin preview template, such as correctly positioning the options menu. Defining custom LESS/CSS classes for your content type is discussed in [Step 5: Add styles](step-5-add-styles.md).
158158

159159
### liveEdit
160160

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

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,19 @@ The development of this tutorial is currently **IN PROGRESS**.
77

88
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.
99

10-
## Configuration
10+
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.
1111

12-
In your configuration file, reference your JavaScript component (`preview.js`) as shown here within the `type` element:
12+
## Add component directories
13+
14+
The directory structure for your Quote components should look like this (`view/adminhtml/web/js/content-type/example-quote/`):
15+
16+
![Create config file](../images/step3-add-component.png)
17+
18+
19+
20+
## Component configuration
21+
22+
In your configuration file, reference your Admin `preview_component` (`preview.js`) as shown here:
1323

1424
```xml
1525
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -29,15 +39,61 @@ The following table describes each component-related attribute from the Quote co
2939
| Attribute | Description |
3040
| ------------------- | ------------------------------------------------------------ |
3141
| `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). |
32-
| `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 this attribute, Page Builder will use `Magento_PageBuilder/js/content-type/preview` by default. |
33-
| `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 this attribute, Page Builder will use `Magento_PageBuilder/js/content-type/master` by default. In |
42+
| `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. |
43+
| `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. |
3444

35-
## Location
45+
## Create preview.js component
3646

37-
Add them to your module here (`view/adminhtml/web/js/content-type/example-quote/`):
3847

39-
![Create config file](../images/step3-add-component.png)
4048

41-
## Create preview component
49+
```js
50+
define([
51+
'Magento_PageBuilder/js/content-type/preview',
52+
], function (PreviewBase) {
53+
'use strict';
54+
var $super;
55+
56+
function Preview(parent, config, stageId) {
57+
PreviewBase.call(this, parent, config, stageId);
58+
}
59+
Preview.prototype = Object.create(PreviewBase.prototype);
60+
$super = PreviewBase.prototype;
61+
62+
Preview.prototype.retrieveOptions = function retrieveOptions() {
63+
var options = $super.retrieveOptions.call(this, arguments);
64+
console.log(options);
65+
66+
// Remove menu options
67+
// delete options.move;
68+
// delete options.duplicate;
69+
// delete options.edit;
70+
// delete options.remove;
71+
72+
// options.edit.preview.config.icon = "<i class='icon-pagebuilder-copy'></i>";
73+
// options.edit.config.icon = "<i class='icon-pagebuilder-copy'></i>";
74+
// options.edit.icon._latestValue = "<i class='icon-pagebuilder-copy'></i>";
75+
76+
// Change option menu icons
77+
// options.edit.icon = "<i class='icon-pagebuilder-copy'></i>";
78+
79+
// Change option menu label
80+
// options.title.preview.config.label = "title.preview.config.label"; // works
81+
// options.title.title = "title.title"; // doesn't work
82+
83+
// Change tooltips
84+
options.move.title = "Drag";
85+
options.duplicate.title = "Copy";
86+
options.remove.title = "Delete";
87+
options.edit.title = "Open Editor";
88+
89+
return options;
90+
};
91+
//
92+
// Preview.prototype.isContainer = function () {
93+
// return false;
94+
// };
95+
96+
return Preview;
97+
});
98+
```
4299

43-
The remainder of this topic is in progress.

0 commit comments

Comments
 (0)