forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContent.js
More file actions
79 lines (69 loc) · 1.72 KB
/
Content.js
File metadata and controls
79 lines (69 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { createNamespace } from '../utils';
import { TouchMixin } from '../mixins/touch';
const [createComponent, bem] = createNamespace('tabs');
const MIN_SWIPE_DISTANCE = 50;
export default createComponent({
mixins: [TouchMixin],
props: {
count: Number,
duration: Number,
animated: Boolean,
swipeable: Boolean,
currentIndex: Number
},
computed: {
style() {
if (this.animated) {
return {
transform: `translate3d(${-1 * this.currentIndex * 100}%, 0, 0)`,
transitionDuration: `${this.duration}s`
};
}
},
listeners() {
if (this.swipeable) {
return {
touchstart: this.touchStart,
touchmove: this.touchMove,
touchend: this.onTouchEnd,
touchcancel: this.onTouchEnd
};
}
}
},
methods: {
// watch swipe touch end
onTouchEnd() {
const { direction, deltaX, currentIndex } = this;
/* istanbul ignore else */
if (direction === 'horizontal' && this.offsetX >= MIN_SWIPE_DISTANCE) {
/* istanbul ignore else */
if (deltaX > 0 && currentIndex !== 0) {
this.$emit('change', currentIndex - 1);
} else if (deltaX < 0 && currentIndex !== this.count - 1) {
this.$emit('change', currentIndex + 1);
}
}
},
genChildren() {
if (this.animated) {
return (
<div class={bem('track')} style={this.style}>
{this.slots()}
</div>
);
}
return this.slots();
}
},
render() {
return (
<div
class={bem('content', { animated: this.animated })}
{...{ on: this.listeners }}
>
{this.genChildren()}
</div>
);
}
});