Skip to content

Commit 2c0076f

Browse files
author
Hwashiang Yu
committed
MC-3476: Design and prototype
- Created prototype for rearranging button.
1 parent d4da457 commit 2c0076f

File tree

8 files changed

+170
-6
lines changed

8 files changed

+170
-6
lines changed

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/_buttons.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
);
2121
.lib-css(border-radius, @button__border-radius);
2222
.lib-css(font-weight, @font-weight__semibold);
23+
min-width: 56px;
2324
}
2425

2526
.pagebuilder-button-secondary {

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/content-type/button-item/_default.less

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,39 @@
99

1010
.pagebuilder-content-type {
1111
.pagebuilder-button-item {
12+
&.pagebuilder-content-type-active {
13+
.button-item-drag-handle {
14+
&.disabled:before {
15+
color: @color-light-gray;
16+
cursor: not-allowed;
17+
}
18+
19+
&.disabled:active:before {
20+
cursor: not-allowed;
21+
}
22+
23+
&:before {
24+
.abs-icon;
25+
color: @color-dark-gray0;
26+
content: @icon-gripper__content;
27+
cursor: move; /* fallback if grab cursor is unsupported */
28+
cursor: grab;
29+
cursor: -moz-grab;
30+
cursor: -webkit-grab;
31+
display: inline-block;
32+
font-size: 16px;
33+
left: 0;
34+
line-height: 2.2rem;
35+
position: absolute;
36+
}
37+
38+
&:active:before {
39+
cursor: grabbing;
40+
cursor: -moz-grabbing;
41+
cursor: -webkit-grabbing;
42+
}
43+
}
44+
}
1245
[contenteditable=true] {
1346
display: inline-block;
1447
min-height: 18px;
@@ -20,7 +53,7 @@
2053
.pagebuilder-options {
2154
bottom: 0;
2255
left: calc(50% - 5px);
23-
transform: translate(-50%, 90%);
56+
transform: translate(-50%, -50%);
2457
li.pagebuilder-options-link {
2558
margin: 0;
2659
}

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/button-item/preview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/buttons/preview.js

Lines changed: 65 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/button-item/default/preview.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
*/
66
-->
77

8-
<div class="pagebuilder-content-type pagebuilder-button-item no-system-border" event="{ click: onMouseOver, focusout: onMouseOut }">
8+
<div class="pagebuilder-content-type pagebuilder-button-item no-system-border focus-options" event="{ click: onMouseOver, focusout: onMouseOut }">
99
<render args="getOptions().template" />
1010
<a attr="data.link.attributes" ko-style="data.link.style" css="data.link.css">
11+
<span class="button-item-drag-handle" css="{disabled: parent.parent.children().length <= 1}"></span>
1112
<span attr="data.link_text.attributes" data-bind="liveEdit: { field: 'button_text', placeholder: buttonPlaceholder }, hasFocus: $parent.parent.preview.isLiveEditing() === $index()" event="{ focusout: onFocusOut.call($data) }"></span>
1213
</a>
1314
</div>

app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/buttons/inline/preview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<div class="pagebuilder-content-type pagebuilder-entity pagebuilder-entity-preview pagebuilder-no-blur pagebuilder-live-edit pagebuilder-buttons" event="{ mouseover: onMouseOver, mouseout: onMouseOut }, mouseoverBubble: false">
99
<render args="getOptions().template" />
10-
<div class="element-children buttons-container" each="parent.getChildren()" attr="Object.assign({}, data.main.attributes(), { id: parent.id + '-children' })" ko-style="data.main.style" css="data.main.css" data-bind="sortableChildren: { handle: '.move-structural', items: '.pagebuilder-content-type-wrapper', connectWith: '.buttons-container', appendTo: 'body' }">
10+
<div class="element-children buttons-container" each="parent.getChildren()" attr="Object.assign({}, data.main.attributes(), { id: parent.id + '-children' })" ko-style="data.main.style" css="data.main.css" data-bind="sortableChildren: getSortableOptions()">
1111
<div class="pagebuilder-content-type-wrapper" template="{ name: preview.previewTemplate, data: preview }" attr="{ id: id }"></div>
1212
</div>
1313
</div>

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/button-item/preview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class Preview extends BasePreview {
2222
public retrieveOptions(): OptionInterface[] {
2323
const options = super.retrieveOptions();
2424
const newOptions = options.filter((option) => {
25-
return (option.code !== "remove");
25+
return (option.code !== "remove" && option.code !== "title" && option.code !== "move");
2626
});
2727
const removeClasses = ["remove-structural"];
2828
let removeFn = this.onOptionRemove;

app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/buttons/preview.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import $ from "jquery";
77
import ko from "knockout";
88
import $t from "mage/translate";
99
import events from "Magento_PageBuilder/js/events";
10+
import {SortableOptionsInterface} from "../../binding/sortable-options";
1011
import Config from "../../config";
1112
import ContentTypeInterface from "../../content-type";
1213
import createContentType from "../../content-type-factory";
@@ -20,6 +21,14 @@ import PreviewCollection from "../preview-collection";
2021
*/
2122
export default class Preview extends PreviewCollection {
2223
public isLiveEditing: KnockoutObservable<boolean> = ko.observable(false);
24+
public disableSorting: KnockoutComputed<void> = ko.computed(() => {
25+
const sortableElement = $(this.wrapperElement).find(".buttons-container");
26+
if (this.parent.children().length <= 1) {
27+
sortableElement.sortable("disable");
28+
} else {
29+
sortableElement.sortable("enable");
30+
}
31+
});
2332

2433
public bindEvents() {
2534
super.bindEvents();
@@ -84,4 +93,60 @@ export default class Preview extends PreviewCollection {
8493
console.error(error);
8594
});
8695
}
96+
97+
/**
98+
* Get the sortable options for the tab heading sorting
99+
*
100+
* @returns {JQueryUI.SortableOptions}
101+
*/
102+
public getSortableOptions(): SortableOptionsInterface {
103+
return {
104+
handle: ".button-item-drag-handle",
105+
items: ".pagebuilder-content-type-wrapper",
106+
containment: "parent",
107+
tolerance: "pointer",
108+
cursor: "grabbing",
109+
cursorAt: { left: 25, top: 25 },
110+
disabled: this.parent.children().length <= 1,
111+
/**
112+
* Provide custom helper element
113+
*
114+
* @param {Event} event
115+
* @param {JQueryUI.Sortable} element
116+
* @returns {Element}
117+
*/
118+
helper(event: Event, element: JQueryUI.Sortable): Element {
119+
const helper = $(element).clone().css({
120+
opacity: "0.7",
121+
width: "auto",
122+
});
123+
helper[0].querySelector(".pagebuilder-options").remove();
124+
return helper[0];
125+
},
126+
placeholder: {
127+
/**
128+
* Provide custom placeholder element
129+
*
130+
* @param {JQuery} item
131+
* @returns {JQuery}
132+
*/
133+
element(item: JQuery) {
134+
const placeholder = item
135+
.clone()
136+
.show()
137+
.css({
138+
display: "inline-block",
139+
opacity: "0.3",
140+
})
141+
.removeClass("focused")
142+
.addClass("sortable-placeholder");
143+
placeholder[0].querySelector(".pagebuilder-options").remove();
144+
return placeholder[0];
145+
},
146+
update() {
147+
return;
148+
},
149+
},
150+
};
151+
}
87152
}

0 commit comments

Comments
 (0)