forked from sparkdesignsystem/spark-design-system
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from RCopeland/stepper-carousel
Stepper carousel
- Loading branch information
Showing
15 changed files
with
1,119 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
.sprk-c-Carousel__frame { | ||
width: 100%; | ||
position: relative; | ||
font-size: 0; | ||
line-height: 0; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
} | ||
|
||
.sprk-c-Carousel__frame-item { | ||
position: relative; | ||
display: inline-block; | ||
font-family: 'Source Sans Pro', sans-serif; | ||
text-align: center; | ||
font-size: $sprk-font-size-body-two; | ||
line-height: $sprk-line-height-body-two; | ||
color: $sprk-white; | ||
width: 100%; | ||
} | ||
|
||
.sprk-c-Carousel__slides { | ||
display: inline-block; | ||
} | ||
|
||
.sprk-c-Carousel__controls { | ||
justify-content: space-between; | ||
display: flex; | ||
width: 76px; | ||
margin: 0 auto; | ||
|
||
@media (min-width: 80rem) { | ||
display: none; | ||
} | ||
} | ||
|
||
.sprk-c-Carousel__prev, | ||
.sprk-c-Carousel__next { | ||
display: block; | ||
cursor: pointer; | ||
} | ||
|
||
.sprk-c-Carousel__next { | ||
right: 0; | ||
} | ||
|
||
.sprk-c-Carousel__prev { | ||
left: 0; | ||
} | ||
|
||
.sprk-c-Carousel__dots { | ||
display: flex; | ||
justify-content: center; | ||
margin: 1rem auto; | ||
|
||
@media (min-width: 80rem) { | ||
display: none; | ||
} | ||
} | ||
|
||
.sprk-c-Carousel__dot { | ||
border: 2px solid $sprk-white; | ||
border-radius: 50%; | ||
display: block; | ||
height: 10px; | ||
width: 10px; | ||
margin-right: 20px; | ||
} | ||
|
||
.sprk-c-Carousel__dot:last-child { | ||
margin-right: 0; | ||
} | ||
|
||
.sprk-c-Carousel__dot--active { | ||
background-color: $sprk-white; | ||
box-shadow: 0 0 0 8px $sprk-green; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { lory } from 'lory.js'; | ||
|
||
const initDots = (dotContainer, count) => { | ||
const dotListItem = document.createElement('li'); | ||
dotListItem.classList.add('sprk-c-Carousel__dot'); | ||
for (let i = 0; i < count; i += 1) { | ||
dotContainer.appendChild(dotListItem.cloneNode()); | ||
} | ||
dotContainer.childNodes[0].classList.add('sprk-c-Carousel__dot--active'); | ||
}; | ||
|
||
// init carousel | ||
const carousel = item => { | ||
let carouselInstance; | ||
const slideCount = item.querySelectorAll('li').length; | ||
const dotContainer = item.querySelector('[data-sprk-carousel-dots]'); | ||
// before init event | ||
item.addEventListener('before.lory.init', () => { | ||
if (dotContainer) { | ||
initDots(dotContainer, slideCount); | ||
} | ||
}); | ||
// after init event | ||
item.addEventListener('after.lory.init', () => { | ||
if (dotContainer) { | ||
const dots = dotContainer.querySelectorAll('li'); | ||
dots.forEach((dot, index) => { | ||
dot.addEventListener('click', event => { | ||
event.preventDefault(); | ||
carouselInstance.slideTo(index); | ||
}); | ||
}); | ||
} | ||
}); | ||
// after slide event | ||
item.addEventListener('after.lory.slide', event => { | ||
if (dotContainer) { | ||
const dots = dotContainer.querySelectorAll('li'); | ||
dots.forEach(dot => { | ||
dot.classList.remove('sprk-c-Carousel__dot--active'); | ||
}); | ||
dots[event.detail.currentSlide - 1].classList.add( | ||
'sprk-c-Carousel__dot--active', | ||
); | ||
item.dispatchEvent( | ||
new CustomEvent('sprk.carousel.slide', { | ||
detail: { | ||
index: [event.detail.currentSlide - 1], | ||
}, | ||
}), | ||
); | ||
} | ||
}); | ||
|
||
carouselInstance = lory(item, { | ||
classNameFrame: 'sprk-c-Carousel__frame', | ||
classNameSlideContainer: 'sprk-c-Carousel__slides', | ||
classNamePrevCtrl: 'sprk-c-Carousel__prev', | ||
classNameNextCtrl: 'sprk-c-Carousel__next', | ||
infinite: 1, | ||
enableMouseEvents: true, | ||
}); | ||
return carouselInstance; | ||
}; | ||
|
||
export { carousel, initDots }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.