mirror of https://github.com/sgoudham/carbon.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
894 B
JavaScript
36 lines
894 B
JavaScript
import React from 'react'
|
|
import Checkmark from './svg/Checkmark'
|
|
|
|
export default class extends React.Component {
|
|
constructor(props) {
|
|
super()
|
|
this.state = { isEnabled: props.enabled || false }
|
|
this.toggle = this.toggle.bind(this)
|
|
}
|
|
|
|
toggle() {
|
|
this.setState({ isEnabled: !this.state.isEnabled })
|
|
this.props.onChange(this.state.isEnabled)
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div className="toggle" onClick={this.toggle}>
|
|
<span className="label">{this.props.label}</span>
|
|
{ this.state.isEnabled ? <Checkmark /> : null }
|
|
<style jsx>{`
|
|
.toggle {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
cursor: pointer;
|
|
user-select: none;
|
|
padding: 8px;
|
|
border-bottom: solid 1px #000;
|
|
}
|
|
`}</style>
|
|
</div>
|
|
)
|
|
}
|
|
}
|