Skip to content

Commit e609822

Browse files
committed
feat: add intermediate state to Toggle component with corresponding styles
1 parent 4e7c1bd commit e609822

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/Common/Toggle/Toggle.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
background-color: var(--white);
6464
transition: all 0.4s ease;
6565
}
66+
67+
&.intermediate::before {
68+
width: 0px;
69+
height: 0px;
70+
}
71+
6672
&.with-icon {
6773
background-color: var(--bg-primary) !important;
6874
svg {

src/Common/Toggle/Toggle.tsx

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import React, { SyntheticEvent, useCallback } from 'react'
1818
import { Icon as IconComponent } from '@Shared/Components'
1919
import { throttle, useEffectAfterMount } from '../Helper'
20+
import { CHECKBOX_VALUE } from '@Common/Types'
2021
import './Toggle.scss'
2122

2223
const Toggle = ({
@@ -31,6 +32,7 @@ const Toggle = ({
3132
throttleOnChange = false,
3233
shouldToggleValueOnLabelClick = false,
3334
isLoading = false,
35+
value = CHECKBOX_VALUE.CHECKED,
3436
...props
3537
}) => {
3638
const [active, setActive] = React.useState(selected)
@@ -70,8 +72,26 @@ const Toggle = ({
7072
}
7173
}
7274

75+
const isIntermediateView = selected && value === CHECKBOX_VALUE.INTERMEDIATE
76+
77+
const renderIcon = () => {
78+
if (isIntermediateView) {
79+
return (
80+
<div className="w-100 h-100 dc__position-abs flex">
81+
<div className="w-8 h-2 br-4 dc__no-shrink bg__white" />
82+
</div>
83+
)
84+
}
85+
86+
if (Icon) {
87+
return <Icon className={`icon-dim-20 br-4 p-2 ${iconClass}`} />
88+
}
89+
90+
return null
91+
}
92+
7393
return isLoading ? (
74-
<IconComponent name='ic-circle-loader' color='B500' size={20} />
94+
<IconComponent name="ic-circle-loader" color="B500" size={20} />
7595
) : (
7696
<label
7797
{...props}
@@ -80,8 +100,11 @@ const Toggle = ({
80100
{...(shouldToggleValueOnLabelClick ? { onClick: handleLabelClick } : {})}
81101
>
82102
<input type="checkbox" checked={!!active} onChange={handleChange} className="toggle__input" />
83-
<span className={`toggle__slider ${Icon ? 'with-icon br-4 dc__border' : 'round'}`} data-testid={dataTestId}>
84-
{Icon && <Icon className={`icon-dim-20 br-4 p-2 ${iconClass}`} />}
103+
<span
104+
className={`toggle__slider ${isIntermediateView ? 'intermediate' : ''} ${Icon ? 'with-icon br-4 dc__border' : 'round'}`}
105+
data-testid={dataTestId}
106+
>
107+
{renderIcon()}
85108
</span>
86109
</label>
87110
)

0 commit comments

Comments
 (0)