Use Preact for settings and show validation
This commit is contained in:
parent
44459e39c3
commit
d33b37cdb9
4 changed files with 99 additions and 18 deletions
50
src/settings/components/ui/input.jsx
Normal file
50
src/settings/components/ui/input.jsx
Normal file
|
@ -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;
|
Reference in a new issue