Skip to content

Commit e686710

Browse files
authored
Merge pull request #51 from vadimkorr/feature/#47-add-disabling-swipe-by-prop
feature/#47 Add disabling swipe by prop
2 parents da7d8ac + 35495d6 commit e686710

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Import component
4747
| `autoplayProgressVisible` | `boolean` | `false` | Show autoplay duration progress indicator |
4848
| `dots` | `boolean` | `true` | Current page indicator dots |
4949
| `timingFunction` | `string` | `'ease-in-out'` | CSS animation timing function |
50+
| `swiping` | `boolean` | `true` | Enable swiping |
5051

5152
## Events
5253

src/components/Carousel/Carousel.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@
9090
*/
9191
export let dots = true
9292
93+
/**
94+
* Enable swiping
95+
*/
96+
export let swiping = true
97+
9398
export async function goTo(pageIndex, options) {
9499
const animated = get(options, 'animated', true)
95100
if (typeof pageIndex !== 'number') {
@@ -281,15 +286,19 @@
281286
282287
// gestures
283288
function handleSwipeStart() {
289+
if (!swiping) return
284290
_duration = 0
285291
}
286292
async function handleThreshold(event) {
293+
if (!swiping) return
287294
await directionFnDescription[event.detail.direction]()
288295
}
289296
function handleSwipeMove(event) {
297+
if (!swiping) return
290298
offset += event.detail.dx
291299
}
292300
function handleSwipeEnd() {
301+
if (!swiping) return
293302
showPage(currentPageIndex)
294303
}
295304
function handleFocused(event) {

src/components/Carousel/stories/CarouselView.svelte

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
*/
5757
export let dots = true
5858
59+
/**
60+
* Enable swiping
61+
*/
62+
export let swiping = true
63+
5964
const colors = [
6065
{ color: '#e5f9f0', text: '0' },
6166
{ color: '#ccf3e2', text: '1' },
@@ -89,6 +94,7 @@
8994
{pauseOnFocus}
9095
{autoplayProgressVisible}
9196
{dots}
97+
{swiping}
9298
on:pageChange={
9399
event => console.log(`Current page index: ${event.detail}`)
94100
}
@@ -115,6 +121,7 @@
115121
{pauseOnFocus}
116122
{autoplayProgressVisible}
117123
{dots}
124+
{swiping}
118125
>
119126
{#each colors2 as { color, text } (color)}
120127
<div
@@ -145,4 +152,4 @@
145152
font-style: italic;
146153
font-size: 18px;
147154
}
148-
</style>
155+
</style>

src/components/Carousel/stories/CarouselViewCustomArrows.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
*/
5757
export let dots = true
5858
59+
/**
60+
* Enable swiping
61+
*/
62+
export let swiping = true
63+
5964
const colors = [
6065
'#e5f9f0',
6166
'#ccf3e2',
@@ -83,6 +88,7 @@
8388
{pauseOnFocus}
8489
{autoplayProgressVisible}
8590
{dots}
91+
{swiping}
8692
let:showPrevPage
8793
let:showNextPage
8894
>
@@ -138,4 +144,4 @@
138144
cursor: pointer;
139145
-webkit-tap-highlight-color: transparent;
140146
}
141-
</style>
147+
</style>

src/components/Carousel/stories/CarouselViewCustomDots.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
*/
5757
export let dots = true
5858
59+
/**
60+
* Enable swiping
61+
*/
62+
export let swiping = true
63+
5964
function onPageChange(event, showPage) {
6065
showPage(Number(event.target.value))
6166
}
@@ -87,6 +92,7 @@
8792
{pauseOnFocus}
8893
{autoplayProgressVisible}
8994
{dots}
95+
{swiping}
9096
let:currentPageIndex
9197
let:pagesCount
9298
let:showPage
@@ -148,4 +154,4 @@
148154
width: 100px;
149155
border-radius: 5px;
150156
}
151-
</style>
157+
</style>

src/docs/Carousel.svx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ Import component
273273
| `autoplayProgressVisible` | `boolean` | `false` | Show autoplay duration progress indicator |
274274
| `dots` | `boolean` | `true` | Current page indicator dots |
275275
| `timingFunction` | `string` | `'ease-in-out'` | CSS animation timing function |
276+
| `swiping` | `boolean` | `true` | Enable swiping |
276277

277278
<Divider />
278279

0 commit comments

Comments
 (0)