Skip to content

Commit

Permalink
Redesign mini-compare chart. Added checkmarks for icons. Backward com…
Browse files Browse the repository at this point in the history
…patibility using "checkmark" class. Horizontal line added.
  • Loading branch information
Rohit Sahu committed Nov 5, 2024
1 parent f8ba10f commit 610807a
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 49 deletions.
17 changes: 16 additions & 1 deletion libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,28 @@ const getMiniCompareChartFooterRows = (el) => {
const decorateFooterRows = (merchCard, footerRows) => {
if (footerRows) {
const footerRowsSlot = createTag('div', { slot: 'footer-rows' });
if (merchCard.classList.contains('checkmark')) {
const firstRow = footerRows[0];
const bgStyle = firstRow.querySelector('div > div:first-child').innerHTML;
const hrElem = createTag('hr', { style: `background: ${bgStyle};` });
footerRowsSlot.appendChild(hrElem);
merchCard.classList.add('has-divider');
const firstRowText = firstRow.querySelector('div > div:last-child').innerHTML;
const firstRowTextParagraph = createTag('div', { class: 'footer-rows-title' }, firstRowText);
footerRowsSlot.appendChild(firstRowTextParagraph);
footerRows.splice(0, 1);
}
footerRows.forEach((row) => {
const rowIcon = row.firstElementChild.querySelector('picture');
const rowText = row.querySelector('div > div:nth-child(2)').innerHTML;
const rowTextParagraph = createTag('div', { class: 'footer-row-cell-description' }, rowText);
const footerRowCell = createTag('div', { class: 'footer-row-cell' });
if (rowIcon) {
rowIcon.classList.add('footer-row-icon');
if (merchCard.classList.contains('checkmark')) {
rowIcon.classList.add('footer-row-icon-checkmark');
} else {
rowIcon.classList.add('footer-row-icon');
}
footerRowCell.appendChild(rowIcon);
}
footerRowCell.appendChild(rowTextParagraph);
Expand Down
63 changes: 48 additions & 15 deletions libs/deps/mas/mas.js

Large diffs are not rendered by default.

61 changes: 47 additions & 14 deletions libs/deps/mas/merch-card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import{LitElement as Yt}from"../lit-all.min.js";import{LitElement as zt,html as J,css as At}from"../lit-all.min.js";var n=class extends zt{static properties={size:{type:String,attribute:!0},src:{type:String,attribute:!0},alt:{type:String,attribute:!0},href:{type:String,attribute:!0}};constructor(){super(),this.size="m",this.alt=""}render(){let{href:t}=this;return t?J`<a href="${t}">
import{LitElement as Yt}from"../lit-all.min.js";import{LitElement as zt,html as J,css as Lt}from"../lit-all.min.js";var n=class extends zt{static properties={size:{type:String,attribute:!0},src:{type:String,attribute:!0},alt:{type:String,attribute:!0},href:{type:String,attribute:!0}};constructor(){super(),this.size="m",this.alt=""}render(){let{href:t}=this;return t?J`<a href="${t}">
<img src="${this.src}" alt="${this.alt}" loading="lazy" />
</a>`:J` <img src="${this.src}" alt="${this.alt}" loading="lazy" />`}static styles=At`
</a>`:J` <img src="${this.src}" alt="${this.alt}" loading="lazy" />`}static styles=Lt`
:host {
--img-width: 32px;
--img-height: 32px;
Expand Down Expand Up @@ -275,7 +275,7 @@ import{LitElement as Yt}from"../lit-all.min.js";import{LitElement as zt,html as
background-position: ${this.card.theme.dir==="ltr"?"left":"right"};
`}return""}get secureLabelFooter(){let t=this.card.secureLabel?$`<span class="secure-transaction-label"
>${this.card.secureLabel}</span
>`:"";return $`<footer>${t}<slot name="footer"></slot></footer>`}async adjustTitleWidth(){let t=this.card.getBoundingClientRect().width,e=this.card.badgeElement?.getBoundingClientRect().width||0;t===0||e===0||this.card.style.setProperty("--consonant-merch-card-heading-xs-max-width",`${Math.round(t-e-16)}px`)}postCardUpdateHook(){}connectedCallbackHook(){}disconnectedCallbackHook(){}renderLayout(){}get aemFragmentMapping(){}};import{html as q,css as Lt}from"../lit-all.min.js";function v(r,t={},e){let a=document.createElement(r);e instanceof HTMLElement?a.appendChild(e):a.innerHTML=e;for(let[o,p]of Object.entries(t))a.setAttribute(o,p);return a}function O(){return window.matchMedia("(max-width: 767px)").matches}function ot(){return window.matchMedia("(max-width: 1024px)").matches}var at="merch-offer-select:ready",nt="merch-card:ready",ct="merch-card:action-menu-toggle";var U="merch-storage:change",I="merch-quantity-selector:change";var P="aem:load",N="aem:error",it="mas:ready",st="mas:error";var dt=`
>`:"";return $`<footer>${t}<slot name="footer"></slot></footer>`}async adjustTitleWidth(){let t=this.card.getBoundingClientRect().width,e=this.card.badgeElement?.getBoundingClientRect().width||0;t===0||e===0||this.card.style.setProperty("--consonant-merch-card-heading-xs-max-width",`${Math.round(t-e-16)}px`)}postCardUpdateHook(){}connectedCallbackHook(){}disconnectedCallbackHook(){}renderLayout(){}get aemFragmentMapping(){}};import{html as q,css as _t}from"../lit-all.min.js";function v(r,t={},e){let a=document.createElement(r);e instanceof HTMLElement?a.appendChild(e):a.innerHTML=e;for(let[o,p]of Object.entries(t))a.setAttribute(o,p);return a}function O(){return window.matchMedia("(max-width: 767px)").matches}function ot(){return window.matchMedia("(max-width: 1024px)").matches}var at="merch-offer-select:ready",nt="merch-card:ready",ct="merch-card:action-menu-toggle";var U="merch-storage:change",I="merch-quantity-selector:change";var P="aem:load",N="aem:error",it="mas:ready",st="mas:error";var dt=`
:root {
--consonant-merch-card-catalog-width: 276px;
--consonant-merch-card-catalog-icon-size: 40px;
Expand Down Expand Up @@ -361,7 +361,7 @@ merch-card[variant="catalog"] .payment-details {
font-style: italic;
font-weight: 400;
line-height: var(--consonant-merch-card-body-line-height);
}`;var _t={title:{tag:"h3",slot:"heading-xs"},prices:{tag:"h3",slot:"heading-xs"},description:{tag:"div",slot:"body-xs"},ctas:{size:"l"},allowedSizes:["wide","super-wide"]},E=class extends d{constructor(t){super(t)}get aemFragmentMapping(){return _t}renderLayout(){return q` <div class="body">
}`;var At={title:{tag:"h3",slot:"heading-xs"},prices:{tag:"h3",slot:"heading-xs"},description:{tag:"div",slot:"body-xs"},ctas:{size:"l"},allowedSizes:["wide","super-wide"]},E=class extends d{constructor(t){super(t)}get aemFragmentMapping(){return At}renderLayout(){return q` <div class="body">
<div class="top-section">
<slot name="icons"></slot> ${this.badge}
<div
Expand All @@ -387,7 +387,7 @@ merch-card[variant="catalog"] .payment-details {
><slot name="callout-content"></slot>`:""}
</div>
${this.secureLabelFooter}
<slot></slot>`}getGlobalCSS(){return dt}toggleActionMenu=t=>{let e=t?.type==="mouseleave"?!0:void 0,a=this.card.shadowRoot.querySelector('slot[name="action-menu-content"]');a&&(e||this.card.dispatchEvent(new CustomEvent(ct,{bubbles:!0,composed:!0,detail:{card:this.card.name,type:"action-menu"}})),a.classList.toggle("hidden",e))};connectedCallbackHook(){this.card.addEventListener("mouseleave",this.toggleActionMenu)}disconnectedCallbackHook(){this.card.removeEventListener("mouseleave",this.toggleActionMenu)}static variantStyle=Lt`
<slot></slot>`}getGlobalCSS(){return dt}toggleActionMenu=t=>{let e=t?.type==="mouseleave"?!0:void 0,a=this.card.shadowRoot.querySelector('slot[name="action-menu-content"]');a&&(e||this.card.dispatchEvent(new CustomEvent(ct,{bubbles:!0,composed:!0,detail:{card:this.card.name,type:"action-menu"}})),a.classList.toggle("hidden",e))};connectedCallbackHook(){this.card.addEventListener("mouseleave",this.toggleActionMenu)}disconnectedCallbackHook(){this.card.removeEventListener("mouseleave",this.toggleActionMenu)}static variantStyle=_t`
:host([variant='catalog']) {
min-height: 330px;
width: var(--consonant-merch-card-catalog-width);
Expand Down Expand Up @@ -612,7 +612,24 @@ merch-card[variant="ccd-action"] .price-strikethrough {
merch-card[variant="mini-compare-chart"] .footer-row-icon {
display: flex;
place-items: center;
align-self: flex-start;
height: 24px;
width: 24px;
align-items: center;
}
merch-card[variant="mini-compare-chart"] .footer-rows-title {
color: var(--Text-text, #2C2C2C); */
font-family: var(--Font-adobe-clean, "Adobe Clean");
/* font-size: 14px; */
/* font-style: normal; */
font-weight: 700;
/* line-height: 150%; */
padding: var(--consonant-merch-spacing-xxs) 0px;
}
merch-card[variant="mini-compare-chart"] [slot="footer-rows"] {
padding: 0px var(--consonant-merch-spacing-s);
}
merch-card[variant="mini-compare-chart"] .footer-row-icon img {
Expand All @@ -621,13 +638,21 @@ merch-card[variant="ccd-action"] .price-strikethrough {
height: var(--consonant-merch-card-mini-compare-chart-icon-size);
}
merch-card[variant="mini-compare-chart"] .footer-row-icon-checkmark img {
max-width: initial;
}
merch-card[variant="mini-compare-chart"] .footer-row-icon-checkmark {
display: flex;
align-items: center;
height: 24px;
}
merch-card[variant="mini-compare-chart"] .footer-row-cell {
border-top: 1px solid var(--consonant-merch-card-border-color);
display: flex;
gap: var(--consonant-merch-spacing-xs);
justify-content: start;
place-items: center;
padding: var(--consonant-merch-spacing-xs) var(--consonant-merch-spacing-s);
align-items: flex-start;
}
merch-card[variant="mini-compare-chart"] .footer-row-cell-description {
Expand Down Expand Up @@ -807,7 +832,7 @@ merch-card .footer-row-cell:nth-child(8) {
<span class="secure-transaction-label"
>${this.card.secureLabel}</span
></slot
>`:B`<slot name="secure-transaction-label"></slot>`;return B`<footer>${t}<slot name="footer"></slot></footer>`};adjustMiniCompareBodySlots(){if(this.card.getBoundingClientRect().width<=2)return;this.updateCardElementMinHeight(this.card.shadowRoot.querySelector(".top-section"),"top-section"),["heading-m","body-m","heading-m-price","body-xxs","price-commitment","offers","promo-text","callout-content"].forEach(a=>this.updateCardElementMinHeight(this.card.shadowRoot.querySelector(`slot[name="${a}"]`),a)),this.updateCardElementMinHeight(this.card.shadowRoot.querySelector("footer"),"footer");let e=this.card.shadowRoot.querySelector(".mini-compare-chart-badge");e&&e.textContent!==""&&this.getContainer().style.setProperty("--consonant-merch-card-mini-compare-chart-top-section-mobile-height","32px")}adjustMiniCompareFooterRows(){if(this.card.getBoundingClientRect().width===0)return;[...this.card.querySelector('[slot="footer-rows"]')?.children].forEach((e,a)=>{let o=Math.max($t,parseFloat(window.getComputedStyle(e).height)||0),p=parseFloat(this.getContainer().style.getPropertyValue(this.getRowMinHeightPropertyName(a+1)))||0;o>p&&this.getContainer().style.setProperty(this.getRowMinHeightPropertyName(a+1),`${o}px`)})}removeEmptyRows(){this.card.querySelectorAll(".footer-row-cell").forEach(e=>{let a=e.querySelector(".footer-row-cell-description");a&&!a.textContent.trim()&&e.remove()})}renderLayout(){return B` <div class="top-section${this.badge?" badge":""}">
>`:B`<slot name="secure-transaction-label"></slot>`;return B`<footer>${t}<slot name="footer"></slot></footer>`};adjustMiniCompareBodySlots(){if(this.card.getBoundingClientRect().width<=2)return;this.updateCardElementMinHeight(this.card.shadowRoot.querySelector(".top-section"),"top-section"),["heading-m","body-m","heading-m-price","body-xxs","price-commitment","offers","promo-text","callout-content","footer-rows"].forEach(a=>this.updateCardElementMinHeight(this.card.shadowRoot.querySelector(`slot[name="${a}"]`),a)),this.updateCardElementMinHeight(this.card.shadowRoot.querySelector("footer"),"footer");let e=this.card.shadowRoot.querySelector(".mini-compare-chart-badge");e&&e.textContent!==""&&this.getContainer().style.setProperty("--consonant-merch-card-mini-compare-chart-top-section-mobile-height","32px")}adjustMiniCompareFooterRows(){if(this.card.getBoundingClientRect().width===0)return;[...this.card.querySelector('[slot="footer-rows"]')?.children].forEach((e,a)=>{let o=Math.max($t,parseFloat(window.getComputedStyle(e).height)||0),p=parseFloat(this.getContainer().style.getPropertyValue(this.getRowMinHeightPropertyName(a+1)))||0;o>p&&this.getContainer().style.setProperty(this.getRowMinHeightPropertyName(a+1),`${o}px`)})}removeEmptyRows(){this.card.querySelectorAll(".footer-row-cell").forEach(e=>{let a=e.querySelector(".footer-row-cell-description");a&&!a.textContent.trim()&&e.remove()})}renderLayout(){return B` <div class="top-section${this.badge?" badge":""}">
<slot name="icons"></slot> ${this.badge}
</div>
<slot name="heading-m"></slot>
Expand Down Expand Up @@ -891,6 +916,10 @@ merch-card .footer-row-cell:nth-child(8) {
--consonant-merch-card-mini-compare-chart-callout-content-height
);
}
:host([variant='mini-compare-chart']) slot[name='footer-rows'] {
min-height: var(--consonant-merch-card-mini-compare-chart-footer-rows-height);
justify-content: flex-start;
}
`};import{html as F,css as Ot}from"../lit-all.min.js";var xt=`
:root {
--consonant-merch-card-plans-width: 300px;
Expand Down Expand Up @@ -1094,7 +1123,7 @@ merch-card[variant="plans"] [slot="quantity-select"] {
grid-template-columns: repeat(4, minmax(276px, var(--consonant-merch-card-segment-width)));
}
}
`;var A=class extends d{constructor(t){super(t)}getGlobalCSS(){return vt}postCardUpdateHook(){this.adjustTitleWidth()}renderLayout(){return W` ${this.badge}
`;var L=class extends d{constructor(t){super(t)}getGlobalCSS(){return vt}postCardUpdateHook(){this.adjustTitleWidth()}renderLayout(){return W` ${this.badge}
<div class="body">
<slot name="heading-xs"></slot>
<slot name="body-xxs"></slot>
Expand Down Expand Up @@ -1158,7 +1187,7 @@ merch-card[variant="special-offers"] span[is="inline-price"][data-template="stri
grid-template-columns: repeat(4, minmax(300px, var(--consonant-merch-card-special-offers-width)));
}
}
`;var Dt={name:{tag:"h4",slot:"detail-m"},title:{tag:"h4",slot:"detail-m"},backgroundImage:{tag:"div",slot:"bg-image"},prices:{tag:"h3",slot:"heading-xs"},description:{tag:"div",slot:"body-xs"},ctas:{size:"l"}},L=class extends d{constructor(t){super(t)}getGlobalCSS(){return bt}get headingSelector(){return'[slot="detail-m"]'}get aemFragmentMapping(){return Dt}renderLayout(){return Y`${this.cardImage}
`;var Dt={name:{tag:"h4",slot:"detail-m"},title:{tag:"h4",slot:"detail-m"},backgroundImage:{tag:"div",slot:"bg-image"},prices:{tag:"h3",slot:"heading-xs"},description:{tag:"div",slot:"body-xs"},ctas:{size:"l"}},_=class extends d{constructor(t){super(t)}getGlobalCSS(){return bt}get headingSelector(){return'[slot="detail-m"]'}get aemFragmentMapping(){return Dt}renderLayout(){return Y`${this.cardImage}
<div class="body">
<slot name="detail-m"></slot>
<slot name="heading-xs"></slot>
Expand Down Expand Up @@ -1288,7 +1317,7 @@ merch-card[variant='twp'] merch-offer-select {
grid-template-columns: repeat(3, var(--consonant-merch-card-twp-width));
}
}
`;var _=class extends d{constructor(t){super(t)}getGlobalCSS(){return yt}renderLayout(){return Bt`${this.badge}
`;var A=class extends d{constructor(t){super(t)}getGlobalCSS(){return yt}renderLayout(){return Bt`${this.badge}
<div class="top-section">
<slot name="icons"></slot>
<slot name="heading-xs"></slot>
Expand Down Expand Up @@ -1560,7 +1589,7 @@ merch-card[variant="ccd-slice"] [slot='body-s'] a:not(.con-button) {
:host([variant='ccd-slice']) .top-section {
align-items: center;
}
`};var Q=(r,t=!1)=>{switch(r.variant){case"catalog":return new E(r);case"ccd-action":return new S(r);case"image":return new H(r);case"inline-heading":return new D(r);case"mini-compare-chart":return new C(r);case"plans":return new z(r);case"product":return new w(r);case"segment":return new A(r);case"special-offers":return new L(r);case"twp":return new _(r);case"ccd-suggested":return new T(r);case"ccd-slice":return new M(r);default:return t?void 0:new w(r)}},St=()=>{let r=[];return r.push(E.variantStyle),r.push(S.variantStyle),r.push(C.variantStyle),r.push(w.variantStyle),r.push(z.variantStyle),r.push(A.variantStyle),r.push(L.variantStyle),r.push(_.variantStyle),r.push(T.variantStyle),r.push(M.variantStyle),r};var kt=document.createElement("style");kt.innerHTML=`
`};var Q=(r,t=!1)=>{switch(r.variant){case"catalog":return new E(r);case"ccd-action":return new S(r);case"image":return new H(r);case"inline-heading":return new D(r);case"mini-compare-chart":return new C(r);case"plans":return new z(r);case"product":return new w(r);case"segment":return new L(r);case"special-offers":return new _(r);case"twp":return new A(r);case"ccd-suggested":return new T(r);case"ccd-slice":return new M(r);default:return t?void 0:new w(r)}},St=()=>{let r=[];return r.push(E.variantStyle),r.push(S.variantStyle),r.push(C.variantStyle),r.push(w.variantStyle),r.push(z.variantStyle),r.push(L.variantStyle),r.push(_.variantStyle),r.push(A.variantStyle),r.push(T.variantStyle),r.push(M.variantStyle),r};var kt=document.createElement("style");kt.innerHTML=`
:root {
--consonant-merch-card-detail-font-size: 12px;
--consonant-merch-card-detail-font-weight: 500;
Expand Down Expand Up @@ -1882,6 +1911,10 @@ merch-card [slot="promo-text"] {
padding: 0;
}
merch-card [slot="footer-rows"] {
min-height: var(--consonant-merch-card-footer-rows-height);
}
div[slot="footer"] {
display: contents;
}
Expand Down
63 changes: 48 additions & 15 deletions libs/features/mas/mas/dist/mas.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions libs/features/mas/web-components/src/global.css.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ merch-card [slot="promo-text"] {
padding: 0;
}
merch-card [slot="footer-rows"] {
min-height: var(--consonant-merch-card-footer-rows-height);
}
div[slot="footer"] {
display: contents;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,24 @@ export const CSS = `
merch-card[variant="mini-compare-chart"] .footer-row-icon {
display: flex;
place-items: center;
align-self: flex-start;
height: 24px;
width: 24px;
align-items: center;
}
merch-card[variant="mini-compare-chart"] .footer-rows-title {
color: var(--Text-text, #2C2C2C); */
font-family: var(--Font-adobe-clean, "Adobe Clean");
/* font-size: 14px; */
/* font-style: normal; */
font-weight: 700;
/* line-height: 150%; */
padding: var(--consonant-merch-spacing-xxs) 0px;
}
merch-card[variant="mini-compare-chart"] [slot="footer-rows"] {
padding: 0px var(--consonant-merch-spacing-s);
}
merch-card[variant="mini-compare-chart"] .footer-row-icon img {
Expand All @@ -68,13 +85,21 @@ export const CSS = `
height: var(--consonant-merch-card-mini-compare-chart-icon-size);
}
merch-card[variant="mini-compare-chart"] .footer-row-icon-checkmark img {
max-width: initial;
}
merch-card[variant="mini-compare-chart"] .footer-row-icon-checkmark {
display: flex;
align-items: center;
height: 24px;
}
merch-card[variant="mini-compare-chart"] .footer-row-cell {
border-top: 1px solid var(--consonant-merch-card-border-color);
display: flex;
gap: var(--consonant-merch-spacing-xs);
justify-content: start;
place-items: center;
padding: var(--consonant-merch-spacing-xs) var(--consonant-merch-spacing-s);
align-items: flex-start;
}
merch-card[variant="mini-compare-chart"] .footer-row-cell-description {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class MiniCompareChart extends VariantLayout {
'offers',
'promo-text',
'callout-content',
'footer-rows',
];

slots.forEach((slot) =>
Expand Down Expand Up @@ -200,5 +201,9 @@ export class MiniCompareChart extends VariantLayout {
--consonant-merch-card-mini-compare-chart-callout-content-height
);
}
:host([variant='mini-compare-chart']) slot[name='footer-rows'] {
min-height: var(--consonant-merch-card-mini-compare-chart-footer-rows-height);
justify-content: flex-start;
}
`;
};

0 comments on commit 610807a

Please sign in to comment.