Form.js 1.4 KB

123
  1. var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};import React from'react';import Module from'../Module';import'./Form.css';const UNIT_REGEX=/[A-Z]/g;class Form extends Module{constructor(a){super(a),this.state={},this.object.onUpdate(()=>this.forceUpdate())}submit(a){return a.preventDefault(),this.formData.set(this.state),this.props.onSubmit&&this.props.onSubmit(this.state),!1}render(){let a=Object.keys(this.object.value||{}).map((a,b)=>(this.state[a]=this.state[a]||this.object.value[a],React.createElement('div',{className:'form-group',key:b},React.createElement('label',null,a),React.createElement('input',{type:'text',className:'form-control',placeholder:a,onChange:b=>this.setState({[a]:b.target.value}),value:this.state[a]}))));return React.createElement('div',null,React.createElement('form',{className:`Form ${Object.getPrototypeOf(this)===Form.prototype?this.props.className||'':''}`,onSubmit:a=>this.submit(a)},a,React.createElement('button',{type:'submit',className:'btn btn-primary'},this.props.buttonText||'Submit'),super.render()))}}Form.EditPosition='center',Form.Inputs=_extends({},Module.Inputs,{object:{type:Module.Types.Link,required:!1}}),Form.Outputs={// ADD Extensions
  2. // ...ExtendedModule.Inputs
  3. formData:{}},Form.Category='Theme';export default Form;