Skip to content

Commit 152f1ae

Browse files
author
Hwashiang Yu
committed
MC-3473: Create widget on frontend and apply width
- Added widget to apply same width on button groups buttons if enabled
1 parent ffdab78 commit 152f1ae

File tree

2 files changed

+42
-0
lines changed
  • app/code/Magento/PageBuilder/view/frontend

2 files changed

+42
-0
lines changed

app/code/Magento/PageBuilder/view/frontend/layout/default.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@
5555
</item>
5656
</item>
5757
</item>
58+
<item name="buttons" xsi:type="array">
59+
<item name="default" xsi:type="array">
60+
<item name="component" xsi:type="string">Magento_PageBuilder/js/content-type/buttons/appearance/inline/widget</item>
61+
</item>
62+
</item>
5863
</argument>
5964
</arguments>
6065
</block>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'jquery'
7+
], function ($) {
8+
'use strict';
9+
10+
/**
11+
* Equalize the width of a list of button-item components
12+
*
13+
* @param {JQuerySerializeArrayElement} buttonList
14+
*/
15+
var equalizeButtonWidth = function (buttonList) {
16+
var buttonMinWidth = 0;
17+
18+
buttonList.each(function () {
19+
var buttonWidth = this.querySelector('[data-element="link"]').offsetWidth;
20+
21+
if (buttonWidth > buttonMinWidth) {
22+
buttonMinWidth = buttonWidth;
23+
}
24+
});
25+
buttonList.each(function () {
26+
this.querySelector('[data-element="link"]').style.width = buttonMinWidth + 'px';
27+
});
28+
};
29+
30+
return function (config, element) {
31+
var $element = $(element);
32+
33+
if ($element.attr('data-same-width') === '1') {
34+
equalizeButtonWidth($element.children());
35+
}
36+
};
37+
});

0 commit comments

Comments
 (0)