From 7a78970d10ab2dfc9b86dd30a76fb1513f43dd35 Mon Sep 17 00:00:00 2001
From: Jason <jason.daurus@gmail.com>
Date: Fri, 17 Jun 2016 07:07:38 +0800
Subject: [web] common

---
 web/src/js/components/common/ToggleInputButton.jsx | 52 ++++++++++++++++++++++
 1 file changed, 52 insertions(+)
 create mode 100644 web/src/js/components/common/ToggleInputButton.jsx

(limited to 'web/src/js/components/common/ToggleInputButton.jsx')

diff --git a/web/src/js/components/common/ToggleInputButton.jsx b/web/src/js/components/common/ToggleInputButton.jsx
new file mode 100644
index 00000000..25d620ae
--- /dev/null
+++ b/web/src/js/components/common/ToggleInputButton.jsx
@@ -0,0 +1,52 @@
+import React, { Component, PropTypes } from 'react'
+import classnames from 'classnames'
+import { Key } from '../../utils'
+
+export default class ToggleInputButton extends Component {
+
+    static propTypes = {
+        name: PropTypes.string.isRequired,
+        txt: PropTypes.string.isRequired,
+        onToggleChanged: PropTypes.func.isRequired
+    }
+
+    constructor(props) {
+        super(props)
+        this.state = { txt: props.txt }
+    }
+
+    onChange(e) {
+        this.setState({ txt: e.target.value })
+    }
+
+    onKeyDown(e) {
+        e.stopPropagation()
+        if (e.keyCode === Key.ENTER) {
+            this.props.onToggleChanged(this.state.txt)
+        }
+    }
+
+    render() {
+        return (
+            <div className="input-group toggle-input-btn">
+                <span className="input-group-btn"
+                      onClick={() => this.props.onToggleChanged(this.state.txt)}>
+                    <div className={classnames('btn', this.props.checked ? 'btn-primary' : 'btn-default')}>
+                        <span className={classnames('fa', this.props.checked ? 'fa-check-square-o' : 'fa-square-o')}/>
+                        &nbsp;
+                        {this.props.name}
+                    </div>
+                </span>
+                <input
+                    className="form-control"
+                    placeholder={this.props.placeholder}
+                    disabled={this.props.checked}
+                    value={this.state.txt}
+                    type={this.props.inputType}
+                    onChange={e => this.onChange(e)}
+                    onKeyDown={e => this.onKeyDown(e)}
+                />
+            </div>
+        )
+    }
+}
-- 
cgit v1.2.3

