ant-design/components/carousel/index.tsx

70 lines
1.6 KiB
TypeScript
Raw Normal View History

2015-11-20 10:57:08 +08:00
// matchMedia polyfill for
// https://github.com/WickyNilliams/enquire.js/issues/82
2016-06-22 13:18:43 +08:00
import assign from 'object-assign';
2015-11-20 10:57:08 +08:00
if (typeof window !== 'undefined') {
2016-08-22 17:26:14 +08:00
const matchMediaPolyfill = function matchMediaPolyfill(mediaQuery: string): MediaQueryList {
2015-11-20 10:57:08 +08:00
return {
2016-08-22 17:26:14 +08:00
media: mediaQuery,
2015-11-20 10:57:08 +08:00
matches: false,
2016-01-05 14:42:06 +08:00
addListener() {
},
removeListener() {
2015-11-20 10:57:08 +08:00
},
};
};
window.matchMedia = window.matchMedia || matchMediaPolyfill;
}
import SlickCarousel from 'react-slick';
2016-09-21 11:54:53 +08:00
import React from 'react';
2015-08-03 14:52:26 +08:00
2016-07-07 20:25:03 +08:00
export type CarouselEffect = 'scrollx' | 'fade'
// Carousel
2016-07-07 20:25:03 +08:00
export interface CarouselProps {
2016-07-13 11:14:24 +08:00
/** 动画效果函数,可取 scrollx, fade */
effect?: CarouselEffect;
/** 是否显示面板指示点 */
2016-08-22 17:26:14 +08:00
dots?: boolean;
2016-07-13 11:14:24 +08:00
/** 垂直显示 */
vertical?: boolean;
/** 是否自动切换 */
autoplay?: boolean;
/** 动画效果 */
easing?: string;
/** 切换面板的回调 */
beforeChange?: (from: number, to: number) => void;
/** 切换面板的回调 */
2016-07-13 17:22:23 +08:00
afterChange?: (current: number) => void;
/** 行内样式 */
2016-07-13 11:14:24 +08:00
style?: React.CSSProperties;
prefixCls?: string;
}
export default class Carousel extends React.Component<CarouselProps, any> {
static defaultProps = {
dots: true,
arrows: false,
prefixCls: 'ant-carousel',
draggable: false,
2016-07-13 11:14:24 +08:00
};
2015-08-03 14:52:26 +08:00
render() {
2016-06-22 13:18:43 +08:00
let props = assign({}, this.props);
2015-08-03 14:52:26 +08:00
if (props.effect === 'fade') {
props.fade = true;
}
let className = props.prefixCls;
2015-08-03 14:52:26 +08:00
if (props.vertical) {
className = `${className} ${className}-vertical`;
2015-08-03 14:52:26 +08:00
}
return (
<div className={className}>
<SlickCarousel ref="slick" {...props} />
2015-08-03 14:52:26 +08:00
</div>
);
}
}