choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
135 lines (114 loc) • 3.78 kB
JavaScript
import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import React, { Component } from 'react';
import debounce from 'lodash/debounce';
import classNames from 'classnames';
import { matchMediaPolifill } from '../_util/mediaQueryListPolyfill';
import ConfigContext from '../config-provider/ConfigContext'; // matchMedia polyfill for
// https://github.com/WickyNilliams/enquire.js/issues/82
if (typeof window !== 'undefined') {
// const matchMediaPolyfill = (mediaQuery: string): MediaQueryList => {
// return {
// media: mediaQuery,
// matches: false,
// addListener() {
// },
// removeListener() {
// },
// };
// };
window.matchMedia = window.matchMedia || matchMediaPolifill;
} // Use require over import (will be lifted up)
// make sure matchMedia polyfill run before require('react-slick')
// eslint-disable-next-line @typescript-eslint/no-var-requires
var SlickCarousel = require('react-slick')["default"];
var Carousel = /*#__PURE__*/function (_Component) {
_inherits(Carousel, _Component);
var _super = _createSuper(Carousel);
function Carousel() {
var _this;
_classCallCheck(this, Carousel);
_this = _super.apply(this, arguments);
_this.onWindowResized = debounce(function () {
var autoplay = _this.props.autoplay;
if (autoplay && _this.slick && _this.slick.innerSlider && _this.slick.innerSlider.autoPlay) {
_this.slick.innerSlider.autoPlay();
}
}, 500, {
leading: false
});
_this.saveSlick = function (node) {
_this.slick = node;
};
return _this;
}
_createClass(Carousel, [{
key: "componentDidMount",
value: function componentDidMount() {
var autoplay = this.props.autoplay;
if (autoplay) {
window.addEventListener('resize', this.onWindowResized);
}
this.innerSlider = this.slick && this.slick.innerSlider;
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
var autoplay = this.props.autoplay;
if (autoplay) {
window.removeEventListener('resize', this.onWindowResized);
this.onWindowResized.cancel();
}
}
}, {
key: "next",
value: function next() {
this.slick.slickNext();
}
}, {
key: "prev",
value: function prev() {
this.slick.slickPrev();
}
}, {
key: "goTo",
value: function goTo(slide) {
this.slick.slickGoTo(slide);
}
}, {
key: "render",
value: function render() {
var getPrefixCls = this.context.getPrefixCls;
var props = _objectSpread({}, this.props);
if (props.effect === 'fade') {
props.fade = true;
}
var prefixCls = getPrefixCls('carousel', props.prefixCls);
var className = classNames(prefixCls, _defineProperty({}, "".concat(prefixCls, "-vertical"), props.vertical));
return /*#__PURE__*/React.createElement("div", {
className: className
}, /*#__PURE__*/React.createElement(SlickCarousel, _extends({
ref: this.saveSlick
}, props)));
}
}], [{
key: "contextType",
get: function get() {
return ConfigContext;
}
}]);
return Carousel;
}(Component);
export { Carousel as default };
Carousel.displayName = 'Carousel';
Carousel.defaultProps = {
dots: true,
arrows: false,
draggable: false
};
//# sourceMappingURL=index.js.map