@@ -52,6 +52,24 @@ const SwitchStyle: any = styled.input`
5252 border-radius : 20px ;
5353 background-color : # ffffff ;
5454 }
55+
56+ & : disabled {
57+ background-color : # e0e0e0 ;
58+ opacity : 0.6 ;
59+ cursor : not-allowed;
60+ }
61+
62+ & : disabled ::before {
63+ background-color : # cccccc ;
64+ }
65+
66+ & : disabled : checked {
67+ background-color : # a0a0a0 ;
68+ }
69+
70+ & : disabled : hover {
71+ cursor : not-allowed;
72+ }
5573` ;
5674
5775const SwitchDiv = styled . div < {
@@ -104,16 +122,18 @@ const JsIconGray = styled(jsIconGray)<Ishow>`
104122interface SwitchProps extends Omit < React . HTMLAttributes < HTMLInputElement > , "value" | "onChange" > {
105123 value : boolean ;
106124 onChange : ( value : boolean ) => void ;
125+ disabled ?: boolean ;
107126}
108127
109128export const Switch = ( props : SwitchProps ) => {
110- const { value, onChange, ...inputChanges } = props ;
129+ const { value, onChange, disabled , ...inputChanges } = props ;
111130 return (
112131 < SwitchStyle
113132 type = "checkbox"
114- checked = { props . value }
115- onClick = { ( ) => props . onChange ( ! props . value ) }
133+ checked = { value }
134+ onClick = { ( ) => onChange ( ! value ) }
116135 onChange = { ( ) => { } }
136+ disabled = { disabled }
117137 { ...inputChanges }
118138 />
119139 ) ;
@@ -154,15 +174,17 @@ export const SwitchWrapper = (props: {
154174export function TacoSwitch ( props : {
155175 label : string ;
156176 checked : boolean ;
157- onChange : ( checked : boolean ) => void ;
177+ disabled ?: boolean ;
178+ onChange ?: ( checked : boolean ) => void ;
158179} ) {
159180 return (
160181 < SwitchWrapper label = { props . label } >
161182 < Switch
162183 onChange = { ( value ) => {
163- props . onChange ( value ) ;
184+ props . onChange ? props . onChange ( value ) : null ;
164185 } }
165186 value = { props . checked }
187+ disabled = { props . disabled }
166188 />
167189 </ SwitchWrapper >
168190 ) ;
0 commit comments