aboutsummaryrefslogtreecommitdiff
path: root/src/settings/components/ui/Input.tsx
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-04-30 14:00:07 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-02 11:14:19 +0900
commitc60d0e7392fc708e961614d6b756a045de74f458 (patch)
tree0b9a5fce1879e38a92d5dbb2915779aee0ad22d6 /src/settings/components/ui/Input.tsx
parent257162e5b6b4993e1dff0d705ffa6f0d809033eb (diff)
Rename .js/.jsx to .ts/.tsx
Diffstat (limited to 'src/settings/components/ui/Input.tsx')
-rw-r--r--src/settings/components/ui/Input.tsx60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/settings/components/ui/Input.tsx b/src/settings/components/ui/Input.tsx
new file mode 100644
index 0000000..13a246b
--- /dev/null
+++ b/src/settings/components/ui/Input.tsx
@@ -0,0 +1,60 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import './Input.scss';
+
+class Input extends React.Component {
+
+ renderText(props) {
+ let inputClassName = props.error ? 'input-error' : '';
+ return <div className='settings-ui-input'>
+ <label htmlFor={props.id}>{ props.label }</label>
+ <input type='text' className={inputClassName} {...props} />
+ </div>;
+ }
+
+ renderRadio(props) {
+ let inputClassName = props.error ? 'input-error' : '';
+ return <div className='settings-ui-input'>
+ <label>
+ <input type='radio' className={inputClassName} {...props} />
+ { props.label }
+ </label>
+ </div>;
+ }
+
+ renderTextArea(props) {
+ let inputClassName = props.error ? 'input-error' : '';
+ return <div className='settings-ui-input'>
+ <label
+ htmlFor={props.id}
+ >{ props.label }</label>
+ <textarea className={inputClassName} {...props} />
+ <p className='settings-ui-input-error'>{ this.props.error }</p>
+ </div>;
+ }
+
+ render() {
+ let { type } = this.props;
+
+ switch (this.props.type) {
+ case 'text':
+ return this.renderText(this.props);
+ case 'radio':
+ return this.renderRadio(this.props);
+ case 'textarea':
+ return this.renderTextArea(this.props);
+ default:
+ console.warn(`Unsupported input type ${type}`);
+ }
+ return null;
+ }
+}
+
+Input.propTypes = {
+ type: PropTypes.string,
+ error: PropTypes.string,
+ label: PropTypes.string,
+ value: PropTypes.string,
+};
+
+export default Input;