2018-03-20 19:06:04 +08:00
|
|
|
import PropTypes from '../_util/vue-types'
|
2018-09-05 21:28:54 +08:00
|
|
|
import VcCheckbox from '../vc-checkbox'
|
|
|
|
import classNames from 'classnames'
|
|
|
|
import { getOptionProps, getAttrs } from '../_util/props-util'
|
|
|
|
|
|
|
|
function noop () {}
|
|
|
|
|
2017-10-27 14:04:48 +08:00
|
|
|
export default {
|
2018-04-08 21:17:20 +08:00
|
|
|
name: 'ARadio',
|
2017-10-27 14:04:48 +08:00
|
|
|
props: {
|
|
|
|
prefixCls: {
|
|
|
|
default: 'ant-radio',
|
|
|
|
type: String,
|
|
|
|
},
|
2017-11-02 12:07:20 +08:00
|
|
|
defaultChecked: Boolean,
|
|
|
|
checked: { type: Boolean, default: undefined },
|
2017-10-27 14:04:48 +08:00
|
|
|
disabled: Boolean,
|
|
|
|
isGroup: Boolean,
|
2018-03-20 19:06:04 +08:00
|
|
|
value: PropTypes.any,
|
2017-10-27 14:04:48 +08:00
|
|
|
name: String,
|
2018-06-01 21:25:16 +08:00
|
|
|
id: String,
|
2018-06-17 16:14:49 +08:00
|
|
|
autoFocus: Boolean,
|
2018-09-05 21:28:54 +08:00
|
|
|
type: PropTypes.string.def('radio'),
|
2017-10-27 14:04:48 +08:00
|
|
|
},
|
|
|
|
model: {
|
|
|
|
prop: 'checked',
|
|
|
|
},
|
2017-11-07 11:58:47 +08:00
|
|
|
inject: {
|
|
|
|
radioGroupContext: { default: undefined },
|
|
|
|
},
|
2017-10-27 14:04:48 +08:00
|
|
|
methods: {
|
|
|
|
handleChange (event) {
|
2017-11-02 12:07:20 +08:00
|
|
|
const targetChecked = event.target.checked
|
2017-11-07 11:58:47 +08:00
|
|
|
this.$emit('input', targetChecked)
|
2018-09-05 21:28:54 +08:00
|
|
|
this.$emit('change', event)
|
2017-10-27 14:04:48 +08:00
|
|
|
},
|
2018-06-17 16:14:49 +08:00
|
|
|
focus () {
|
2018-09-05 21:28:54 +08:00
|
|
|
this.$refs.vcCheckbox.focus()
|
2018-06-17 16:14:49 +08:00
|
|
|
},
|
|
|
|
blur () {
|
2018-09-05 21:28:54 +08:00
|
|
|
this.$refs.vcCheckbox.blur()
|
2017-11-07 11:58:47 +08:00
|
|
|
},
|
2017-11-02 12:07:20 +08:00
|
|
|
},
|
2018-09-05 21:28:54 +08:00
|
|
|
|
2018-03-19 09:43:31 +08:00
|
|
|
render () {
|
2018-09-05 21:28:54 +08:00
|
|
|
const { $slots, $listeners, radioGroupContext: radioGroup } = this
|
|
|
|
const props = getOptionProps(this)
|
|
|
|
const children = $slots.default
|
|
|
|
const { mouseenter = noop, mouseleave = noop, ...restListeners } = $listeners
|
|
|
|
const {
|
|
|
|
prefixCls,
|
|
|
|
...restProps
|
|
|
|
} = props
|
|
|
|
const radioProps = { props: { ...restProps, prefixCls }, on: restListeners, attrs: getAttrs(this) }
|
|
|
|
|
|
|
|
if (radioGroup) {
|
|
|
|
radioProps.props.name = radioGroup.name
|
|
|
|
radioProps.on.change = radioGroup.onRadioChange
|
|
|
|
radioProps.props.checked = props.value === radioGroup.stateValue
|
|
|
|
radioProps.props.disabled = props.disabled || radioGroup.disabled
|
|
|
|
} else {
|
|
|
|
radioProps.on.change = this.handleChange
|
2018-06-17 17:22:26 +08:00
|
|
|
}
|
2018-09-05 21:28:54 +08:00
|
|
|
const wrapperClassString = classNames({
|
2018-06-17 17:46:09 +08:00
|
|
|
[`${prefixCls}-wrapper`]: true,
|
2018-09-05 21:28:54 +08:00
|
|
|
[`${prefixCls}-wrapper-checked`]: radioProps.props.checked,
|
|
|
|
[`${prefixCls}-wrapper-disabled`]: radioProps.props.disabled,
|
|
|
|
})
|
2018-06-17 17:46:09 +08:00
|
|
|
|
2018-03-19 09:43:31 +08:00
|
|
|
return (
|
2018-06-17 16:14:49 +08:00
|
|
|
<label
|
2018-06-17 17:46:09 +08:00
|
|
|
class={wrapperClassString}
|
2018-09-05 21:28:54 +08:00
|
|
|
onMouseenter={mouseenter}
|
|
|
|
onMouseleave={mouseleave}
|
2018-06-17 16:14:49 +08:00
|
|
|
>
|
2018-09-05 21:28:54 +08:00
|
|
|
<VcCheckbox
|
|
|
|
{...radioProps}
|
|
|
|
ref='vcCheckbox'
|
|
|
|
/>
|
|
|
|
{children !== undefined ? <span>{children}</span> : null}
|
2018-03-19 09:43:31 +08:00
|
|
|
</label>
|
|
|
|
)
|
|
|
|
},
|
2017-10-27 14:04:48 +08:00
|
|
|
}
|