Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "none",
"semi": false,
"singleQuote": true,
"arrowParens": "avoid"
}
2 changes: 1 addition & 1 deletion dist/vue-snap.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
padding: 0;
}

.vs-carousel__wrapper::-webkit-scrollbar {
.vs-carousel__wrapper.vs-carousel__wrapper--hide-scrollbar::-webkit-scrollbar {
display: none;
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
},
"homepage": "https://github.com/bartdominiak/vue-snap#README",
"peerDependencies": {
"vue": "^2.6.12"
"vue": "^2.6.14"
},
"dependencies": {
"core-js": "^3.8.0",
Expand Down Expand Up @@ -72,7 +72,7 @@
"vue-lazy": "^0.3.0",
"vue-loader": "^15.9.5",
"vue-style-loader": "^4.1.2",
"vue-template-compiler": "^2.6.12",
"vue-template-compiler": "^2.6.14",
"vuepress": "^1.7.1"
},
"husky": {
Expand Down
59 changes: 59 additions & 0 deletions src/components/Carousel/Carousel.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,35 @@ export const MultipleCustomArrows = (_, { argTypes }) => ({
`
})

export const MultipleCustomArrowsIcons = (_, { argTypes }) => ({
props: Object.keys(argTypes),
data: () => ({ carouselMock }),
components: { Carousel, Slide },
methods: actions('pageEvent', 'boundLeftEvent', 'boundRightEvent', 'mountedEvent'),
template: `
<carousel
class="story-carousel story-carousel--colors story-carousel--multiple"
:hide-arrows="hideArrows"
:hide-arrows-on-bound="hideArrowsOnBound"
@page="pageEvent"
@bound-left="boundLeftEvent"
@bound-right="boundRightEvent"
@mounted="mountedEvent"
>
<slide
class="story-carousel__slide"
v-for="{ id, content } in carouselMock"
:key="id"
>
{{ content }}
</slide>

<template #arrowLeftIcon>L</template>
<template #arrowRightIcon>R</template>
</carousel>
`
})

export const NonRegular = (_, { argTypes }) => ({
props: Object.keys(argTypes),
data: () => ({ carouselMock }),
Expand Down Expand Up @@ -132,6 +161,36 @@ export const NonRegular = (_, { argTypes }) => ({
`
})

export const WithScrollbar = (_, { argTypes }) => ({
props: Object.keys(argTypes),
data: () => ({ carouselMock }),
components: { Carousel, Slide },
methods: actions('pageEvent', 'boundLeftEvent', 'boundRightEvent', 'mountedEvent'),
template: `
<carousel
class="story-carousel story-carousel--colors story-carousel--multiple"
:hide-arrows="hideArrows"
:hide-arrows-on-bound="hideArrowsOnBound"
:hide-scrollbar="hideScrollbar"
@page="pageEvent"
@bound-left="boundLeftEvent"
@bound-right="boundRightEvent"
@mounted="mountedEvent"
>
<slide
class="story-carousel__slide"
v-for="{ id, content } in carouselMock"
:key="id"
>
{{ content }}
</slide>
</carousel>
`
})
WithScrollbar.args = {
hideScrollbar: false
}

export const Images = (_, { argTypes }) => ({
props: Object.keys(argTypes),
data: () => ({ carouselMock }),
Expand Down
60 changes: 36 additions & 24 deletions src/components/Carousel/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
:is="tag"
ref="vsWrapper"
class="vs-carousel__wrapper"
:class="{
'vs-carousel__wrapper--hide-scrollbar': hideScrollbar
}"
>
<!-- @slot Slot for Slides -->
<slot />
Expand All @@ -13,36 +16,34 @@
<slot
v-if="!hideArrows"
name="arrows"
:change-slide="changeSlide"
:bound-left="boundLeft"
:bound-right="boundRight"
v-bind="{
hideArrowsOnBound,
changeSlide,
boundLeft,
boundRight,
i18n
}"
>
<button
v-show="hideArrowsOnBound ? !boundLeft : true"
type="button"
:aria-label="i18n.slideLeft"
:disabled="boundLeft"
class="
vs-carousel__arrows
vs-carousel__arrows--left
"
class="vs-carousel__arrows vs-carousel__arrows--left"
@click="changeSlide(-1)"
>
<slot name="arrowLeftIcon"> ← </slot>
</button>

<button
v-show="hideArrowsOnBound ? !boundRight : true"
type="button"
:aria-label="i18n.slideRight"
:disabled="boundRight"
class="
vs-carousel__arrows
vs-carousel__arrows--right
"
class="vs-carousel__arrows vs-carousel__arrows--right"
@click="changeSlide(1)"
>
<slot name="arrowRightIcon"> → </slot>
</button>
</slot>
</div>
Expand Down Expand Up @@ -88,6 +89,13 @@ export default {
const translations = ['slideLeft', 'slideRight']
return translations.every(key => key in config)
}
},
/**
* Scrollbar
*/
hideScrollbar: {
type: Boolean,
default: true
}
},
data: () => ({
Expand Down Expand Up @@ -140,7 +148,7 @@ export default {
* @type {Event}
*/
this.$emit('bound-right', true)
},
}
},
mounted() {
this.calcOnInit()
Expand Down Expand Up @@ -224,7 +232,7 @@ export default {
this.wrapperVisibleWidth = this.$refs.vsWrapper.offsetWidth
},
calcSlidesWidth() {
const childNodes = [ ...this.$refs.vsWrapper.children ]
const childNodes = [...this.$refs.vsWrapper.children]

this.slidesWidth = childNodes.map(node => ({
offsetLeft: node.offsetLeft,
Expand All @@ -233,11 +241,13 @@ export default {
},
getCurrentPage() {
// Last element if there is nothing left to scroll
if (approximatelyEqual(
this.currentPos + this.wrapperVisibleWidth,
this.wrapperScrollWidth,
5
)) {
if (
approximatelyEqual(
this.currentPos + this.wrapperVisibleWidth,
this.wrapperScrollWidth,
5
)
) {
return this.slidesWidth.length - 1
}

Expand All @@ -264,10 +274,12 @@ export default {
this.calcOnInit()
})

this.observer.observe(
this.$refs.vsWrapper,
{ attributes: true, childList: true, characterData: true, subtree: true }
)
this.observer.observe(this.$refs.vsWrapper, {
attributes: true,
childList: true,
characterData: true,
subtree: true
})
},
changeSlide(direction) {
this.goToSlide(this.currentPage + direction)
Expand Down
Loading