Code Monkey home page Code Monkey logo

react-id-swiper's Introduction

npm Version Coverage Status Weekly download Total Downloads Build Status

Package Quality

react-id-swiper ( Newest version 4.0.0 )

A library to use Swiper as a ReactJs component

Demo

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.

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
  • Find more info about Swiper custom build HERE
  • <= 3.x documentation

Documentation

Installation and setup

  • From version 2.0.0, it requires React & ReactDOM ver >=16.8.0 to use Hooks
  • From version 2.4.0, it requires Swiper ver >= 5.0.0

Npm package

By npm

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

By Yarn

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

CDN

<script src="https://unpkg.com/[email protected]/lib/react-id-swiper.js"></script>
<script src="https://unpkg.com/[email protected]/lib/react-id-swiper.min.js"></script>

Styling

Swiper stylesheet file is required

Use Swiper stylesheet file from CDN

<link rel="stylesheet" href="https://unpkg.com/swiper/css/swiper.css">
<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

import 'swiper/css/swiper.css'

scss

import 'swiper/swiper.scss'

less

import 'swiper/swiper.less'

Examples

Live Examples

Codesandbox Live Examples

Default

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

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

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

const ManipulatingSwiper = () => {
  const ref = useRef(null);

  const ref = useRef(null);

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

  const goPrev = () => {
    if (ref.current !== null && ref.current.swiper !== null) {
      ref.current.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

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:
module: {
  rules: [
    {
      exclude: [/node_modules\/(?!(swiper|dom7)\/).*/, /\.test\.js(x)?$/],
      test: /\.js(x)?$/,
      use: [{ loader: 'babel-loader' }],
    }
  ],
}

Adding customized css classes

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.

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 👎

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

GOOD CODE 👍

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

Bug report

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

Edit ReactIdSwiper - DEMO

Authors

See also the list of contributors who participated in this project.

Buy me a coffee

Buy Me A Coffee

License

This project is licensed under the MIT License - see the LICENSE file for details

react-id-swiper's People

Contributors

adrianvlupu avatar akichim21 avatar allenfang avatar flydiverny avatar gareys avatar greenkeeper[bot] avatar jpetitcolas avatar kidjp85 avatar nimatrueway avatar nytr0gen avatar timkindberg avatar valse avatar whyboris avatar wubaiqing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-id-swiper's Issues

Incompatible with Create React App

We're having some great success with this component, thank you! But we cannot add this to our bundle with Create React App due to Uglyifier not working with ES6 code. This has complicated our build process, and I'm sure others would be facing the same situation.

If the NPM module had been babeled, then everything would just work.

Steps to reproduce:

Expected output:

  • App is built correctly

Actual output:

$ react-scripts build 
Creating an optimized production build...
Failed to compile.
 
static/js/main.0f8e7deb.js from UglifyJs
SyntaxError: Unexpected token: name (ReactIdSwiper) [./~/react-id-swiper/src/react-swiper.js:28,0]

Heads up; not compatible with server side rendered React applications

Hi there, I tested this package in my React application which is rendered by my node server before the client takes over.

Because the window variable and multiple DOM references are used in the swiper library, I can't use it. My Node server can't access these client only references.

Example: var ua = window.navigator.userAgent.toLowerCase();

Consider this as a heads up. I bet more people are running into this issue. Fixing this would mean that you have to port the entire swiper library to React conventions, which is a lot of work.

Add custom pagination [button like pagination filled by some text]

I am trying to get some functionality where I can add custom tiles instead of pagination(Example slider is attached), I know there is an option of custom pagination but I am not able to add custom button tiles, I have to edit global scss file for that or it can not be achieve

screen shot 2017-11-16 at 2 59 35 pm

navigator is not defined

I am trying to add this in an isomorphic app. When the server-side code is being run, app throws below error as navigator obj is undefined.

node_modules\swiper\dist\js\swiper.js:3627
var ua = navigator.userAgent.toLowerCase();
^
ReferenceError: navigator is not defined.

Could you please help me on how to get rid of this issue.

Parallax support

Hi! I can't seem to get the parallax background working without changing your index.js file.

According to this the parallax background needs to be inserted between the "swiper-container" and the "swiper-wrapper". There is no option for that right now (as far as I can see).

Perhaps you can consider supporting parallax in this plugin?

Thanks in advance!

next set of slides never becomes visible

I am passing these parameters:

const params = {
pagination: '.swiper-pagination',
slidesPerView: 2,
paginationClickable: true,
spaceBetween: 30
};

I have 12 slides in the slider. It only shows as many slides as I mention in slides per view and scrolling to right never gives more elements no matter I pass 3 or 6 or 1

looks like this with 2 slides per view. next set of slides never appears

iisuegit

Duplicated Key, 'encountered two children with the same key'

Hey, hello and thanks for this awesome work.

We have a production application using your lib, and we're having some problems.
In development, or even in production, we get this errors:

Warning: flattenChildren(...): Encountered two children with the same key, `.$58283`. Child keys must be unique; when two children share a key, only the first child will be used.

The swiper is getting this '58283' from the key that i'm giving to my components, so both swiper and my components are rendering a same key.

I was trying to fix that on my own code, no success.
I was looking the source of react-id-swiper, and i might have fixed that:

return React.cloneElement(e, { key: Date.now() + index, className: [self.props.slideClass, e.props.className, noSwipingClass].join(' ') });

If i add this line to the code, the components are rendered with different keys, so the problem solves! :)

Can we add that (or something similar) on the code?
Should I add a PR?

Thanks!

cc @renatogalvones.

[question] nested swipers?

Hey there,
I was wondering if you could update the demos to provide a demo of nested swipers, similar to in the swiper demos: http://idangero.us/swiper/demos/11-nested.html source: https://github.com/nolimits4web/Swiper/blob/master/demos/11-nested.html

Is that behavior doable with this wrapper, currently? also, is it possible to combine the above nested sliders + a scrollable container slide ( https://github.com/nolimits4web/Swiper/blob/master/demos/32-scroll-container.html )?

I tried something like:

const vProps = {
  direction: 'vertical'
}
<Swiper>
  <div>horizontal slide one</div>
  <div>horizontal slide two</div>
  <div>
    <Swiper {vProps}>
      <div>vertical slide one</div>
      <div>vertical slide two</div>
    </Swiper>
  </div>
</Swiper>

which allowed me to swipe horizontally to the nested stack, and swipe vertically in the nested stack, but I could not swipe back to the horizontal slides ( ie I could go from horizontal slide two to vertical slide one, but not the reverse).

All slides rendering on first slide?

Hi again

So, ive been having this issue for a while now. When i want to use a horizontal swiper (and i copy the code exactly as the demo) i get all my slide contents rendering on the FIRST slide only...and the swiper still swipes in the correct direction (only without any info on the slide, of course).

Any thoughts at all? I really need to figure this out soon.

class BedOfRoses extends React.Component {
    render() {
        const params = {
            pagination: '.swiper-pagination',
            paginationClickable: true,
            nextButton: '.swiper-button-next',
            prevButton: '.swiper-button-prev',
            spaceBetween: 30
        };
        return (
            <Swiper>
                <div>Slide 1</div>
                <div>Slide 2</div>
                <div>Slide 3</div>
                <div>Slide 4</div>
                <div>Slide 5</div>
            </Swiper>

        );

    }
}

export default BedOfRoses;

untitled

swiper loop not working

I have a swiper with 5 slides. I have an issue when passing these parameters:

...
render() {
        const params = {
            direction: 'horizontal',
            paginationClickable: true,
            autoplay: 10000,
            autoplayDisableOnInteraction: false,
            loop:true
        };

for whatever reason, it will loop through once, and then when it gets back to the first slide, it wont continue. I inspected the elements and there are 6 slide divs in place...

I tried passing these parameters, and they fixed the issue in a sort of hacked way:

...
render() {
        const params = {
            direction: 'horizontal',
            paginationClickable: true,
            autoplay: 10000,
            autoplayDisableOnInteraction: false,
            slidesPerView:'auto',
            initialSlide:3,
            loop:true,
            loopedSlides:1,
        };

In this case, my slides no longer display in the order i placed them in the html, so i need to pass 'initialSlide: 3' to get to my 'first' slide... which is weird...

And the other issue with this fix is that when the user swipes, it almost skips back at the last slide and glitches. I'm developing this for a web-view app, and i've seen this issue on every mobile device i've tested on, and can also reproduce it in my browser. So it is most definitely an issue with the swiper itself.

Can you offer any help with this?

Thank you for making this

We are trying to do our own swiper react component and it's working ok, but it will be much better to have a singular one we can all work on. Thank you!!!

Creating a nested swiper

I'm wondering how to create a nested swiper like the one on the Swiper Demos for the iDangerous Swiper: [https://github.com/nolimits4web/Swiper/blob/master/demos/11-nested.html].

Here is what my code looks like:

var Mobile = React.createClass({
    render: function () {
        var vParams = {
            direction: 'vertical',
            pagination: '.swiper-pagination-v',
            paginationClickable: true,
            keyboardControl: true,
            nextButton: '.arrow-down'
        };
        var hParams = {
            direction: 'horizontal',
            pagination: '.swiper-pagination-h',
            paginationClickable: true,
            spaceBetween: 50,
            keyboardControl: true,
            nextButton: '.swiper-button-next',
            prevButton: '.swiper-button-prev',
        };
        return (
            <div className="mobile">
                 <Swiper 
                    direction={vParams.direction}
                    pagination={vParams.pagination}
                    paginationClickable={vParams.paginationClickable}
                    keyboardControl={vParams.keyboardControl}
                    nextButton={vParams.nextButton}
                    >

                    <div className="swiper-slide">
                         <div className="main-container">
                            <div className="content">
                                <h1 className="home-title">TITLE</h1>
                                <div className="arrow-container">
                                    <img src={require("../images/arrow-down-black.png")} className="arrow-down" />
                                </div>
                            </div>
                        </div>
                    </div>

                    {/*nested swiper*/}
                    <div className="swiper-slide">
                        <Swiper
                            direction={hParams.direction}
                            pagination={hParams.pagination}
                            paginationClickable={hParams.paginationClickable}
                            spaceBetween={hParams.spaceBetween}
                            keyboardControl={hParams.keyboardControl}
                            nextButton={hParams.nextButton}
                            prevButton={hParams.prevButton}
                        >
                            <div className="swiper-slide"></div>
                            <div className="swiper-slide"></div>
                            <div className="swiper-slide"></div>
                            <div className="swiper-slide"></div>
                        </Swiper>

                   <div className="swiper-slide"></div>
             </div>

any thoughts?

Swiper does not work with images properly

I am upgrading my website from using idangerous swiper to using this react wrapper for the swiper.

It does not work with images as far as I can tell :

My code looks like this :

import c1 from "./ichartsImages/grid4_yfill.png"
import c2 from "./ichartsImages/grid1.png"
        
...

<Swiper>
  <div style={{backgroundImage:"url(" + c2 + ")"}}></div>
  <div style={{backgroundImage:"url(" + c3 + ")"}}></div>
</Swiper>

The images to do not fit properly, and are repeated. I would expect the component to fit the images for me.

In my old code, there were a bunch of CSS classes which are missing in this component. However this worked perfectly :

    <div class="swiper-container">
        <div class="swiper-wrapper">
            <div class="swiper-slide" style="background-image:url(ichartsImages/grid4_yfill.png)"></div>
            <div class="swiper-slide" style="background-image:url(ichartsImages/grid1.png)"></div>

Not sure why the react component does not work. Perhaps you need CSS classes? Anyway, i think the examples need to be more comprehensive.

problems on "Backend"

Hi there!

I have a problem on React at the server side... I got ReferenceError: navigator is not defined
at D:\workspace\travelcoup-web-ui\node_modules\swiper\dist\js\swiper.js:4443:42

Some Ideas for a fix?

Thx! Great Job!

Cya crazyx13th

Linking two swipers together

Is it possible to achieve linking of two swipers like this vanilla swiper demo is doing?: http://idangero.us/swiper/demos/300-thumbs-gallery.html

The vanilla swiper source code is here: https://github.com/nolimits4web/Swiper/blob/master/demos/300-thumbs-gallery.html

They are doing something like this (I believe the bottom two lines are the important linking bits):

    var galleryTop = new Swiper('.gallery-top', {
      spaceBetween: 10,
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      },
    });
    var galleryThumbs = new Swiper('.gallery-thumbs', {
      spaceBetween: 10,
      centeredSlides: true,
      slidesPerView: 'auto',
      touchRatio: 0.2,
      slideToClickedSlide: true,
    });
    galleryTop.controller.control = galleryThumbs;
    galleryThumbs.controller.control = galleryTop;

If this is not possible I'd like to suggest as a feature request.

Event Props do not work/reflect actual swiper API

The Swiper api utilizes an object on to house the event listeners in the params setup of the swiper. The api of this react utility is not compatible and can be misleading. The propTypes and examples should be updated.

How to use custom prev and next buttons?

Hi! I tried, inside prevButton and nextButton params, to put a custom class instead of swiper-button-prev and swiper-button-next and the buttons stopped working.

How is it possible to create custom prev and next buttons using your wrapper?

Cannot use this.setState in onSlideChangeEnd

I would like to call this.setState from the onSlideChangeEnd in order to keep track of the activeIndex in the state of the container component (that has the Swiper component). However, this triggers an error: swiper.js:4147 Uncaught TypeError: Cannot read property 'emitterEventListeners' of null whenever the slide is changed.

Interestingly, the activeIndex in the<p>tag does get updated correctly when clicking between different slides using the pagination buttons, but the slides themselves keep snapping back to the initial slide.

I don't understand why you cannot call this.setState within Swiper's transition callbacks. Is there another way for the state to be updated with Swiper's activeIndex?


class Foo extends React.Component {

  constructor(props) {
    super(props)
    this.state = {activeIndex: null}
    this.swiper = null
  }

  componentDidMount(){
    this.setState({activeIndex: this.swiper.activeIndex})
  }

  render() {

    const params = {
      pagination: '.swiper-pagination',
      paginationClickable: true,
      onSlideChangeEnd:(swiper)=>{
        this.setState({activeIndex: swiper.activeIndex})
      },
      onInit: (swiper)=>{this.swiper = swiper},
      runCallbacksOnInit: true,
    }

    return (
      <div>
        <p>Current Active Index: {this.state.activeIndex}</p>
        <Swiper {...params}>
           <div><Bar /></div>
           <div><Baz /></div>
        </Swiper>
      <div>
    );
  }
}

init event no long passes swiper instance as an argument

this doesn't work anymore:

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

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

even this won't work as the swiper instance is no longer passed as an argument to the init event:

on: {
  init: (swiper) => {
    this.swiper = swiper
  }
}

but... this works:

render() {
  const params = {
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev'
    },
    pagination: {
      el: '.swiper-pagination',
      dynamicBullets: true,
      clickable: true
    }
  };

  return(
    <div>
      <Swiper {...params} ref={node => this.swiper = node !== null ? node.swiper : null }>
        <div>Slide 1</div>
        <div>Slide 2</div>
        <div>Slide 3</div>
        <div>Slide 4</div>
        <div>Slide 5</div>
      </Swiper>
    </div>
  );
}

ie9

support ie9?

Problem with pagination rendering

Hi!

I have issue with rendering pagination bullets. As soon as i refresh my page, only one swiper pagination bullet will appear. If i resize the screen just a bit, all bullets will come back.
I'm stuck a bit. Maybe you can help?

Check the gif, please.

why

Two valid but unequal nodes with the same `data-reactid` if loop is set to true

Uncaught Error: ReactMount: Two valid but unequal nodes with the same `data-reactid`: .3.2.0.0.0.0.0.0.$2.0.$1/=1$1.0.0
    at invariant (invariant.js:39)
    at Object.getID (ReactMount.js:119)
    at findParent (ReactEventListener.js:39)
    at handleTopLevelWithoutPath (ReactEventListener.js:87)
    at handleTopLevelImpl (ReactEventListener.js:73)
    at ReactDefaultBatchingStrategyTransaction.perform (Transaction.js:136)
    at Object.batchedUpdates (ReactDefaultBatchingStrategy.js:62)
    at Object.batchedUpdates (ReactUpdates.js:94)
    at dispatchEvent (ReactEventListener.js:204)

My component looks like this:


<Swiper {...params} key="2">
                        <div id="firstSlide" key="1">
                        <a id="sliderLink1" href={`${config.root}/trends/satin.html?dir=desc&order=production_date&icn=MainBanner1_22122016&ici=Desktop_MainBanner1_Satin_20122016_V1`} >
                        <img id="sliderImage1" alt="sweats-cards"  name="sweats-cards-9-12-16" src="http://img.stalkbuylove.com/media/wysiwyg/new_banners/Desktop_MainBanner_Jackets_20122016_V1.jpg" />
                        </a>
                        </div>

                       ```
 <div id="secondSlide" key="2">
                        <a id="sliderLink2" href={`${config.root}/trends/satin.html?dir=desc&order=production_date&icn=MainBanner1_22122016&ici=Desktop_MainBanner1_Satin_20122016_V1`}>
                        <img id="sliderImage2" alt="sweats-cards"  name="sweats-cards-9-12-16" src="http://img.stalkbuylove.com/media/wysiwyg/new_banners/Desktop_MainBanner1_27122016_V1.jpg" />
                        </a>
                        </div>

                      </Swiper>

It's really annoying. Why do I keep getting this and how do I fix it?

Adding styles (not classes)

It would be great if you could add your own styles to the elements. Modifying the class name still don't make it possible to have calculated style properties.

const params = {
  containerStyle: {
    padding: 10 + 10,
  },
  spaceBetween: 30
};
return (
  <Swiper {...params}>
    <div>Slide 1</div>
    <div>Slide 2</div>
  </Swiper>
);

Point out BC in swiper

Hi,
i think it would be nice if you would point out breaking changes of the main Swiper if you upgrade your dependencies.

Cheers,
Toni

es6 require/render

Hello and thanks for the good work here!


I was using version 1.3.1 and doing like the files below. I've upgraded to 1.4.0 and now it seems to be broken. Can you help me with this?

I tried several approaches, but i want to know if i am doing something wrong first.

Using last version of React with Isomorphic Rendering.

version: 1.4.0
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object. Check the render method of CardSlider.


Container file:

...

let Swiper;

class Container extends Component {
  constructor() {
    super();

    this.swiper = null;
  }

  componentWillMount() {
    Swiper = require('react-id-swiper');
  }

  ...

  render() {
    ...

    return (
      <CardSlider
        params={params}
        slides={this.props.slides}
        Swiper={Swiper}
        updateSliderDimensions={this.updateSliderDimensions}
      />
    );
  }
}

...

Presentation file:

...

function CardSlider({ params, slides, Swiper, updateSliderDimensions }) {
  ...

  return (
    <Swiper {...params}>
      {cards}
    </Swiper>
  );
}

...

Control param for thumbnails

Hello! Thank you for your package.

There is an example in official docs with two-way control (Gallery with thumbnails).

Do you have the same function in your package?

image

More callback function

I'm using this swiper in my current project and it's so good. But when load many complex items, it became slow and not smooth. So I think we only render 3 item on init : prev item, current item display and next item, and when swiping next item done, it'll return callback function onSwipeDone to load and replace 3 new item. That'll limit 3 item to performance display

So, I meam, I hope you support some callback function as: onSwipeDone (each swipe one item), onSwiping. It could be ?

p/s : 3 items depending on swipe setting, it's should be 3* (number item display) and pagination number can set on init by manual

Swiper instance

How do you get the swiper instance in order to manipulate it outside of the swiper component ?

I didn't see anything in the documentation which is actually an important part.

How do you deal with react rerender, let's say you have on each slide a onClick function, when you click a slide lets say #10, react rerender the swiper component to the begining of the slider #1.

I have tried componentShouldUpdate return false which prevent the rerender of the swiper, but i don't get the slide's state update that im expecting upon onClick()

Force update the swiper

I am having a dynamic array of component to render in swiper, however, when adding the new component to the array, it does not shown correctly in the swiper, which function should I call to force update the swiper

slidesPerView absolute adjustments?

Thank you for all the work that was put into this package!

Is there a way to not define how many slides fit per view, but rather to fit as many slides in the container that react-id-swiper is currently in based on the defined with of each slide?

For example, lets say I have a couple of 200px wide slides.
When container is

  • 1,000px --> 5 slides fit in to the swiper,
  • 900px --> 4.5 slides fit into the swiper,
  • 500px --> 2.5 slides fit into the swiper

... and so on without me having to define the breakpoints. The reason for this, it is hard to define a breakpoints for all screen sizes, etc. and what often ends up happening is the swiper will try to put as an example three 200px slides into a 500px container, there by cutting off some of the slides.

slidesPerView: "auto" --> did not work for me. It simply defaulted to one slide per view.

Thanks!

Unexpected token: name (ReactIdSwiper) from UglifyJs

}(this, function (React, ReactDOM, Swiper, objectAssign, PropTypes) {
  'use strict';

  var defaultProps = {
    containerClass: 'swiper-container',
    wrapperClass: 'swiper-wrapper',
    slideClass: 'swiper-slide'
  }

  class ReactIdSwiper extends React.Component {

You should compile classes to ES5 before publishing the package.

Update to React 16

Hi,

React 16 has been released recently, so it's a good reason to update package.json.
I tested my app with the current react-id-swiper and React 16, works good.

Add custom template for controls button

Originally, Swiper provides flexible controls structure, html example
<div class="swiper-button-prev"><span class="font-icon-big-arr-left"></span></div>

It would be great feature to pass some jsx to slider params for this case.

Thank you for this plugin and your attention.

api document show add rebuildOnUpdate

hi,I use react-id-swiper,it's good!
but I found my view don't update immediately,it take me for a long time to slove this problem:
set
rebuildOnUpdate : true
in params object.

I think api document show add rebuildOnUpdate

in loop mode, the component events can't be worked if swipe from the first slide to the last slide

in loop mode, the component events can't be worked if swipe from the first slide to the last slide.
for example:

<Swiper {...params}>
  {
      imgList.map((list, i) =>
        <img key={i} onClick={this.onDocClick.bind(this, list.url)} src={list.imgUrl} />
      )
   }
 </Swiper>

the onClick method will worked as well in no-loop, but in loop mode, if swipe from the first slide to the last slide, it couldn't worked.
I know the Swiper will clone the first and the last of the element in loop mode, how to make it right in react?

prev and back buttons not changing the slide

Slides change on autoplay and with pagination click but forward and back button do not work at all.

 <div id="homePageSlider">
                          <Swiper>
                                 <img alt="sweats-cards" classname="lazyload banner_main" name="sweats-cards-9-12-16" src=xyz.jpg" />
                          </Swiper>
                        </div>
                      </div>

I have tried passing this const params = {
pagination: '.swiper-pagination',
nextButton: '.swiper-button-next',
prevButton: '.swiper-button-prev',
paginationClickable: true,
spaceBetween: 30,
centeredSlides: true
};

as well but no luck

Dynamic Data

HI,thank you for making this useful tool,I have some problems

{list.map((item, index) => {
     return (
        <div key={index}>
            slide
        </div>
      )
    }) : null
}

but swiper doesn`t work,I can't drag it,please tell me how to solve this problem,thank you!

1.5.3 is broke

screen shot 2017-10-31 at 17 20 31

hello there. I think you newest version is not working, slides are not being rendered correctly and slider cannot be closed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.