From ae7556d8d0100bd50c90bca1df056b4224c0300d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Jove=CC=81?= Date: Tue, 3 Dec 2024 20:03:57 +0100 Subject: [PATCH 1/4] Include new icons and use SVG as icons instead of image --- icons/arrow-right.svg | 4 ++++ icons/calendar.svg | 1 + icons/chevron-right.svg | 1 + icons/download.svg | 1 + scripts/aem.js | 25 ++++++++++++++++--------- 5 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 icons/arrow-right.svg create mode 100644 icons/calendar.svg create mode 100644 icons/chevron-right.svg create mode 100644 icons/download.svg diff --git a/icons/arrow-right.svg b/icons/arrow-right.svg new file mode 100644 index 0000000..96f7e2d --- /dev/null +++ b/icons/arrow-right.svg @@ -0,0 +1,4 @@ + + + + diff --git a/icons/calendar.svg b/icons/calendar.svg new file mode 100644 index 0000000..5f88313 --- /dev/null +++ b/icons/calendar.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/chevron-right.svg b/icons/chevron-right.svg new file mode 100644 index 0000000..0c2bf7a --- /dev/null +++ b/icons/chevron-right.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/download.svg b/icons/download.svg new file mode 100644 index 0000000..db03e46 --- /dev/null +++ b/icons/download.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scripts/aem.js b/scripts/aem.js index 40662e6..0ba253a 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -403,7 +403,7 @@ function decorateButtons(element) { && twoup.childNodes.length === 1 && twoup.tagName === 'P' ) { - a.className = 'button primary'; + a.className = 'button button--secondary'; twoup.classList.add('button-container'); } if ( @@ -412,7 +412,7 @@ function decorateButtons(element) { && twoup.childNodes.length === 1 && twoup.tagName === 'P' ) { - a.className = 'button secondary'; + a.className = 'button button--tertiary'; twoup.classList.add('button-container'); } } @@ -426,16 +426,23 @@ function decorateButtons(element) { * @param {string} [prefix] prefix to be added to icon src * @param {string} [alt] alt text to be added to icon */ -function decorateIcon(span, prefix = '', alt = '') { +async function decorateIcon(span, prefix = '', alt = '') { const iconName = Array.from(span.classList) .find((c) => c.startsWith('icon-')) .substring(5); - const img = document.createElement('img'); - img.dataset.iconName = iconName; - img.src = `${window.hlx.codeBasePath}${prefix}/icons/${iconName}.svg`; - img.alt = alt; - img.loading = 'lazy'; - span.append(img); + + const resp = await fetch(`${window.hlx.codeBasePath}${prefix}/icons/${iconName}.svg`); + if (resp.ok) { + const iconHTML = await resp.text(); + if (iconHTML.match(/