aboutsummaryrefslogtreecommitdiff
path: root/src/settings/components/form/PropertiesForm.jsx
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-04-30 13:05:06 +0900
committerGitHub <noreply@github.com>2019-04-30 13:05:06 +0900
commit457d954e08923b4accd28a919c72d0b61db1bb98 (patch)
tree9d198f7c7d37893621d4e2a27749070a435854cd /src/settings/components/form/PropertiesForm.jsx
parent3d9a251ce293885cda57cd3eebd111f6181132f0 (diff)
parent037ee5fd40af0117a1eb8d362b4ae97429499f16 (diff)
Merge pull request #576 from ueokande/move-to-react
Move to React
Diffstat (limited to 'src/settings/components/form/PropertiesForm.jsx')
-rw-r--r--src/settings/components/form/PropertiesForm.jsx65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/settings/components/form/PropertiesForm.jsx b/src/settings/components/form/PropertiesForm.jsx
new file mode 100644
index 0000000..979fdd8
--- /dev/null
+++ b/src/settings/components/form/PropertiesForm.jsx
@@ -0,0 +1,65 @@
+import './PropertiesForm.scss';
+import React from 'react';
+import PropTypes from 'prop-types';
+
+class PropertiesForm extends React.Component {
+
+ render() {
+ let types = this.props.types;
+ let value = this.props.value;
+
+ return <div className='form-properties-form'>
+ {
+ Object.keys(types).map((name) => {
+ let type = types[name];
+ let inputType = null;
+ if (type === 'string') {
+ inputType = 'text';
+ } else if (type === 'number') {
+ inputType = 'number';
+ } else if (type === 'boolean') {
+ inputType = 'checkbox';
+ }
+ return <div key={name} className='form-properties-form-row'>
+ <label>
+ <span className='column-name'>{name}</span>
+ <input type={inputType} name={name}
+ className='column-input'
+ value={value[name] ? value[name] : ''}
+ onChange={this.bindValue.bind(this)}
+ onBlur={this.props.onBlur}
+ checked={value[name]}
+ />
+ </label>
+ </div>;
+ })
+ }
+ </div>;
+ }
+
+ bindValue(e) {
+ let name = e.target.name;
+ let next = { ...this.props.value };
+ if (e.target.type.toLowerCase() === 'checkbox') {
+ next[name] = e.target.checked;
+ } else if (e.target.type.toLowerCase() === 'number') {
+ next[name] = Number(e.target.value);
+ } else {
+ next[name] = e.target.value;
+ }
+
+ this.props.onChange(next);
+ }
+}
+
+PropertiesForm.propTypes = {
+ value: PropTypes.objectOf(PropTypes.any),
+ onChange: PropTypes.func,
+};
+
+PropertiesForm.defaultProps = {
+ value: {},
+ onChange: () => {},
+};
+
+export default PropertiesForm;