aboutsummaryrefslogtreecommitdiffstats
path: root/src/react/Checkbox.js
blob: bef6945f8dd56c0e49d88620d2f0baee99d9991d (plain)
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
38
39
40
41
42
43
44
45
import React from 'react';

class Checkbox extends React.Component {

	render() {
		let {checked = false, disabled, value, label, inputRef, className, name} = this.props;
		let dataTestId = this.props['data-test-id'];

		return (
			<div className={`sdc-checkbox ${className || ''}`}>
				<label>
					<input
						className='sdc-checkbox__input'
						ref={inputRef}
						data-test-id={dataTestId}
						type='checkbox'
						checked={checked}
						name={name}
						value={value}
						onChange={(e) => this.onChange(e)}
						disabled={disabled} />
					<span className='sdc-checkbox__label'>{label}</span>
				</label>
			</div>
		);
	}

	onChange(e) {
		let {onChange} = this.props;
		if (onChange) {
			onChange(e.target.checked);
		}
	}

	getChecked() {
		return this.props.checked;
	}

	getValue() {
		return this.props.value;
	}

}

export default Checkbox;