-
+
+
+
@@ -19,6 +20,14 @@
type: Boolean,
default: false
},
+ checkable: {
+ type: Boolean,
+ default: false
+ },
+ checked: {
+ type: Boolean,
+ default: true
+ },
color: {
validator (value) {
return oneOf(value, ['blue', 'green', 'red', 'yellow', 'default']);
@@ -33,14 +42,20 @@
type: [String, Number]
}
},
+ data () {
+ return {
+ isChecked: this.checked
+ };
+ },
computed: {
classes () {
return [
`${prefixCls}`,
{
- [`${prefixCls}-${this.color}`]: !!this.color,
+ [`${prefixCls}-${this.color}`]: !!this.color && (this.checkable && this.isChecked),
[`${prefixCls}-${this.type}`]: !!this.type,
- [`${prefixCls}-closable`]: this.closable
+ [`${prefixCls}-closable`]: this.closable,
+ [`${prefixCls}-checkable`]: this.checkable
}
];
},
@@ -56,10 +71,17 @@
},
methods: {
close (event) {
+ this._emitAction(event, 'on-close');
+ },
+ check (event) {
+ this.isChecked = !this.isChecked;
+ this._emitAction(event, 'on-check');
+ },
+ _emitAction (event, action) {
if (this.name === undefined) {
- this.$emit('on-close', event);
+ this.$emit(action, event);
} else {
- this.$emit('on-close', event, this.name);
+ this.$emit(action, event, this.name);
}
}
}