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

96 lines
3.2 KiB
React
Raw Normal View History

2018-01-30 09:54:45 -05:00
var classNames = require('classnames');
var defaults = require('lodash.defaults');
var React = require('react');
var Slider = require('react-slick');
2018-01-30 09:54:45 -05:00
var Thumbnail = require('../thumbnail/thumbnail.jsx');
2015-09-08 14:56:28 -04:00
2018-01-30 09:54:45 -05:00
var frameless = require('../../lib/frameless.js');
2015-09-08 14:56:28 -04:00
require('slick-carousel/slick/slick.scss');
require('slick-carousel/slick/slick-theme.scss');
require('./carousel.scss');
2018-01-30 09:54:45 -05:00
/**
* Displays content in horizontal scrolling box. Example usage: splash page rows.
*/
var Carousel = React.createClass({
type: 'Carousel',
propTypes: {
items: React.PropTypes.array
},
getDefaultProps: function () {
return {
items: require('./carousel.json'),
showRemixes: false,
showLoves: false,
type: 'project'
};
},
render: function () {
var settings = this.props.settings || {};
defaults(settings, {
centerMode: false,
dots: false,
infinite: false,
lazyLoad: true,
slidesToShow: 5,
slidesToScroll: 5,
variableWidth: true,
responsive: [
{breakpoint: frameless.mobile, settings: {
2016-07-21 10:12:16 -04:00
arrows: true,
slidesToScroll: 1,
slidesToShow: 1,
centerMode: true
2018-01-30 09:54:45 -05:00
}},
{breakpoint: frameless.tablet, settings: {
2016-07-21 10:12:16 -04:00
slidesToScroll: 2,
slidesToShow: 2
2018-01-30 09:54:45 -05:00
}},
{breakpoint: frameless.desktop, settings: {
2016-07-21 10:12:16 -04:00
slidesToScroll: 4,
slidesToShow: 4
2018-01-30 09:54:45 -05:00
}}
]
});
var arrows = this.props.items.length > settings.slidesToShow;
var classes = classNames(
'carousel',
this.props.className
);
return (
<Slider className={classes} arrows={arrows} {... settings}>
{this.props.items.map(function (item) {
var href = '';
switch (this.props.type) {
case 'gallery':
href = '/studios/' + item.id + '/';
break;
case 'project':
href = '/projects/' + item.id + '/';
break;
default:
href = '/' + item.type + '/' + item.id + '/';
}
2018-01-30 09:54:45 -05:00
return (
<Thumbnail key={[this.key, item.id].join('.')}
showLoves={this.props.showLoves}
showRemixes={this.props.showRemixes}
type={this.props.type}
href={href}
title={item.title}
src={item.image}
creator={item.author.username}
remixes={item.stats.remixes}
loves={item.stats.loves} />
);
}.bind(this))}
</Slider>
);
}
});
module.exports = Carousel;