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/switch/index.jsx

60 lines
1.5 KiB

import PropTypes from '../_util/vue-types'
7 years ago
import { getOptionProps, getComponentFromProp } from '../_util/props-util'
import VcSwitch from '../vc-switch'
export default {
name: 'ASwitch',
model: {
prop: 'checked',
event: 'change',
},
props: {
prefixCls: PropTypes.string.def('ant-switch'),
// size=default and size=large are the same
size: PropTypes.oneOf(['small', 'default', 'large']),
disabled: PropTypes.bool,
checkedChildren: PropTypes.any,
unCheckedChildren: PropTypes.any,
tabIndex: PropTypes.number,
checked: PropTypes.bool,
defaultChecked: PropTypes.bool,
autoFocus: PropTypes.bool,
loading: PropTypes.bool,
},
methods: {
focus () {
7 years ago
this.$refs.refSwitchNode.focus()
},
blur () {
7 years ago
this.$refs.refSwitchNode.blur()
},
},
render () {
const { prefixCls, size, loading, ...restProps } = getOptionProps(this)
const classes = {
[`${prefixCls}-small`]: size === 'small',
[`${prefixCls}-loading`]: loading,
}
const switchProps = {
props: {
...restProps,
prefixCls,
},
on: this.$listeners,
class: classes,
ref: 'refSwitchNode',
}
return (
<VcSwitch
{...switchProps}
>
7 years ago
<template slot='checkedChildren'>{getComponentFromProp(this, 'checkedChildren')}</template>
<template slot='unCheckedChildren'>{getComponentFromProp(this, 'unCheckedChildren')}</template>
</VcSwitch>
)
},
}