@@ -11,7 +11,7 @@ import useConfigInject from '../config-provider/hooks/useConfigInject';
11
11
import { useInjectFormItemContext } from '../form/FormItemContext' ;
12
12
import omit from '../_util/omit' ;
13
13
import type { FocusEventHandler } from '../_util/EventInterface' ;
14
-
14
+ import useStyle from './style' ;
15
15
export const SwitchSizes = tuple ( 'small' , 'default' ) ;
16
16
type CheckedType = boolean | string | number ;
17
17
export const switchProps = ( ) => ( {
@@ -89,6 +89,7 @@ const Switch = defineComponent({
89
89
) ;
90
90
91
91
const { prefixCls, direction, size } = useConfigInject ( 'switch' , props ) ;
92
+ const [ wrapSSR , hashId ] = useStyle ( prefixCls ) ;
92
93
const refSwitchNode = ref ( ) ;
93
94
const focus = ( ) => {
94
95
refSwitchNode . value ?. focus ( ) ;
@@ -148,47 +149,52 @@ const Switch = defineComponent({
148
149
[ `${ prefixCls . value } -disabled` ] : props . disabled ,
149
150
[ prefixCls . value ] : true ,
150
151
[ `${ prefixCls . value } -rtl` ] : direction . value === 'rtl' ,
152
+ [ hashId . value ] : true ,
151
153
} ) ) ;
152
154
153
- return ( ) => (
154
- < Wave insertExtraNode >
155
- < button
156
- { ...omit ( props , [
157
- 'prefixCls' ,
158
- 'checkedChildren' ,
159
- 'unCheckedChildren' ,
160
- 'checked' ,
161
- 'autofocus' ,
162
- 'checkedValue' ,
163
- 'unCheckedValue' ,
164
- 'id' ,
165
- 'onChange' ,
166
- 'onUpdate:checked' ,
167
- ] ) }
168
- { ...attrs }
169
- id = { props . id ?? formItemContext . id . value }
170
- onKeydown = { handleKeyDown }
171
- onClick = { handleClick }
172
- onBlur = { handleBlur }
173
- onMouseup = { handleMouseUp }
174
- type = "button"
175
- role = "switch"
176
- aria-checked = { checked . value as any }
177
- disabled = { props . disabled || props . loading }
178
- class = { [ attrs . class , classNames . value ] }
179
- ref = { refSwitchNode }
180
- >
181
- < div class = { `${ prefixCls . value } -handle` } >
182
- { props . loading ? < LoadingOutlined class = { `${ prefixCls . value } -loading-icon` } /> : null }
183
- </ div >
184
- < span class = { `${ prefixCls . value } -inner` } >
185
- { checkedStatus . value
186
- ? getPropsSlot ( slots , props , 'checkedChildren' )
187
- : getPropsSlot ( slots , props , 'unCheckedChildren' ) }
188
- </ span >
189
- </ button >
190
- </ Wave >
191
- ) ;
155
+ return ( ) =>
156
+ wrapSSR (
157
+ < Wave insertExtraNode >
158
+ < button
159
+ { ...omit ( props , [
160
+ 'prefixCls' ,
161
+ 'checkedChildren' ,
162
+ 'unCheckedChildren' ,
163
+ 'checked' ,
164
+ 'autofocus' ,
165
+ 'checkedValue' ,
166
+ 'unCheckedValue' ,
167
+ 'id' ,
168
+ 'onChange' ,
169
+ 'onUpdate:checked' ,
170
+ ] ) }
171
+ { ...attrs }
172
+ id = { props . id ?? formItemContext . id . value }
173
+ onKeydown = { handleKeyDown }
174
+ onClick = { handleClick }
175
+ onBlur = { handleBlur }
176
+ onMouseup = { handleMouseUp }
177
+ type = "button"
178
+ role = "switch"
179
+ aria-checked = { checked . value as any }
180
+ disabled = { props . disabled || props . loading }
181
+ class = { [ attrs . class , classNames . value ] }
182
+ ref = { refSwitchNode }
183
+ >
184
+ < div class = { `${ prefixCls . value } -handle` } >
185
+ { props . loading ? < LoadingOutlined class = { `${ prefixCls . value } -loading-icon` } /> : null }
186
+ </ div >
187
+ < span class = { `${ prefixCls . value } -inner` } >
188
+ < span class = { `${ prefixCls . value } -inner-checked` } >
189
+ { getPropsSlot ( slots , props , 'checkedChildren' ) }
190
+ </ span >
191
+ < span class = { `${ prefixCls . value } -inner-unchecked` } >
192
+ { getPropsSlot ( slots , props , 'unCheckedChildren' ) }
193
+ </ span >
194
+ </ span >
195
+ </ button >
196
+ </ Wave > ,
197
+ ) ;
192
198
} ,
193
199
} ) ;
194
200
0 commit comments