Skip to content

Commit

Permalink
Merge branch 'feature/twe-34-division-page-hero' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
albinazs committed Jan 21, 2025
2 parents 36ecde2 + 97ef147 commit 3955682
Show file tree
Hide file tree
Showing 17 changed files with 228 additions and 39 deletions.
4 changes: 3 additions & 1 deletion docs/front-end/breakpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ $breakpoints: (
'x-large' '(min-width: 1280px)',
// secondary breakpoints - use sparingly
'small' '(min-width: 410px)',
'xx-large' '(min-width: 1800px)'
'menu' '(min-width: 800px)',
'xx-large' '(min-width: 1440px)',
'xxx-large' '(min-width: 1800px)'
);
```

Expand Down
21 changes: 20 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
},
"dependencies": {
"js-cookie": "^3.0.5",
"lite-youtube-embed": "^0.3.2"
"lite-youtube-embed": "^0.3.2",
"swiper": "^11.2.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
<path fill="currentColor" d="M6.02 4.297 10.06.22l.576.513-5 5.05-5-5.05.577-.513 4.039 4.078h.769Z"/>
</symbol>

<symbol id="pause" viewBox="0 0 40 40" fill="none">
<rect x="0.5" y="0.5" width="39" height="39" rx="19.5" stroke="currentColor" stroke-opacity="0.5"/><rect x="15" y="13" width="3" height="14" rx="1.5" fill="currentColor"/><rect x="22" y="13" width="3" height="14" rx="1.5" fill="currentColor"/>
</symbol>

<symbol id="play" viewBox="0 0 40 40" fill="none">
<rect x="0.5" y="0.5" width="39" height="39" rx="19.5" stroke="currentColor" stroke-opacity="0.5"/><path d="M26.8478 19.5985C27.1171 19.7984 27.1171 20.2016 26.8478 20.4015L17.1034 27.6349C16.7734 27.8798 16.3053 27.6443 16.3053 27.2334L16.3053 12.7666C16.3053 12.3557 16.7734 12.1202 17.1034 12.3651L26.8478 19.5985Z" fill="currentColor"/>
</symbol>

<symbol id="ring-one" viewBox="0 0 33 33">
<path d="M4.08 6.641a4 4 0 012.708-2.708l8.565-2.52a4 4 0 012.257 0l.283-.959-.283.96 8.566 2.519a4 4 0 012.709 2.708l2.519 8.566a4 4 0 010 2.257l-2.52 8.565a4 4 0 01-2.708 2.71l-8.566 2.518a3.998 3.998 0 01-2.257 0l-8.565-2.519a4 4 0 01-2.709-2.709l-2.52-8.565a4 4 0 010-2.257L4.08 6.64z" fill="none" stroke="currentColor" stroke-width="2"/>
</symbol>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
<div>
{% if value.static_text %}<span>{{ value.static_text }}</span>{% endif %}
<div data-dynamic-hero class="dynamic-hero">
{% if value.static_text %}<h2 class="heading heading--three heading--light">{{ value.static_text }}</h2>{% endif %}
{% if value.dynamic_text %}
{% if value.dynamic_text|length > 1 %}
{# If there's more than one dynamic text, show the controls for the loop. #}
<ul>
{% for text in value.dynamic_text %}
<li>{{ text }}</li>
{% endfor %}
</ul>
{# If there's more than one dynamic text, show Swiper carousel structure and controls for the loop. #}
<div class="swiper">
<ul class="swiper-wrapper">
{% for text in value.dynamic_text %}
<li class="swiper-slide">
{# Fixed px values required to control the font size for all browsers and prevent slide overflow#}
<h3 class="heading heading--mega text-[60px] lg:text-[100px]">{{ text }}</h3>
</li>
{% endfor %}
</ul>
</div>
<div class="dynamic-hero__controls" aria-label="Carousel controls">
<button class="dynamic-hero__control" aria-label="Previous message" data-dynamic-hero-prev>{% include "patterns/atoms/icons/icon.html" with name="chevron" classname="dynamic-hero__control--prev" %}</button>
<button class="dynamic-hero__control" aria-label="Pause autoplay" data-dynamic-hero-pause>{% include "patterns/atoms/icons/icon.html" with name="pause" classname="dynamic-hero__control--pause" %}</button>
<button class="dynamic-hero__control hidden" aria-label="Resume autoplay" data-dynamic-hero-play>{% include "patterns/atoms/icons/icon.html" with name="play" classname="dynamic-hero__control--play" %}</button>
<button class="dynamic-hero__control" aria-label="Next message" data-dynamic-hero-next>{% include "patterns/atoms/icons/icon.html" with name="chevron" classname="dynamic-hero__control--next" %}</button>
</div>
{% else %}
{# If there's only one dynamic text, don't show the controls for the loop. #}
{# If there's only one dynamic text, don't show Swiper carousel structure and controls for the loop. #}
{% for text in value.dynamic_text %}
<span>{{ text }}</span>
<h3 class="heading heading--mega">{{ text }}</h3>
{% endfor %}
{% endif %}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ context:
value:
static_text: We help charities and nonprofits
dynamic_text:
- 'future-proof your funding streams.'
- 'transform lives through digital innovation.'
- 'increase supporter acquisition and retention.'
- 'deliver life-changing digital services.'
- 'scale social impact through technology.'
- 'transform lives through digital innovation.'
- 'future-proof your funding streams.'

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
{% block content %}

<div class="grid grid--spacer-large streamfield">
<div class="grid__title">
<h1 class="heading heading--mega">{{ page.title }}</h1>
<h1 class="sr-only">{{ page.title }}</h1>

<p>{{ page.label }}</p>
</div>

<div class="grid__title">{% include_block page.hero %}</div>
<div class="grid__dynamic-hero">{% include_block page.hero %}</div>

{% include_block page.body %}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ <h2 class="underline mt-8 mb-2">Home page hero</h2>
{% include "patterns/molecules/home-page-hero/home-page-hero.html" %}
</div>

<div>
<h2 class="underline mt-8 mb-2">Dynamic hero</h2>
{% include "patterns/molecules/streamfield/blocks/dynamic_hero_block.html" %}
</div>

<div>
<h2 class="underline mt-8 mb-2">Values block</h2>
{% include "patterns/molecules/streamfield/blocks/values_block.html" %}
Expand Down
72 changes: 72 additions & 0 deletions tbx/static_src/javascript/components/dynamic-hero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import Swiper from 'swiper';
// eslint-disable-next-line import/no-unresolved
import { Autoplay } from 'swiper/modules';

export default class DynamicHero {
static selector() {
return '[data-dynamic-hero]';
}

constructor(node) {
this.node = node;
this.swiperContainer = this.node.querySelector('.swiper');
this.slides = this.node.querySelectorAll('.swiper-slide');
this.nextButton = this.node.querySelector('[data-dynamic-hero-next]');
this.prevButton = this.node.querySelector('[data-dynamic-hero-prev]');
this.pauseButton = this.node.querySelector('[data-dynamic-hero-pause]');
this.playButton = this.node.querySelector('[data-dynamic-hero-play]');
this.bindEvents();
}

bindEvents() {
if (!this.swiperContainer) {
return;
}

// Check if the user prefers reduced motion - don't autoplay if they do
const isReduced =
window.matchMedia('(prefers-reduced-motion: reduce)').matches ===
true;

this.swiper = new Swiper(this.swiperContainer, {
modules: [Autoplay],
direction: 'vertical',
slidesPerView: 1,
speed: 1000,
loop: true,
autoplay: {
delay: 5000,
enabled: !isReduced,
},
});

if (this.nextButton) {
this.nextButton.addEventListener('click', () =>
this.swiper.slideNext(),
);
}

if (this.prevButton) {
this.prevButton.addEventListener('click', () =>
this.swiper.slidePrev(),
);
}

if (this.pauseButton) {
this.pauseButton.addEventListener('click', () => {
this.swiper.autoplay.stop();
this.pauseButton.classList.add('hidden');
this.playButton.classList.remove('hidden');
});
}

if (this.playButton) {
this.playButton.addEventListener('click', () => {
this.swiper.autoplay.start();
this.swiper.slideNext();
this.playButton.classList.add('hidden');
this.pauseButton.classList.remove('hidden');
});
}
}
}
2 changes: 2 additions & 0 deletions tbx/static_src/javascript/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import YouTubeConsentManager from './components/youtube-embed';
import Tabs from './components/tabs';
import TableHint from './components/table-hint';
import ModeSwitcher from './components/mode-switcher';
import DynamicHero from './components/dynamic-hero';

// IE11 polyfills
import foreachPolyfill from './polyfills/foreach-polyfill';
Expand Down Expand Up @@ -37,5 +38,6 @@ document.addEventListener('DOMContentLoaded', () => {
initComponent(Tabs);
initComponent(TableHint);
initComponent(ModeSwitcher);
initComponent(DynamicHero);
new DesktopCloseMenus();
});
74 changes: 74 additions & 0 deletions tbx/static_src/sass/components/_dynamic-hero.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@use 'config' as *;

// Set fixed height to prevent Swiper's infinite height issue https://swiperjs.com/get-started#swiper-css-stylessize
.dynamic-hero {
.swiper {
max-width: 100%;
height: 380px;

@include media-query(medium) {
height: 240px;
}

@include media-query(menu) {
height: 160px;
}

@include media-query(large) {
height: 320px;
}

@include media-query(xx-large) {
height: 250px;
}
}

.swiper-slide {
padding-bottom: 20px;
}

&__controls {
display: flex;
}

&__control {
display: flex;
align-items: center;
justify-content: center;
height: 40px;
width: 40px;
opacity: 1;
visibility: visible;
transition: $transition;

&:hover,
&:focus {
color: var(--color--link-interaction);
}

&:focus {
@include focus-style();
}

&--prev {
transform: rotate(90deg);
}

&--next {
transform: rotate(-90deg);
}

&--pause,
&--play {
height: 40px;
width: 40px;
}

&.hidden {
opacity: 0;
visibility: hidden;
pointer-events: none;
position: absolute;
}
}
}
9 changes: 9 additions & 0 deletions tbx/static_src/sass/components/_grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
}
}

&__dynamic-hero {
grid-column: 2 / span 4;
margin-bottom: $spacer-medium;

@include media-query(large) {
grid-column: 2 / span 12;
}
}

&__intro {
margin-bottom: $spacer-medium;
grid-column: 2 / span 4;
Expand Down
2 changes: 1 addition & 1 deletion tbx/static_src/sass/components/_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
margin-right: $spacer-medium;
}

@include media-query(xx-large) {
@include media-query(xxx-large) {
margin-right: 0;
}
}
Expand Down
5 changes: 3 additions & 2 deletions tbx/static_src/sass/config/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ $breakpoints: (
'x-large' '(min-width: 1280px)',
// secondary breakpoints - use sparingly
'small' '(min-width: 410px)',
'xx-large' '(min-width: 1800px)',
'menu' '(min-width: 800px)'
'menu' '(min-width: 800px)',
'xx-large' '(min-width: 1440px)',
'xxx-large' '(min-width: 1800px)'
);

// Layout
Expand Down
2 changes: 2 additions & 0 deletions tbx/static_src/sass/main.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// CSS from external vendors (available as npm)
@use '../../../node_modules/lite-youtube-embed/src/lite-yt-embed.css';
@use '../../../node_modules/swiper/swiper.scss';

// Base
@use 'base/base';
Expand All @@ -19,6 +20,7 @@
@use 'components/contact-cta';
@use 'components/cookie-message';
@use 'components/division-signpost';
@use 'components/dynamic-hero';
@use 'components/employee-owned-icon';
@use 'components/event-block';
@use 'components/featured-case-study';
Expand Down

0 comments on commit 3955682

Please sign in to comment.