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-158927] Countdown Timer feedbacks incorporated #2955

Merged
merged 23 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 22 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
5 changes: 4 additions & 1 deletion libs/blocks/notification/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Notification - v1.2
*/

import { decorateBlockText, decorateBlockBg, decorateTextOverrides, decorateMultiViewport } from '../../utils/decorate.js';
import { decorateBlockText, decorateBlockBg, decorateTextOverrides, decorateMultiViewport, loadCDT } from '../../utils/decorate.js';
import { createTag, getConfig, loadStyle } from '../../utils/utils.js';

const { miloLibs, codeRoot } = getConfig();
Expand Down Expand Up @@ -135,6 +135,9 @@ async function decorateLockup(lockupArea, el) {
async function decorateForegroundText(el, container) {
const text = container?.querySelector('h1, h2, h3, h4, h5, h6, p')?.closest('div');
text?.classList.add('text');
if (el.classList.contains('countdown-timer') && !el.classList.contains('pill') && !el.classList.contains('ribbon')) {
await loadCDT(text, el.classList);
}
const iconArea = text?.querySelector('p:has(picture)');
iconArea?.classList.add('icon-area');
if (iconArea?.textContent.trim()) await decorateLockup(iconArea, el);
Expand Down
34 changes: 18 additions & 16 deletions libs/features/cdt/cdt.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
.timer-label {
font-size: var(--type-body-s-size);
font-weight: 700;
height: 27px;
}

.light .timer-label {
line-height: var(--type-body-xxl-size);
color: #000;
}

Expand All @@ -28,15 +25,20 @@
}

.horizontal .timer-label {
margin: 0 2px 27px;
margin: 0 2px var(--type-body-xxl-size);
}

.timer-block {
display: flex;
.timer-separator {
margin: 0px 2px;
line-height: var(--type-body-xxl-size);
}

.horizontal .timer-block {
margin-left: 10px;
margin-inline-start: 10px;
}

.timer-block {
display: flex;
}

.timer-fragment {
Expand All @@ -46,15 +48,13 @@
}

.timer-box {
padding: 0 9px;
width: 10px;
padding: 0 calc(var(--font-size-multiplier, 1) * 9px);
width: var(--type-detail-s-size);
border-radius: 5px;
font-size: var(--type-body-m-size);
font-weight: 700;
text-align: center;
}

.light .timer-box {
line-height: var(--type-body-xxl-size);
background-color: #222;
color: #FFF;
}
Expand All @@ -64,6 +64,10 @@
color: #1D1D1D;
}

html[dir="rtl"] .timer-unit-container {
flex-direction: row-reverse;
}

.timer-unit-container {
display: flex;
column-gap: 2px;
Expand All @@ -75,9 +79,7 @@
font-size: var(--type-body-xs-size);
font-weight: 400;
text-align: start;
}

.light .timer-unit-label {
line-height: var(--type-body-xxl-size);
color: #464646;
}

Expand Down
12 changes: 7 additions & 5 deletions libs/features/cdt/cdt.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ function loadCountdownTimer(
) {
let isVisible = false;
let interval;
const oneMinuteinMs = 60000;

const instant = new URL(window.location.href)?.searchParams?.get('instant');
let currentTime = instant ? Date.parse(instant) : Date.now();

function appendTimerBox(parent, value, label) {
const fragment = createTag('div', { class: 'timer-fragment' }, null, { parent });
Expand Down Expand Up @@ -52,9 +56,6 @@ function loadCountdownTimer(
}

function updateCountdown() {
const instant = new URL(window.location.href)?.searchParams?.get('instant');
const currentTime = instant ? new Date(instant) : Date.now();

for (let i = 0; i < timeRangesEpoch.length; i += 2) {
const startTime = timeRangesEpoch[i];
const endTime = timeRangesEpoch[i + 1];
Expand All @@ -66,6 +67,7 @@ function loadCountdownTimer(
const hoursLeft = Math.floor((diffTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutesLeft = Math.floor((diffTime % (1000 * 60 * 60)) / (1000 * 60));
render(daysLeft, hoursLeft, minutesLeft);
currentTime += oneMinuteinMs;
return;
}
}
Expand All @@ -76,7 +78,6 @@ function loadCountdownTimer(
}

function startCountdown() {
const oneMinuteinMs = 60000;
updateCountdown();
interval = setInterval(updateCountdown, oneMinuteinMs);
}
Expand Down Expand Up @@ -108,13 +109,14 @@ export default async function initCDT(el, classList) {
const parsedTime = Date.parse(time?.trim());
return Number.isNaN(parsedTime) ? null : parsedTime;
});

if (timeRangesEpoch.includes(null)) {
throw new Error('Invalid format for countdown timer range');
}

const cdtDiv = createTag('div', { class: 'countdown-timer' }, null, { parent: el });
cdtDiv.classList.add(isMobile() ? 'vertical' : 'horizontal');
cdtDiv.classList.add(classList.contains('dark') ? 'dark' : 'light');
if (classList.contains('dark')) cdtDiv.classList.add('dark');
if (classList.contains('center')) cdtDiv.classList.add('center');

loadCountdownTimer(cdtDiv, cdtLabel, cdtDays, cdtHours, cdtMins, timeRangesEpoch);
Expand Down
2 changes: 1 addition & 1 deletion libs/utils/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,6 @@ export async function loadCDT(el, classList) {
.then(({ default: initCDT }) => initCDT(el, classList)),
]);
} catch (error) {
window.lana?.log(`Failed to load countdown timer module: ${error}`, { tags: 'countdown-timer' });
window.lana?.log(`WARN: Failed to load countdown timer: ${error}`, { tags: 'errorType=warn,module=countdown-timer' });
}
}
46 changes: 45 additions & 1 deletion test/blocks/notification/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -495,5 +495,49 @@ <h3 id="desktop-content"><strong>Desktop content</strong></h3>
</div>
</div>
</div>

<div>
<h3 id="banner-notifications-default">Banner Notifications (default) with Countdown countdown-timer</h3>
<p>notification</p>
<div class="notification countdown-timer">
<div>
<div>
<picture>
<source media="(max-width: 400px)" srcset="./">
<img alt="mock" loading="lazy" src="">
</picture>
</div>
<div>
<picture>
<source media="(max-width: 400px)" srcset="./">
<img alt="mock" loading="lazy" src="">
</picture>
</div>
<div>
<picture>
<source media="(max-width: 400px)" srcset="./">
<img alt="mock" loading="lazy" src="">
</picture>
</div>
</div>
<div>
<div>
<h3 id="heading-m-2430-lorem-ipsum-dolor-sit-amet-consetetur-sadis-elitr">Heading M 24/30 Lorem ipsum dolor sit amet, consetetur sadis elitr.</h3>
<p>Body M 18/27 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eius. <a href="https://usc-word-edit.officeapps.live.com/we/wordeditorframe.aspx?ui=en%2DUS&#x26;rs=en%2DUS&#x26;wopisrc=https%3A%2F%2Fadobe.sharepoint.com%2Fsites%2Fadobecom%2F_vti_bin%2Fwopi.ashx%2Ffiles%2F3de33d38f15646ef97bcba87d26c1aeb&#x26;wdenableroaming=1&#x26;mscc=1&#x26;hid=0CDF68A0-90AA-D000-70F9-F912044D2A2F&#x26;wdorigin=Other&#x26;jsapi=1&#x26;jsapiver=v1&#x26;newsession=1&#x26;corrid=7bf09044-0a00-45c1-8cdd-5ab811dd1859&#x26;usid=7bf09044-0a00-45c1-8cdd-5ab811dd1859&#x26;sftc=1&#x26;cac=1&#x26;mtf=1&#x26;sfp=1&#x26;instantedit=1&#x26;wopicomplete=1&#x26;wdredirectionreason=Unified_SingleFlush&#x26;rct=Medium&#x26;ctp=LeastProtected">See terms</a>.</p>
<p><em><a href="https://www.adobe.com/">Call to action</a></em> <strong><a href="https://www.adobe.com/">Call to action</a></strong></p>
</div>
<div>
<picture>
<source media="(max-width: 400px)" srcset="./">
<img alt="mock" loading="lazy" src="">
</picture>
</div>
</div>
</div>
<div class="section-metadata">
<div>
<div data-valign="middle">style</div>
<div data-valign="middle"><strong>l spacing</strong></div>
</div>
</div>
</div>
<div></div>
14 changes: 10 additions & 4 deletions test/blocks/notification/notification.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { readFile } from '@web/test-runner-commands';
import { expect } from '@esm-bundle/chai';
import { setConfig } from '../../../libs/utils/utils.js';
import { setConfig, getConfig } from '../../../libs/utils/utils.js';

const mockBody = await readFile({ path: './mocks/body.html' });
const { default: init } = await import('../../../libs/blocks/notification/notification.js');

const locales = { '': { ietf: 'en-US', tk: 'hah7vzn.css' } };
const conf = { locales };
const conf = { locales, miloLibs: 'http://localhost:2000/libs' };
setConfig(conf);
getConfig().locale.contentRoot = '/test/blocks/notification/mocks';

const mockBody = await readFile({ path: './mocks/body.html' });
const { default: init } = await import('../../../libs/blocks/notification/notification.js');
document.head.innerHTML = '<link rel="stylesheet" href="../../../libs/blocks/notification/notification.css"><meta name="countdown-timer" content="2024-08-26 12:00:00 PST,2026-08-30 00:00:00 PST">';

describe('notification', async () => {
let notifs;
Expand Down Expand Up @@ -45,6 +48,9 @@ describe('notification', async () => {
const border = notifs[2].querySelector(':scope > .border');
expect(border).to.exist;
});
it('has a cdt', () => {
expect(notifs[15].querySelectorAll('.timer-label')).to.have.lengthOf(1);
});
});

describe('ribbon notifications', () => {
Expand Down
Loading