Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.