2.0.3 • Published 5 months ago

react-touch-swiper v2.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

react-touch-swiper

Touch and drag slider component for React

Slider Gif

  • Touch friendly on mobile
  • Responsive to viewport resizing
  • Supports mouse drag by default
  • Simple API
  • Sizes to any size parent container
  • small bundle size with zero dependencies

Install

npm i react-touch-swiper

Usage

import React from 'react'
import { Slider } from 'react-touch-swiper'

// here we are importing some images
// but the Slider children should be an array of node like img
// or your own components

import images from './images'

function App() {
  return (
    <Slider
      onSlideComplete={(event,slideIndex) => {
        console.log('sliding completed', slideIndex)
      }}
      onSlide={(event,slideIndex) => {
        console.log("sliding", slideIndex)
      }}
      onSlideStart={(event,slideIndex) => {
        console.log('sliding started', slideIndex)
      }}
      keyEvent={false}
      controllButton={false}
      activeIndex={0}
      threshHold={100}
      transition={0.3}
      scaleEffect={true}
    >
      {images.map(({ url, title }, index) => (
        <img src={url} key={index} alt={title} />
      ))}
    </Slider>
  )
}

export default App

Available Props

PropTypeDefaultDescription
onSlideComplete(event: eventObject, completedIndex: number) => voidA function that gets called when sliding completed
onSlideStart(event: eventObject, startedIndex: number) => voidA function that gets called when sliding started
onSliding(event: eventObject, currentIndex: number) => voidA function that gets called when sliding
activeIndexnumber0Set to start on this index or use state to update the current index
threshHoldnumber100A pixel value that must be dragged before slide snaps to its position customise with your value according to size of the window
transitionnumber0.3The transition delay in seconds
scaleEffectbooleanfalsescale effect for individual slides while dragging
keyEventbooleanfalseEnable arrow key navigation
controllButtonbooleanfalseShow control buttons
autoSlidingbooleanfalseenable auto sliding based on time interval
autoSlideTimeIntervalnumber3000specific auto sliding time interval in ms
disableDefaultPaddingbooleanfalseremove default padding of slide element (0.3rem)
styleobject{}specific custom style to slider parent component (width, height, etc ..)

License

MIT © 2023 Hamdan-KT

2.0.3

5 months ago

2.0.2

5 months ago

2.0.1

5 months ago

2.0.0

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago