mirror of https://github.com/sgoudham/carbon.git
Add toggle component
parent
2729531ad6
commit
77b1a722d8
@ -0,0 +1,34 @@
|
||||
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 })
|
||||
}
|
||||
|
||||
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>
|
||||
)
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
import React from 'react'
|
||||
|
||||
export default () => (
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="9" height="7" viewBox="0 0 9 7">
|
||||
<polygon fill="#FFFFFF" fillRule="evenodd" points="2.852 5.016 8.275 0 9 .67 2.852 6.344 0 3.711 .713 3.042"/>
|
||||
</svg>
|
||||
)
|
Loading…
Reference in New Issue