UNPKG

configro-form-builder

Version:

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

81 lines (80 loc) 3.17 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; exports.__esModule = true; var react_1 = require("react"); var react_bootstrap_1 = require("react-bootstrap"); var ButtonBuilder_1 = require("../component/ButtonBuilder"); var InputBuilder_1 = require("../component/InputBuilder"); var Builder = /** @class */ (function (_super) { __extends(Builder, _super); function Builder() { return _super !== null && _super.apply(this, arguments) || this; } Builder.prototype.render = function () { var output; var formInput = __assign({}, this.props); switch (formInput.typeOf) { case "ConfigroButton": output = <ButtonBuilder_1["default"] {...formInput}/>; break; case "ConfigroInput": output = <InputBuilder_1["default"] {...formInput}/>; break; } return output; }; return Builder; }(react_1["default"].Component)); var FormBuilder = /** @class */ (function (_super) { __extends(FormBuilder, _super); function FormBuilder() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.handleFormSubmit = function (event) { event.preventDefault(); var formData = new Map(); var formElements = event.currentTarget.elements; for (var index = 0; index < formElements.length; index++) { var item = formElements.item(index); if (item.getAttribute("name") !== null) formData.set(String(item.getAttribute("name")), item.value); } _this.props.onFormSubmit(formData); }; return _this; } FormBuilder.prototype.render = function () { var formInputs = this.props.data.map(function (input, index) { return <react_bootstrap_1.Form.Group key={index}> <Builder key={index} {...input}/> </react_bootstrap_1.Form.Group>; }); return <react_bootstrap_1.Form onSubmit={this.handleFormSubmit}> {formInputs} </react_bootstrap_1.Form>; }; return FormBuilder; }(react_1["default"].Component)); exports["default"] = FormBuilder;