UNPKG

14.4 kBTypeScriptView Raw
1import { Component, JSX } from 'solid-js';
2import { SwiperOptions, Swiper as SwiperClass } from '../types';
3
4interface SwiperProps extends SwiperOptions {
5 /**
6 * Swiper container tag
7 *
8 * @default 'div'
9 */
10 tag?: string;
11
12 /**
13 * Swiper wrapper tag
14 *
15 * @default 'div'
16 */
17 wrapperTag?: string;
18
19 /**
20 * Get Swiper instance
21 */
22 onSwiper?: (swiper: SwiperClass) => void;
23
24 /**
25 * Event will be fired in when autoplay started
26 */
27 onAutoplayStart?: (swiper: SwiperClass) => void;
28 /**
29 * Event will be fired when autoplay stopped
30 */
31 onAutoplayStop?: (swiper: SwiperClass) => void;
32 /**
33 * Event will be fired on autoplay pause (on mouse/pointer enter), when `pauseOnMouseEnter` enabled
34 */
35 onAutoplayPause?: (swiper: SwiperClass) => void;
36 /**
37 * Event will be fired on autoplay resume (on mouse/pointer leave), when `pauseOnMouseEnter` enabled
38 */
39 onAutoplayResume?: (swiper: SwiperClass) => void;
40 /**
41 * Event will be fired when slide changed with autoplay
42 */
43 onAutoplay?: (swiper: SwiperClass) => void;/**
44 * Event will be fired on window hash change
45 */
46 onHashChange?: (swiper: SwiperClass) => void;
47 /**
48 * Event will be fired when swiper updates the hash
49 */
50 onHashSet?: (swiper: SwiperClass) => void;/**
51 * Event will be fired on key press
52 */
53 onKeyPress?: (swiper: SwiperClass, keyCode: string) => void;/**
54 * Event will be fired in the beginning of lazy loading of image
55 */
56 onLazyImageLoad?: (swiper: SwiperClass, slideEl: HTMLElement, imageEl: HTMLElement) => void;
57 /**
58 * Event will be fired when lazy loading image will be loaded
59 */
60 onLazyImageReady?: (swiper: SwiperClass, slideEl: HTMLElement, imageEl: HTMLElement) => void;/**
61 * Event will be fired on mousewheel scroll
62 */
63 onScroll?: (swiper: SwiperClass, event: WheelEvent) => void;/**
64 * Event will be fired on navigation hide
65 */
66 onNavigationHide?: (swiper: SwiperClass) => void;
67 /**
68 * Event will be fired on navigation show
69 */
70 onNavigationShow?: (swiper: SwiperClass) => void;
71 /**
72 * Event will be fired on navigation prev button click
73 */
74 onNavigationPrev?: (swiper: SwiperClass) => void;
75 /**
76 * Event will be fired on navigation next button click
77 */
78 onNavigationNext?: (swiper: SwiperClass) => void;/**
79 * Event will be fired after pagination rendered
80 */
81 onPaginationRender?: (swiper: SwiperClass, paginationEl: HTMLElement) => void;
82
83 /**
84 * Event will be fired when pagination updated
85 */
86 onPaginationUpdate?: (swiper: SwiperClass, paginationEl: HTMLElement) => void;
87
88 /**
89 * Event will be fired on pagination hide
90 */
91 onPaginationHide?: (swiper: SwiperClass) => void;
92
93 /**
94 * Event will be fired on pagination show
95 */
96 onPaginationShow?: (swiper: SwiperClass) => void;/**
97 * Event will be fired on draggable scrollbar drag start
98 */
99 onScrollbarDragStart?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
100
101 /**
102 * Event will be fired on draggable scrollbar drag move
103 */
104 onScrollbarDragMove?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
105
106 /**
107 * Event will be fired on draggable scrollbar drag end
108 */
109 onScrollbarDragEnd?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;/**
110 * Event will be fired on zoom change
111 */
112 onZoomChange?: (swiper: SwiperClass, scale: number, imageEl: HTMLElement, slideEl: HTMLElement) => void;
113
114 /**
115 * Fired right after Swiper initialization.
116 * @note Note that with `swiper.on('init')` syntax it will
117 * work only in case you set `init: false` parameter.
118 *
119 * @example
120 * ```js
121 * const swiper = new Swiper('.swiper', {
122 * init: false,
123 * // other parameters
124 * });
125 * swiper.on('init', function() {
126 * // do something
127 * });
128 * // init Swiper
129 * swiper.init();
130 * ```
131 *
132 * @example
133 * ```js
134 * // Otherwise use it as the parameter:
135 * const swiper = new Swiper('.swiper', {
136 * // other parameters
137 * on: {
138 * init: function () {
139 * // do something
140 * },
141 * }
142 * });
143 * ```
144 */
145 onInit?: (swiper: SwiperClass) => any;
146
147 /**
148 * Event will be fired right before Swiper destroyed
149 */
150 onBeforeDestroy?: (swiper: SwiperClass) => void;
151
152 /**
153 * Event will be fired when currently active slide is changed
154 */
155 onSlideChange?: (swiper: SwiperClass) => void;
156
157 /**
158 * Event will be fired in the beginning of animation to other slide (next or previous).
159 */
160 onSlideChangeTransitionStart?: (swiper: SwiperClass) => void;
161
162 /**
163 * Event will be fired after animation to other slide (next or previous).
164 */
165 onSlideChangeTransitionEnd?: (swiper: SwiperClass) => void;
166
167 /**
168 * Same as "slideChangeTransitionStart" but for "forward" direction only
169 */
170 onSlideNextTransitionStart?: (swiper: SwiperClass) => void;
171
172 /**
173 * Same as "slideChangeTransitionEnd" but for "forward" direction only
174 */
175 onSlideNextTransitionEnd?: (swiper: SwiperClass) => void;
176
177 /**
178 * Same as "slideChangeTransitionStart" but for "backward" direction only
179 */
180 onSlidePrevTransitionStart?: (swiper: SwiperClass) => void;
181
182 /**
183 * Same as "slideChangeTransitionEnd" but for "backward" direction only
184 */
185 onSlidePrevTransitionEnd?: (swiper: SwiperClass) => void;
186
187 /**
188 * Event will be fired in the beginning of transition.
189 */
190 onTransitionStart?: (swiper: SwiperClass) => void;
191
192 /**
193 * Event will be fired after transition.
194 */
195 onTransitionEnd?: (swiper: SwiperClass) => void;
196
197 /**
198 * Event will be fired when user touch Swiper. Receives `touchstart` event as an arguments.
199 */
200 onTouchStart?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
201
202 /**
203 * Event will be fired when user touch and move finger over Swiper. Receives `touchmove` event as an arguments.
204 */
205 onTouchMove?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
206
207 /**
208 * Event will be fired when user touch and move finger over Swiper in direction opposite to direction parameter. Receives `touchmove` event as an arguments.
209 */
210 onTouchMoveOpposite?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
211
212 /**
213 * Event will be fired when user touch and move finger over Swiper and move it. Receives `touchmove` event as an arguments.
214 */
215 onSliderMove?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
216
217 /**
218 * Event will be fired when user release Swiper. Receives `touchend` event as an arguments.
219 */
220 onTouchEnd?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
221
222 /**
223 * Event will be fired when user click/tap on Swiper. Receives `touchend` event as an arguments.
224 */
225 onClick?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
226
227 /**
228 * Event will be fired when user click/tap on Swiper. Receives `touchend` event as an arguments.
229 */
230 onTap?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
231
232 /**
233 * Event will be fired when user double tap on Swiper's container. Receives `touchend` event as an arguments
234 */
235 onDoubleTap?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
236
237 /**
238 * Event will be fired right after all inner images are loaded. updateOnImagesReady should be also enabled
239 */
240 onImagesReady?: (swiper: SwiperClass) => void;
241
242 /**
243 * Event will be fired when Swiper progress is changed, as an arguments it receives progress that is always from 0 to 1
244 */
245 onProgress?: (swiper: SwiperClass, progress: number) => void;
246
247 /**
248 * Event will be fired when Swiper reach its beginning (initial position)
249 */
250 onReachBeginning?: (swiper: SwiperClass) => void;
251
252 /**
253 * Event will be fired when Swiper reach last slide
254 */
255 onReachEnd?: (swiper: SwiperClass) => void;
256
257 /**
258 * Event will be fired when Swiper goes to beginning or end position
259 */
260 onToEdge?: (swiper: SwiperClass) => void;
261
262 /**
263 * Event will be fired when Swiper goes from beginning or end position
264 */
265 onFromEdge?: (swiper: SwiperClass) => void;
266
267 /**
268 * Event will be fired when swiper's wrapper change its position. Receives current translate value as an arguments
269 */
270 onSetTranslate?: (swiper: SwiperClass, translate: number) => void;
271
272 /**
273 * Event will be fired everytime when swiper starts animation. Receives current transition duration (in ms) as an arguments
274 */
275 onSetTransition?: (swiper: SwiperClass, transition: number) => void;
276
277 /**
278 * Event will be fired on window resize right before swiper's onresize manipulation
279 */
280 onResize?: (swiper: SwiperClass) => void;
281
282 /**
283 * Event will be fired if observer is enabled and it detects DOM mutations
284 */
285 onObserverUpdate?: (swiper: SwiperClass) => void;
286
287 /**
288 * Event will be fired right before "loop fix"
289 */
290 onBeforeLoopFix?: (swiper: SwiperClass) => void;
291
292 /**
293 * Event will be fired after "loop fix"
294 */
295 onLoopFix?: (swiper: SwiperClass) => void;
296
297 /**
298 * Event will be fired on breakpoint change
299 */
300 onBreakpoint?: (swiper: SwiperClass, breakpointParams: SwiperOptions) => void;
301
302 /**
303 * !INTERNAL: Event will fired right before breakpoint change
304 */
305 _beforeBreakpoint?: (swiper: SwiperClass, breakpointParams: SwiperOptions) => void;
306
307 /**
308 * !INTERNAL: Event will fired after setting CSS classes on swiper container element
309 */
310 _containerClasses?: (swiper: SwiperClass, classNames: string) => void;
311
312 /**
313 * !INTERNAL: Event will fired after setting CSS classes on swiper slide element
314 */
315 _slideClass?: (swiper: SwiperClass, slideEl: HTMLElement, classNames: string) => void;
316
317 /**
318 * !INTERNAL: Event will fired after setting CSS classes on all swiper slides
319 */
320 _slideClasses?: (
321 swiper: SwiperClass,
322 slides: { slideEl: HTMLElement; classNames: string; index: number }[],
323 ) => void;
324
325 /**
326 * !INTERNAL: Event will fired as soon as swiper instance available (before init)
327 */
328 _swiper?: (swiper: SwiperClass) => void;
329
330 /**
331 * !INTERNAL: Event will be fired on free mode touch end (release) and there will no be momentum
332 */
333 _freeModeNoMomentumRelease?: (swiper: SwiperClass) => void;
334
335 /**
336 * Event will fired on active index change
337 */
338 onActiveIndexChange?: (swiper: SwiperClass) => void;
339 /**
340 * Event will fired on snap index change
341 */
342 onSnapIndexChange?: (swiper: SwiperClass) => void;
343 /**
344 * Event will fired on real index change
345 */
346 onRealIndexChange?: (swiper: SwiperClass) => void;
347 /**
348 * Event will fired right after initialization
349 */
350 onAfterInit?: (swiper: SwiperClass) => void;
351 /**
352 * Event will fired right before initialization
353 */
354 onBeforeInit?: (swiper: SwiperClass) => void;
355 /**
356 * Event will fired before resize handler
357 */
358 onBeforeResize?: (swiper: SwiperClass) => void;
359 /**
360 * Event will fired before slide change transition start
361 */
362 onBeforeSlideChangeStart?: (swiper: SwiperClass) => void;
363 /**
364 * Event will fired before transition start
365 */
366 onBeforeTransitionStart?: (swiper: SwiperClass, speed: number, internal: any) => void; // what is internal?
367 /**
368 * Event will fired on direction change
369 */
370 onChangeDirection?: (swiper: SwiperClass) => void;
371 /**
372 * Event will be fired when user double click/tap on Swiper
373 */
374 onDoubleClick?: (swiper: SwiperClass, event: MouseEvent | TouchEvent | PointerEvent) => void;
375 /**
376 * Event will be fired on swiper destroy
377 */
378 onDestroy?: (swiper: SwiperClass) => void;
379 /**
380 * Event will be fired on momentum bounce
381 */
382 onMomentumBounce?: (swiper: SwiperClass) => void;
383 /**
384 * Event will be fired on orientation change (e.g. landscape -> portrait)
385 */
386 onOrientationchange?: (swiper: SwiperClass) => void;
387 /**
388 * Event will be fired in the beginning of animation of resetting slide to current one
389 */
390 onSlideResetTransitionStart?: (swiper: SwiperClass) => void;
391 /**
392 * Event will be fired in the end of animation of resetting slide to current one
393 */
394 onSlideResetTransitionEnd?: (swiper: SwiperClass) => void;
395 /**
396 * Event will be fired with first touch/drag move
397 */
398 onSliderFirstMove?: (swiper: SwiperClass, event: TouchEvent) => void;
399 /**
400 * Event will be fired when number of slides has changed
401 */
402 onSlidesLengthChange?: (swiper: SwiperClass) => void;
403 /**
404 * Event will be fired when slides grid has changed
405 */
406 onSlidesGridLengthChange?: (swiper: SwiperClass) => void;
407 /**
408 * Event will be fired when snap grid has changed
409 */
410 onSnapGridLengthChange?: (swiper: SwiperClass) => void;
411 /**
412 * Event will be fired after swiper.update() call
413 */
414 onUpdate?: (swiper: SwiperClass) => void;
415 /**
416 * Event will be fired when swiper is locked (when `watchOverflow` enabled)
417 */
418 onLock?: (swiper: SwiperClass) => void;
419 /**
420 * Event will be fired when swiper is unlocked (when `watchOverflow` enabled)
421 */
422 onUnlock?: (swiper: SwiperClass) => void;
423
424}
425
426interface SlideData {
427 isActive: boolean;
428 isVisible: boolean;
429 isDuplicate: boolean;
430 isPrev: boolean;
431 isNext: boolean;
432}
433
434interface SwiperSlideProps {
435 /**
436 * Slide tag
437 *
438 * @default 'div'
439 */
440 tag?: string;
441
442 /**
443 * Enables additional wrapper required for zoom mode
444 *
445 * @default false
446 */
447 zoom?: boolean;
448
449 /**
450 * Slide's index in slides array/collection
451 *
452 * @default false
453 */
454 virtualIndex?: number;
455
456 /**
457 * Slide's child element or render function
458 *
459 * @default undefined
460 */
461 children?: JSX.Element | ((slideData: SlideData) => JSX.Element);
462}
463
464interface SwiperProps
465 extends Omit<
466 JSX.HTMLAttributes<HTMLElement>,
467 | 'onProgress'
468 | 'onClick'
469 | 'onTouchEnd'
470 | 'onTouchMove'
471 | 'onTouchStart'
472 | 'onTransitionEnd'
473 | 'onKeyPress'
474 | 'onDoubleClick'
475 | 'onScroll'
476 > {}
477interface SwiperSlideProps extends Omit<JSX.HTMLAttributes<HTMLElement>, 'children'> {}
478
479declare const Swiper: Component<SwiperProps>;
480declare const SwiperSlide: Component<SwiperSlideProps>;
481
482declare const useSwiper: () => SwiperClass;
483declare const useSwiperSlide: () => SlideData;
484
485export { Swiper, SwiperSlide, SwiperProps, SwiperSlideProps, useSwiper, useSwiperSlide };