2020-08-17 15:07:16 -05:00
|
|
|
import React from 'react'
|
2020-08-17 15:59:29 -05:00
|
|
|
import PropTypes from 'prop-types'
|
2020-07-14 18:46:10 -05:00
|
|
|
import { CX } from '../constants'
|
2020-03-24 00:39:12 -04:00
|
|
|
import Text from './text'
|
|
|
|
|
2020-08-17 19:57:35 -05:00
|
|
|
class Switch extends React.PureComponent {
|
2020-03-24 00:39:12 -04:00
|
|
|
|
2020-09-01 14:54:17 -05:00
|
|
|
handleOnChange = (e) => {
|
|
|
|
this.props.onChange(e.currentTarget.checked)
|
|
|
|
}
|
|
|
|
|
2020-03-24 00:39:12 -04:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
description,
|
|
|
|
label,
|
|
|
|
checked,
|
|
|
|
onChange,
|
|
|
|
onKeyDown,
|
|
|
|
disabled,
|
|
|
|
labelProps
|
|
|
|
} = this.props
|
|
|
|
|
2020-07-14 18:46:10 -05:00
|
|
|
const checkboxContainerClasses = CX({
|
2020-03-24 00:39:12 -04:00
|
|
|
cursorPointer: 1,
|
2020-08-18 15:49:11 -05:00
|
|
|
d: 1,
|
2020-08-18 15:43:06 -05:00
|
|
|
h24PX: 1,
|
|
|
|
w50PX: 1,
|
2020-03-24 00:39:12 -04:00
|
|
|
circle: 1,
|
|
|
|
border1PX: 1,
|
2020-04-23 23:17:27 -04:00
|
|
|
mlAuto: 1,
|
2020-05-03 01:22:49 -04:00
|
|
|
bgPrimary: 1,
|
2020-03-24 00:39:12 -04:00
|
|
|
borderColorSecondary: 1,
|
2020-04-29 18:32:49 -04:00
|
|
|
bgBrand: checked,
|
2020-03-24 00:39:12 -04:00
|
|
|
})
|
|
|
|
|
2020-07-14 18:46:10 -05:00
|
|
|
const checkboxLabelClasses = CX({
|
2020-08-18 15:49:11 -05:00
|
|
|
d: 1,
|
2020-04-29 18:32:49 -04:00
|
|
|
m1PX: 1,
|
2020-08-18 15:43:06 -05:00
|
|
|
h20PX: 1,
|
|
|
|
w20PX: 1,
|
2020-03-24 00:39:12 -04:00
|
|
|
circle: 1,
|
2020-04-23 02:13:29 -04:00
|
|
|
posAbs: 1,
|
2020-04-29 18:32:49 -04:00
|
|
|
bgSecondary: !checked,
|
|
|
|
bgPrimary: checked,
|
2020-03-24 00:39:12 -04:00
|
|
|
left0: !checked,
|
|
|
|
right0: checked,
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
2020-08-18 15:49:11 -05:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.py5, _s.aiCenter].join(' ')}>
|
2020-09-02 17:54:50 -05:00
|
|
|
<Text {...labelProps} htmlFor={id} className={_s.mr10}>
|
2020-03-24 00:39:12 -04:00
|
|
|
{label}
|
|
|
|
</Text>
|
|
|
|
|
|
|
|
<label className={checkboxContainerClasses} htmlFor={id}>
|
|
|
|
<span className={checkboxLabelClasses} />
|
2020-09-01 14:54:17 -05:00
|
|
|
<input type='checkbox' id={id} onChange={this.handleOnChange} disabled={disabled} className={[_s.visibilityHidden].join(' ')} />
|
2020-03-24 00:39:12 -04:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2020-07-14 18:46:10 -05:00
|
|
|
|
2020-08-17 19:57:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Switch.propTypes = {
|
|
|
|
id: PropTypes.string.isRequired,
|
|
|
|
description: PropTypes.string,
|
|
|
|
label: PropTypes.string,
|
|
|
|
checked: PropTypes.bool,
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
onKeyDown: PropTypes.func,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
labelProps: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Switch
|