aboutsummaryrefslogtreecommitdiffstats
path: root/src/react/Checkbox.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/react/Checkbox.js')
-rw-r--r--src/react/Checkbox.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/react/Checkbox.js b/src/react/Checkbox.js
new file mode 100644
index 0000000..bef6945
--- /dev/null
+++ b/src/react/Checkbox.js
@@ -0,0 +1,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;