Skip to content

Instantly share code, notes, and snippets.

@mathisonian
Created August 14, 2017 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathisonian/9c0988540ce12c99e1f53e830d4ac292 to your computer and use it in GitHub Desktop.
Save mathisonian/9c0988540ce12c99e1f53e830d4ac292 to your computer and use it in GitHub Desktop.
slideshow
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