Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWPW-158004] Fix callout & grey line alignment issues in product merch cards #2946

Merged
merged 18 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,25 @@ const simplifyHrs = (el) => {
hrs.forEach((hr) => {
if (hr.parentElement.tagName === 'P') {
hr.parentElement.replaceWith(hr);
hr.style.width = '100%';
Axelcureno marked this conversation as resolved.
Show resolved Hide resolved
}
});
if (el.variant === PRODUCT) {
const calloutContent = el.querySelector('div[slot="callout-content"]');
const bodySlot = el.querySelector('div[slot="body-xs"]');
if (calloutContent && bodySlot) {
const bodyLowerContent = createTag('div', { slot: 'body-lower' });
const elements = [...bodySlot.children];
elements.forEach((element) => {
if (element.tagName !== 'P') {
bodyLowerContent.append(element);
}
});
if (bodyLowerContent.childNodes.length > 0) {
calloutContent.parentElement.appendChild(bodyLowerContent);
}
}
}
};

const getMiniCompareChartFooterRows = (el) => {
Expand Down Expand Up @@ -496,7 +513,7 @@ export default async function init(el) {
}
}
let footerRows;
if ([MINI_COMPARE_CHART, PLANS, SEGMENT].includes(cardType)) {
if ([MINI_COMPARE_CHART, PLANS, SEGMENT, PRODUCT].includes(cardType)) {
intersectionObserver.observe(merchCard);
}
if (cardType === MINI_COMPARE_CHART) {
Expand Down
278 changes: 194 additions & 84 deletions libs/deps/mas/mas.js

Large diffs are not rendered by default.

168 changes: 97 additions & 71 deletions libs/deps/mas/merch-card.js

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion libs/features/mas/mocks/offers.json
Original file line number Diff line number Diff line change
Expand Up @@ -1102,5 +1102,43 @@
"language": "MULT",
"merchant": "ADOBE"
}
]
],
"nTbB50pS4lLGv_x1l_UKggd-lxxo2zAJ7WYDa2mW19s-mult": [
{
"offerSelectorIds": [
"nTbB50pS4lLGv_x1l_UKggd-lxxo2zAJ7WYDa2mW19s"
],
"offerId": "44C623423443E5D4D7F53719C25F71D7",
"startDate": "2022-08-08T07:00:00.000Z",
"endDate": "2099-12-20T07:58:00.000Z",
"priceDetails": {
"price": 22.19,
"priceWithoutDiscount": 23.99,
"priceWithoutTax": 22.19,
"priceWithoutDiscountAndTax": 23.99,
"usePrecision": true,
"formatString": "'US$'#,##0.00",
"taxDisplay": "TAX_EXCLUSIVE",
"taxTerm": "TAX"
},
"analytics": "{\"offerId\":\"44C623423443E5D4D7F53719C25F71D7\",\"label\":\"acrobat_pro_dc_plus_sign_funnel_team\",\"price\":\"22.19\",\"amountWithoutTax\":\"22.19\",\"commitmentType\":\"YEAR\",\"billingFrequency\":\"MONTHLY\",\"currencyCode\":\"USD\"}",
"productArrangementCode": "acrobat_pro_dc_plus_sign_funnel_team",
"productArrangement": {
"productFamily": "ACROBAT",
"productCode": "ASIG"
},
"buyingProgram": "RETAIL",
"commitment": "YEAR",
"term": "MONTHLY",
"customerSegment": "TEAM",
"marketSegments": [
"COM"
],
"salesChannel": "DIRECT",
"offerType": "PROMOTION",
"pricePoint": "ACROBAT_PRO_ASIG_FY22_LO_TEAM_BUNDLE_7_5_OFF_WW_COM",
"language": "MULT",
"merchant": "ADOBE"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,9 @@ export class MiniCompareChart extends VariantLayout {
super(card);
}

#container;

getRowMinHeightPropertyName = (index) =>
`--consonant-merch-card-footer-row-${index}-min-height`;

getContainer() {
this.#container = this.#container ?? this.card.closest('[class*="-merch-cards"]') ?? this.card.parentElement;
return this.#container;
}

getGlobalCSS() {
return CSS;
}
Expand Down
71 changes: 68 additions & 3 deletions libs/features/mas/web-components/src/variants/product.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { VariantLayout } from "./variant-layout";
import { html } from 'lit';
import { isMobile } from '../utils.js';
import { html, css } from 'lit';
import { CSS } from './product.css.js';

export class Product extends VariantLayout {
Expand All @@ -11,16 +12,80 @@ export class Product extends VariantLayout {
return CSS;
}

adjustProductBodySlots() {
if (this.card.getBoundingClientRect().width === 0) return;

const slots = [
'heading-xs',
'body-xxs',
'body-xs',
'promo-text',
'callout-content',
'body-lower',
];

slots.forEach((slot) =>
this.updateCardElementMinHeight(
this.card.shadowRoot.querySelector(`slot[name="${slot}"]`),
slot
),
);
}

renderLayout() {
return html` ${this.badge}
<div class="body">
<slot name="icons"></slot>
<slot name="heading-xs"></slot>
<slot name="body-xxs"></slot>
${!this.promoBottom ? html`<slot name="promo-text"></slot><slot name="callout-content"></slot>` : ''}
${!this.promoBottom ? html`<slot name="promo-text"></slot>` : ''}
<slot name="body-xs"></slot>
${this.promoBottom ? html`<slot name="promo-text"></slot><slot name="callout-content"></slot>` : ''}
${this.promoBottom ? html`<slot name="promo-text"></slot>` : ''}
<slot name="callout-content"></slot>
<slot name="body-lower"></slot>
</div>
${this.secureLabelFooter}`;
}

connectedCallbackHook() {
super.connectedCallbackHook();
window.addEventListener('resize', this.postCardUpdateHook.bind(this));
}

disconnectedCallbackHook() {
window.removeEventListener('resize', this.postCardUpdateHook.bind(this));
super.disconnectedCallbackHook();
}

postCardUpdateHook() {
if (!isMobile()) {
this.adjustProductBodySlots();
}
}

static variantStyle = css`
:host([variant='product']) > slot:not([name='icons']) {
display: block;
}
:host([variant='product']) slot[name='body-xs'] {
min-height: var(--consonant-merch-card-product-body-xs-height);
display: block;
}
:host([variant='product']) slot[name='heading-xs'] {
min-height: var(--consonant-merch-card-product-heading-xs-height);
display: block;
}
:host([variant='product']) slot[name='body-xxs'] {
min-height: var(--consonant-merch-card-product-body-xxs-height);
display: block;
}
:host([variant='product']) slot[name='promo-text'] {
min-height: var(--consonant-merch-card-product-promo-text-height);
display: block;
}
:host([variant='product']) slot[name='callout-content'] {
min-height: var(--consonant-merch-card-product-callout-content-height);
display: block;
}
`;
}
26 changes: 26 additions & 0 deletions libs/features/mas/web-components/src/variants/variant-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ export class VariantLayout {

card;

#container;

getContainer() {
this.#container = this.#container ?? this.card.closest('[class*="-merch-cards"]') ?? this.card.parentElement;
return this.#container;
}

insertVariantStyle() {
if (!VariantLayout.styleMap[this.card.variant]) {
VariantLayout.styleMap[this.card.variant] = true;
Expand All @@ -14,6 +21,25 @@ export class VariantLayout {
}
}

updateCardElementMinHeight(el, name) {
rahulgupta999 marked this conversation as resolved.
Show resolved Hide resolved
const elMinHeightPropertyName = `--consonant-merch-card-${this.card.variant}-${name}-height`;
const height = Math.max(
0,
parseInt(window.getComputedStyle(el).height) || 0,
);
const maxMinHeight =
parseInt(
this.getContainer().style.getPropertyValue(elMinHeightPropertyName),
) || 0;

if (height > maxMinHeight) {
this.getContainer().style.setProperty(
elMinHeightPropertyName,
`${height}px`,
);
}
}

constructor(card) {
this.card = card;
this.insertVariantStyle();
Expand Down
1 change: 1 addition & 0 deletions libs/features/mas/web-components/src/variants/variants.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const getVariantStyles = () => {
styles.push(Catalog.variantStyle);
styles.push(CCDAction.variantStyle);
styles.push(MiniCompareChart.variantStyle);
styles.push(Product.variantStyle);
styles.push(Plans.variantStyle);
styles.push(Segment.variantStyle);
styles.push(SpecialOffer.variantStyle);
Expand Down
Loading
Loading