Skip to content

Commit b0aec43

Browse files
MC-855: Pagebuilder - Tab Minimum Height Displays Differently On Stage & Storefront
1 parent 7a56fd4 commit b0aec43

File tree

10 files changed

+72
-41
lines changed

10 files changed

+72
-41
lines changed

app/code/Magento/PageBuilder/Test/Mftf/Section/PageBuilderTabsSection.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<element name="tabHeader" type="button" selector="(//li[contains(@role, 'tab')])[{{arg1}}]" parameterized="true"/>
6464
<element name="tabHeaderItemActive" type="button" selector="(//div[@data-role='tabs']//descendant::*[@role='tablist'])/li[{{arg1}}][contains(@class, 'ui-state-active')]" parameterized="true"/>
6565
<element name="tabPanel" type="button" selector="(//div[@class='tabs-content']//div[@role='tabpanel'])[{{arg1}}]" parameterized="true"/>
66-
<element name="tabContent" type="button" selector="(//div[@class='tabs-content']//div[@data-role='tab-item'])[{{arg1}}]" parameterized="true"/>
66+
<element name="tabContent" type="button" selector="div.tabs-content div[data-role=tab-item]:nth-child({{arg1}})" parameterized="true"/>
6767
<element name="tabContentAdvancedStyles" type="button" selector="(//div[@class='tabs-content']//div[@data-role='tab-item'])[{{arg1}}][@style='border-radius: 0px 12px 12px; border: 10px solid rgb(0, 0, 0);']" parameterized="true"/>
6868
<element name="tabContentMinimumHeight" type="button" selector="(//div[@class='tabs-content']//div[@data-role='tab-item'])[{{arg1}}][contains(@style, 'min-height: {{arg2}}px')]" parameterized="true"/>
6969
<element name="tabContentBackgroundColor" type="button" selector="(//div[@class='tabs-content']//div[@data-role='tab-item'])[{{arg1}}][contains(@style, 'background-color: {{arg2}}')]" parameterized="true"/>

app/code/Magento/PageBuilder/Test/Mftf/Test/AdminPageBuilderTabItemConfigurationTests.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,12 @@
598598
<see selector="{{TabOnStorefront.tabHeader('2')}}" userInput="{{PageBuilderTabNameRandom2.value}}" stepKey="seeTab2TitleStorefront"/>
599599
<seeElement selector="{{TabOnStorefront.tabContentBackgroundColor('2', PageBuilderTabBackgroundColorGreen.rgb)}}" stepKey="seeTab2BackgroundColor"/>
600600
<seeElement selector="{{TabOnStorefront.tabContentMinimumHeight('2', PageBuilderTabMinimumHeight600Property.value)}}" stepKey="seeTab2MinHeight"/>
601+
<comment userInput="User sees Tab 2 with height that equals to sum of min-height + paddingTop + paddingBottom" stepKey="verifyMinHeight"/>
602+
<executeJS function="return document.querySelector('{{TabOnStorefront.tabContent('2')}}').offsetHeight" stepKey="tab2Height"/>
603+
<assertEquals stepKey="assertTabMinHeight">
604+
<expectedResult type="variable">680</expectedResult>
605+
<actualResult type="variable">tab2Height</actualResult>
606+
</assertEquals>
601607
</test>
602608
<test name="AddTabsWithBackgroundJpgTopCoverScrollFixedNoBackgroundRepeat">
603609
<annotations>

app/code/Magento/PageBuilder/view/adminhtml/web/css/source/content-type/_preview.less

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,21 @@
5353
}
5454

5555
&.empty-placeholder {
56-
-moz-transition: .3s;
5756
left: 0;
5857
text-align: center;
59-
transition: .3s;
6058
width: 100%;
6159
z-index: 1;
6260
}
6361

6462
&.empty-placeholder-background {
63+
-moz-transition: .3s;
64+
-webkit-transition: .3s;
6565
background: url('@{baseDir}Magento_PageBuilder/css/images/cms-empty-row.svg') no-repeat center center;
6666
background-size: 505px 97px;
67-
box-sizing: border-box;
6867
height: 170px;
69-
-webkit-transition: .3s;
7068
padding-top: 130px;
7169
position: absolute;
70+
transition: .3s;
7271
}
7372
}
7473

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

Lines changed: 26 additions & 14 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/template/content-type/row/contained/preview.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="pagebuilder-display-label"
2020
text="function () { return displayLabel().toUpperCase(); }()"></div>
2121
<div class="pagebuilder-empty-container empty-placeholder"
22-
css="{visible: parent.children().length == 0}"
23-
translate="'Drag content types or columns here'"></div>
22+
css="placeholderCss()"
23+
translate="'Drag content types or columns here'"/>
2424
</div>
2525
</div>

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

Whitespace-only changes.

app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/row/full-bleed/preview.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
<div class="pagebuilder-display-label"
1717
text="function () { return displayLabel().toUpperCase(); }()"></div>
1818
<div class="pagebuilder-empty-container empty-placeholder"
19-
css="{visible: parent.children().length == 0}"
20-
translate="'Drag content types or columns here'"></div>
19+
css="placeholderCss()"
20+
translate="'Drag content types or columns here'"/>
2121
</div>

app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/row/full-width/preview.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
<div class="pagebuilder-display-label"
1717
text="function () { return displayLabel().toUpperCase(); }()"></div>
1818
<div class="pagebuilder-empty-container empty-placeholder"
19-
css="{visible: parent.children().length == 0}"
20-
translate="'Drag content types or columns here'"></div>
21-
</div>
19+
css="placeholderCss()"
20+
translate="'Drag content types or columns here'"/>
21+
</div>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<div class="pagebuilder-content-type type-container pagebuilder-tab-item" attr="Object.assign({}, {id: parent.id}, data.main.attributes())" ko-style="Object.assign({}, data.main.style(), {borderRadius: data.main.style().borderRadius || $parent.parent.preview.data.headers.style().borderRadius})" css="Object.assign({'empty-container': parent.children().length == 0}, data.main.css())">
99
<render args="previewChildTemplate" />
1010
<div class="pagebuilder-empty-container empty-placeholder"
11-
css="getPlaceholderStyles()"
11+
css="placeholderCss()"
1212
translate="'Drag content types or columns here'"/>
1313
</div>

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export default class Preview {
3939
public data: ObservableObject = {};
4040
public displayLabel: KnockoutObservable<string>;
4141
public wrapperElement: Element;
42+
public placeholderCss: KnockoutObservable<object>;
43+
public isPlaceholderVisible: KnockoutObservable<boolean> = ko.observable(true);
44+
public isEmpty: KnockoutObservable<boolean> = ko.observable(true);
4245

4346
/**
4447
* @deprecated
@@ -75,6 +78,10 @@ export default class Preview {
7578
this.edit = new Edit(this.parent, this.parent.dataStore);
7679
this.observableUpdater = observableUpdater;
7780
this.displayLabel = ko.observable(this.config.label);
81+
this.placeholderCss = ko.observable({
82+
"visible": this.isEmpty,
83+
"empty-placeholder-background": this.isPlaceholderVisible,
84+
});
7885
this.setupDataFields();
7986
this.bindEvents();
8087
}
@@ -434,8 +441,16 @@ export default class Preview {
434441
this.parent.dataStore.subscribe(
435442
(data: DataObject) => {
436443
this.updateObservables();
444+
this.updatePlaceholderVisibility(data);
437445
},
438446
);
447+
if (this.parent.children) {
448+
this.parent.children.subscribe(
449+
(children: any[]) => {
450+
this.isEmpty(!children.length);
451+
},
452+
);
453+
}
439454
}
440455

441456
/**
@@ -563,20 +578,19 @@ export default class Preview {
563578
}
564579

565580
/**
566-
* Show/hide empty placeholder
567-
* @returns {object}
581+
* Update placeholder background visibility base on height and padding
582+
*
583+
* @param {DataObject} data
568584
*/
569-
public getPlaceholderStyles(): object {
570-
let style = this.data.main.style(),
571-
minHeight = parseFloat(style.minHeight) || 300,
572-
paddingBottom = parseFloat(style.paddingBottom) || 0,
573-
paddingTop = parseFloat(style.paddingBottom) || 0,
574-
isBackgroundVisible = paddingBottom + paddingTop + minHeight > 130,
575-
isVisible = this.parent.children().length == 0;
576-
577-
return {
578-
visible: isVisible,
579-
'empty-placeholder-background': isBackgroundVisible
580-
}
585+
private updatePlaceholderVisibility(data: DataObject): void {
586+
const minHeight = !_.isEmpty(data.min_height) ? parseFloat(data.min_height as string) : 130;
587+
const marginsAndPadding = _.isString(data.margins_and_padding) && data.margins_and_padding ?
588+
JSON.parse(data.margins_and_padding as string) :
589+
data.margins_and_padding || {};
590+
const padding = marginsAndPadding.padding || {};
591+
const paddingBottom = parseFloat(padding.bottom) || 0;
592+
const paddingTop = parseFloat(padding.top) || 0;
593+
594+
this.isPlaceholderVisible(paddingBottom + paddingTop + minHeight >= 130);
581595
}
582596
}

0 commit comments

Comments
 (0)