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

Countdown in hero #66 #264

Merged
merged 28 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f3a3cbc
add countdown timer in hero block
taimurCognizant Nov 21, 2023
d062e56
remove countdown timer on timeout
taimurCognizant Nov 21, 2023
422c98b
fix digit width in counter
taimurCognizant Nov 22, 2023
f0cdec9
refactor gaps, UI improvements for all variants
taimurCognizant Nov 22, 2023
a12ba14
fix layout shift when timer content changes
taimurCognizant Nov 22, 2023
b742acc
add comment
taimurCognizant Nov 22, 2023
698bc46
fix button padding for tablet
taimurCognizant Nov 22, 2023
5befb65
fix better text wrapping
taimurCognizant Nov 22, 2023
fb23baa
fix hero container takes at least the height of the viewport, and in …
taimurCognizant Nov 22, 2023
97114ed
cleanup comment
taimurCognizant Nov 22, 2023
7cff829
fix linting errors
taimurCognizant Nov 22, 2023
542e95b
fix use font shorthand
taimurCognizant Nov 23, 2023
9e68ef1
fix css variable
taimurCognizant Nov 23, 2023
8f751e4
fix use labels from placeholder.json
taimurCognizant Nov 23, 2023
7fcbda6
fix use flexbox and pseudo element for colon
taimurCognizant Nov 23, 2023
de84703
fix set width of largest segment in timer
taimurCognizant Nov 23, 2023
2ff0ed2
fix hero height with inpage navigation
taimurCognizant Nov 23, 2023
3f9b806
update hero gradient
taimurCognizant Nov 23, 2023
a0d33dd
add variant to right align background in hero
taimurCognizant Nov 23, 2023
4c22760
refactor better class names for positioning
taimurCognizant Nov 24, 2023
875ac1f
refactor combine styles
taimurCognizant Nov 24, 2023
c7c482b
cleanup styles
taimurCognizant Nov 27, 2023
25e961c
fix hero background
taimurCognizant Nov 28, 2023
a3c8469
fix remove if element exist
taimurCognizant Nov 28, 2023
1d6e9e8
add play icon
cogniSyb Nov 29, 2023
9298a88
Merge branch 'develop' into 66-countdown-in-hero
cogniSyb Nov 29, 2023
6947739
refactor typography and sizing
cogniSyb Nov 29, 2023
03f9696
fix plural rules
cogniSyb Nov 29, 2023
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
84 changes: 69 additions & 15 deletions blocks/v2-hero/v2-hero.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,27 @@
--scroll-dot-width: 9px;
--v2-hero-padding: 32px;

height: calc(100vh - var(--nav-height));
min-height: calc(100vh - var(--nav-height));
overflow: hidden;
position: relative;
background-color: var(--c-grey-1);
}

/* Reduce the Hero height by the inpage-navigation height */
.v2-inpage-navigation-wrapper + .v2-hero-container .v2-hero {
height: calc(100vh - (var(--nav-height) + var(--inpage-navigation-height) - 2px));
min-height: calc(100vh - (var(--nav-height) + var(--inpage-navigation-height) - 2px));
}

@supports (height: 1svh) {
.v2-hero {
height: calc(100svh - var(--nav-height));
min-height: calc(100svh - var(--nav-height));
}

.v2-inpage-navigation-wrapper + .v2-hero-container .v2-hero {
height: calc(100svh - (var(--nav-height) + var(--inpage-navigation-height) - 2px));
.v2-inpage-navigation-wrapper + .v2-hero-container .v2-hero,
.v2-inpage-navigation-wrapper + .v2-hero-container .v2-hero__content-wrapper {
min-height: calc(100svh - (var(--nav-height) + var(--inpage-navigation-height) - 2px));
}

}

.section.v2-hero-container {
Expand All @@ -58,15 +61,19 @@
width: 100%;
}

.v2-hero--background-right .v2-hero__image, .v2-hero--background-right .v2-hero__video {
object-position: center right;
}

.v2-hero__content-wrapper {
color: var(--c-main-black);
position: relative;
display: flex;
flex-direction: column;
height: 100%;
min-height: calc(100svh - var(--nav-height));
padding: var(--v2-hero-padding);
padding-bottom: calc((var(--v2-hero-padding) * 2) + var(--scroll-icon-height));
background: linear-gradient(180deg, rgb(255 255 255 / 50%) 0%, rgb(255 255 255 / 0%) 100%);
background: linear-gradient(180deg, rgb(255 255 255 / 40%) 0%, rgb(255 255 255 / 0%) 100%);
taimurCognizant marked this conversation as resolved.
Show resolved Hide resolved
}

.v2-hero--centered .v2-hero__content-wrapper {
Expand All @@ -75,18 +82,22 @@
text-align: center;
}

.v2-hero--left .v2-hero__content-wrapper {
.v2-hero--left-center .v2-hero__content-wrapper {
justify-content: center;
}

.v2-hero--bottom .v2-hero__content-wrapper {
.v2-hero--center-bottom .v2-hero__content-wrapper {
align-items: center;
justify-content: flex-end;
text-align: center;
}

.v2-hero--dark {
background-color: var(--c-grey-4);
}

.v2-hero--dark .v2-hero__content-wrapper {
background: linear-gradient(180deg, rgb(0 0 0 / 50%) 0%, rgb(0 0 0 / 0%) 100%);
background: linear-gradient(180deg, rgb(0 0 0 / 40%) 0%, rgb(0 0 0 / 0%) 100%);
taimurCognizant marked this conversation as resolved.
Show resolved Hide resolved
color: var(--c-white);
}

Expand All @@ -99,7 +110,7 @@
}

.v2-hero--centered .v2-hero__content > *,
.v2-hero--bottom .v2-hero__content > * {
.v2-hero--center-bottom .v2-hero__content > * {
margin-left: auto;
margin-right: auto;
}
Expand All @@ -109,18 +120,19 @@
font-size: 70px;
line-height: 85%;
letter-spacing: 5px;
margin-bottom: 8px;
text-wrap: balance;
}

.v2-hero__title,
.v2-hero__content p {
margin: 10px 0 0;
margin: 0;
}

.v2-hero__buttons-wrapper {
display: inline-flex;
flex-flow: column wrap;
gap: 8px;
margin-top: 24px;
gap: 24px;
padding: 24px 0;
}

/* Scroll icon */
Expand All @@ -146,6 +158,48 @@
width: var(--scroll-dot-width);
}

/* START - Countdown */

.v2-hero__countdown {
display: flex;
gap: 32px;
padding: 24px 0;
}

.v2-hero--centered .v2-hero__countdown, .v2-hero--center-bottom .v2-hero__countdown {
justify-content: center;
}

.v2-hero__countdown-segment {
taimurCognizant marked this conversation as resolved.
Show resolved Hide resolved
position: relative;
flex-basis: 50px;
text-align: center;
}

.v2-hero__countdown-segment + .v2-hero__countdown-segment::before {
content: ":";
position: absolute;
font: 400 var(--f-heading-3-5-font-size) / var(--f-heading-3-5-line-height) var(--ff-volvo-novum-medium);
top: 0;
left: -16px;
transform: translate(-50%, 0);
}

.v2-hero__countdown-number {
font: 400 var(--f-heading-3-5-font-size) / var(--f-heading-3-5-line-height) var(--ff-volvo-novum-medium);
letter-spacing: 0.25px;
font-feature-settings: 'tnum';
}

.v2-hero__countdown-label {
font: 400 var(--f-caption-font-size) / var(--f-caption-line-height) var(--ff-volvo-novum);
letter-spacing: var(--f-caption-letter-spacing);
text-transform: capitalize;
}

/* END - Countdown */


@media (min-width: 744px) {
.v2-hero {
--v2-hero-padding: 50px;
Expand Down
81 changes: 75 additions & 6 deletions blocks/v2-hero/v2-hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,49 @@ import {
createVideo,
} from '../../scripts/video-helper.js';
import {
createElement,
removeEmptyTags,
variantsClassesToBEM,
createElement, getTextLabel, removeEmptyTags, variantsClassesToBEM,
} from '../../scripts/common.js';

const variantClasses = ['centered', 'left', 'bottom', 'dark'];
const variantClasses = ['centered', 'left-center', 'center-bottom', 'dark', 'background-right'];
let intervalId = null;
const blockName = 'v2-hero';

export default async function decorate(block) {
const blockName = 'v2-hero';
function updateCountdownElement(block, elementId, value, label) {
const element = block.querySelector(`#${elementId}`);
element.textContent = value.toString().padStart(2, '0');
element.nextElementSibling.textContent = label;
}

function updateCountdown(eventTime, block) {
const now = new Date();
const diff = eventTime - now;

// Check if the event time has passed
if (diff <= 0) {
block.querySelector(`.${blockName}__countdown-wrapper`)?.remove();
clearInterval(intervalId);
return;
}

// Calculate time left
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((diff % (1000 * 60)) / 1000);

// Format labels
const dayLabel = days <= 1 ? getTextLabel('day') : `${getTextLabel('day')}s`;
const hourLabel = hours <= 1 ? getTextLabel('hour') : `${getTextLabel('hour')}s`;
const minuteLabel = minutes <= 1 ? getTextLabel('minute') : `${getTextLabel('minute')}s`;
const secondLabel = seconds <= 1 ? getTextLabel('second') : `${getTextLabel('second')}s`;

updateCountdownElement(block, 'days', days, dayLabel);
updateCountdownElement(block, 'hours', hours, hourLabel);
updateCountdownElement(block, 'minutes', minutes, minuteLabel);
updateCountdownElement(block, 'seconds', seconds, secondLabel);
}

export default async function decorate(block) {
// add Hero variant classnames
variantsClassesToBEM(block.classList, variantClasses, blockName);

Expand Down Expand Up @@ -45,6 +78,38 @@ export default async function decorate(block) {
const content = block.querySelector(':scope > div > div');
content.classList.add(`${blockName}__content`);

// Countdown timer
const blockSection = block.parentElement?.parentElement;
if (blockSection && blockSection.dataset?.countdownDate) {
const countDownWrapper = createElement('div', { classes: `${blockName}__countdown-wrapper` });
countDownWrapper.innerHTML = `<div class="${blockName}__countdown">
<div class="${blockName}__countdown-segment">
taimurCognizant marked this conversation as resolved.
Show resolved Hide resolved
<div id="days" class="${blockName}__countdown-number">00</div>
<div class="${blockName}__countdown-label">Days</div>
taimurCognizant marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div class="${blockName}__countdown-segment">
<div id="hours" class="${blockName}__countdown-number">00</div>
<div class="${blockName}__countdown-label">Hours</div>
</div>
<div class="${blockName}__countdown-segment">
<div id="minutes" class="${blockName}__countdown-number">00</div>
<div class="${blockName}__countdown-label">Minutes</div>
</div>
<div class="${blockName}__countdown-segment">
<div id="seconds" class="${blockName}__countdown-number">00</div>
<div class="${blockName}__countdown-label">Seconds</div>
</div>
</div>`;
content.prepend(countDownWrapper);

const eventTimeIso = blockSection.dataset.countdownDate;
const eventTime = new Date(eventTimeIso);
updateCountdown(eventTime, block);
intervalId = setInterval(() => {
updateCountdown(eventTime, block);
}, 1000);
}

// convert all headings to h1
const headings = [...content.querySelectorAll('h1, h2, h3, h4, h5, h6')];
headings.forEach((heading) => {
Expand All @@ -58,6 +123,10 @@ export default async function decorate(block) {
}
});

// render all paragraph as H6 with the class
const paragraphs = [...content.querySelectorAll('p')];
paragraphs.forEach((paragraph) => paragraph.classList.add('h6'));

const buttonsWrapper = createElement('div', { classes: `${blockName}__buttons-wrapper` });
const ctaButtons = content.querySelectorAll('.button-container > a');
[...ctaButtons].forEach((b, i) => {
Expand Down
16 changes: 16 additions & 0 deletions placeholder.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@
{
"Key": "vinformat-length",
"Text": "Please fill out this field"
},
{
"Key": "day",
"Text": "day"
},
{
"Key": "hour",
"Text": "hour"
},
{
"Key": "minute",
"Text": "minute"
},
{
"Key": "second",
"Text": "second"
}
],
":type": "sheet"
Expand Down