Content.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.default = void 0;
  5. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  6. var _utils = require("../utils");
  7. var _touch = require("../mixins/touch");
  8. var _createNamespace = (0, _utils.createNamespace)('tabs'),
  9. createComponent = _createNamespace[0],
  10. bem = _createNamespace[1];
  11. var MIN_SWIPE_DISTANCE = 50;
  12. var _default = createComponent({
  13. mixins: [_touch.TouchMixin],
  14. props: {
  15. count: Number,
  16. duration: [Number, String],
  17. animated: Boolean,
  18. swipeable: Boolean,
  19. currentIndex: Number
  20. },
  21. computed: {
  22. style: function style() {
  23. if (this.animated) {
  24. return {
  25. transform: "translate3d(" + -1 * this.currentIndex * 100 + "%, 0, 0)",
  26. transitionDuration: this.duration + "s"
  27. };
  28. }
  29. },
  30. listeners: function listeners() {
  31. if (this.swipeable) {
  32. return {
  33. touchstart: this.touchStart,
  34. touchmove: this.touchMove,
  35. touchend: this.onTouchEnd,
  36. touchcancel: this.onTouchEnd
  37. };
  38. }
  39. }
  40. },
  41. methods: {
  42. // watch swipe touch end
  43. onTouchEnd: function onTouchEnd() {
  44. var direction = this.direction,
  45. deltaX = this.deltaX,
  46. currentIndex = this.currentIndex;
  47. /* istanbul ignore else */
  48. if (direction === 'horizontal' && this.offsetX >= MIN_SWIPE_DISTANCE) {
  49. /* istanbul ignore else */
  50. if (deltaX > 0 && currentIndex !== 0) {
  51. this.$emit('change', currentIndex - 1);
  52. } else if (deltaX < 0 && currentIndex !== this.count - 1) {
  53. this.$emit('change', currentIndex + 1);
  54. }
  55. }
  56. },
  57. genChildren: function genChildren() {
  58. var h = this.$createElement;
  59. if (this.animated) {
  60. return h("div", {
  61. "class": bem('track'),
  62. "style": this.style
  63. }, [this.slots()]);
  64. }
  65. return this.slots();
  66. }
  67. },
  68. render: function render() {
  69. var h = arguments[0];
  70. return h("div", {
  71. "class": bem('content', {
  72. animated: this.animated
  73. }),
  74. "on": (0, _extends2.default)({}, this.listeners)
  75. }, [this.genChildren()]);
  76. }
  77. });
  78. exports.default = _default;