You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/checkbox/Checkbox.vue

97 lines
2.1 KiB

7 years ago
<template>
<label :class="classes">
<span :class="checkboxClass">
<input :name="name" type="checkbox" :disabled="disabled"
7 years ago
:class="`${prefixCls}-input`" :checked="stateChecked"
7 years ago
@change="handleChange"
/>
<span :class="`${prefixCls}-inner`" />
</span>
<span v-if="hasDefaultSlot">
<slot></slot>
</span>
</label>
</template>
<script>
export default {
name: 'Checkbox',
props: {
prefixCls: {
default: 'ant-checkbox',
type: String,
},
7 years ago
defaultChecked: Boolean,
checked: { type: Boolean, default: undefined },
7 years ago
disabled: Boolean,
isGroup: Boolean,
value: [String, Number, Boolean],
name: String,
indeterminate: Boolean,
onGroupChange: Function,
},
model: {
prop: 'checked',
},
7 years ago
data () {
const { checked, defaultChecked } = this
return {
stateChecked: checked === undefined ? defaultChecked : checked,
}
},
7 years ago
computed: {
hasDefaultSlot () {
return !!this.$slots.default
},
classes () {
const { prefixCls } = this
return {
[`${prefixCls}-wrapper`]: true,
}
},
checkboxClass () {
7 years ago
const { prefixCls, indeterminate, stateChecked, disabled } = this
7 years ago
return {
[`${prefixCls}`]: true,
7 years ago
[`${prefixCls}-checked`]: stateChecked,
7 years ago
[`${prefixCls}-disabled`]: disabled,
[`${prefixCls}-indeterminate`]: indeterminate,
}
},
},
mounted () {
},
methods: {
handleChange (event) {
7 years ago
const targetChecked = event.target.checked
this.$emit('input', targetChecked)
const { name, value, checked } = this
if (checked === undefined) {
this.stateChecked = targetChecked
}
7 years ago
const target = {
name,
value,
7 years ago
checked: targetChecked,
7 years ago
}
this.$emit('change', {
target,
stopPropagation () {
event.stopPropagation()
},
preventDefault () {
event.preventDefault()
},
})
if (this.isGroup) {
this.onGroupChange({ target })
}
},
},
7 years ago
watch: {
checked (val) {
this.stateChecked = val
},
},
7 years ago
}
</script>