@@ -16,7 +16,6 @@ import {
1616 Styles ,
1717 tasty ,
1818} from '../../../tasty' ;
19- import { Base } from '../../Base' ;
2019import { useFocus } from '../../../utils/react/interactions' ;
2120import { mergeProps } from '../../../utils/react' ;
2221import { HiddenInput } from '../../HiddenInput' ;
@@ -31,14 +30,19 @@ import {
3130 WithNullableSelected ,
3231} from '../../../utils/react/nullableValue' ;
3332
34- const BaseSwitchWrapperElement = tasty ( {
33+ const SwitchWrapperElement = tasty ( {
3534 qa : 'SwitchWrapper' ,
3635 styles : {
3736 position : 'relative' ,
37+ margin : {
38+ '' : 0 ,
39+ 'inside-form & side-label' : '1x top' ,
40+ } ,
3841 } ,
3942} ) ;
4043
41- const SwitchWrapperElement = tasty ( {
44+ const SwitchLabelElement = tasty ( {
45+ as : 'label' ,
4246 qa : 'SwitchWrapper' ,
4347 styles : {
4448 position : 'relative' ,
@@ -73,10 +77,6 @@ const SwitchElement = tasty({
7377 } ,
7478 transition : 'theme' ,
7579 cursor : 'pointer' ,
76- marginTop : {
77- '' : null ,
78- 'inside-form & side-label' : '-3px' ,
79- } ,
8080 placeSelf : {
8181 '' : null ,
8282 'inside-form & side-label' : 'start' ,
@@ -164,32 +164,31 @@ function Switch(props: WithNullableSelected<CubeSwitchProps>, ref) {
164164 // eslint-disable-next-line react-hooks/rules-of-hooks
165165 let { inputProps } = useSwitch ( props , useToggleState ( props ) , inputRef ) ;
166166
167+ const mods = {
168+ 'inside-form' : insideForm ,
169+ 'side-label' : labelPosition === 'side' ,
170+ checked : inputProps . checked ,
171+ disabled : isDisabled ,
172+ hovered : isHovered ,
173+ focused : isFocused ,
174+ } ;
175+
167176 const switchField = (
168- < BaseSwitchWrapperElement qa = { qa || 'Switch' } >
177+ < SwitchWrapperElement qa = { qa || 'Switch' } mods = { mods } >
169178 < HiddenInput
170179 data-qa = "HiddenInput"
171180 { ...mergeProps ( inputProps , focusProps ) }
172181 ref = { inputRef }
173182 />
174- < SwitchElement
175- mods = { {
176- 'inside-form' : insideForm ,
177- 'side-label' : labelPosition === 'side' ,
178- checked : inputProps . checked ,
179- disabled : isDisabled ,
180- hovered : isHovered ,
181- focused : isFocused ,
182- } }
183- styles = { inputStyles }
184- >
183+ < SwitchElement mods = { mods } styles = { inputStyles } >
185184 < SwitchThumbElement
186185 styles = { thumbStyles }
187186 mods = { {
188187 checked : inputProps . checked ,
189188 } }
190189 />
191190 </ SwitchElement >
192- </ BaseSwitchWrapperElement >
191+ </ SwitchWrapperElement >
193192 ) ;
194193
195194 if ( insideForm ) {
@@ -217,9 +216,9 @@ function Switch(props: WithNullableSelected<CubeSwitchProps>, ref) {
217216 }
218217
219218 return (
220- < SwitchWrapperElement
221- as = "label"
219+ < SwitchLabelElement
222220 styles = { styles }
221+ mods = { mods }
223222 { ...hoverProps }
224223 { ...filterBaseProps ( otherProps ) }
225224 ref = { domRef }
@@ -242,7 +241,7 @@ function Switch(props: WithNullableSelected<CubeSwitchProps>, ref) {
242241 ) : null }
243242 </ Element >
244243 ) }
245- </ SwitchWrapperElement >
244+ </ SwitchLabelElement >
246245 ) ;
247246}
248247
0 commit comments