1.0.10 • Published 3 years ago

react-tiga-swiper v1.0.10

Weekly downloads
128
License
MIT
Repository
github
Last release
3 years ago

react-tiga-swiper

a fantastic react swiper component

NPM JavaScript Style Guide

Install

npm install --save react-tiga-swiper

Usage

import React, { useRef, useState } from "react";
import Swiper,{SwipeRef} from 'react-tiga-swiper';
import 'react-tiga-swiper/dist/index.css';

function App() {
  const swiperRef = useRef<SwipeRef>(null);
  const [index, setIndex] = useState<any>();
  const swiperData = ["#99CCCC", "#FFCC99", "#FFCCCC", "#FFFFCC","#CCFFFF"];

  const swipeTo = () => {
    const swiperInstance = swiperRef.current;
    const currPage: string = index * 1 + '';
    swiperInstance?.swipeTo(parseInt(currPage, 10));
  };

  const prev = () => {
    const swiperInstance = swiperRef.current;
    swiperInstance?.prev();
  };

  const next = () => {
    const swiperInstance = swiperRef.current;
    swiperInstance?.next();
  };

  const onChange = (currPage: number, prevPage: number) => {
    console.log(currPage, prevPage);
  };

  return (
    <>
      <div style={{ marginBottom: 20 }}>
        <div className="manu-action">
          <input
            type="number"
            value={index}
            onChange={(e) => setIndex(e.target.value)}
          />
          <span className="btn" onClick={swipeTo}>swipe to (index start 0)</span>
        </div>
        <div className="more-action">
          <span className="btn" onClick={prev}>prev</span>
          <span className="btn" onClick={next}>next</span>
        </div>
      </div>
      <Swiper
        className="demo-swiper-container"
        autoPlay={3000}
        selectedIndex={0}
        showIndicators={true}
        indicator={null}
        dots={null}
        direction="vertical"
        loop={false}
        ref={swiperRef}
        onChange={onChange}
      >
        {swiperData.map((item: string, key) => (
          <div key={key} style={{backgroundColor: item}}>{key + 1}</div>
        ))}
      </Swiper>
    </>
  );
}

API

attributedesctypedefaultothers
durationAnimation duration(ms)number300
autoPlayAutoplay interval(ms)number3000
selectedIndexindex of initial swiper, start from 0number0
directionscroll directionstringhorizontal | 'vertical
loopwhether to enable loopbooltrue
touchablewhether to enable touchablebooltrue
showIndicatorswhether to enable show indicatorsbooltrue
showDotswhether to enable show dotsbooltrue
dotsbottom dotsReact.ReactNodenull
indicatorindicatorReact.ReactNodenull
stylestyleReact.CSSProperties{}
classNameclassNamestring''
onChangeemitted when currage swipe changed(current: number, prev: number): voidnoop

Swipe Methods

methodsdescargumentdesc
swipeToswipe to target indexindexstart 0
prevswipe to prev item
nextswipe to next item

License

MIT © xigua1994

1.0.9

3 years ago

1.0.10

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago