Created
August 14, 2017 18:02
-
-
Save mathisonian/9c0988540ce12c99e1f53e830d4ac292 to your computer and use it in GitHub Desktop.
slideshow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const React = require('react'); | |
const IdyllComponent = require('idyll-component'); | |
const Slide = require('./slide'); | |
class Slideshow extends IdyllComponent { | |
getChildren(children) { | |
let processedChildren = []; | |
React.Children.forEach(children, (child) => { | |
if (typeof child === 'string') { | |
return; | |
} | |
if ((child.type.name && child.type.name.toLowerCase() === 'slide') || child.type.prototype instanceof Slide) { | |
processedChildren.push(child); | |
} else { | |
processedChildren = processedChildren.concat(this.getChildren(child.props.children)); | |
} | |
}) | |
return processedChildren; | |
} | |
render() { | |
return ( | |
<div className="slideshow" style={{position: 'relative'}}> | |
{this.getChildren(this.props.children)[this.props.currentSlide-1]} | |
</div> | |
); | |
} | |
} | |
Slideshow.defaultProps = { | |
currentSlide: 1 | |
}; | |
module.exports = Slideshow; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment