aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/components/fields/CheckField.js
blob: 33f4f8343a3c2077541a34dc8addba333b243128 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React, {Component} from 'react';
import './CheckField.scss';
import './common.scss';
import {randomClassName} from "../../utils";

const classNames = require('classnames');

class CheckField 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( "field", "check-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 != null ? name : "")}</label>
                </div>
            </div>
        );
    }
}

export default CheckField;