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

feat(carousel): Styles update - FRONT-4571 #3583

Merged
merged 21 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
27fa5d3
feat(carousel): Using pause-outline icon - FRONT-4571
planctus Aug 23, 2024
bc9c48a
feat(carousel): Styles - FRONT-4571
planctus Aug 23, 2024
dff2a20
Merge branch 'v4-dev' into FRONT-4571-Carousel-update
planctus Aug 26, 2024
78b7f87
feat(carousel): Increasing margin in controls for EC - FRONT-4571
planctus Aug 26, 2024
af11ee7
Merge branch 'FRONT-4571-Carousel-update' of github.com:ec-europa/eur…
planctus Aug 26, 2024
088249a
feat(carousel): Alignment of the play button in large viewports - FRO…
planctus Aug 26, 2024
fb8405e
feat(carousel): Reintroducing shadows, removing border bottom - FRONT…
planctus Aug 26, 2024
d39dede
feat(carousel): Padding in the controls area - FRONT-4571
planctus Aug 26, 2024
e87b3cb
feat(carousel): Single slide display, hiding element initially - FRON…
planctus Aug 27, 2024
914c640
feat(carousel): Removing debug - FRONT-4571
planctus Aug 27, 2024
fc57943
Merge branch 'v4-dev' into FRONT-4571-Carousel-update
planctus Aug 27, 2024
53a6fa0
feat(carousel): fixing full width use case - FRONT-4571
planctus Aug 27, 2024
8200dbd
Merge branch 'FRONT-4571-Carousel-update' of github.com:ec-europa/eur…
planctus Aug 27, 2024
5621394
feat(carousel): Only hide on init - FRONT-4571
planctus Aug 27, 2024
eff0f12
feat(carousel): Adding text in the demo for grid content - FRONT-4571
planctus Aug 28, 2024
0b5b9ed
feat(carousel): Consistent calculations removing the scrollbar before…
planctus Aug 29, 2024
92afd68
Merge branch 'v4-dev' into FRONT-4571-Carousel-update
planctus Aug 29, 2024
c80a4cb
Merge branch 'v4-dev' of github.com:ec-europa/europa-component-librar…
planctus Sep 2, 2024
c2098f1
Merge branch 'v4-dev' into FRONT-4571-Carousel-update
planctus Sep 3, 2024
1e24caf
feat(carousel): Css only layout, js is only sliding now - FRONT-4571
planctus Sep 3, 2024
7bd460e
Merge branch 'v4-dev' into FRONT-4571-Carousel-update
emeryro Sep 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ exports[`Carousel Default renders correctly 1`] = `
focusable="false"
>
<use
xlink:href="/icons.svg#pause"
xlink:href="/icons.svg#pause-outline"
/>
</svg>
</span>
Expand Down Expand Up @@ -448,7 +448,7 @@ exports[`Carousel Default renders correctly with extra attributes 1`] = `
focusable="false"
>
<use
xlink:href="/icons.svg#pause"
xlink:href="/icons.svg#pause-outline"
/>
</svg>
</span>
Expand Down Expand Up @@ -832,7 +832,7 @@ exports[`Carousel Default renders correctly with extra class names 1`] = `
focusable="false"
>
<use
xlink:href="/icons.svg#pause"
xlink:href="/icons.svg#pause-outline"
/>
</svg>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
extra_classes: 'ecl-carousel__pause',
icon: {
path: _icon_path,
name: 'pause',
name: 'pause-outline',
size: 'm',
extra_classes: 'ecl-carousel__icon-default',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const renderStory = async (data, args) => {
}
if (args.grid_content) {
story +=
'<div class="ecl-container"><p class="ecl-u-type-paragraph">Content inside the grid</p></div>';
'<div class="ecl-container"><p class="ecl-u-type-paragraph ecl-u-pt-xl">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque eleifend auctor libero et scelerisque. Phasellus malesuada sem vel augue egestas facilisis. Curabitur velit nibh, scelerisque in massa vitae, consectetur tempor ligula. Nunc vehicula tellus vel nunc facilisis, ac condimentum nulla lacinia. Integer at vulputate sapien.</p></div>';
}

return story;
Expand Down
86 changes: 56 additions & 30 deletions src/implementations/vanilla/components/carousel/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class Carousel {
this.cloneLastSLide = null;
this.executionCount = 0;
this.maxExecutions = 5;
this.slideWidth = 0;

// Bind `this` for use in callbacks
this.handleAutoPlay = this.handleAutoPlay.bind(this);
Expand Down Expand Up @@ -115,7 +116,8 @@ export class Carousel {
throw new TypeError('Called init but ECL is not present');
}
ECL.components = ECL.components || new Map();

// Hide the carousel initially, we will show it in handleesize()
this.element.style.opacity = 0;
this.btnPlay = queryOne(this.playSelector, this.element);
this.btnPause = queryOne(this.pauseSelector, this.element);
this.slidesContainer = queryOne(this.slidesClass, this.element);
Expand Down Expand Up @@ -145,23 +147,27 @@ export class Carousel {
const lastSlide = this.slides[this.slides.length - 1];

// Clone first and last slide
this.cloneFirstSLide = firstSlide.cloneNode(true);
this.cloneLastSLide = lastSlide.cloneNode(true);
this.slidesContainer.appendChild(this.cloneFirstSLide);
this.slidesContainer.insertBefore(this.cloneLastSLide, firstSlide);
this.cloneFirstSlide = firstSlide.cloneNode(true);
this.cloneLastSlide = lastSlide.cloneNode(true);
this.slidesContainer.appendChild(this.cloneFirstSlide);
this.slidesContainer.insertBefore(this.cloneLastSlide, firstSlide);

// Initialize the js for the two cloned slides
const cloneFirstBanner = new ECL.Banner(
this.cloneFirstSlide.firstElementChild,
);
const cloneLastBanner = new ECL.Banner(
this.cloneLastSlide.firstElementChild,
);

cloneFirstBanner.init();
cloneLastBanner.init();

// Refresh the slides variable after adding new cloned slides
this.slides = queryAll(this.slideClass, this.element);

// Initialize position of slides and size of the carousel
this.slides.forEach((slide) => {
slide.style.width = `${100 / this.slides.length}%`;
});
this.handleResize();

// Initialze pagination and navigation
this.checkIndex();

this.handleResize();
// Bind events
if (this.navigationItems) {
this.navigationItems.forEach((nav, index) => {
Expand Down Expand Up @@ -268,6 +274,9 @@ export class Carousel {
}
const heightValues = this.slides.map((slide) => {
const banner = queryOne('.ecl-banner', slide);
const bannerInstance = ECL.components.get(banner);
const ratio = bannerInstance.defaultRatio();
bannerInstance.setHeight(ratio);
const height = parseInt(banner.style.height, 10);
if (banner.style.height === 'auto') {
return 0;
Expand Down Expand Up @@ -317,12 +326,28 @@ export class Carousel {
this.slides.forEach((slide) => {
const banner = queryOne('.ecl-banner', slide);
let bannerImage = null;
let bannerVideo = null;
let bannerFooter = null;
if (banner) {
banner.style.height = '';
bannerImage = queryOne('img', banner);
bannerVideo = queryOne('video', banner);
bannerFooter = queryOne('.ecl-banner__credit', banner);

if (bannerImage) {
bannerImage.style.aspectRatio = '';
}
if (bannerVideo) {
bannerVideo.style.aspectRatio = '';
}
if (bannerFooter) {
setTimeout(() => {
banner.style.setProperty(
'--banner-footer-height',
`${bannerFooter.offsetHeight}px`,
);
}, 100);
}
}
});
}
Expand Down Expand Up @@ -399,7 +424,8 @@ export class Carousel {
* @param {Boolean} transition
*/
moveSlides(transition) {
const newOffset = this.container.offsetWidth * this.index;
const newOffset = this.slideWidth * this.index;

this.slidesContainer.style.transitionDuration = transition ? '0.4s' : '0s';
if (this.direction === 'rtl') {
this.slidesContainer.style.right = `-${newOffset}px`;
Expand All @@ -410,8 +436,14 @@ export class Carousel {

/**
* Action to update slides index and position.
* @param {Event} e
*/
checkIndex() {
checkIndex(e) {
if (e) {
if (e.propertyName !== 'left') {
return;
}
}
// Update index
if (this.index === 0) {
this.index = this.total;
Expand Down Expand Up @@ -520,36 +552,30 @@ export class Carousel {
);
clearInterval(this.intervalId);
clearTimeout(this.resizeTimer);
let containerWidth = 0;

// We set 250ms delay which is higher than the 200ms delay in the banner.
this.resizeTimer = setTimeout(() => {
if (vw >= 998) {
this.intervalId = setInterval(this.checkBannerHeights, 100);
} else {
this.resetBannerHeights();
}
}, 250);

if (vw >= 768) {
containerWidth = this.container.offsetWidth;
} else {
containerWidth = this.container.offsetWidth + 15;
}

this.slidesContainer.style.width = `${
containerWidth * this.slides.length
}px`;

this.moveSlides(false);
this.slideWidth = this.slides[0].scrollWidth;
this.checkIndex();
setTimeout(() => {
// Reveal the carousel
this.element.style.opacity = 1;
}, 250);
}, 250);

// Add class to set a left margin to banner content and avoid arrow overlapping
if (vw >= 1140 && vw <= 1260) {
this.container.classList.add('ecl-carousel-container--padded');
} else {
this.container.classList.remove('ecl-carousel-container--padded');
}

// Desactivate autoPlay for mobile or activate autoPlay onLoad for desktop
// Deactivate autoPlay for mobile or activate autoPlay onLoad for desktop
if ((vw <= 768 && this.autoPlay) || (vw > 768 && this.autoPlay === null)) {
this.handleAutoPlay();
}
Expand Down
67 changes: 17 additions & 50 deletions src/implementations/vanilla/components/carousel/carousel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,38 +34,30 @@ $carousel: null !default;
}

.ecl-carousel__container {
box-sizing: border-box;
box-shadow: inset 0 -4px 12px -9px
rgba(map.get($theme, 'color', 'black'), 0.6);
order: 1;
width: calc(100% - var(--s-xl));
width: 100%;
}

.ecl-carousel__slides {
display: flex;
flex-direction: row;
list-style: none;
margin: 0;
padding: 0;
position: relative;
width: 100%;
}

.ecl-carousel__slide {
position: relative;
scroll-snap-type: x mandatory;

&::before {
background: map.get($theme, 'color', 'white');
content: '';
display: block;
height: 100%;
left: calc(-1 * var(--s-2xs));
position: absolute;
top: 0;
width: var(--s-2xs);
.ecl-carousel__slide {
flex: 0 0 auto;
scroll-snap-align: start;
width: 100%;
}
}

.ecl-carousel__slide .ecl-banner__credit {
margin-inline-end: var(--s-2xs);
width: auto;
}

Expand All @@ -83,6 +75,10 @@ $carousel: null !default;
display: flex;
justify-content: space-between;
}

.ecl-carousel__pause {
display: none;
}
}

.ecl-carousel__controls,
Expand Down Expand Up @@ -115,12 +111,6 @@ $carousel: null !default;
}
}

.ecl-carousel-container--padded .ecl-banner {
.ecl-container {
margin-inline-start: 100px;
}
}

/* stylelint-disable-next-line order/order */
@include breakpoints.up('s') {
.ecl-carousel__navigation {
Expand All @@ -143,6 +133,11 @@ $carousel: null !default;

/* stylelint-disable-next-line order/order */
@include breakpoints.up('l') {
.ecl-carousel__controls .ecl-container {
padding-inline-start: var(--s-2xl);
padding-inline-end: var(--s-2xl);
}

.ecl-carousel {
.ecl-banner {
height: initial;
Expand All @@ -153,10 +148,6 @@ $carousel: null !default;
}
}

.ecl-carousel__container {
width: 100%;
}

.ecl-carousel__slide {
position: relative;

Expand All @@ -177,21 +168,6 @@ $carousel: null !default;

/* stylelint-disable-next-line order/order */
@include breakpoints.up('xl') {
.ecl-container
.ecl-carousel:not(.ecl-carousel--full-width)
.ecl-banner
.ecl-container {
margin-inline-start: 120px;
}

.ecl-container
.ecl-carousel:not(.ecl-carousel--full-width)
.ecl-banner
.ecl-banner__credit
.ecl-container {
margin-inline-start: 60px;
}

.ecl-carousel__prev {
left: var(--s-m);
}
Expand Down Expand Up @@ -232,12 +208,3 @@ $carousel: null !default;
margin-inline-start: -50vw;
width: 100vw;
}

// stylelint-disable-next-line plugin/selector-bem-pattern, selector-max-compound-selectors
.ecl-container
.ecl-carousel--full-width
.ecl-banner:not(.ecl-banner--full-width)
.ecl-container {
padding-inline-start: var(--s-m);
padding-inline-end: var(--s-m);
}
4 changes: 2 additions & 2 deletions src/themes/ec/variables/_carousel.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

$carousel: (
box-shadow: var(--sh-6),
separator: 1px solid var(--c-n),
separator: none,
controls-background: map.get($color, 'white'),
controls-padding: var(--s-xs) 0,
controls-padding: var(--s-m) 0,
navigation-background-active: var(--c-n),
navigation-color-active: var(--c-d),
navigation-border-active: var(--c-n),
Expand Down
Loading