69 lines
1.6 KiB
JavaScript
Raw Normal View History

2020-03-24 00:39:12 -04:00
import classNames from 'classnames/bind'
import Text from './text'
const cx = classNames.bind(_s)
export default class Switch extends PureComponent {
static 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,
}
render() {
const {
id,
description,
label,
checked,
onChange,
onKeyDown,
disabled,
labelProps
} = this.props
const checkboxContainerClasses = cx({
cursorPointer: 1,
default: 1,
height24PX: 1,
width50PX: 1,
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
})
const checkboxLabelClasses = cx({
default: 1,
2020-04-29 18:32:49 -04:00
m1PX: 1,
2020-03-24 00:39:12 -04:00
height20PX: 1,
width20PX: 1,
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 (
<div className={[_s.default, _s.flexRow, _s.py5, _s.alignItemsCenter].join(' ')}>
2020-03-25 23:11:32 -04:00
<Text {...labelProps} className={_s.mr10}>
2020-03-24 00:39:12 -04:00
{label}
</Text>
<label className={checkboxContainerClasses} htmlFor={id}>
<span className={checkboxLabelClasses} />
<input type='checkbox' id={id} onChange={onChange} disabled={disabled} className={[_s.visibilityHidden].join(' ')} />
</label>
</div>
)
}
}