diff options
author | Emiliano Ciavatta | 2020-09-23 21:16:58 +0000 |
---|---|---|
committer | Emiliano Ciavatta | 2020-09-23 21:16:58 +0000 |
commit | 05678b74d98247c957faa1ca3d0bafc5f68974d1 (patch) | |
tree | 05a539466f0c91bced4d93bec2cb20e4325274b2 /frontend/src/components/fields/BooleanField.js | |
parent | 04ee54be31931111bf89e50e4e54ac92b9a19d7a (diff) |
Add BooleanField
Diffstat (limited to 'frontend/src/components/fields/BooleanField.js')
-rw-r--r-- | frontend/src/components/fields/BooleanField.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/frontend/src/components/fields/BooleanField.js b/frontend/src/components/fields/BooleanField.js new file mode 100644 index 0000000..06a6da7 --- /dev/null +++ b/frontend/src/components/fields/BooleanField.js @@ -0,0 +1,37 @@ +import React, {Component} from 'react'; +import './BooleanField.scss'; +import {randomClassName} from "../../utils"; + +const classNames = require('classnames'); + +class BooleanField extends Component { + + constructor(props) { + super(props); + + this.id = `field-${this.props.name || "noname"}-${randomClassName()}`; + } + + render() { + + const checked = this.props.checked || false; + const small = this.props.small || false; + const name = this.props.name || null; + const handler = () => { + if (this.props.onChange) { + this.props.onChange(!checked); + } + }; + + return ( + <div className={classNames( "boolean-field", {"field-checked" : checked}, {"field-small": small})}> + <div className="field-input"> + <input type="checkbox" id={this.id} checked={checked} onChange={handler} /> + <label htmlFor={this.id}>{(checked ? "✓ " : "✗ ") + name}</label> + </div> + </div> + ); + } +} + +export default BooleanField; |