forked from youzan/vant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTitle.js
More file actions
76 lines (66 loc) · 1.54 KB
/
Title.js
File metadata and controls
76 lines (66 loc) · 1.54 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
import { createNamespace } from '../utils';
const [createComponent, bem] = createNamespace('tab');
export default createComponent({
props: {
type: String,
color: String,
title: String,
isActive: Boolean,
ellipsis: Boolean,
disabled: Boolean,
scrollable: Boolean,
activeColor: String,
inactiveColor: String,
swipeThreshold: Number
},
computed: {
style() {
const style = {};
const { color, isActive } = this;
const isCard = this.type === 'card';
// card theme color
if (color && isCard) {
style.borderColor = color;
if (!this.disabled) {
if (isActive) {
style.backgroundColor = color;
} else {
style.color = color;
}
}
}
const titleColor = isActive ? this.activeColor : this.inactiveColor;
if (titleColor) {
style.color = titleColor;
}
if (this.scrollable && this.ellipsis) {
style.flexBasis = `${88 / this.swipeThreshold}%`;
}
return style;
}
},
methods: {
onClick() {
this.$emit('click');
}
},
render() {
return (
<div
role="tab"
aria-selected={this.isActive}
class={bem({
active: this.isActive,
disabled: this.disabled,
complete: !this.ellipsis
})}
style={this.style}
onClick={this.onClick}
>
<span class={{ 'van-ellipsis': this.ellipsis }}>
{this.slots() || this.title}
</span>
</div>
);
}
});