Skip to content

Commit

Permalink
Mwpw-147034: Custom border color + badge/border color decoupling [Mer…
Browse files Browse the repository at this point in the history
…ch card] (#2499)

MWPW-147907: Allow for 24pt font size for price [Merch Card]
  • Loading branch information
Axelcureno authored Jul 22, 2024
1 parent 31c21e8 commit c8ea741
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,17 @@ const parseContent = async (el, merchCard) => {
};

const getBadgeStyle = (badgeMetadata) => {
const badgeStyleRegex = /^#[0-9a-fA-F]+, #[0-9a-fA-F]+$/;
const badgeStyleRegex = /^#[0-9a-fA-F]+, #[0-9a-fA-F]+(, #[0-9a-fA-F]+)?$/;
if (!badgeStyleRegex.test(badgeMetadata[0]?.innerText)) return null;
const style = badgeMetadata[0].innerText;
const badgeBackgroundColor = style.split(',')[0].trim();
const badgeColor = style.split(',')[1].trim();
const style = badgeMetadata[0].innerText.split(',').map((s) => s.trim());
if (style.length < 2) return null;
const badgeBackgroundColor = style[0];
const badgeColor = style[1];
const borderColor = style[2] !== 'none' ? style[2] : null;
const badgeWrapper = badgeMetadata[0].parentNode;
const badgeText = badgeMetadata[1].innerText;
badgeWrapper.remove();
return { badgeBackgroundColor, badgeColor, badgeText };
return { badgeBackgroundColor, badgeColor, badgeText, borderColor };
};

const getActionMenuContent = (el) => {
Expand Down Expand Up @@ -454,7 +456,11 @@ export default async function init(el) {
);
merchCard.setAttribute('badge-color', badge.badgeColor);
merchCard.setAttribute('badge-text', badge.badgeText);
if (badge.borderColor) merchCard.setAttribute('border-color', badge.borderColor);
merchCard.classList.add('badge-card');
} else if (badgeMetadata.children.length === 1) {
const borderColor = badgeMetadata.children[0].innerText.trim();
if (borderColor.startsWith('#')) merchCard.setAttribute('border-color', borderColor);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/blocks/merch-card/mocks/plans-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ <h5>Maecenas porttitor enim.</h5>
</div>
<div class="merch-card plans icons skip-ribbon skip-altCta">
<div>
<div> </div>
<div>#EDCC2D</div>
<div>LOREM IPSUM DOLOR</div>
</div>
<div>
Expand Down

0 comments on commit c8ea741

Please sign in to comment.