1
- import type { ExtractPropTypes , PropType } from 'vue' ;
1
+ import type { ExtractPropTypes } from 'vue' ;
2
2
import { computed , defineComponent , ref } from 'vue' ;
3
3
import PropTypes from '../_util/vue-types' ;
4
4
import VcCheckbox from '../vc-checkbox/Checkbox' ;
@@ -9,31 +9,36 @@ import { FormItemInputContext, useInjectFormItemContext } from '../form/FormItem
9
9
import omit from '../_util/omit' ;
10
10
import type { FocusEventHandler , MouseEventHandler } from '../_util/EventInterface' ;
11
11
import { useInjectRadioGroupContext , useInjectRadioOptionTypeContext } from './context' ;
12
+ import { booleanType , functionType } from '../_util/type' ;
13
+
14
+ // CSSINJS
15
+ import useStyle from './style' ;
12
16
13
17
export const radioProps = ( ) => ( {
14
18
prefixCls : String ,
15
- checked : { type : Boolean , default : undefined } ,
16
- disabled : { type : Boolean , default : undefined } ,
17
- isGroup : { type : Boolean , default : undefined } ,
19
+ checked : booleanType ( ) ,
20
+ disabled : booleanType ( ) ,
21
+ isGroup : booleanType ( ) ,
18
22
value : PropTypes . any ,
19
23
name : String ,
20
24
id : String ,
21
- autofocus : { type : Boolean , default : undefined } ,
22
- onChange : Function as PropType < ( event : RadioChangeEvent ) => void > ,
23
- onFocus : Function as PropType < FocusEventHandler > ,
24
- onBlur : Function as PropType < FocusEventHandler > ,
25
- onClick : Function as PropType < MouseEventHandler > ,
26
- 'onUpdate:checked' : Function as PropType < ( checked : boolean ) => void > ,
27
- 'onUpdate:value' : Function as PropType < ( checked : boolean ) => void > ,
25
+ autofocus : booleanType ( ) ,
26
+ onChange : functionType < ( event : RadioChangeEvent ) => void > ( ) ,
27
+ onFocus : functionType < FocusEventHandler > ( ) ,
28
+ onBlur : functionType < FocusEventHandler > ( ) ,
29
+ onClick : functionType < MouseEventHandler > ( ) ,
30
+ 'onUpdate:checked' : functionType < ( checked : boolean ) => void > ( ) ,
31
+ 'onUpdate:value' : functionType < ( checked : boolean ) => void > ( ) ,
28
32
} ) ;
29
33
30
34
export type RadioProps = Partial < ExtractPropTypes < ReturnType < typeof radioProps > > > ;
31
35
32
36
export default defineComponent ( {
33
37
compatConfig : { MODE : 3 } ,
34
38
name : 'ARadio' ,
39
+ inheritAttrs : false ,
35
40
props : radioProps ( ) ,
36
- setup ( props , { emit, expose, slots } ) {
41
+ setup ( props , { emit, expose, slots, attrs } ) {
37
42
const formItemContext = useInjectFormItemContext ( ) ;
38
43
const formItemInputContext = FormItemInputContext . useInject ( ) ;
39
44
const radioOptionTypeContext = useInjectRadioOptionTypeContext ( ) ;
@@ -42,10 +47,14 @@ export default defineComponent({
42
47
43
48
const { prefixCls : radioPrefixCls , direction } = useConfigInject ( 'radio' , props ) ;
44
49
const prefixCls = computed ( ( ) =>
45
- ( radioGroupContext ?. optionType . value || radioOptionTypeContext ) === 'button'
50
+ radioGroupContext ?. optionType . value === 'button' || radioOptionTypeContext === 'button'
46
51
? `${ radioPrefixCls . value } -button`
47
52
: radioPrefixCls . value ,
48
53
) ;
54
+
55
+ // Style
56
+ const [ wrapSSR , hashId ] = useStyle ( radioPrefixCls ) ;
57
+
49
58
const focus = ( ) => {
50
59
vcCheckbox . value . focus ( ) ;
51
60
} ;
@@ -89,19 +98,23 @@ export default defineComponent({
89
98
} else {
90
99
rProps . onChange = handleChange ;
91
100
}
92
- const wrapperClassString = classNames ( {
93
- [ `${ prefixCls . value } -wrapper` ] : true ,
94
- [ `${ prefixCls . value } -wrapper-checked` ] : rProps . checked ,
95
- [ `${ prefixCls . value } -wrapper-disabled` ] : rProps . disabled ,
96
- [ `${ prefixCls . value } -wrapper-rtl` ] : direction . value === 'rtl' ,
97
- [ `${ prefixCls . value } -wrapper-in-form-item` ] : formItemInputContext . isFormItemInput ,
98
- } ) ;
101
+ const wrapperClassString = classNames (
102
+ {
103
+ [ `${ prefixCls . value } -wrapper` ] : true ,
104
+ [ `${ prefixCls . value } -wrapper-checked` ] : rProps . checked ,
105
+ [ `${ prefixCls . value } -wrapper-disabled` ] : rProps . disabled ,
106
+ [ `${ prefixCls . value } -wrapper-rtl` ] : direction . value === 'rtl' ,
107
+ [ `${ prefixCls . value } -wrapper-in-form-item` ] : formItemInputContext . isFormItemInput ,
108
+ } ,
109
+ attrs . class ,
110
+ hashId . value ,
111
+ ) ;
99
112
100
- return (
101
- < label class = { wrapperClassString } >
113
+ return wrapSSR (
114
+ < label { ... attrs } class = { wrapperClassString } >
102
115
< VcCheckbox { ...rProps } type = "radio" ref = { vcCheckbox } />
103
116
{ slots . default && < span > { slots . default ( ) } </ span > }
104
- </ label >
117
+ </ label > ,
105
118
) ;
106
119
} ;
107
120
} ,
0 commit comments