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-160360 - Decorate standalone text with body default styles #3060

Merged
merged 24 commits into from
Nov 7, 2024
Merged
Changes from 10 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ba29e8a
style wrappers when no nested elements
Sartxi Oct 14, 2024
382b372
better logic and check for text nodes in elements
Sartxi Oct 17, 2024
3d83484
dialing in util
Sartxi Oct 18, 2024
3db81be
keep contains text function in decorate js
Sartxi Oct 28, 2024
280382a
Merge branch 'stage' of https://github.com/adobecom/milo into sartxi/…
Sartxi Oct 28, 2024
bd03de9
use is magic in emtpy elements selector
Sartxi Oct 28, 2024
971bfc0
simplify el contains text function
Sartxi Oct 29, 2024
8b0f0c0
Merge branch 'stage' of https://github.com/adobecom/milo into sartxi/…
Sartxi Oct 30, 2024
b1ad69d
Merge branch 'stage' of https://github.com/adobecom/milo into sartxi/…
Sartxi Nov 4, 2024
3ca02e5
Merge branch 'stage' of https://github.com/adobecom/milo into sartxi/…
Sartxi Nov 4, 2024
4cd0f18
early return in block text decorator
Sartxi Nov 4, 2024
49261ee
codecov on decorate block text
Sartxi Nov 4, 2024
8e62a11
adjust decorate and marquee anchors to hopefully pass tests
Sartxi Nov 5, 2024
46dad6c
style wrappers when no nested elements
Sartxi Oct 14, 2024
d621948
better logic and check for text nodes in elements
Sartxi Oct 17, 2024
405a9a8
dialing in util
Sartxi Oct 18, 2024
c649b97
keep contains text function in decorate js
Sartxi Oct 28, 2024
3f268ef
use is magic in emtpy elements selector
Sartxi Oct 28, 2024
b95e1cc
simplify el contains text function
Sartxi Oct 29, 2024
603fd46
early return in block text decorator
Sartxi Nov 4, 2024
a8061bc
codecov on decorate block text
Sartxi Nov 4, 2024
2cbb145
adjust decorate and marquee anchors to hopefully pass tests
Sartxi Nov 5, 2024
6bfb3ce
fix marquee anchors for nala
Sartxi Nov 6, 2024
e08bd9f
Merge branch 'sartxi/MWPW-160360-text' of https://github.com/adobecom…
Sartxi Nov 6, 2024
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
18 changes: 12 additions & 6 deletions libs/utils/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export function decorateIconArea(el) {
});
}

function elContainsText(el) {
return [...el.childNodes].some(({ nodeType, innerText, textContent }) => (
(nodeType === Node.ELEMENT_NODE && innerText.trim() !== '')
|| (nodeType === Node.TEXT_NODE && textContent.trim() !== '')
));
}

export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) {
let headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6');
if (!el.classList.contains('default')) {
Expand All @@ -77,13 +84,12 @@ export function decorateBlockText(el, config = ['m', 's', 'm'], type = null) {
decorateIconArea(el);
}
}
const emptyEls = el.querySelectorAll('p:not([class]), ul:not([class]), ol:not([class])');
const bodyStyle = `body-${config[1]}`;
const emptyEls = el.querySelectorAll(':is(p, ul, ol, div):not([class])');
if (emptyEls.length) {
emptyEls.forEach((p) => p.classList.add(`body-${config[1]}`));
} else {
[...el.querySelectorAll('div:not([class])')]
.filter((emptyDivs) => emptyDivs.textContent.trim() !== '')
.forEach((text) => text.classList.add(`body-${config[1]}`));
[...emptyEls].filter(elContainsText).forEach((e) => e.classList.add(bodyStyle));
} else if (!el.classList.length && elContainsText(el)) {
el.classList.add(bodyStyle);
}
}
const buttonSize = config.length > 3 ? `button-${config[3]}` : '';
Expand Down
Loading