ant-design-vue/components/switch/index.jsx

60 lines
1.5 KiB
React
Raw Normal View History

2018-03-19 02:16:27 +00:00
2018-02-27 04:14:29 +00:00
import PropTypes from '../_util/vue-types'
2018-02-27 07:28:30 +00:00
import { getOptionProps, getComponentFromProp } from '../_util/props-util'
2018-02-27 04:14:29 +00:00
import VcSwitch from '../vc-switch'
export default {
name: 'vSwitch',
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 () {
2018-02-27 07:28:30 +00:00
this.$refs.refSwitchNode.focus()
2018-02-27 04:14:29 +00:00
},
blur () {
2018-02-27 07:28:30 +00:00
this.$refs.refSwitchNode.blur()
2018-02-27 04:14:29 +00:00
},
},
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}
>
2018-02-27 07:28:30 +00:00
<template slot='checkedChildren'>{getComponentFromProp(this, 'checkedChildren')}</template>
<template slot='unCheckedChildren'>{getComponentFromProp(this, 'unCheckedChildren')}</template>
2018-02-27 04:14:29 +00:00
</VcSwitch>
)
},
}
2018-03-19 02:16:27 +00:00