Skip to content

Commit

Permalink
Merge pull request #408 from ismail9k/pr-388
Browse files Browse the repository at this point in the history
Feat: Support Ability to Breakpoints Relative to The Carousel Width
  • Loading branch information
ismail9k authored Nov 1, 2024
2 parents d6064f7 + 4ec5eb7 commit 3a01880
Show file tree
Hide file tree
Showing 22 changed files with 14,247 additions and 1,905 deletions.
34 changes: 16 additions & 18 deletions docs/config.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# Config


## Available Props

| Prop | Default | Description |
| ---------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| `itemsToShow` | 1 | count of items to showed per view (can be a fraction). |
| `itemsToScroll` | 1 | number of slides to be scrolled |
| ~~`currentSlide`~~ | ~~0~~ | ~~index number of the initial slide.~~ <Badge text="Deprecated 0.1.20" type="danger"/> |
| `wrapAround` | false | enable infinite scrolling mode. |
| `snapAlign` | 'center' | controls the carousel position alignment, can be 'start', 'end', 'center-[odd\|even]' |
| `transition` | 300 | sliding transition time in ms. |
| `autoplay` | 0 | Auto play time in ms. |
| ~~`settings`~~ | ~~{ }~~ | ~~an object to pass all settings.~~ <Badge text="Deprecated 0.3.0" type="danger"/> |
| `breakpoints` | null | an object to pass all the breakpoints settings. |
| `modelValue` | 0 | index number of the initial slide. <Badge text="0.1.20"/> |
| `mouseDrag` | true | toggle mouse dragging <Badge text="0.1.23"/> |
| `touchDrag` | true | toggle pointer touch dragging <Badge text="0.1.23"/> |
| `pauseAutoplayOnHover` | false | toggle if auto play should pause on mouse hover <Badge text="0.1.25"/> |
| `dir` | ltr | controls the carousel direction. Available values 'ltr', 'rtl' <Badge text="0.1.38"/> |
| `i18n` | [`{ ariaNextSlide: ...}`](#i18n) | Used to translate and/or change aria labels and additional texts used in the carousel. <Badge text="0.3.1"/> |
| Prop | Default | Description |
| ---------------------- | -------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `itemsToShow` | 1 | count of items to showed per view (can be a fraction). |
| `itemsToScroll` | 1 | number of slides to be scrolled |
| `wrapAround` | false | enable infinite scrolling mode. |
| `snapAlign` | 'center' | controls the carousel position alignment, can be 'start', 'end', 'center-[odd\|even]' |
| `transition` | 300 | sliding transition time in ms. |
| `autoplay` | 0 | Auto play time in ms. |
| `breakpointMode` | 'viewport' | determines how the carousel breakpoints are calculated. acceptable values: 'viewport', 'carousel' <Badge text="0.5.0"/> |
| `breakpoints` | null | an object to pass all the breakpoints settings. |
| `modelValue` | 0 | index number of the initial slide. <Badge text="0.1.20"/> |
| `mouseDrag` | true | toggle mouse dragging <Badge text="0.1.23"/> |
| `touchDrag` | true | toggle pointer touch dragging <Badge text="0.1.23"/> |
| `pauseAutoplayOnHover` | false | toggle if auto play should pause on mouse hover <Badge text="0.1.25"/> |
| `dir` | ltr | controls the carousel direction. Available values 'ltr', 'rtl' <Badge text="0.1.38"/> |
| `i18n` | [`{ ariaNextSlide: ...}`](#i18n) | Used to translate and/or change aria labels and additional texts used in the carousel. <Badge text="0.3.1"/> |

## Slots

Expand Down
94 changes: 43 additions & 51 deletions docs/examples/ExampleActiveClasses.vue
Original file line number Diff line number Diff line change
@@ -1,73 +1,65 @@
<script setup>
import { Carousel, Pagination, Navigation, Slide } from '../../dist/carousel.es'
import '../../dist/carousel.css'
const config = {
itemsToShow: 3.95,
wrapAround: true,
transition: 500,
}
</script>

<template>
<Carousel id="activeClasses" :itemsToShow="3.95" :wrapAround="true" :transition="500">
<Carousel v-bind="config">
<Slide v-for="slide in 10" :key="slide">
<div class="carousel__item">{{ slide }}</div>
</Slide>

<template #addons>
<Navigation />
<Pagination />
</template>
</Carousel>
</template>

<script>
import { defineComponent } from 'vue'
import { Carousel, Pagination, Navigation, Slide } from '../../dist/carousel.es'

import '../../dist/carousel.css'
export default defineComponent({
name: 'Basic',
components: {
Carousel,
Slide,
Pagination,
Navigation,
},
})
</script>

<style lang="stylus">
#activeClasses {
.carousel__slide {
padding: 5;
}
<style lang="stylus" scoped>
.carousel__slide {
padding: 5;
}
.carousel__viewport {
perspective: 2000px;
}
.carousel__viewport {
perspective: 2000px;
}
.carousel__track {
transform-style: preserve-3d;
}
.carousel__track {
transform-style: preserve-3d;
}
.carousel__slide--sliding {
transition: 0.5s;
}
.carousel__slide--sliding {
transition: 0.5s;
}
.carousel__slide {
opacity: 0.9;
transform: rotateY(-20deg) scale(0.9);
}
.carousel__slide {
opacity: 0.9;
transform: rotateY(-20deg) scale(0.9);
}
.carousel__slide--active ~ .carousel__slide {
transform: rotateY(20deg) scale(0.9);
}
.carousel__slide--active ~ .carousel__slide {
transform: rotateY(20deg) scale(0.9);
}
.carousel__slide--prev {
opacity: 1;
transform: rotateY(-10deg) scale(0.95);
}
.carousel__slide--prev {
opacity: 1;
transform: rotateY(-10deg) scale(0.95);
}
.carousel__slide.carousel__slide--next {
opacity: 1;
transform: rotateY(10deg) scale(0.95);
}
.carousel__slide.carousel__slide--next {
opacity: 1;
transform: rotateY(10deg) scale(0.95);
}
.carousel__slide--active {
opacity: 1;
transform: rotateY(0) scale(1);
}
.carousel__slide--active {
opacity: 1;
transform: rotateY(0) scale(1);
}
</style>
30 changes: 13 additions & 17 deletions docs/examples/ExampleAutoplay.vue
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
<script setup>
import '../../dist/carousel.css'
import { Carousel, Slide, Navigation } from '../../dist/carousel.es'
const config = {
autoplay: 2000,
wrapAround: true,
pauseAutoplayOnHover: true,
}
</script>

<template>
<Carousel :autoplay="2000" :wrap-around="true" pause-autoplay-on-hover>
<Carousel v-bind="config">
<Slide v-for="slide in 10" :key="slide">
<div class="carousel__item">{{ slide }}</div>
</Slide>

<template #addons>
<Pagination />
<Navigation />
</template>
</Carousel>
</template>

<script>
import { defineComponent } from 'vue'
import { Carousel, Pagination, Slide } from '../../dist/carousel.es'
import '../../dist/carousel.css'
export default defineComponent({
name: 'Autoplay',
components: {
Carousel,
Slide,
Pagination,
},
})
</script>
22 changes: 5 additions & 17 deletions docs/examples/ExampleBasic.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<script setup>
import { Carousel, Pagination, Navigation, Slide } from '../../dist/carousel.es'
import '../../dist/carousel.css'
</script>

<template>
<Carousel>
<Slide v-for="slide in 10" :key="slide">
Expand All @@ -10,20 +15,3 @@
</template>
</Carousel>
</template>

<script>
import { defineComponent } from 'vue'
import { Carousel, Pagination, Navigation, Slide } from '../../dist/carousel.es'
import '../../dist/carousel.css'
export default defineComponent({
name: 'Basic',
components: {
Carousel,
Slide,
Pagination,
Navigation,
},
})
</script>
86 changes: 46 additions & 40 deletions docs/examples/ExampleBreakpoints.vue
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
<template>
<Carousel v-bind="settings" :breakpoints="breakpoints">
<Slide v-for="slide in 10" :key="slide">
<div class="carousel__item">{{ slide }}</div>
</Slide>

<template #addons>
<Navigation />
</template>
</Carousel>
</template>

<script>
import { defineComponent } from 'vue'
<script setup>
import { Carousel, Navigation, Slide } from '../../dist/carousel.es'
import '../../dist/carousel.css'
export default defineComponent({
name: 'Breakpoints',
components: {
Carousel,
Slide,
Navigation,
},
data: () => ({
// carousel settings
settings: {
itemsToShow: 1,
// Carousel configuration
const config = {
itemsToShow: 1,
snapAlign: 'center',
// 'breakpointMode' determines how the carousel breakpoints are calculated
// Acceptable values: 'viewport' (default) | 'carousel'
// 'viewport' - breakpoints are based on the viewport width
// 'carousel' - breakpoints are based on the carousel width
breakpointMode: 'carousel',
// Breakpoints are mobile-first
// Any settings not specified will fall back to the carousel's default settings
breakpoints: {
// 300px and up
300: {
itemsToShow: 2,
snapAlign: 'center',
},
// breakpoints are mobile first
// any settings not specified will fallback to the carousel settings
breakpoints: {
// 700px and up
700: {
itemsToShow: 3.5,
snapAlign: 'center',
},
// 1024 and up
1024: {
itemsToShow: 5,
snapAlign: 'start',
},
// 400px and up
400: {
itemsToShow: 3,
snapAlign: 'start',
},
}),
})
// 500px and up
500: {
itemsToShow: 4,
snapAlign: 'start',
},
},
}
</script>

<template>
<!-- Resizable container for testing 'carousel' breakpointMode -->
<!-- Drag the right edge to adjust the width and see the breakpoints change -->
<div style="resize: horizontal; border: 2px dashed gray; overflow: auto">
<Carousel v-bind="config">
<Slide v-for="slide in 10" :key="slide">
<div class="carousel__item">{{ slide }}</div>
</Slide>
<template #addons>
<Navigation />
</template>
</Carousel>
</div>
</template>


41 changes: 0 additions & 41 deletions docs/examples/ExampleCustomLabels.vue

This file was deleted.

Loading

0 comments on commit 3a01880

Please sign in to comment.