Skip to content

Commit

Permalink
Merge branch 'master' of github.com:helsingborg-stad/styleguide
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Thulin committed Sep 17, 2021
2 parents 4096fc4 + 171d50f commit 438827a
Show file tree
Hide file tree
Showing 13 changed files with 431 additions and 103 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@helsingborg-stad/styleguide",
"appname": "styleguide",
"version": "0.11.257",
"version": "0.11.261",
"description": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
Expand Down
7 changes: 7 additions & 0 deletions source/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Pagination from './pagination';
import ResizeByChildren from './resizeByChildren';
import KeepInViewPort from './keepInViewPort';
import ButtonToggle from './buttonToggle';
import TestimonialCarousel from './testimonials';

import './datepicker';
import './helpers/swipe';
Expand Down Expand Up @@ -74,6 +75,12 @@ if(paginations) {
})
}

const testimonialCarousels = document.querySelectorAll('[js-testimonials--is-carousel]');
if (testimonialCarousels) {
testimonialCarousels.forEach((testimonial) => {
const testimonialInstance = new TestimonialCarousel(testimonial);
})
}

SortInstance.applySort();
ToggleInstance.applyToggle();
Expand Down
108 changes: 108 additions & 0 deletions source/js/testimonials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
export default class TestimonialCarousel {
constructor (carousel) {
this.CAROUSEL = carousel;
this.ITEMS = carousel.querySelectorAll('.c-testimonial');
this.IS_LARGE_SCREEN = this.isLargeScreen();

this.init(this.ITEMS);
this.windowResize();
this.addButtonListeners();
}

// eslint-disable-next-line class-methods-use-this
init() {
// If desktop show two first card, else just one
const keys = Array.from(this.ITEMS.keys());
const show = this.IS_LARGE_SCREEN ? keys.slice(0,2) : keys.slice(0,1);
const hide = this.IS_LARGE_SCREEN ? keys.slice(2) : keys.slice(1);
const buttons = this.CAROUSEL.parentElement.querySelectorAll('.c-testimonials__button');

if (hide.length === 0) {
buttons.forEach((button) => {
button.classList.add('u-display--none');
});
} else {
buttons.forEach((button) => {
button.classList.remove('u-display--none');
});
}

this.CAROUSEL.setAttribute('js-testimonials-iteration', 0);

this.toggleVisible(show);
this.toggleHidden(hide);
}

addButtonListeners() {
const backButton = this.CAROUSEL.parentElement.querySelector('[js-testimonials__back]');
const forwardButton = this.CAROUSEL.parentElement.querySelector('[js-testimonials__forward]');

backButton.addEventListener('click', () => {
const current = parseInt(this.CAROUSEL.getAttribute('js-testimonials-iteration'), 10);
const amount = Math.ceil(this.IS_LARGE_SCREEN ? this.ITEMS.length /2 : this.ITEMS.length); // Desktop has half the slides
const next = current === 0 ? amount -1 : current -1;

this.CAROUSEL.setAttribute('js-testimonials-iteration', next);
this.updateCarousel(current)
})

forwardButton.addEventListener('click', () => {
const current = parseInt(this.CAROUSEL.getAttribute('js-testimonials-iteration'), 10);
const amount = Math.ceil(this.IS_LARGE_SCREEN ? this.ITEMS.length /2 : this.ITEMS.length); // Desktop has half amount of slides as it shows two slides at a time
const next = current === amount -1 ? 0 : current +1;

this.CAROUSEL.setAttribute('js-testimonials-iteration', next);
this.updateCarousel(current)
})
}

updateCarousel(currentIndex) {
const nextInt = parseInt(this.CAROUSEL.getAttribute('js-testimonials-iteration'), 10);

if(!this.IS_LARGE_SCREEN) {
this.toggleVisible([nextInt]);
this.toggleHidden([currentIndex]);
} else {
const sibling = nextInt * 2;
const currentSibling = currentIndex * 2;

this.toggleVisible([nextInt *2, sibling +1]);
this.toggleHidden([currentIndex *2, currentSibling +1]);
}
}

toggleVisible(list) {
list.forEach((i) => {
if(this.ITEMS[i] !== undefined) {
this.ITEMS[i].classList.add('c-testimonial--is-visible');
this.ITEMS[i].classList.remove('c-testimonial--is-hidden');
}
})
}

toggleHidden(list) {
list.forEach((i) => {
if(this.ITEMS[i] !== undefined) {
this.ITEMS[i].classList.add('c-testimonial--is-hidden');
this.ITEMS[i].classList.remove('c-testimonial--is-visible');
}
})
}

windowResize() {
window.addEventListener('resize', (e) => {
if(this.isLargeScreen() !== this.IS_LARGE_SCREEN) {
this.IS_LARGE_SCREEN = this.isLargeScreen();
this.init(this.ITEMS)
}
});
}

// eslint-disable-next-line class-methods-use-this
isLargeScreen() {
const body = document.querySelector('body');
const width = window.innerWidth / parseFloat(getComputedStyle(body)['font-size']);

return width >= 78; // 78em is the breakpoint for large screen
}
}
34 changes: 20 additions & 14 deletions source/sass/component/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
.c-nav__item {
display: flex;
flex-direction: row;
align-items: center;
}

.c-nav__link {
display: flex;
flex-direction: row;
align-items: center;
}
}

Expand Down Expand Up @@ -174,7 +177,6 @@
}

.c-nav__link {
display: flex;
align-items: center;
padding-top: $base;
padding-bottom: $base;
Expand Down Expand Up @@ -252,7 +254,6 @@
}

.c-nav--horizontal {

align-items: flex-start;

.c-nav__item .c-nav__link:hover:after,
Expand All @@ -261,6 +262,16 @@
display: block;
}

/* Prevent outside viewport */
.c-nav__item:last-child ul.c-nav.c-nav--depth-1 {
right: 0;
/* Arrow adjust */
&:after {
left: auto;
right: calc(#{$base} * 2);
}
}

.c-nav__link {
font-weight: 500;
white-space: nowrap;
Expand All @@ -278,16 +289,15 @@
}
}

.c-nav__item {
display: block;
}

/* Dropdown Menu */
ul.c-nav.c-nav--depth-1 {
flex-direction: column;
flex-grow: 1;
flex-basis: 0;
position: absolute;
bottom: 0;
background: $color-white;
width: calc(#{$base} * 32);
width: auto;
min-width: calc(#{$base} * 15);
background-color: $color-white;
border-radius: $border-radius-sm;
Expand All @@ -310,14 +320,14 @@
}

.c-nav__link {
display: inline-block;
padding: calc(#{$base} * 1.5) calc(#{$base} * 2);
text-decoration: none;
background-color: $color-white;
position: relative;
z-index: $level-9;
white-space: normal;
color: $color-black;
white-space: nowrap;

&:after {
bottom: calc(#{$base} * 1.5);
Expand All @@ -326,6 +336,7 @@

.c-nav__item {
overflow: hidden;
width: 100%;
}

.c-nav__item + .c-nav__item {
Expand All @@ -349,13 +360,8 @@
}

.c-nav__item:hover ul.c-nav.c-nav--depth-1 {
display: block;
}

.c-nav.c-nav--depth-1.c-nav--calculated .c-nav__link {
display: block;
display: flex;
}

}


Expand Down
35 changes: 17 additions & 18 deletions source/sass/component/_slider.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,27 @@
overflow: hidden;
position: relative;
border-radius: $border-radius-md;
padding-top: 70%;

.c-slider__inner {
display: flex;
transition: all 0.7s ease-in-out;
height: 100%;

position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;

.c-segment {
min-width: 100%;
}
}
}
}

@include mq(map_get($breakpoints-map, "xs"), map_get($breakpoints-map, "sm")) {
.c-slider {
.c-slider__container {
min-height: 70vw;
}
}
}

@include mq(map_get($breakpoints-map, "md")) {

.c-slider {
Expand All @@ -75,6 +77,7 @@

.c-slider__container {
padding-top: Min(100%,80vh);
min-height: 0;
}

&.c-slider--16-9 {
Expand All @@ -101,16 +104,12 @@
}
}

// &__inner {
// position: absolute;
// top: 0;
// bottom: 0;
// right: 0;
// left: 0;
// }

&__container {
height: 0;
.c-slider__inner {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
}

.c-slider__item__image {
Expand Down Expand Up @@ -162,7 +161,7 @@
position: absolute;
bottom: - map-get($spacers, "5");

@include mq(map_get($breakpoints-map, "xs"), "sm") {
@include mq(map_get($breakpoints-map, "xs"), map_get($breakpoints-map, "sm")) {
bottom: - map-get($spacers, "6");
padding-bottom:7px;
}
Expand Down
2 changes: 1 addition & 1 deletion source/sass/component/_slider_item.scss
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
}

.c-slider__item__container {
padding: map-get($spacers, "2");
padding: map-get($spacers, "4") map-get($spacers, "2");
border-radius: $border-radius-lg;
max-width: calc(#{$base} * 100);
margin-left: auto;
Expand Down
Loading

0 comments on commit 438827a

Please sign in to comment.