Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ismail9k/vue3-carousel into 172-i…
Browse files Browse the repository at this point in the history
…temstoshow-auto
  • Loading branch information
ismail9k committed Jan 6, 2025
2 parents 016928f + 8d01e32 commit c04f51d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 22 deletions.
42 changes: 22 additions & 20 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

## Available Props

| Prop | Default | Description |
| ---------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `enabled` | true | Controlled weather the carousel is enabled or disabled. <Badge text="0.8.0"/> |
| `itemsToShow` | 1 | Count of items to showed per view (can be a fraction). Must be between 1 and the total number of slides. If set to a value less than 1, it defaults to 1. If set to a value greater than the total number of slides, it defaults to the total number of slides. |
| `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. |
| `mouseDrag` | true | Toggle mouse dragging |
| `touchDrag` | true | Toggle pointer touch dragging |
| `pauseAutoplayOnHover` | false | Toggle if auto play should pause on mouse hover |
| `dir` | 'ltr' | Controls the carousel direction. Available values: 'ltr', 'rtl', 'ttb', 'btt' or use verbose 'left-to-right', 'right-to-left', 'top-to-bottom', 'bottom-to-top' <Badge text="0.7.0"/> |
| `i18n` | [`{ ariaNextSlide: ...}`](#i18n) | Used to translate and/or change aria labels and additional texts used in the carousel. <Badge text="0.3.1"/> |
| `gap` | 0 | Used to add gap between the slides. <Badge text="0.6.0"/> |
| `height` | 'auto' | Carousel track height. <Badge text="0.7.0"/> |
| `ignoreAnimations` | false | List of animation names to ignore for size calculations. Can be a boolean, string, or array of strings. <Badge text="0.10.0"/> |
| Prop | Default | Description |
| -------------------------- | -------------------------------- |-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `enabled` | true | Controlled weather the carousel is enabled or disabled. <Badge text="0.8.0"/> |
| `itemsToShow` | 1 | Count of items to showed per view (can be a fraction). Must be between 1 and the total number of slides. If set to a value less than 1, it defaults to 1. If set to a value greater than the total number of slides, it defaults to the total number of slides. |
| `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. |
| `mouseDrag` | true | Toggle mouse dragging |
| `touchDrag` | true | Toggle pointer touch dragging |
| `pauseAutoplayOnHover` | false | Toggle if auto play should pause on mouse hover |
| `dir` | 'ltr' | Controls the carousel direction. Available values: 'ltr', 'rtl', 'ttb', 'btt' or use verbose 'left-to-right', 'right-to-left', 'top-to-bottom', 'bottom-to-top' <Badge text="0.7.0"/> |
| `i18n` | [`{ ariaNextSlide: ...}`](#i18n) | Used to translate and/or change aria labels and additional texts used in the carousel. <Badge text="0.3.1"/> |
| `gap` | 0 | Used to add gap between the slides. <Badge text="0.6.0"/> |
| `height` | 'auto' | Carousel track height. <Badge text="0.7.0"/> |
| `ignoreAnimations` | false | List of animation names to ignore for size calculations. Can be a boolean, string, or array of strings. <Badge text="0.10.0"/> |
| `preventExcessiveDragging` | false | Prevents unwanted dragging behavior when the carousel reaches its first or last slide. <Badge text="0.13.0" /> |



## Slots
Expand Down
23 changes: 21 additions & 2 deletions src/components/Carousel/Carousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,8 +795,27 @@ export const Carousel = defineComponent({
// Include user drag interaction offset
const dragOffset = isVertical.value ? dragged.y : dragged.x

const totalOffset = scrolledOffset.value + dragOffset

let totalOffset = scrolledOffset.value + dragOffset

if (!config.wrapAround && config.preventExcessiveDragging) {
let maxSlidingValue = 0
if (isAuto.value) {
maxSlidingValue = slidesRect.value.reduce(
(acc, slide) => acc + slide[dimension.value],
0
)
} else {
maxSlidingValue =
(slidesCount.value - Number(config.itemsToShow)) * effectiveSlideSize.value
}
const min = isReversed.value ? 0 : -1 * maxSlidingValue
const max = isReversed.value ? maxSlidingValue : 0
totalOffset = getNumberInRange({
val: totalOffset,
min,
max,
})
}
return `translate${translateAxis}(${totalOffset}px)`
})

Expand Down
13 changes: 13 additions & 0 deletions src/components/Carousel/carouselProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,17 @@ export const carouselProps = {
return SLIDE_EFFECTS.includes(value)
},
},
preventExcessiveDragging: {
default: false,
type: Boolean,
validator(value: boolean, props: { wrapAround?: boolean }) {
if (value && props.wrapAround)
console.warn( /* eslint-disable-line no-console */
'[vue3-carousel warn]: preventExcessiveDragging cannot be used with wrapAround. ' +
'The preventExcessiveDragging setting will be ignored.'
);

return true;
}
}
}
1 change: 1 addition & 0 deletions src/shared/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ export const DEFAULT_CONFIG: CarouselConfig = {
i18n: I18N_DEFAULT_CONFIG,
ignoreAnimations: false,
slideEffect: SLIDE_EFFECTS[0],
preventExcessiveDragging: false
}
1 change: 1 addition & 0 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface CarouselConfig {
i18n: { [key in I18nKeys]?: string }
ignoreAnimations: boolean | string[] | string
slideEffect: SlideEffect
preventExcessiveDragging: boolean
}

export type VueClass = string | Record<string, boolean> | VueClass[]

0 comments on commit c04f51d

Please sign in to comment.