Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. "use strict";
  2. var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
  3. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  4. exports.__esModule = true;
  5. exports.default = void 0;
  6. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  7. var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
  8. var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
  9. var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
  10. var _react = _interopRequireWildcard(require("react"));
  11. var _propTypes = _interopRequireDefault(require("prop-types"));
  12. var _Carousel = _interopRequireDefault(require("./Carousel"));
  13. var _CarouselItem = _interopRequireDefault(require("./CarouselItem"));
  14. var _CarouselControl = _interopRequireDefault(require("./CarouselControl"));
  15. var _CarouselIndicators = _interopRequireDefault(require("./CarouselIndicators"));
  16. var _CarouselCaption = _interopRequireDefault(require("./CarouselCaption"));
  17. var propTypes = {
  18. items: _propTypes.default.array.isRequired,
  19. indicators: _propTypes.default.bool,
  20. controls: _propTypes.default.bool,
  21. autoPlay: _propTypes.default.bool,
  22. defaultActiveIndex: _propTypes.default.number,
  23. activeIndex: _propTypes.default.number,
  24. next: _propTypes.default.func,
  25. previous: _propTypes.default.func,
  26. goToIndex: _propTypes.default.func
  27. };
  28. var UncontrolledCarousel =
  29. /*#__PURE__*/
  30. function (_Component) {
  31. (0, _inheritsLoose2.default)(UncontrolledCarousel, _Component);
  32. function UncontrolledCarousel(props) {
  33. var _this;
  34. _this = _Component.call(this, props) || this;
  35. _this.animating = false;
  36. _this.state = {
  37. activeIndex: props.defaultActiveIndex || 0
  38. };
  39. _this.next = _this.next.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
  40. _this.previous = _this.previous.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
  41. _this.goToIndex = _this.goToIndex.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
  42. _this.onExiting = _this.onExiting.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
  43. _this.onExited = _this.onExited.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
  44. return _this;
  45. }
  46. var _proto = UncontrolledCarousel.prototype;
  47. _proto.onExiting = function onExiting() {
  48. this.animating = true;
  49. };
  50. _proto.onExited = function onExited() {
  51. this.animating = false;
  52. };
  53. _proto.next = function next() {
  54. if (this.animating) return;
  55. var nextIndex = this.state.activeIndex === this.props.items.length - 1 ? 0 : this.state.activeIndex + 1;
  56. this.setState({
  57. activeIndex: nextIndex
  58. });
  59. };
  60. _proto.previous = function previous() {
  61. if (this.animating) return;
  62. var nextIndex = this.state.activeIndex === 0 ? this.props.items.length - 1 : this.state.activeIndex - 1;
  63. this.setState({
  64. activeIndex: nextIndex
  65. });
  66. };
  67. _proto.goToIndex = function goToIndex(newIndex) {
  68. if (this.animating) return;
  69. this.setState({
  70. activeIndex: newIndex
  71. });
  72. };
  73. _proto.render = function render() {
  74. var _this2 = this;
  75. var _this$props = this.props,
  76. defaultActiveIndex = _this$props.defaultActiveIndex,
  77. autoPlay = _this$props.autoPlay,
  78. indicators = _this$props.indicators,
  79. controls = _this$props.controls,
  80. items = _this$props.items,
  81. goToIndex = _this$props.goToIndex,
  82. props = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["defaultActiveIndex", "autoPlay", "indicators", "controls", "items", "goToIndex"]);
  83. var activeIndex = this.state.activeIndex;
  84. var slides = items.map(function (item) {
  85. return _react.default.createElement(_CarouselItem.default, {
  86. onExiting: _this2.onExiting,
  87. onExited: _this2.onExited,
  88. key: item.src
  89. }, _react.default.createElement("img", {
  90. className: "d-block w-100",
  91. src: item.src,
  92. alt: item.altText
  93. }), _react.default.createElement(_CarouselCaption.default, {
  94. captionText: item.caption,
  95. captionHeader: item.header || item.caption
  96. }));
  97. });
  98. return _react.default.createElement(_Carousel.default, (0, _extends2.default)({
  99. activeIndex: activeIndex,
  100. next: this.next,
  101. previous: this.previous,
  102. ride: autoPlay ? 'carousel' : undefined
  103. }, props), indicators && _react.default.createElement(_CarouselIndicators.default, {
  104. items: items,
  105. activeIndex: props.activeIndex || activeIndex,
  106. onClickHandler: goToIndex || this.goToIndex
  107. }), slides, controls && _react.default.createElement(_CarouselControl.default, {
  108. direction: "prev",
  109. directionText: "Previous",
  110. onClickHandler: props.previous || this.previous
  111. }), controls && _react.default.createElement(_CarouselControl.default, {
  112. direction: "next",
  113. directionText: "Next",
  114. onClickHandler: props.next || this.next
  115. }));
  116. };
  117. return UncontrolledCarousel;
  118. }(_react.Component);
  119. UncontrolledCarousel.propTypes = propTypes;
  120. UncontrolledCarousel.defaultProps = {
  121. controls: true,
  122. indicators: true,
  123. autoPlay: true
  124. };
  125. var _default = UncontrolledCarousel;
  126. exports.default = _default;