diff --git a/README.md b/README.md index b8e2330..90d0441 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# react-owl-carousel +# react-owl-carousel [![npm version](https://img.shields.io/npm/v/react-owl-carousel.svg?style=flat)](https://www.npmjs.com/package/react-owl-carousel) [React](http://facebook.github.io/react/) + [Owl Carousel 1.3](http://owlgraphic.com/owlcarousel/) ### 1.Getting Started diff --git a/components/OwlCarousel.jsx b/components/OwlCarousel.jsx index edafaa6..5d01cf5 100644 --- a/components/OwlCarousel.jsx +++ b/components/OwlCarousel.jsx @@ -1,6 +1,7 @@ 'use strict'; -import React from 'react'; +import React, {PropTypes} from 'react'; +import {findDOMNode} from 'react-dom'; import '../src/owl.carousel.css'; import '../src/owl.carousel.js'; @@ -55,109 +56,33 @@ const Owl_Carousel_Options = [ * stop() */ -const OwlCarousel = React.createClass({ +class OwlCarousel extends React.Component { + constructor(props, context) { + super(props, context); - getDefaultProps() { - return { - style : {}, - }; - }, - - propTypes: { - children : React.PropTypes.oneOfType([ - React.PropTypes.element, - React.PropTypes.arrayOf(React.PropTypes.element.isRequired), - ]).isRequired, - - style : React.PropTypes.object, - id : React.PropTypes.string, - - items : React.PropTypes.number, - itemsCustom : React.PropTypes.arrayOf(React.PropTypes.arrayOf(React.PropTypes.number).isRequired), - itemsDesktop : React.PropTypes.arrayOf(React.PropTypes.number.isRequired), - itemsDesktopSmall : React.PropTypes.arrayOf(React.PropTypes.number.isRequired), - itemsTablet : React.PropTypes.arrayOf(React.PropTypes.number.isRequired), - itemsTabletSmall : React.PropTypes.arrayOf(React.PropTypes.number.isRequired), - itemsMobile : React.PropTypes.arrayOf(React.PropTypes.number.isRequired), - singleItem : React.PropTypes.bool, - itemsScaleUp : React.PropTypes.bool, - - slideSpeed : React.PropTypes.number, - paginationSpeed : React.PropTypes.number, - rewindSpeed : React.PropTypes.number, - - autoPlay : React.PropTypes.oneOfType([ - React.PropTypes.bool, - React.PropTypes.number, - ]), - stopOnHover : React.PropTypes.bool, - - navigation : React.PropTypes.bool, - navigationText : React.PropTypes.arrayOf(React.PropTypes.string), - rewindNav : React.PropTypes.bool, - scrollPerPage : React.PropTypes.bool, - - pagination : React.PropTypes.bool, - paginationNumbers : React.PropTypes.bool, - - responsive : React.PropTypes.bool, - responsiveRefreshRate : React.PropTypes.number, - responsiveBaseWidth : function(props, propName, componentName) { - if ( - props[propName] && - !$(props[propName]).length - ) { - return new Error('React-owl-carousel: the props `responsiveBaseWidth` needs jQuery selector.'); - } - }, - - baseClass : React.PropTypes.string, - theme : React.PropTypes.string, - - lazyLoad : React.PropTypes.bool, - lazyFollow : React.PropTypes.bool, - lazyEffect : React.PropTypes.bool, - - autoHeight : React.PropTypes.bool, - - jsonPath : React.PropTypes.string, - jsonSuccess : React.PropTypes.func, - - dragBeforeAnimFinish : React.PropTypes.bool, - mouseDrag : React.PropTypes.bool, - touchDrag : React.PropTypes.bool, - - addClassActive : React.PropTypes.bool, - - //build-in transitionStyle: 'fade', 'backSlide', 'goDown', 'scaleUp' - transitionStyle : React.PropTypes.string, - - beforeUpdate : React.PropTypes.func, - afterUpdate : React.PropTypes.func, - beforeInit : React.PropTypes.func, - afterInit : React.PropTypes.func, - beforeMove : React.PropTypes.func, - afterMove : React.PropTypes.func, - afterAction : React.PropTypes.func, - startDragging : React.PropTypes.func, - afterLazyLoad: React.PropTypes.func, - }, + this.next = () => $(findDOMNode(this)).data('owlCarousel').next(); + this.prev = () => $(findDOMNode(this)).data('owlCarousel').prev(); + this.goTo = (x) => $(findDOMNode(this)).data('owlCarousel').goTo(x); + this.jumpTo = (x) => $(findDOMNode(this)).data('owlCarousel').jumpTo(x); + this.play = () => $(findDOMNode(this)).data('owlCarousel').play(); + this.stop = () => $(findDOMNode(this)).data('owlCarousel').stop(); + } componentDidMount() { - $(React.findDOMNode(this)).owlCarousel(this.getOptions()); - }, + $(findDOMNode(this)).owlCarousel(this.getOptions()); + } componentWillReceiveProps(nextProps) { - $(React.findDOMNode(this)).data('owlCarousel').destroy(); - }, + $(findDOMNode(this)).data('owlCarousel').destroy(); + } componentDidUpdate(prevProps, prevState) { - $(React.findDOMNode(this)).owlCarousel(this.getOptions()); - }, + $(findDOMNode(this)).owlCarousel(this.getOptions()); + } componentWillUnmount() { - $(React.findDOMNode(this)).data('owlCarousel').destroy(); - }, + $(findDOMNode(this)).data('owlCarousel').destroy(); + } getOptions() { const options = {}; @@ -169,10 +94,9 @@ const OwlCarousel = React.createClass({ }); return options; - }, + } render() { - const { items, itemsDesktop, @@ -215,43 +139,92 @@ const OwlCarousel = React.createClass({ ...props, } = this.props; - touchDrag !== false - ? React.initializeTouchEvents(true) - : React.initializeTouchEvents(false); - return (