diff --git a/javascripts/src/components/common/StandardFieldComponent.tsx b/javascripts/src/components/common/StandardFieldComponent.tsx index 48c23aaf..14380c43 100644 --- a/javascripts/src/components/common/StandardFieldComponent.tsx +++ b/javascripts/src/components/common/StandardFieldComponent.tsx @@ -30,7 +30,7 @@ export default class StandardFieldComponent extends React.Component{stickyErrorMessage} : "" return
- {this.renderChildren()} + {this.props.children} {errorDiv} {stickyErrorDiv }
diff --git a/javascripts/src/components/common/fields.tsx b/javascripts/src/components/common/fields.tsx index 84e8d55f..459f4155 100644 --- a/javascripts/src/components/common/fields.tsx +++ b/javascripts/src/components/common/fields.tsx @@ -6,6 +6,8 @@ import LabeledFieldComponent from "./LabeledFieldComponent"; import {injectIntl, InjectedIntl} from 'react-intl'; import {HoudiniField} from "../../lib/houdini_form"; import ReactInput from "./form/ReactInput"; +import ReactSelect from './form/ReactSelect'; +import ReactTextarea from "./form/ReactTextarea"; export const BasicField = observer((props:{field:Field, placeholder?:string, label?:string, wrapperClassName?:string, inputClassNames?:string}) =>{ @@ -14,7 +16,46 @@ export const BasicField = observer((props:{field:Field, placeholder?:string, lab inputId={props.field.id} labelText={field.label} inError={field.hasError} error={field.error} inStickyError={field.hasServerError} stickyError={field.serverError} className={props.wrapperClassName} > - -}) \ No newline at end of file +}) + +export const SelectField = observer((props:{field:Field, placeholder?:string, label?:string, wrapperClassName?:string, inputClassNames?:string, options?:Array<{id:any, name:string}>}) =>{ + let field = props.field as HoudiniField + return + + + + +}) + +export const TextareaField = observer((props:{field:Field, placeholder?:string, label?:string, wrapperClassName?:string, inputClassNames?:string, rows?:number}) =>{ + let field = props.field as HoudiniField + return + + + + +}) + +export const CurrencyField = observer((props:{field:Field,placeholder?:string, label?:string, currencySymbol?:string, wrapperClassName?:string, inputClassNames?:string}) => { + let field = props.field as HoudiniField + let currencySymbolId = props.field.id + "_____currency_symbol" + return +
+ {props.currencySymbol} + +
+
+ + +}); \ No newline at end of file diff --git a/javascripts/src/components/common/form/ReactInput.tsx b/javascripts/src/components/common/form/ReactInput.tsx index d63d756c..3df05eae 100644 --- a/javascripts/src/components/common/form/ReactInput.tsx +++ b/javascripts/src/components/common/form/ReactInput.tsx @@ -5,24 +5,18 @@ import {InjectedIntlProps, injectIntl} from 'react-intl'; import {Field} from "mobx-react-form"; import {observable, action, toJS, runInAction} from 'mobx'; import {InputHTMLAttributes} from 'react'; +import {ReactInputProps} from "./react_input_props"; +import {SelectHTMLAttributes} from "react"; +import {ReactSelectProps} from "./ReactSelect"; +import {castToNullIfUndef} from "../../../lib/utils"; +type InputTypes = ReactInputProps & + InputHTMLAttributes -export interface ReactInputProps -{ - field:Field - label?:string - placeholder?:string -} +class ReactInput extends React.Component { -function castToNullIfUndef(i:any){ - return i === undefined ? null : i -} - - -class ReactInput extends React.Component, {}> { - - constructor(props:ReactInputProps){ + constructor(props:InputTypes){ super(props) } @@ -43,7 +37,7 @@ class ReactInput extends React.Component, prevState: Readonly<{}>): void { + componentDidUpdate(prevProps: Readonly, prevState: Readonly<{}>): void { this.updateProps() } @@ -53,18 +47,9 @@ class ReactInput extends React.Component, - {...ourProps, ...this.field.bind() }) - return elem - - } - ///Removes the properties we don't want to put into the input element @action.bound - winnowProps(): ReactInputProps & InputHTMLAttributes { + winnowProps(): InputTypes { let ourProps = {...this.props} delete ourProps.field delete ourProps.value @@ -73,14 +58,7 @@ class ReactInput extends React.Component - } } } diff --git a/javascripts/src/components/common/form/ReactSelect.spec.tsx b/javascripts/src/components/common/form/ReactSelect.spec.tsx new file mode 100644 index 00000000..7cb9e7b5 --- /dev/null +++ b/javascripts/src/components/common/form/ReactSelect.spec.tsx @@ -0,0 +1,10 @@ +// License: LGPL-3.0-or-later +import * as React from 'react'; +import 'jest'; +import ReactSelect from './ReactSelect' + +describe('ReactSelect', () => { + test('your test here', () => { + expect(false).toBe(true) + }) +}) \ No newline at end of file diff --git a/javascripts/src/components/common/form/ReactSelect.tsx b/javascripts/src/components/common/form/ReactSelect.tsx new file mode 100644 index 00000000..a6d71056 --- /dev/null +++ b/javascripts/src/components/common/form/ReactSelect.tsx @@ -0,0 +1,80 @@ +// License: LGPL-3.0-or-later +import * as React from 'react'; +import { observer } from 'mobx-react'; +import {InjectedIntlProps, injectIntl} from 'react-intl'; +import {Field} from "../../../../../types/mobx-react-form"; +import {InputHTMLAttributes} from "react"; +import {action, observable} from "mobx"; +import {SelectHTMLAttributes} from "react"; +import {ReactInputProps} from "./react_input_props"; +import {castToNullIfUndef} from "../../../lib/utils"; + + +export interface ReactSelectProps extends ReactInputProps +{ + options?:Array<{id:any, name:string}> +} + +type InputTypes = ReactSelectProps & SelectHTMLAttributes + +class ReactSelect extends React.Component { + + constructor(props:InputTypes){ + super(props) + } + + @observable + field:Field + + + @action.bound + componentWillMount(){ + + this.field = this.props.field + + + this.updateProps() + } + + componentWillUnmount(){ + } + + + componentDidUpdate(prevProps: Readonly, prevState: Readonly<{}>): void { + this.updateProps() + } + + @action.bound + updateProps() { + this.field.set('label', castToNullIfUndef(this.props.label)) + this.field.set('placeholder', castToNullIfUndef(this.props.placeholder)) + } + + + ///Removes the properties we don't want to put into the input element + @action.bound + winnowProps(): InputTypes { + let ourProps = {...this.props} + delete ourProps.field + delete ourProps.value + delete ourProps.options + return ourProps + + } + + render() { + + return + + } +} + +export default observer(ReactSelect) + + + diff --git a/javascripts/src/components/common/form/ReactTextarea.spec.tsx b/javascripts/src/components/common/form/ReactTextarea.spec.tsx new file mode 100644 index 00000000..7cb9e7b5 --- /dev/null +++ b/javascripts/src/components/common/form/ReactTextarea.spec.tsx @@ -0,0 +1,10 @@ +// License: LGPL-3.0-or-later +import * as React from 'react'; +import 'jest'; +import ReactSelect from './ReactSelect' + +describe('ReactSelect', () => { + test('your test here', () => { + expect(false).toBe(true) + }) +}) \ No newline at end of file diff --git a/javascripts/src/components/common/form/ReactTextarea.tsx b/javascripts/src/components/common/form/ReactTextarea.tsx new file mode 100644 index 00000000..a948a2af --- /dev/null +++ b/javascripts/src/components/common/form/ReactTextarea.tsx @@ -0,0 +1,65 @@ +// License: LGPL-3.0-or-later +import * as React from 'react'; +import { observer } from 'mobx-react'; +import {InjectedIntlProps, injectIntl} from 'react-intl'; +import {Field} from "../../../../../types/mobx-react-form"; +import {InputHTMLAttributes, ReactText, TextareaHTMLAttributes} from "react"; +import {action, observable} from "mobx"; +import {ReactInputProps} from "./react_input_props"; +import {castToNullIfUndef} from "../../../lib/utils"; + +type InputTypes = ReactInputProps & TextareaHTMLAttributes + + +class ReactTextarea extends React.Component { + + constructor(props:InputTypes){ + super(props) + } + + @observable + field:Field + + + @action.bound + componentWillMount(){ + + this.field = this.props.field + + + this.updateProps() + } + + componentWillUnmount(){ + } + + + componentDidUpdate(prevProps: Readonly, prevState: Readonly<{}>): void { + this.updateProps() + } + + @action.bound + updateProps() { + this.field.set('label', castToNullIfUndef(this.props.label)) + this.field.set('placeholder', castToNullIfUndef(this.props.placeholder)) + } + + ///Removes the properties we don't want to put into the input element + @action.bound + winnowProps(): InputTypes { + let ourProps = {...this.props} + delete ourProps.field + delete ourProps.value + return ourProps + + } + + render() { + return