swiper-react.d.ts 14 KB

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