# react-id-swiper

> ReactJs component for iDangerous Swiper

Latest version **4.0.0** (published 2020-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-id-swiper
pnpm add react-id-swiper
yarn add react-id-swiper
bun add react-id-swiper
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2020-06-22 |
| First published | 2016-04-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 6.11.0 |
| Dependencies | 1 |
| Unpacked size | 66.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1478 |
| Author | Phuc Nguyen Hoang |
| Maintainers | phuc.nguyen |
| Keywords | iDangerous, Swiper, Reactjs |

## Links

- npm: https://www.npmjs.com/package/react-id-swiper
- Repository: https://github.com/kidjp85/react-id-swiper
- Homepage: https://github.com/kidjp85/react-id-swiper#readme
- Issues: https://github.com/kidjp85/react-id-swiper/issues
- npm.io page: https://npm.io/package/react-id-swiper

## Dependencies (1)

- [object-assign](https://npm.io/package/object-assign.md) ^4.1.1

## Alternatives

- [adhdev](https://npm.io/package/adhdev.md) — 11.1K weekly downloads
- [react-slide-button](https://npm.io/package/react-slide-button.md) — 310 weekly downloads
- [better](https://npm.io/package/better.md) — 42 weekly downloads
- [react-native-swipe-image](https://npm.io/package/react-native-swipe-image.md) — 22 weekly downloads
- [nl.fokkezb.pulltorefresh](https://npm.io/package/nl.fokkezb.pulltorefresh.md) — 11 weekly downloads

## Recent versions

- 4.0.0 (latest) — 2020-06-22
- 3.0.0 — 2020-02-28
- 2.4.0 — 2019-11-06
- 2.3.2 — 2019-07-24
- 2.3.1 — 2019-06-27
- 2.3.0 — 2019-06-27
- 2.3.0-beta4 — 2019-06-27
- 2.3.0-beta3 — 2019-06-27
- 2.3.0-beta2 — 2019-06-27
- 2.3.0-beta1 — 2019-06-27
- 2.3.0-beta — 2019-06-27
- 2.1.2 — 2019-04-16
- 2.1.1 — 2019-03-25
- 2.1.0 — 2019-03-14
- 2.1.0-beta — 2019-03-14
- … 44 more at https://npm.io/package/react-id-swiper/versions

## README

[![npm Version](https://img.shields.io/npm/v/react-id-swiper.svg?style=flat-square)](https://npmjs.org/package/react-id-swiper)
[![Coverage Status](https://img.shields.io/codecov/c/github/moroshko/react-autosuggest/master.svg?style=flat-square)](https://codecov.io/gh/kidjp85/react-id-swiper)
[![Weekly download](https://img.shields.io/npm/dw/react-id-swiper.svg?style=flat-square)](https://npmjs.org/package/react-id-swiper)
[![Total Downloads](https://img.shields.io/npm/dt/react-id-swiper.svg?style=flat-square)](https://npmjs.org/package/react-id-swiper)
[![Build Status](https://travis-ci.org/kidjp85/react-id-swiper.svg?branch=master)](https://travis-ci.org/kidjp85/react-id-swiper)

[![Package Quality](http://npm.packagequality.com/badge/react-id-swiper.png)](http://packagequality.com/#?package=react-id-swiper)

react-id-swiper ( Newest version 4.0.0 )
========================================
> A library to use [Swiper](http://www.idangero.us/swiper/get-started/) as a ReactJs component

![Demo](https://media.giphy.com/media/mByDrCTcJch4HVhmfi/giphy.gif)

What is Swiper?
===============

Swiper - is the free and most modern mobile touch slider with hardware accelerated transitions and amazing native behavior.

It is intended to be used in mobile websites, mobile web apps, and mobile native/hybrid apps. Designed mostly for iOS, but also works great on latest Android, Windows Phone 8 and modern Desktop browsers.

Swiper is not compatible with all platforms, it is a modern touch slider which is focused only on modern apps/platforms to bring the best experience and simplicity. Swiper does work well with [Gatsby](https://www.gatsbyjs.org/).

# Props

| Name               | Type     | Default value    | Description                                      |
| ------------------ | -------- | ---------------- | -------------------------------------------------|
| ContainerEl        | String   | 'div'            | Element type for container                       |
| containerClass     | String   | swiper-container | Swiper container class name                      |
| WrapperEl          | String   | 'div'            | Element type for wrapper                         |
| wrapperClass       | String   | swiper-wrapper   | Swiper wrapper class name                        |
| slideClass         | String   | swiper-slide     | Swiper slide class name                          |
| shouldSwiperUpdate | Boolean  | false            | Update swiper when component is updated          |
| rebuildOnUpdate    | Boolean  | false            | Rebuild swiper when component is updated         |
| noSwiping          | Boolean  | false            | Disable swiping by condition                     |
| activeSlideKey     | String   | null             | Initial slide index                              |
| renderPrevButton   | function |                  | Render props function for prev button            |
| renderNextButton   | function |                  | Render props function for next button            |
| renderScrollbar    | function |                  | Render props function for scrollbar              |
| renderPagination   | function |                  | Render props function for pagination             |
| renderParallax     | function |                  | Render props function for parallax               |

**If you want to use Swiper custom build to reduce bundle size, you need to use extra props below.**

# Custom build extra props

| Name               | Type     | Default value    | Description                                      |
| ------------------ | -------- | ---------------- | -------------------------------------------------|
| Swiper             | Class    |                  | Swiper class                                     |
| modules            | array    |                  | Array of Swiper necessary modules                |


**NOTE:**

* You can also use Swiper's original params too. Swiper API documentation [HERE](http://idangero.us/swiper/api/)
* Find more info about Swiper custom build [HERE](https://idangero.us/swiper/api/#custom-build)
* [<= 3.x documentation](docs/3.x-document.md)

# Documentation

- [Get Started](https://react-id-swiper.ashernguyen.site/doc/get-started)
- [API](https://react-id-swiper.ashernguyen.site/doc/api)
- [Custom Build](https://react-id-swiper.ashernguyen.site/doc/custom-build)
- [Examples](https://react-id-swiper.ashernguyen.site/example/default)

# Installation and setup

- From version 2.0.0, it requires **React & ReactDOM ver >=16.8.0** to use [Hooks](https://reactjs.org/docs/hooks-intro.html)
- From version 2.4.0, it requires **Swiper ver >= 5.0.0**

## Npm package

> By npm

```bash
npm install --save react-id-swiper@latest swiper@latest
```

> By Yarn

```bash
yarn add react-id-swiper@latest swiper@latest
```

## CDN

```html
<script src="https://unpkg.com/react-id-swiper@3.0.0/lib/react-id-swiper.js"></script>
```

```html
<script src="https://unpkg.com/react-id-swiper@3.0.0/lib/react-id-swiper.min.js"></script>
```

# Styling

**Swiper stylesheet file is required**

Use Swiper stylesheet file from CDN

```html
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.css">
```

```html
<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.min.css">
```

**Or from Swiper package**

You should import directly from `Swiper` package which supports css, scss and less

> css

```javascript
import 'swiper/css/swiper.css'
```

> scss

```javascript
import 'swiper/swiper.scss'
```

> less

```javascript
import 'swiper/swiper.less'
```

# Examples

[Numerous live examples](https://react-id-swiper.ashernguyen.site/example/default):

>Navigation, Pagination, Pagination / Dynamic Bullets, Progress Pagination, Fraction Pagination, Custom Pagination, Scrollbar, Vertical slider, Space Between Slides, Mutiple Slides Per View, Auto Slides Per View / Carousel Mode, Centered Slides, Centered Slides + Auto Slides Per View, Free Mode / No Fixed Positions, Scroll Container, Multiple Row Slides Layout, Nested Swipers, Grab Cursor, Loop Mode / Infinite Loop, Loop Mode With Multiple Slides Per Group, Fade Effect, 3D Cube Effect, 3D Coverflow Effect, 3D Flip Effect, Mousewheel-control, Auto Play, Thumbs Gallery With Two-way Control, RTL Layout, Parallax, Lazyload Image, Responsive Breakpoints, Manipulating component outside Swiper, Customized Component

## Default

```javascript
import React from 'react';
import Swiper from 'react-id-swiper';
import 'swiper/css/swiper.css';

const SimpleSwiper = () => (
  <Swiper>
    <div>Slide 1</div>
    <div>Slide 2</div>
    <div>Slide 3</div>
    <div>Slide 4</div>
    <div>Slide 5</div>
  </Swiper>
)

export default SimpleSwiper;
```

## Using params

```javascript
import React from 'react';
import Swiper from 'react-id-swiper';

const SimpleSwiperWithParams = () => {
  const params = {
    pagination: {
      el: '.swiper-pagination',
      type: 'bullets',
      clickable: true
    },
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev'
    },
    spaceBetween: 30
  }

  return(
    <Swiper {...params}>
      <div>Slide 1</div>
      <div>Slide 2</div>
      <div>Slide 3</div>
      <div>Slide 4</div>
      <div>Slide 5</div>
    </Swiper>
  )
}

export default SimpleSwiperWithParams;
```

## Manipulating swiper from outside swiper component

```javascript
import React, { useState, useRef } from 'react';
import Swiper from 'react-id-swiper';

const ManipulatingSwiper = () => {
  const [swiper, setSwiper] = useState(null);

  const ref = useRef(null);

  const goNext = () => {
    if (ref.current !== null && ref.current.swiper !== null) {
      swiper.slideNext();
    }
  };

  const goPrev = () => {
    if (ref.current !== null && ref.current.swiper !== null) {
      swiper.slidePrev();
    }
  };

  return (
    <div>
      <Swiper ref={ref}>
        <div>Slide 1</div>
        <div>Slide 2</div>
        <div>Slide 3</div>
        <div>Slide 4</div>
        <div>Slide 5</div>
      </Swiper>
      <button onClick={goPrev}>Prev</button>
      <button onClick={goNext}>Next</button>
    </div>
  );
};

export default ManipulatingSwiper;
```

## Custom build Swiper

You can find the [WORKING DEMO REPO HERE](https://github.com/kidjp85/react-id-swiper-custom-build)

```javascript
import React from 'react';
import ReactIdSwiperCustom from 'react-id-swiper/lib/ReactIdSwiper.custom';
import { Swiper, Navigation, Pagination } from 'swiper/js/swiper.esm';

const CustomBuildSwiper = () => {
  const params = {
    // Provide Swiper class as props
    Swiper,
    // Add modules you need
    modules: [Navigation, Pagination],
    pagination: {
      el: '.swiper-pagination',
      type: 'bullets',
      clickable: true
    },
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev'
    },
    spaceBetween: 30
  }

  return(
    <ReactIdSwiperCustom {...params}>
      <div>Slide 1</div>
      <div>Slide 2</div>
      <div>Slide 3</div>
      <div>Slide 4</div>
      <div>Slide 5</div>
    </ReactIdSwiperCustom>
  )
}

export default CustomBuildSwiper;
```

**NOTE**:
* If you use Webpack & Babel you need to setup Babel loader config in `webpack.config.js` like below:

```javascript
module: {
  rules: [
    {
      exclude: [/node_modules\/(?!(swiper|dom7)\/).*/, /\.test\.js(x)?$/],
      test: /\.js(x)?$/,
      use: [{ loader: 'babel-loader' }],
    }
  ],
}
```

## Adding customized css classes

```javascript
const params = {
  pagination: {
    el: '.swiper-pagination.customized-swiper-pagination',
  }, // Add your class name for pagination container
  navigation: {
    nextEl: '.swiper-button-next.customized-swiper-button-next', // Add your class name for next button
    prevEl: '.swiper-button-prev.customized-swiper-button-prev' // Add your class name for prev button
  },
  containerClass: 'customized-swiper-container' // Replace swiper-container with customized-swiper-container
}
```

## Adding customized components

For customized rendering to work, you have to use same classname with params el.

```javascript
const params = {
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev'
  },
  renderPrevButton: () => <button className="swiper-button-prev">Prev</button>,
  renderNextButton: () => <button className="swiper-button-next">Next</button>,
}
```

## Workable slides

Each slide should be wrapped by HTML element

> BAD CODE :thumbsdown:

```javascript
<Swiper {...params}>
  Slide content
</Swiper>
```

> GOOD CODE :thumbsup:

```javascript
<Swiper {...params}>
  <span>Slide content</span>
</Swiper>
```

# Bug report

**Please use the prepared Codesanbox below to reproduce your issue. Thank you!!**

[![Edit ReactIdSwiper - DEMO](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/p8j61y7j7?fontsize=14)


# Authors

* **Asher Nguyen** - *Initial work* - [Asher Nguyen](https://github.com/kidjp85)

See also the list of [contributors](https://github.com/kidjp85/react-id-swiper/contributors) who participated in this project.


# Buy me a coffee

<a href="https://www.buymeacoffee.com/kidjp85" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-green.png" alt="Buy Me A Coffee" style="height: 51px !important;width: 217px !important;" ></a>

# License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

---
_Source: https://npm.io/package/react-id-swiper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
