Skip to content

Commit 0bab6f4

Browse files
committed
MC-5025: Right/Left Margin Not Working For Content Types
- fix video with margins to fit inside parent - skip tslint error due to strict rule we can ignore
1 parent 779dbe6 commit 0bab6f4

File tree

4 files changed

+172
-96
lines changed

4 files changed

+172
-96
lines changed

app/code/Magento/PageBuilder/view/adminhtml/pagebuilder/content_type/video.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<css name="css_classes"/>
3131
</element>
3232
<element name="wrapper">
33-
<style name="max_width" source="max_width" converter="Magento_PageBuilder/js/converter/style/remove-px"/>
33+
<style name="max_width" source="max_width" converter="Magento_PageBuilder/js/content-type/video/converter/style/max-width"/>
3434
<style name="border" source="border_style" converter="Magento_PageBuilder/js/converter/style/border-style"/>
3535
<style name="border_color" source="border_color"/>
3636
<style name="border_width" source="border_width" converter="Magento_PageBuilder/js/converter/style/remove-px"/>

app/code/Magento/PageBuilder/view/adminhtml/web/js/content-type/video/converter/style/max-width.js

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
import ConverterInterface from "../../../../converter/converter-interface";
7+
import {DataObject} from "../../../../data-store";
8+
9+
/**
10+
* Subtract margin from max-width to fit inside parent container
11+
*
12+
* @api
13+
*/
14+
export default class MaxWidth implements ConverterInterface {
15+
/**
16+
* Convert value to internal format
17+
*
18+
* @param value string
19+
* @returns {string | object}
20+
*/
21+
public fromDom(value: string): object | string {
22+
if (value.indexOf("100%") !== -1) {
23+
return "";
24+
}
25+
return value.replace("px", "");
26+
}
27+
28+
/**
29+
* Convert value to knockout format
30+
*
31+
* @param name string
32+
* @param data Object
33+
* @returns {string | object}
34+
*/
35+
public toDom(name: string, data: DataObject): string {
36+
if (data.max_width !== "") {
37+
return data.max_width + "px";
38+
}
39+
const margins = data.margins_and_padding.margin || {};
40+
const marginLeft = margins.left ? parseInt(margins.left as string, 10) : 0;
41+
const marginRight = margins.right ? parseInt(margins.right as string, 10) : 0;
42+
43+
return "calc(100% - " + (marginLeft + marginRight) + "px)";
44+
}
45+
}

0 commit comments

Comments
 (0)