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