@@ -8,7 +8,14 @@ import { getUniqueId } from '@Shared/Helpers'
88import { Icon } from '../Icon'
99import { INDETERMINATE_ICON_WIDTH_MAP , LOADING_COLOR_MAP } from './constants'
1010import { SwitchProps } from './types'
11- import { getSwitchContainerClass , getSwitchIconColor , getSwitchThumbClass , getSwitchTrackColor } from './utils'
11+ import {
12+ getSwitchContainerClass ,
13+ getSwitchIconColor ,
14+ getSwitchThumbClass ,
15+ getSwitchTrackColor ,
16+ getThumbPadding ,
17+ getThumbPosition ,
18+ } from './utils'
1219
1320const Switch = ( {
1421 ariaLabel,
@@ -40,24 +47,26 @@ const Switch = ({
4047
4148 const showIndeterminateIcon = ariaCheckedValue === 'mixed'
4249
43- const renderContent = ( ) => {
44- if ( isLoading ) {
45- return < Icon name = "ic-circle-loader" color = { LOADING_COLOR_MAP [ variant ] } />
46- }
47-
48- return (
49- < motion . span
50- className = { `flex flex-grow-1 ${ shape === 'rounded' ? 'p-2 br-12' : 'p-1 br-4' } ${ isChecked ? 'right' : 'left' } ` }
51- layout
52- animate = { {
53- backgroundColor : getSwitchTrackColor ( { shape, variant, isChecked } ) ,
54- } }
55- transition = { { type : 'spring' , stiffness : 300 , damping : 30 } }
56- >
50+ const renderContent = ( ) => (
51+ < motion . span
52+ className = { `flex flex-grow-1 ${ getThumbPadding ( { shape, isLoading } ) } ${ getThumbPosition ( { isChecked, isLoading } ) } ` }
53+ layout
54+ transition = { { ease : 'easeInOut' , duration : 0.2 } }
55+ >
56+ { isLoading ? (
57+ < motion . span
58+ transition = { { ease : 'easeInOut' , duration : 0.2 } }
59+ layoutId = "loader"
60+ className = "flex-grow-1 h-100 dc__fill-available-space dc__no-shrink"
61+ >
62+ < Icon key = "progressing" name = "ic-circle-loader" color = { LOADING_COLOR_MAP [ variant ] } size = { null } />
63+ </ motion . span >
64+ ) : (
5765 < motion . span
66+ layoutId = "thumb"
5867 className = { getSwitchThumbClass ( { shape, size, showIndeterminateIcon } ) }
5968 layout
60- transition = { { type : 'spring ' , stiffness : 500 , damping : 35 } }
69+ transition = { { ease : 'easeInOut ' , duration : 0.2 } }
6170 >
6271 < AnimatePresence >
6372 { showIndeterminateIcon ? (
@@ -84,15 +93,16 @@ const Switch = ({
8493 iconColor,
8594 variant,
8695 } ) }
96+ size = { null }
8797 />
8898 </ motion . span >
8999 )
90100 ) }
91101 </ AnimatePresence >
92102 </ motion . span >
93- </ motion . span >
94- )
95- }
103+ ) }
104+ </ motion . span >
105+ )
96106
97107 return (
98108 < Tooltip alwaysShowTippyOnHover = { ! ! tooltipContent } content = { tooltipContent } >
@@ -119,7 +129,7 @@ const Switch = ({
119129 data-testid = { dataTestId }
120130 disabled = { isDisabled || isLoading }
121131 aria-disabled = { isDisabled }
122- className = { `p-0-imp h-100 flex flex-grow-1 dc__transparent ${ isDisabled ? 'dc__disabled' : '' } dc__fill-available-space` }
132+ className = { `p-0-imp h-100 flex flex-grow-1 dc__no-border ${ shape === 'rounded' ? 'br-12' : 'br-4' } ${ getSwitchTrackColor ( { shape , variant , isChecked , isLoading } ) } ${ isDisabled ? 'dc__disabled' : '' } dc__fill-available-space` }
123133 onClick = { onChange }
124134 >
125135 { renderContent ( ) }
0 commit comments