Skip to content

Commit 2ee3e70

Browse files
author
Hwashiang Yu
committed
MC-3477: Polish prototype and apply rearranging in preview
- Added animation and polish to the button rearranging
1 parent 2c0076f commit 2ee3e70

File tree

2 files changed

+132
-11
lines changed
  • app/code/Magento/PageBuilder/view/adminhtml/web

2 files changed

+132
-11
lines changed

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

Lines changed: 72 additions & 5 deletions
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/ts/js/content-type/buttons/preview.ts

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import PreviewCollection from "../preview-collection";
2121
*/
2222
export default class Preview extends PreviewCollection {
2323
public isLiveEditing: KnockoutObservable<boolean> = ko.observable(false);
24+
/**
25+
* Keeps track of number of button item to disable sortable if there is only 1.
26+
*/
2427
public disableSorting: KnockoutComputed<void> = ko.computed(() => {
2528
const sortableElement = $(this.wrapperElement).find(".buttons-container");
2629
if (this.parent.children().length <= 1) {
@@ -93,19 +96,19 @@ export default class Preview extends PreviewCollection {
9396
console.error(error);
9497
});
9598
}
96-
9799
/**
98-
* Get the sortable options for the tab heading sorting
100+
* Get the sortable options for the buttons sorting
99101
*
100102
* @returns {JQueryUI.SortableOptions}
101103
*/
102104
public getSortableOptions(): SortableOptionsInterface {
105+
let placeholderGhost: JQuery;
103106
return {
104107
handle: ".button-item-drag-handle",
105108
items: ".pagebuilder-content-type-wrapper",
106-
containment: "parent",
107-
tolerance: "pointer",
108109
cursor: "grabbing",
110+
containment: "parent",
111+
revert: 200,
109112
cursorAt: { left: 25, top: 25 },
110113
disabled: this.parent.children().length <= 1,
111114
/**
@@ -133,10 +136,11 @@ export default class Preview extends PreviewCollection {
133136
element(item: JQuery) {
134137
const placeholder = item
135138
.clone()
136-
.show()
137139
.css({
138140
display: "inline-block",
139-
opacity: "0.3",
141+
opacity: 0,
142+
width: item.width(),
143+
height: item.height(),
140144
})
141145
.removeClass("focused")
142146
.addClass("sortable-placeholder");
@@ -147,6 +151,56 @@ export default class Preview extends PreviewCollection {
147151
return;
148152
},
149153
},
154+
/**
155+
* Logic for starting the sorting
156+
* Adding the placeholderGhost
157+
*
158+
* @param {Event} event
159+
* @param {JQueryUI.Sortable} element
160+
*/
161+
start(event, element) {
162+
placeholderGhost = element.placeholder
163+
.clone()
164+
.css({
165+
opacity: 0.3,
166+
position: "absolute",
167+
left: element.placeholder.position().left,
168+
top: element.placeholder.position().top,
169+
});
170+
element.item.parent().append(placeholderGhost);
171+
events.trigger("stage:interactionStart");
172+
},
173+
/**
174+
* Logic for changing element position during the sorting
175+
* Set the width and height of the moving placeholder animation
176+
* Add animation of placeholder ghost to the placeholder position
177+
*
178+
* @param {Event} event
179+
* @param {JQueryUI.Sortable} element
180+
*/
181+
change(event, element) {
182+
element.placeholder.stop(true, false);
183+
if (this.getAttribute("data-appearance") === "stacked") {
184+
element.placeholder.css({height: element.item.height() / 2});
185+
element.placeholder.animate({height: element.item.height()}, 200, "linear");
186+
}
187+
if (this.getAttribute("data-appearance") === "inline") {
188+
element.placeholder.css({width: element.item.width() / 2});
189+
element.placeholder.animate({width: element.item.width()}, 200, "linear");
190+
}
191+
placeholderGhost.stop(true, false).animate({
192+
left: element.placeholder.position().left,
193+
top: element.placeholder.position().top,
194+
}, 200);
195+
},
196+
/**
197+
* Logic for post sorting
198+
* Removing the placeholderGhost
199+
*/
200+
stop() {
201+
placeholderGhost.remove();
202+
events.trigger("stage:interactionStop");
203+
},
150204
};
151205
}
152206
}

0 commit comments

Comments
 (0)