diff --git a/javascripts/src/components/common/form/ReactForm.tsx b/javascripts/src/components/common/form/ReactForm.tsx new file mode 100644 index 00000000..0abe4b5c --- /dev/null +++ b/javascripts/src/components/common/form/ReactForm.tsx @@ -0,0 +1,49 @@ +// License: LGPL-3.0-or-later +import * as React from 'react'; +import { observer, Provider } from 'mobx-react'; +import {Field, Form} from "mobx-react-form"; +import {observable, action, toJS} from 'mobx'; + +export interface ReactFormProps +{ + form:Form +} + +///Mostly useless class but, at some point, will replace all our form elements +class ReactForm extends React.Component { + + + + @observable + form:Form + + @action.bound + componentWillMount() + { + this.form = this.props.form + } + + + + + componentDidUpdate(){ + + + } + + componentWillUnmount(){ + } + + + render() { + + return
+ {this.props.children} +
+ } +} + +export default observer(ReactForm) + + + diff --git a/javascripts/src/components/common/form/ReactInput.spec.tsx b/javascripts/src/components/common/form/ReactInput.spec.tsx new file mode 100644 index 00000000..204e9982 --- /dev/null +++ b/javascripts/src/components/common/form/ReactInput.spec.tsx @@ -0,0 +1,162 @@ +// License: LGPL-3.0-or-later +import * as React from 'react'; +import 'jest'; +import ReactInput from './ReactInput' +import {Form} from "mobx-react-form"; +import ReactForm from "./ReactForm"; +import {mount} from 'enzyme'; +import {toJS, observable, action, runInAction} from 'mobx'; +import {observer} from 'mobx-react'; +import {InputHTMLAttributes} from 'react'; + + + +@observer +class TestChange extends React.Component{ + @observable + remove:boolean + @observable + form: Form + + @action.bound + componentWillMount(){ + this.form = new Form({fields:[{ + name: 'name', + extra: null} + ]}) + } + + + + @action.bound + onClick(){ + this.remove = true + } + render() { + let reactInput = !this.remove ? + {this.props.children} + : undefined + + return + + {reactInput} +