2017-07-20 13:47:14 -04:00
|
|
|
// This component handles json returned via proxy from a django server,
|
|
|
|
// or directly from a django server, and the model structure that system
|
|
|
|
// has.
|
2018-01-30 11:53:12 -05:00
|
|
|
const classNames = require('classnames');
|
|
|
|
const defaults = require('lodash.defaults');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const React = require('react');
|
|
|
|
const Slider = require('react-slick');
|
2017-07-20 13:47:14 -04:00
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
const Thumbnail = require('../thumbnail/thumbnail.jsx');
|
2017-07-20 13:47:14 -04:00
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
const frameless = require('../../lib/frameless.js');
|
2017-07-20 13:47:14 -04:00
|
|
|
|
|
|
|
require('slick-carousel/slick/slick.scss');
|
|
|
|
require('slick-carousel/slick/slick-theme.scss');
|
|
|
|
require('./carousel.scss');
|
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
const Carousel = props => {
|
|
|
|
defaults(props.settings, {
|
|
|
|
centerMode: false,
|
|
|
|
dots: false,
|
|
|
|
infinite: false,
|
|
|
|
lazyLoad: true,
|
|
|
|
slidesToShow: 5,
|
|
|
|
slidesToScroll: 5,
|
|
|
|
variableWidth: true,
|
|
|
|
responsive: [
|
|
|
|
{
|
|
|
|
breakpoint: frameless.mobile,
|
|
|
|
settings: {
|
2017-07-20 13:47:14 -04:00
|
|
|
arrows: true,
|
|
|
|
slidesToScroll: 1,
|
|
|
|
slidesToShow: 1,
|
|
|
|
centerMode: true
|
2018-01-30 11:53:12 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
breakpoint: frameless.tablet,
|
|
|
|
settings: {
|
2017-07-20 13:47:14 -04:00
|
|
|
slidesToScroll: 2,
|
|
|
|
slidesToShow: 2
|
2018-01-30 11:53:12 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
breakpoint: frameless.desktop,
|
|
|
|
settings: {
|
2017-07-20 13:47:14 -04:00
|
|
|
slidesToScroll: 4,
|
|
|
|
slidesToShow: 4
|
2018-01-30 11:53:12 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
const arrows = props.items.length > props.settings.slidesToShow;
|
|
|
|
return (
|
|
|
|
<Slider
|
|
|
|
arrows={arrows}
|
|
|
|
className={classNames('carousel', props.className)}
|
|
|
|
{... props.settings}
|
|
|
|
>
|
|
|
|
{props.items.map(item => {
|
|
|
|
let href = '';
|
|
|
|
switch (item.type) {
|
|
|
|
case 'gallery':
|
|
|
|
href = `/studios/${item.id}/`;
|
|
|
|
break;
|
|
|
|
case 'project':
|
|
|
|
href = `/projects/${item.id}/`;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
href = `/${item.type}/${item.id}/`;
|
|
|
|
}
|
2017-07-20 13:47:14 -04:00
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
return (
|
|
|
|
<Thumbnail
|
|
|
|
creator={item.creator}
|
|
|
|
href={href}
|
|
|
|
key={[props.type, item.id].join('.')}
|
|
|
|
loves={item.love_count}
|
|
|
|
remixes={item.remixers_count}
|
|
|
|
showLoves={props.showLoves}
|
|
|
|
showRemixes={props.showRemixes}
|
|
|
|
src={item.thumbnail_url}
|
|
|
|
title={item.title}
|
|
|
|
type={item.type}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</Slider>
|
|
|
|
);
|
|
|
|
};
|
2017-07-20 13:47:14 -04:00
|
|
|
|
2018-01-30 11:53:12 -05:00
|
|
|
Carousel.propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
items: PropTypes.arrayOf(PropTypes.any),
|
|
|
|
settings: PropTypes.shape({
|
|
|
|
centerMode: PropTypes.bool,
|
|
|
|
dots: PropTypes.bool,
|
|
|
|
infinite: PropTypes.bool,
|
|
|
|
lazyLoad: PropTypes.bool,
|
|
|
|
slidesToShow: PropTypes.number,
|
|
|
|
slidesToScroll: PropTypes.number,
|
|
|
|
variableWidth: PropTypes.bool,
|
|
|
|
responsive: PropTypes.array
|
|
|
|
}),
|
|
|
|
showLoves: PropTypes.bool,
|
|
|
|
showRemixes: PropTypes.bool,
|
|
|
|
type: PropTypes.string
|
|
|
|
};
|
|
|
|
|
|
|
|
Carousel.defaultProps = {
|
|
|
|
items: require('./carousel.json'),
|
|
|
|
settings: {},
|
|
|
|
showRemixes: false,
|
|
|
|
showLoves: false,
|
|
|
|
type: 'project'
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Carousel;
|