1- import React , { useEffect , useState } from 'react'
1+ import React from 'react'
22import PropTypes from 'prop-types'
33import classNames from 'classnames'
44
55//component - CoreUI / CSwitch
6-
76const CSwitch = props => {
87
98 let {
@@ -16,19 +15,9 @@ const CSwitch = props => {
1615 labelOff,
1716 variant,
1817 shape,
19- checked,
20- onCheckedChange,
2118 ...attributes
2219 } = props
2320
24- const [ isChecked , setIsChecked ] = useState ( checked )
25- useEffect ( ( ) => setIsChecked ( checked ) , [ checked ] )
26-
27- const change = e => {
28- setIsChecked ( e . target . checked )
29- onCheckedChange && onCheckedChange ( e . target . checked )
30- }
31-
3221 //render
3322 const classes = classNames (
3423 'c-switch form-check-label' ,
@@ -49,14 +38,13 @@ const CSwitch = props => {
4938 < input
5039 className = { inputClasses }
5140 type = "checkbox"
52- onChange = { change }
53- checked = { ! ! isChecked }
5441 { ...attributes }
5542 ref = { innerRef }
5643 />
57- < span className = "c-switch-slider"
58- data-checked = { labelOn }
59- data-unchecked = { labelOff }
44+ < span
45+ className = "c-switch-slider"
46+ data-checked = { labelOn }
47+ data-unchecked = { labelOff }
6048 />
6149 </ label >
6250 )
@@ -70,10 +58,8 @@ CSwitch.propTypes = {
7058 shape : PropTypes . oneOf ( [ '' , 'pill' , 'square' ] ) ,
7159 variant : PropTypes . oneOf ( [ '' , '3d' , 'opposite' , 'outline' ] ) ,
7260 color : PropTypes . string ,
73- checked : PropTypes . bool ,
7461 labelOn : PropTypes . string ,
7562 labelOff : PropTypes . string ,
76- onCheckedChange : PropTypes . func
77- } ;
63+ }
7864
7965export default CSwitch
0 commit comments