aboutsummaryrefslogtreecommitdiff
path: root/src/settings/components/ui/input.jsx
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-11-19 08:23:51 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-11-26 11:40:12 +0900
commitd33b37cdb9d2956f5f2d23ab4e71e35db137b16e (patch)
tree36e9bb6012c338259ed997d4ceda180e999beecc /src/settings/components/ui/input.jsx
parent44459e39c3526673ac2ac7065c5659e4af5ea7d8 (diff)
Use Preact for settings and show validation
Diffstat (limited to 'src/settings/components/ui/input.jsx')
-rw-r--r--src/settings/components/ui/input.jsx50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/settings/components/ui/input.jsx b/src/settings/components/ui/input.jsx
new file mode 100644
index 0000000..9b6c229
--- /dev/null
+++ b/src/settings/components/ui/input.jsx
@@ -0,0 +1,50 @@
+import { h, Component } from 'preact';
+import './input.scss';
+
+class Input extends Component {
+
+ renderRadio(props) {
+ let inputClasses = 'form-field-input';
+ if (props.error) {
+ inputClasses += ' input-error';
+ }
+ return <div>
+ <label>
+ <input className={ inputClasses } type='radio' {...props} />
+ { props.label }
+ </label>
+ </div>;
+ }
+
+ renderTextArea(props) {
+ let inputClasses = 'form-field-input';
+ if (props.error) {
+ inputClasses += ' input-error';
+ }
+ return <div>
+ <label
+ className='form-field-label'
+ htmlFor={props.id}
+ >{ props.label }</label>
+ <textarea className={inputClasses} {...props} />
+
+ <p className='form-field-error'>{ this.props.error }</p>
+ </div>;
+ }
+
+ render() {
+ let { type } = this.props;
+
+ switch (this.props.type) {
+ case 'radio':
+ return this.renderRadio(this.props);
+ case 'textarea':
+ return this.renderTextArea(this.props);
+ default:
+ console.warn(`Unsupported input type ${type}`);
+ }
+ return null;
+ }
+}
+
+export default Input;