scratch-www/src/components/carousel/carousel.jsx

69 lines
2.3 KiB
React
Raw Normal View History

var defaults = require('lodash.defaults');
2015-09-08 14:56:28 -04:00
var React = require('react');
var Slider = require('react-slick');
2015-09-08 14:56:28 -04:00
var Thumbnail = require('../thumbnail/thumbnail.jsx');
require('slick-carousel/slick/slick.scss');
require('slick-carousel/slick/slick-theme.scss');
require('./carousel.scss');
var Carousel = React.createClass({
2015-10-09 16:16:37 -04:00
type: 'Carousel',
2015-09-08 14:56:28 -04:00
propTypes: {
items: React.PropTypes.array
},
getDefaultProps: function () {
return {
items: require('./carousel.json'),
showRemixes: false,
showLoves: false
2015-09-08 14:56:28 -04:00
};
},
render: function () {
var settings = this.props.settings || {};
defaults(settings, {
dots: false,
infinite: false,
lazyLoad: true,
slidesToShow: 5,
slidesToScroll: 5,
variableWidth: true
});
var arrows = this.props.items.length > settings.slidesToShow;
2015-09-08 14:56:28 -04:00
return (
<Slider className={'carousel ' + this.props.className} arrows={arrows} {... settings}>
2015-09-10 15:00:07 -04:00
{this.props.items.map(function (item) {
var href = '';
switch (item.type) {
case 'gallery':
href = '/studio/' + item.id + '/';
break;
case 'project':
href = '/projects/' + item.id + '/';
break;
default:
href = '/' + item.type + '/' + item.id + '/';
}
2015-09-08 14:56:28 -04:00
return (
<Thumbnail key={item.id}
showLoves={this.props.showLoves}
showRemixes={this.props.showRemixes}
type={item.type}
href={href}
2015-09-08 14:56:28 -04:00
title={item.title}
src={item.thumbnail_url}
creator={item.creator}
remixes={item.remixers_count}
loves={item.love_count} />
2015-09-08 14:56:28 -04:00
);
}.bind(this))}
2015-09-08 14:56:28 -04:00
</Slider>
);
}
});
module.exports = Carousel;