Latest repo

This commit is contained in:
Marc
2025-06-02 16:42:16 +00:00
parent 53ddf1a329
commit cde5fae175
27907 changed files with 3875388 additions and 1 deletions

View File

@@ -0,0 +1,200 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fadeAnimationHandler = exports.slideStopSwipingHandler = exports.slideSwipeAnimationHandler = exports.slideAnimationHandler = void 0;
var _react = require("react");
var _CSSTranslate = _interopRequireDefault(require("../../CSSTranslate"));
var _utils = require("./utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/**
* Main animation handler for the default 'sliding' style animation
* @param props
* @param state
*/
var slideAnimationHandler = function slideAnimationHandler(props, state) {
var returnStyles = {};
var selectedItem = state.selectedItem;
var previousItem = selectedItem;
var lastPosition = _react.Children.count(props.children) - 1;
var needClonedSlide = props.infiniteLoop && (selectedItem < 0 || selectedItem > lastPosition); // Handle list position if it needs a clone
if (needClonedSlide) {
if (previousItem < 0) {
if (props.centerMode && props.centerSlidePercentage && props.axis === 'horizontal') {
returnStyles.itemListStyle = (0, _utils.setPosition)(-(lastPosition + 2) * props.centerSlidePercentage - (100 - props.centerSlidePercentage) / 2, props.axis);
} else {
returnStyles.itemListStyle = (0, _utils.setPosition)(-(lastPosition + 2) * 100, props.axis);
}
} else if (previousItem > lastPosition) {
returnStyles.itemListStyle = (0, _utils.setPosition)(0, props.axis);
}
return returnStyles;
}
var currentPosition = (0, _utils.getPosition)(selectedItem, props); // if 3d is available, let's take advantage of the performance of transform
var transformProp = (0, _CSSTranslate.default)(currentPosition, '%', props.axis);
var transitionTime = props.transitionTime + 'ms';
returnStyles.itemListStyle = {
WebkitTransform: transformProp,
msTransform: transformProp,
OTransform: transformProp,
transform: transformProp
};
if (!state.swiping) {
returnStyles.itemListStyle = _objectSpread(_objectSpread({}, returnStyles.itemListStyle), {}, {
WebkitTransitionDuration: transitionTime,
MozTransitionDuration: transitionTime,
OTransitionDuration: transitionTime,
transitionDuration: transitionTime,
msTransitionDuration: transitionTime
});
}
return returnStyles;
};
/**
* Swiping animation handler for the default 'sliding' style animation
* @param delta
* @param props
* @param state
* @param setState
*/
exports.slideAnimationHandler = slideAnimationHandler;
var slideSwipeAnimationHandler = function slideSwipeAnimationHandler(delta, props, state, setState) {
var returnStyles = {};
var isHorizontal = props.axis === 'horizontal';
var childrenLength = _react.Children.count(props.children);
var initialBoundry = 0;
var currentPosition = (0, _utils.getPosition)(state.selectedItem, props);
var finalBoundry = props.infiniteLoop ? (0, _utils.getPosition)(childrenLength - 1, props) - 100 : (0, _utils.getPosition)(childrenLength - 1, props);
var axisDelta = isHorizontal ? delta.x : delta.y;
var handledDelta = axisDelta; // prevent user from swiping left out of boundaries
if (currentPosition === initialBoundry && axisDelta > 0) {
handledDelta = 0;
} // prevent user from swiping right out of boundaries
if (currentPosition === finalBoundry && axisDelta < 0) {
handledDelta = 0;
}
var position = currentPosition + 100 / (state.itemSize / handledDelta);
var hasMoved = Math.abs(axisDelta) > props.swipeScrollTolerance;
if (props.infiniteLoop && hasMoved) {
// When allowing infinite loop, if we slide left from position 0 we reveal the cloned last slide that appears before it
// if we slide even further we need to jump to other side so it can continue - and vice versa for the last slide
if (state.selectedItem === 0 && position > -100) {
position -= childrenLength * 100;
} else if (state.selectedItem === childrenLength - 1 && position < -childrenLength * 100) {
position += childrenLength * 100;
}
}
if (!props.preventMovementUntilSwipeScrollTolerance || hasMoved || state.swipeMovementStarted) {
if (!state.swipeMovementStarted) {
setState({
swipeMovementStarted: true
});
}
returnStyles.itemListStyle = (0, _utils.setPosition)(position, props.axis);
} //allows scroll if the swipe was within the tolerance
if (hasMoved && !state.cancelClick) {
setState({
cancelClick: true
});
}
return returnStyles;
};
/**
* Default 'sliding' style animination handler for when a swipe action stops.
* @param props
* @param state
*/
exports.slideSwipeAnimationHandler = slideSwipeAnimationHandler;
var slideStopSwipingHandler = function slideStopSwipingHandler(props, state) {
var currentPosition = (0, _utils.getPosition)(state.selectedItem, props);
var itemListStyle = (0, _utils.setPosition)(currentPosition, props.axis);
return {
itemListStyle: itemListStyle
};
};
/**
* Main animation handler for the default 'fade' style animation
* @param props
* @param state
*/
exports.slideStopSwipingHandler = slideStopSwipingHandler;
var fadeAnimationHandler = function fadeAnimationHandler(props, state) {
var transitionTime = props.transitionTime + 'ms';
var transitionTimingFunction = 'ease-in-out';
var slideStyle = {
position: 'absolute',
display: 'block',
zIndex: -2,
minHeight: '100%',
opacity: 0,
top: 0,
right: 0,
left: 0,
bottom: 0,
transitionTimingFunction: transitionTimingFunction,
msTransitionTimingFunction: transitionTimingFunction,
MozTransitionTimingFunction: transitionTimingFunction,
WebkitTransitionTimingFunction: transitionTimingFunction,
OTransitionTimingFunction: transitionTimingFunction
};
if (!state.swiping) {
slideStyle = _objectSpread(_objectSpread({}, slideStyle), {}, {
WebkitTransitionDuration: transitionTime,
MozTransitionDuration: transitionTime,
OTransitionDuration: transitionTime,
transitionDuration: transitionTime,
msTransitionDuration: transitionTime
});
}
return {
slideStyle: slideStyle,
selectedStyle: _objectSpread(_objectSpread({}, slideStyle), {}, {
opacity: 1,
position: 'relative'
}),
prevStyle: _objectSpread({}, slideStyle)
};
};
exports.fadeAnimationHandler = fadeAnimationHandler;

View File

@@ -0,0 +1,830 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactEasySwipe = _interopRequireDefault(require("react-easy-swipe"));
var _cssClasses = _interopRequireDefault(require("../../cssClasses"));
var _Thumbs = _interopRequireDefault(require("../Thumbs"));
var _document = _interopRequireDefault(require("../../shims/document"));
var _window = _interopRequireDefault(require("../../shims/window"));
var _utils = require("./utils");
var _animations = require("./animations");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var Carousel = /*#__PURE__*/function (_React$Component) {
_inherits(Carousel, _React$Component);
var _super = _createSuper(Carousel);
// @ts-ignore
function Carousel(props) {
var _this;
_classCallCheck(this, Carousel);
_this = _super.call(this, props);
_defineProperty(_assertThisInitialized(_this), "thumbsRef", void 0);
_defineProperty(_assertThisInitialized(_this), "carouselWrapperRef", void 0);
_defineProperty(_assertThisInitialized(_this), "listRef", void 0);
_defineProperty(_assertThisInitialized(_this), "itemsRef", void 0);
_defineProperty(_assertThisInitialized(_this), "timer", void 0);
_defineProperty(_assertThisInitialized(_this), "animationHandler", void 0);
_defineProperty(_assertThisInitialized(_this), "setThumbsRef", function (node) {
_this.thumbsRef = node;
});
_defineProperty(_assertThisInitialized(_this), "setCarouselWrapperRef", function (node) {
_this.carouselWrapperRef = node;
});
_defineProperty(_assertThisInitialized(_this), "setListRef", function (node) {
_this.listRef = node;
});
_defineProperty(_assertThisInitialized(_this), "setItemsRef", function (node, index) {
if (!_this.itemsRef) {
_this.itemsRef = [];
}
_this.itemsRef[index] = node;
});
_defineProperty(_assertThisInitialized(_this), "autoPlay", function () {
if (_react.Children.count(_this.props.children) <= 1) {
return;
}
_this.clearAutoPlay();
if (!_this.props.autoPlay) {
return;
}
_this.timer = setTimeout(function () {
_this.increment();
}, _this.props.interval);
});
_defineProperty(_assertThisInitialized(_this), "clearAutoPlay", function () {
if (_this.timer) clearTimeout(_this.timer);
});
_defineProperty(_assertThisInitialized(_this), "resetAutoPlay", function () {
_this.clearAutoPlay();
_this.autoPlay();
});
_defineProperty(_assertThisInitialized(_this), "stopOnHover", function () {
_this.setState({
isMouseEntered: true
}, _this.clearAutoPlay);
});
_defineProperty(_assertThisInitialized(_this), "startOnLeave", function () {
_this.setState({
isMouseEntered: false
}, _this.autoPlay);
});
_defineProperty(_assertThisInitialized(_this), "isFocusWithinTheCarousel", function () {
if (!_this.carouselWrapperRef) {
return false;
}
if ((0, _document.default)().activeElement === _this.carouselWrapperRef || _this.carouselWrapperRef.contains((0, _document.default)().activeElement)) {
return true;
}
return false;
});
_defineProperty(_assertThisInitialized(_this), "navigateWithKeyboard", function (e) {
if (!_this.isFocusWithinTheCarousel()) {
return;
}
var axis = _this.props.axis;
var isHorizontal = axis === 'horizontal';
var keyNames = {
ArrowUp: 38,
ArrowRight: 39,
ArrowDown: 40,
ArrowLeft: 37
};
var nextKey = isHorizontal ? keyNames.ArrowRight : keyNames.ArrowDown;
var prevKey = isHorizontal ? keyNames.ArrowLeft : keyNames.ArrowUp;
if (nextKey === e.keyCode) {
_this.increment();
} else if (prevKey === e.keyCode) {
_this.decrement();
}
});
_defineProperty(_assertThisInitialized(_this), "updateSizes", function () {
if (!_this.state.initialized || !_this.itemsRef || _this.itemsRef.length === 0) {
return;
}
var isHorizontal = _this.props.axis === 'horizontal';
var firstItem = _this.itemsRef[0];
if (!firstItem) {
return;
}
var itemSize = isHorizontal ? firstItem.clientWidth : firstItem.clientHeight;
_this.setState({
itemSize: itemSize
});
if (_this.thumbsRef) {
_this.thumbsRef.updateSizes();
}
});
_defineProperty(_assertThisInitialized(_this), "setMountState", function () {
_this.setState({
hasMount: true
});
_this.updateSizes();
});
_defineProperty(_assertThisInitialized(_this), "handleClickItem", function (index, item) {
if (_react.Children.count(_this.props.children) === 0) {
return;
}
if (_this.state.cancelClick) {
_this.setState({
cancelClick: false
});
return;
}
_this.props.onClickItem(index, item);
if (index !== _this.state.selectedItem) {
_this.setState({
selectedItem: index
});
}
});
_defineProperty(_assertThisInitialized(_this), "handleOnChange", function (index, item) {
if (_react.Children.count(_this.props.children) <= 1) {
return;
}
_this.props.onChange(index, item);
});
_defineProperty(_assertThisInitialized(_this), "handleClickThumb", function (index, item) {
_this.props.onClickThumb(index, item);
_this.moveTo(index);
});
_defineProperty(_assertThisInitialized(_this), "onSwipeStart", function (event) {
_this.setState({
swiping: true
});
_this.props.onSwipeStart(event);
});
_defineProperty(_assertThisInitialized(_this), "onSwipeEnd", function (event) {
_this.setState({
swiping: false,
cancelClick: false,
swipeMovementStarted: false
});
_this.props.onSwipeEnd(event);
_this.clearAutoPlay();
if (_this.state.autoPlay) {
_this.autoPlay();
}
});
_defineProperty(_assertThisInitialized(_this), "onSwipeMove", function (delta, event) {
_this.props.onSwipeMove(event);
var animationHandlerResponse = _this.props.swipeAnimationHandler(delta, _this.props, _this.state, _this.setState.bind(_assertThisInitialized(_this)));
_this.setState(_objectSpread({}, animationHandlerResponse)); // If we have not moved, we should have an empty object returned
// Return false to allow scrolling when not swiping
return !!Object.keys(animationHandlerResponse).length;
});
_defineProperty(_assertThisInitialized(_this), "decrement", function () {
var positions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
_this.moveTo(_this.state.selectedItem - (typeof positions === 'number' ? positions : 1));
});
_defineProperty(_assertThisInitialized(_this), "increment", function () {
var positions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
_this.moveTo(_this.state.selectedItem + (typeof positions === 'number' ? positions : 1));
});
_defineProperty(_assertThisInitialized(_this), "moveTo", function (position) {
if (typeof position !== 'number') {
return;
}
var lastPosition = _react.Children.count(_this.props.children) - 1;
if (position < 0) {
position = _this.props.infiniteLoop ? lastPosition : 0;
}
if (position > lastPosition) {
position = _this.props.infiniteLoop ? 0 : lastPosition;
}
_this.selectItem({
// if it's not a slider, we don't need to set position here
selectedItem: position
}); // don't reset auto play when stop on hover is enabled, doing so will trigger a call to auto play more than once
// and will result in the interval function not being cleared correctly.
if (_this.state.autoPlay && _this.state.isMouseEntered === false) {
_this.resetAutoPlay();
}
});
_defineProperty(_assertThisInitialized(_this), "onClickNext", function () {
_this.increment(1);
});
_defineProperty(_assertThisInitialized(_this), "onClickPrev", function () {
_this.decrement(1);
});
_defineProperty(_assertThisInitialized(_this), "onSwipeForward", function () {
_this.increment(1);
if (_this.props.emulateTouch) {
_this.setState({
cancelClick: true
});
}
});
_defineProperty(_assertThisInitialized(_this), "onSwipeBackwards", function () {
_this.decrement(1);
if (_this.props.emulateTouch) {
_this.setState({
cancelClick: true
});
}
});
_defineProperty(_assertThisInitialized(_this), "changeItem", function (newIndex) {
return function (e) {
if (!(0, _utils.isKeyboardEvent)(e) || e.key === 'Enter') {
_this.moveTo(newIndex);
}
};
});
_defineProperty(_assertThisInitialized(_this), "selectItem", function (state) {
// Merge in the new state while updating updating previous item
_this.setState(_objectSpread({
previousItem: _this.state.selectedItem
}, state), function () {
// Run animation handler and update styles based on it
_this.setState(_this.animationHandler(_this.props, _this.state));
});
_this.handleOnChange(state.selectedItem, _react.Children.toArray(_this.props.children)[state.selectedItem]);
});
_defineProperty(_assertThisInitialized(_this), "getInitialImage", function () {
var selectedItem = _this.props.selectedItem;
var item = _this.itemsRef && _this.itemsRef[selectedItem];
var images = item && item.getElementsByTagName('img') || [];
return images[0];
});
_defineProperty(_assertThisInitialized(_this), "getVariableItemHeight", function (position) {
var item = _this.itemsRef && _this.itemsRef[position];
if (_this.state.hasMount && item && item.children.length) {
var slideImages = item.children[0].getElementsByTagName('img') || [];
if (slideImages.length > 0) {
var image = slideImages[0];
if (!image.complete) {
// if the image is still loading, the size won't be available so we trigger a new render after it's done
var onImageLoad = function onImageLoad() {
_this.forceUpdate();
image.removeEventListener('load', onImageLoad);
};
image.addEventListener('load', onImageLoad);
}
} // try to get img first, if img not there find first display tag
var displayItem = slideImages[0] || item.children[0];
var height = displayItem.clientHeight;
return height > 0 ? height : null;
}
return null;
});
var initState = {
initialized: false,
previousItem: props.selectedItem,
selectedItem: props.selectedItem,
hasMount: false,
isMouseEntered: false,
autoPlay: props.autoPlay,
swiping: false,
swipeMovementStarted: false,
cancelClick: false,
itemSize: 1,
itemListStyle: {},
slideStyle: {},
selectedStyle: {},
prevStyle: {}
};
_this.animationHandler = typeof props.animationHandler === 'function' && props.animationHandler || props.animationHandler === 'fade' && _animations.fadeAnimationHandler || _animations.slideAnimationHandler;
_this.state = _objectSpread(_objectSpread({}, initState), _this.animationHandler(props, initState));
return _this;
}
_createClass(Carousel, [{
key: "componentDidMount",
value: function componentDidMount() {
if (!this.props.children) {
return;
}
this.setupCarousel();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps, prevState) {
if (!prevProps.children && this.props.children && !this.state.initialized) {
this.setupCarousel();
}
if (!prevProps.autoFocus && this.props.autoFocus) {
this.forceFocus();
}
if (prevState.swiping && !this.state.swiping) {
// We stopped swiping, ensure we are heading to the new/current slide and not stuck
this.setState(_objectSpread({}, this.props.stopSwipingHandler(this.props, this.state)));
}
if (prevProps.selectedItem !== this.props.selectedItem || prevProps.centerMode !== this.props.centerMode) {
this.updateSizes();
this.moveTo(this.props.selectedItem);
}
if (prevProps.autoPlay !== this.props.autoPlay) {
if (this.props.autoPlay) {
this.setupAutoPlay();
} else {
this.destroyAutoPlay();
}
this.setState({
autoPlay: this.props.autoPlay
});
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.destroyCarousel();
}
}, {
key: "setupCarousel",
value: function setupCarousel() {
var _this2 = this;
this.bindEvents();
if (this.state.autoPlay && _react.Children.count(this.props.children) > 1) {
this.setupAutoPlay();
}
if (this.props.autoFocus) {
this.forceFocus();
}
this.setState({
initialized: true
}, function () {
var initialImage = _this2.getInitialImage();
if (initialImage && !initialImage.complete) {
// if it's a carousel of images, we set the mount state after the first image is loaded
initialImage.addEventListener('load', _this2.setMountState);
} else {
_this2.setMountState();
}
});
}
}, {
key: "destroyCarousel",
value: function destroyCarousel() {
if (this.state.initialized) {
this.unbindEvents();
this.destroyAutoPlay();
}
}
}, {
key: "setupAutoPlay",
value: function setupAutoPlay() {
this.autoPlay();
var carouselWrapper = this.carouselWrapperRef;
if (this.props.stopOnHover && carouselWrapper) {
carouselWrapper.addEventListener('mouseenter', this.stopOnHover);
carouselWrapper.addEventListener('mouseleave', this.startOnLeave);
}
}
}, {
key: "destroyAutoPlay",
value: function destroyAutoPlay() {
this.clearAutoPlay();
var carouselWrapper = this.carouselWrapperRef;
if (this.props.stopOnHover && carouselWrapper) {
carouselWrapper.removeEventListener('mouseenter', this.stopOnHover);
carouselWrapper.removeEventListener('mouseleave', this.startOnLeave);
}
}
}, {
key: "bindEvents",
value: function bindEvents() {
// as the widths are calculated, we need to resize
// the carousel when the window is resized
(0, _window.default)().addEventListener('resize', this.updateSizes); // issue #2 - image loading smaller
(0, _window.default)().addEventListener('DOMContentLoaded', this.updateSizes);
if (this.props.useKeyboardArrows) {
(0, _document.default)().addEventListener('keydown', this.navigateWithKeyboard);
}
}
}, {
key: "unbindEvents",
value: function unbindEvents() {
// removing listeners
(0, _window.default)().removeEventListener('resize', this.updateSizes);
(0, _window.default)().removeEventListener('DOMContentLoaded', this.updateSizes);
var initialImage = this.getInitialImage();
if (initialImage) {
initialImage.removeEventListener('load', this.setMountState);
}
if (this.props.useKeyboardArrows) {
(0, _document.default)().removeEventListener('keydown', this.navigateWithKeyboard);
}
}
}, {
key: "forceFocus",
value: function forceFocus() {
var _this$carouselWrapper;
(_this$carouselWrapper = this.carouselWrapperRef) === null || _this$carouselWrapper === void 0 ? void 0 : _this$carouselWrapper.focus();
}
}, {
key: "renderItems",
value: function renderItems(isClone) {
var _this3 = this;
if (!this.props.children) {
return [];
}
return _react.Children.map(this.props.children, function (item, index) {
var isSelected = index === _this3.state.selectedItem;
var isPrevious = index === _this3.state.previousItem;
var style = isSelected && _this3.state.selectedStyle || isPrevious && _this3.state.prevStyle || _this3.state.slideStyle || {};
if (_this3.props.centerMode && _this3.props.axis === 'horizontal') {
style = _objectSpread(_objectSpread({}, style), {}, {
minWidth: _this3.props.centerSlidePercentage + '%'
});
}
if (_this3.state.swiping && _this3.state.swipeMovementStarted) {
style = _objectSpread(_objectSpread({}, style), {}, {
pointerEvents: 'none'
});
}
var slideProps = {
ref: function ref(e) {
return _this3.setItemsRef(e, index);
},
key: 'itemKey' + index + (isClone ? 'clone' : ''),
className: _cssClasses.default.ITEM(true, index === _this3.state.selectedItem, index === _this3.state.previousItem),
onClick: _this3.handleClickItem.bind(_this3, index, item),
style: style
};
return /*#__PURE__*/_react.default.createElement("li", slideProps, _this3.props.renderItem(item, {
isSelected: index === _this3.state.selectedItem,
isPrevious: index === _this3.state.previousItem
}));
});
}
}, {
key: "renderControls",
value: function renderControls() {
var _this4 = this;
var _this$props = this.props,
showIndicators = _this$props.showIndicators,
labels = _this$props.labels,
renderIndicator = _this$props.renderIndicator,
children = _this$props.children;
if (!showIndicators) {
return null;
}
return /*#__PURE__*/_react.default.createElement("ul", {
className: "control-dots"
}, _react.Children.map(children, function (_, index) {
return renderIndicator && renderIndicator(_this4.changeItem(index), index === _this4.state.selectedItem, index, labels.item);
}));
}
}, {
key: "renderStatus",
value: function renderStatus() {
if (!this.props.showStatus) {
return null;
}
return /*#__PURE__*/_react.default.createElement("p", {
className: "carousel-status"
}, this.props.statusFormatter(this.state.selectedItem + 1, _react.Children.count(this.props.children)));
}
}, {
key: "renderThumbs",
value: function renderThumbs() {
if (!this.props.showThumbs || !this.props.children || _react.Children.count(this.props.children) === 0) {
return null;
}
return /*#__PURE__*/_react.default.createElement(_Thumbs.default, {
ref: this.setThumbsRef,
onSelectItem: this.handleClickThumb,
selectedItem: this.state.selectedItem,
transitionTime: this.props.transitionTime,
thumbWidth: this.props.thumbWidth,
labels: this.props.labels,
emulateTouch: this.props.emulateTouch
}, this.props.renderThumbs(this.props.children));
}
}, {
key: "render",
value: function render() {
var _this5 = this;
if (!this.props.children || _react.Children.count(this.props.children) === 0) {
return null;
}
var isSwipeable = this.props.swipeable && _react.Children.count(this.props.children) > 1;
var isHorizontal = this.props.axis === 'horizontal';
var canShowArrows = this.props.showArrows && _react.Children.count(this.props.children) > 1; // show left arrow?
var hasPrev = canShowArrows && (this.state.selectedItem > 0 || this.props.infiniteLoop) || false; // show right arrow
var hasNext = canShowArrows && (this.state.selectedItem < _react.Children.count(this.props.children) - 1 || this.props.infiniteLoop) || false;
var itemsClone = this.renderItems(true);
var firstClone = itemsClone.shift();
var lastClone = itemsClone.pop();
var swiperProps = {
className: _cssClasses.default.SLIDER(true, this.state.swiping),
onSwipeMove: this.onSwipeMove,
onSwipeStart: this.onSwipeStart,
onSwipeEnd: this.onSwipeEnd,
style: this.state.itemListStyle,
tolerance: this.props.swipeScrollTolerance
};
var containerStyles = {};
if (isHorizontal) {
swiperProps.onSwipeLeft = this.onSwipeForward;
swiperProps.onSwipeRight = this.onSwipeBackwards;
if (this.props.dynamicHeight) {
var itemHeight = this.getVariableItemHeight(this.state.selectedItem); // swiperProps.style.height = itemHeight || 'auto';
containerStyles.height = itemHeight || 'auto';
}
} else {
swiperProps.onSwipeUp = this.props.verticalSwipe === 'natural' ? this.onSwipeBackwards : this.onSwipeForward;
swiperProps.onSwipeDown = this.props.verticalSwipe === 'natural' ? this.onSwipeForward : this.onSwipeBackwards;
swiperProps.style = _objectSpread(_objectSpread({}, swiperProps.style), {}, {
height: this.state.itemSize
});
containerStyles.height = this.state.itemSize;
}
return /*#__PURE__*/_react.default.createElement("div", {
"aria-label": this.props.ariaLabel,
className: _cssClasses.default.ROOT(this.props.className),
ref: this.setCarouselWrapperRef,
tabIndex: this.props.useKeyboardArrows ? 0 : undefined
}, /*#__PURE__*/_react.default.createElement("div", {
className: _cssClasses.default.CAROUSEL(true),
style: {
width: this.props.width
}
}, this.renderControls(), this.props.renderArrowPrev(this.onClickPrev, hasPrev, this.props.labels.leftArrow), /*#__PURE__*/_react.default.createElement("div", {
className: _cssClasses.default.WRAPPER(true, this.props.axis),
style: containerStyles
}, isSwipeable ? /*#__PURE__*/_react.default.createElement(_reactEasySwipe.default, _extends({
tagName: "ul",
innerRef: this.setListRef
}, swiperProps, {
allowMouseEvents: this.props.emulateTouch
}), this.props.infiniteLoop && lastClone, this.renderItems(), this.props.infiniteLoop && firstClone) : /*#__PURE__*/_react.default.createElement("ul", {
className: _cssClasses.default.SLIDER(true, this.state.swiping),
ref: function ref(node) {
return _this5.setListRef(node);
},
style: this.state.itemListStyle || {}
}, this.props.infiniteLoop && lastClone, this.renderItems(), this.props.infiniteLoop && firstClone)), this.props.renderArrowNext(this.onClickNext, hasNext, this.props.labels.rightArrow), this.renderStatus()), this.renderThumbs());
}
}]);
return Carousel;
}(_react.default.Component);
exports.default = Carousel;
_defineProperty(Carousel, "displayName", 'Carousel');
_defineProperty(Carousel, "defaultProps", {
ariaLabel: undefined,
axis: 'horizontal',
centerSlidePercentage: 80,
interval: 3000,
labels: {
leftArrow: 'previous slide / item',
rightArrow: 'next slide / item',
item: 'slide item'
},
onClickItem: _utils.noop,
onClickThumb: _utils.noop,
onChange: _utils.noop,
onSwipeStart: function onSwipeStart() {},
onSwipeEnd: function onSwipeEnd() {},
onSwipeMove: function onSwipeMove() {
return false;
},
preventMovementUntilSwipeScrollTolerance: false,
renderArrowPrev: function renderArrowPrev(onClickHandler, hasPrev, label) {
return /*#__PURE__*/_react.default.createElement("button", {
type: "button",
"aria-label": label,
className: _cssClasses.default.ARROW_PREV(!hasPrev),
onClick: onClickHandler
});
},
renderArrowNext: function renderArrowNext(onClickHandler, hasNext, label) {
return /*#__PURE__*/_react.default.createElement("button", {
type: "button",
"aria-label": label,
className: _cssClasses.default.ARROW_NEXT(!hasNext),
onClick: onClickHandler
});
},
renderIndicator: function renderIndicator(onClickHandler, isSelected, index, label) {
return /*#__PURE__*/_react.default.createElement("li", {
className: _cssClasses.default.DOT(isSelected),
onClick: onClickHandler,
onKeyDown: onClickHandler,
value: index,
key: index,
role: "button",
tabIndex: 0,
"aria-label": "".concat(label, " ").concat(index + 1)
});
},
renderItem: function renderItem(item) {
return item;
},
renderThumbs: function renderThumbs(children) {
var images = _react.Children.map(children, function (item) {
var img = item; // if the item is not an image, try to find the first image in the item's children.
if (item.type !== 'img') {
img = _react.Children.toArray(item.props.children).find(function (children) {
return children.type === 'img';
});
}
if (!img) {
return undefined;
}
return img;
});
if (images.filter(function (image) {
return image;
}).length === 0) {
console.warn("No images found! Can't build the thumb list without images. If you don't need thumbs, set showThumbs={false} in the Carousel. Note that it's not possible to get images rendered inside custom components. More info at https://github.com/leandrowd/react-responsive-carousel/blob/master/TROUBLESHOOTING.md");
return [];
}
return images;
},
statusFormatter: _utils.defaultStatusFormatter,
selectedItem: 0,
showArrows: true,
showIndicators: true,
showStatus: true,
showThumbs: true,
stopOnHover: true,
swipeScrollTolerance: 5,
swipeable: true,
transitionTime: 350,
verticalSwipe: 'standard',
width: '100%',
animationHandler: 'slide',
swipeAnimationHandler: _animations.slideSwipeAnimationHandler,
stopSwipingHandler: _animations.slideStopSwipingHandler
});

View File

@@ -0,0 +1 @@
"use strict";

View File

@@ -0,0 +1,80 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.setPosition = exports.getPosition = exports.isKeyboardEvent = exports.defaultStatusFormatter = exports.noop = void 0;
var _react = require("react");
var _CSSTranslate = _interopRequireDefault(require("../../CSSTranslate"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var noop = function noop() {};
exports.noop = noop;
var defaultStatusFormatter = function defaultStatusFormatter(current, total) {
return "".concat(current, " of ").concat(total);
};
exports.defaultStatusFormatter = defaultStatusFormatter;
var isKeyboardEvent = function isKeyboardEvent(e) {
return e ? e.hasOwnProperty('key') : false;
};
/**
* Gets the list 'position' relative to a current index
* @param index
*/
exports.isKeyboardEvent = isKeyboardEvent;
var getPosition = function getPosition(index, props) {
if (props.infiniteLoop) {
// index has to be added by 1 because of the first cloned slide
++index;
}
if (index === 0) {
return 0;
}
var childrenLength = _react.Children.count(props.children);
if (props.centerMode && props.axis === 'horizontal') {
var currentPosition = -index * props.centerSlidePercentage;
var lastPosition = childrenLength - 1;
if (index && (index !== lastPosition || props.infiniteLoop)) {
currentPosition += (100 - props.centerSlidePercentage) / 2;
} else if (index === lastPosition) {
currentPosition += 100 - props.centerSlidePercentage;
}
return currentPosition;
}
return -index * 100;
};
/**
* Sets the 'position' transform for sliding animations
* @param position
* @param forceReflow
*/
exports.getPosition = getPosition;
var setPosition = function setPosition(position, axis) {
var style = {};
['WebkitTransform', 'MozTransform', 'MsTransform', 'OTransform', 'transform', 'msTransform'].forEach(function (prop) {
// @ts-ignore
style[prop] = (0, _CSSTranslate.default)(position, '%', axis);
});
return style;
};
exports.setPosition = setPosition;

View File

@@ -0,0 +1,385 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _cssClasses = _interopRequireDefault(require("../cssClasses"));
var _dimensions = require("../dimensions");
var _CSSTranslate = _interopRequireDefault(require("../CSSTranslate"));
var _reactEasySwipe = _interopRequireDefault(require("react-easy-swipe"));
var _window = _interopRequireDefault(require("../shims/window"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var isKeyboardEvent = function isKeyboardEvent(e) {
return e.hasOwnProperty('key');
};
var Thumbs = /*#__PURE__*/function (_Component) {
_inherits(Thumbs, _Component);
var _super = _createSuper(Thumbs);
function Thumbs(_props) {
var _this;
_classCallCheck(this, Thumbs);
_this = _super.call(this, _props);
_defineProperty(_assertThisInitialized(_this), "itemsWrapperRef", void 0);
_defineProperty(_assertThisInitialized(_this), "itemsListRef", void 0);
_defineProperty(_assertThisInitialized(_this), "thumbsRef", void 0);
_defineProperty(_assertThisInitialized(_this), "setItemsWrapperRef", function (node) {
_this.itemsWrapperRef = node;
});
_defineProperty(_assertThisInitialized(_this), "setItemsListRef", function (node) {
_this.itemsListRef = node;
});
_defineProperty(_assertThisInitialized(_this), "setThumbsRef", function (node, index) {
if (!_this.thumbsRef) {
_this.thumbsRef = [];
}
_this.thumbsRef[index] = node;
});
_defineProperty(_assertThisInitialized(_this), "updateSizes", function () {
if (!_this.props.children || !_this.itemsWrapperRef || !_this.thumbsRef) {
return;
}
var total = _react.Children.count(_this.props.children);
var wrapperSize = _this.itemsWrapperRef.clientWidth;
var itemSize = _this.props.thumbWidth ? _this.props.thumbWidth : (0, _dimensions.outerWidth)(_this.thumbsRef[0]);
var visibleItems = Math.floor(wrapperSize / itemSize);
var showArrows = visibleItems < total;
var lastPosition = showArrows ? total - visibleItems : 0;
_this.setState(function (_state, props) {
return {
itemSize: itemSize,
visibleItems: visibleItems,
firstItem: showArrows ? _this.getFirstItem(props.selectedItem) : 0,
lastPosition: lastPosition,
showArrows: showArrows
};
});
});
_defineProperty(_assertThisInitialized(_this), "handleClickItem", function (index, item, e) {
if (!isKeyboardEvent(e) || e.key === 'Enter') {
var handler = _this.props.onSelectItem;
if (typeof handler === 'function') {
handler(index, item);
}
}
});
_defineProperty(_assertThisInitialized(_this), "onSwipeStart", function () {
_this.setState({
swiping: true
});
});
_defineProperty(_assertThisInitialized(_this), "onSwipeEnd", function () {
_this.setState({
swiping: false
});
});
_defineProperty(_assertThisInitialized(_this), "onSwipeMove", function (delta) {
var deltaX = delta.x;
if (!_this.state.itemSize || !_this.itemsWrapperRef || !_this.state.visibleItems) {
return false;
}
var leftBoundary = 0;
var childrenLength = _react.Children.count(_this.props.children);
var currentPosition = -(_this.state.firstItem * 100) / _this.state.visibleItems;
var lastLeftItem = Math.max(childrenLength - _this.state.visibleItems, 0);
var lastLeftBoundary = -lastLeftItem * 100 / _this.state.visibleItems; // prevent user from swiping left out of boundaries
if (currentPosition === leftBoundary && deltaX > 0) {
deltaX = 0;
} // prevent user from swiping right out of boundaries
if (currentPosition === lastLeftBoundary && deltaX < 0) {
deltaX = 0;
}
var wrapperSize = _this.itemsWrapperRef.clientWidth;
var position = currentPosition + 100 / (wrapperSize / deltaX); // if 3d isn't available we will use left to move
if (_this.itemsListRef) {
['WebkitTransform', 'MozTransform', 'MsTransform', 'OTransform', 'transform', 'msTransform'].forEach(function (prop) {
_this.itemsListRef.style[prop] = (0, _CSSTranslate.default)(position, '%', _this.props.axis);
});
}
return true;
});
_defineProperty(_assertThisInitialized(_this), "slideRight", function (positions) {
_this.moveTo(_this.state.firstItem - (typeof positions === 'number' ? positions : 1));
});
_defineProperty(_assertThisInitialized(_this), "slideLeft", function (positions) {
_this.moveTo(_this.state.firstItem + (typeof positions === 'number' ? positions : 1));
});
_defineProperty(_assertThisInitialized(_this), "moveTo", function (position) {
// position can't be lower than 0
position = position < 0 ? 0 : position; // position can't be higher than last postion
position = position >= _this.state.lastPosition ? _this.state.lastPosition : position;
_this.setState({
firstItem: position
});
});
_this.state = {
selectedItem: _props.selectedItem,
swiping: false,
showArrows: false,
firstItem: 0,
visibleItems: 0,
lastPosition: 0
};
return _this;
}
_createClass(Thumbs, [{
key: "componentDidMount",
value: function componentDidMount() {
this.setupThumbs();
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (this.props.selectedItem !== this.state.selectedItem) {
this.setState({
selectedItem: this.props.selectedItem,
firstItem: this.getFirstItem(this.props.selectedItem)
});
}
if (this.props.children === prevProps.children) {
return;
} // This will capture any size changes for arrow adjustments etc.
// usually in the same render cycle so we don't see any flickers
this.updateSizes();
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
this.destroyThumbs();
}
}, {
key: "setupThumbs",
value: function setupThumbs() {
// as the widths are calculated, we need to resize
// the carousel when the window is resized
(0, _window.default)().addEventListener('resize', this.updateSizes); // issue #2 - image loading smaller
(0, _window.default)().addEventListener('DOMContentLoaded', this.updateSizes); // when the component is rendered we need to calculate
// the container size to adjust the responsive behaviour
this.updateSizes();
}
}, {
key: "destroyThumbs",
value: function destroyThumbs() {
// removing listeners
(0, _window.default)().removeEventListener('resize', this.updateSizes);
(0, _window.default)().removeEventListener('DOMContentLoaded', this.updateSizes);
}
}, {
key: "getFirstItem",
value: function getFirstItem(selectedItem) {
var firstItem = selectedItem;
if (selectedItem >= this.state.lastPosition) {
firstItem = this.state.lastPosition;
}
if (selectedItem < this.state.firstItem + this.state.visibleItems) {
firstItem = this.state.firstItem;
}
if (selectedItem < this.state.firstItem) {
firstItem = selectedItem;
}
return firstItem;
}
}, {
key: "renderItems",
value: function renderItems() {
var _this2 = this;
return this.props.children.map(function (img, index) {
var itemClass = _cssClasses.default.ITEM(false, index === _this2.state.selectedItem);
var thumbProps = {
key: index,
ref: function ref(e) {
return _this2.setThumbsRef(e, index);
},
className: itemClass,
onClick: _this2.handleClickItem.bind(_this2, index, _this2.props.children[index]),
onKeyDown: _this2.handleClickItem.bind(_this2, index, _this2.props.children[index]),
'aria-label': "".concat(_this2.props.labels.item, " ").concat(index + 1),
style: {
width: _this2.props.thumbWidth
}
};
return /*#__PURE__*/_react.default.createElement("li", _extends({}, thumbProps, {
role: "button",
tabIndex: 0
}), img);
});
}
}, {
key: "render",
value: function render() {
var _this3 = this;
if (!this.props.children) {
return null;
}
var isSwipeable = _react.Children.count(this.props.children) > 1; // show left arrow?
var hasPrev = this.state.showArrows && this.state.firstItem > 0; // show right arrow
var hasNext = this.state.showArrows && this.state.firstItem < this.state.lastPosition; // obj to hold the transformations and styles
var itemListStyles = {};
var currentPosition = -this.state.firstItem * (this.state.itemSize || 0);
var transformProp = (0, _CSSTranslate.default)(currentPosition, 'px', this.props.axis);
var transitionTime = this.props.transitionTime + 'ms';
itemListStyles = {
WebkitTransform: transformProp,
MozTransform: transformProp,
MsTransform: transformProp,
OTransform: transformProp,
transform: transformProp,
msTransform: transformProp,
WebkitTransitionDuration: transitionTime,
MozTransitionDuration: transitionTime,
MsTransitionDuration: transitionTime,
OTransitionDuration: transitionTime,
transitionDuration: transitionTime,
msTransitionDuration: transitionTime
};
return /*#__PURE__*/_react.default.createElement("div", {
className: _cssClasses.default.CAROUSEL(false)
}, /*#__PURE__*/_react.default.createElement("div", {
className: _cssClasses.default.WRAPPER(false),
ref: this.setItemsWrapperRef
}, /*#__PURE__*/_react.default.createElement("button", {
type: "button",
className: _cssClasses.default.ARROW_PREV(!hasPrev),
onClick: function onClick() {
return _this3.slideRight();
},
"aria-label": this.props.labels.leftArrow
}), isSwipeable ? /*#__PURE__*/_react.default.createElement(_reactEasySwipe.default, {
tagName: "ul",
className: _cssClasses.default.SLIDER(false, this.state.swiping),
onSwipeLeft: this.slideLeft,
onSwipeRight: this.slideRight,
onSwipeMove: this.onSwipeMove,
onSwipeStart: this.onSwipeStart,
onSwipeEnd: this.onSwipeEnd,
style: itemListStyles,
innerRef: this.setItemsListRef,
allowMouseEvents: this.props.emulateTouch
}, this.renderItems()) : /*#__PURE__*/_react.default.createElement("ul", {
className: _cssClasses.default.SLIDER(false, this.state.swiping),
ref: function ref(node) {
return _this3.setItemsListRef(node);
},
style: itemListStyles
}, this.renderItems()), /*#__PURE__*/_react.default.createElement("button", {
type: "button",
className: _cssClasses.default.ARROW_NEXT(!hasNext),
onClick: function onClick() {
return _this3.slideLeft();
},
"aria-label": this.props.labels.rightArrow
})));
}
}]);
return Thumbs;
}(_react.Component);
exports.default = Thumbs;
_defineProperty(Thumbs, "displayName", 'Thumbs');
_defineProperty(Thumbs, "defaultProps", {
axis: 'horizontal',
labels: {
leftArrow: 'previous slide / item',
rightArrow: 'next slide / item',
item: 'slide item'
},
selectedItem: 0,
thumbWidth: 80,
transitionTime: 350
});