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
80
81
82
83
84
85
86
87
88
89
90
|
<script lang="ts">
import VueIcon from '@/components/icon/VueIcon.vue';
import {Component, Emit, Prop, Vue, Watch} from 'vue-property-decorator';
@Component({
components: {
VueIcon,
}
})
export default class VueButton extends Vue {
name = 'VueButton';
isDisabledFake = false;
@Prop({type: Boolean, default: false}) isDisabled!: boolean;
@Prop({type: Boolean, default: false}) isLoading!: boolean;
@Prop({
type: String,
default: 'normal',
validator(colorType) {
return ['normal', 'primary', 'warning', 'danger', 'info', 'success', 'attention']
.indexOf(colorType) > -1;
}
}) colorType!: string;
@Prop({type: String, default: 'button'}) theme!: 'button' | 'link' | 'text';
@Prop({type: String, default: 'normal'}) size!: 'small' | 'normal' | 'big';
@Prop({type: String, default: ''}) icon!: 'settings' | 'loading' | 'right' |
'left' | 'download' | 'arrow-down' | 'thumbs-up' | '';
@Prop({
type: String,
default: 'left',
validator(userValue) {
return userValue === 'left' || userValue === 'right';
}
}) iconPosition!: string;
get loadingStatus() {
// return this.isLoading ? this.isLoading : (!!this.icon && !this.isLoading);
return this.isLoading || (!!this.icon && !this.isLoading);
}
get loadingName() {
return this.isLoading ? 'loading' : this.icon;
}
get classes() {
return {
'vue-button': 'vue-button',
'is-disabled': this.isDisabled,
'is-disabled-fake': this.isDisabledFake,
'activeHover': !this.isDisabled,
[`icon-${this.iconPosition}`]: true,
[`vue-button-${this.colorType}`]: true,
[`vue-button-theme-${this.theme}`]: true,
[`vue-button-size-${this.size}`]: true,
};
}
@Watch('isLoading')
onIsLoadingChange(val: boolean) {
this.isDisabledFake = val;
}
@Emit('click')
clickLoading(/*e: MouseEvent*/) {
return /*e.target.value*/;
}
}
</script>
<template>
<div class="vue-button-wrapper">
<button :class="classes"
:colorType="colorType"
:disabled="isDisabled"
:theme="theme"
@click="clickLoading"
type="button">
<VueIcon v-if="loadingStatus"
class="vue-svg"
:icon-name="loadingName"
:scale="1"
:class="{loading: isLoading && !isDisabled,
[`vue-button-size-${this.size}`]: true}"/>
<div class="content">
<slot></slot>
</div>
</button>
</div>
</template>
|