Skip to content

Commit

Permalink
chore: update nuka-carousel to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Liang committed Dec 12, 2018
1 parent d271f39 commit a0e47ee
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 167 deletions.
87 changes: 49 additions & 38 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"mocha": "^5.2.0",
"moment": "^2.20.1",
"node-sass": "^4.9.4",
"nuka-carousel": "github:Adslot/nuka-carousel#3c7154d9331b0d54eddfd00fe4ff18fd9432ede7",
"nuka-carousel": "^4.4.3",
"null-loader": "^0.1.1",
"object-assign": "^4.1.1",
"postcss-loader": "^2.1.0",
Expand Down
59 changes: 17 additions & 42 deletions src/components/adslot-ui/Carousel/index.jsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,25 @@
import _ from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Carousel from 'nuka-carousel';

require('./styles.scss');
import './styles.scss';

const baseClass = 'carousel-component';
const navigationDelay = 600;
const decoratorStyles = {
bottom: 0,
width: '30px',
};

export const getPrevDecorator = () => {
let previousSlideThrottled;
const component = ({ previousSlide }) => {
if (!previousSlideThrottled) {
previousSlideThrottled = _.throttle(previousSlide, navigationDelay);
}
return <button className={`${baseClass}-prev`} onClick={previousSlideThrottled} />;
};
component.propTypes = { previousSlide: PropTypes.func.isRequired };

return {
component,
position: 'TopLeft',
style: decoratorStyles,
};
};

export const getNextDecorator = () => {
let nextSlideThrottled;
const component = ({ nextSlide }) => {
if (!nextSlideThrottled) {
nextSlideThrottled = _.throttle(nextSlide, navigationDelay);
}
return <button className={`${baseClass}-next`} onClick={nextSlideThrottled} />;
};
component.propTypes = { nextSlide: PropTypes.func.isRequired };
export const PrevButton = ({ previousSlide }) => <button className={`${baseClass}-prev`} onClick={previousSlide} />;

return {
component,
position: 'TopRight',
style: decoratorStyles,
};
};
export const NextButton = ({ nextSlide }) => <button className={`${baseClass}-next`} onClick={nextSlide} />;

const CarouselComponent = props => {
const { className, children } = props;
const decorators = [getPrevDecorator(), getNextDecorator()];

return (
<Carousel decorators={decorators} {...props} className={classNames(baseClass, className)}>
<Carousel
{...props}
renderCenterLeftControls={PrevButton}
renderCenterRightControls={NextButton}
className={classNames(baseClass, className)}
>
{children}
</Carousel>
);
Expand All @@ -63,6 +30,14 @@ CarouselComponent.propTypes = {
children: PropTypes.node,
};

PrevButton.propTypes = {
previousSlide: PropTypes.func.isRequired,
};

NextButton.propTypes = {
nextSlide: PropTypes.func.isRequired,
};

// See Nuka Carousel docs for other options:
// https://github.com/FormidableLabs/nuka-carousel
CarouselComponent.defaultProps = {
Expand Down
Loading

0 comments on commit a0e47ee

Please sign in to comment.