2018-05-21 15:03:46 -05:00
|
|
|
// License: LGPL-3.0-or-later
|
|
|
|
import * as React from 'react';
|
|
|
|
import {observer} from "mobx-react";
|
|
|
|
import {Field} from "../../../../types/mobx-react-form";
|
|
|
|
import LabeledFieldComponent from "./LabeledFieldComponent";
|
|
|
|
import {injectIntl, InjectedIntl} from 'react-intl';
|
2018-06-29 12:42:56 -05:00
|
|
|
import {HoudiniField} from "../../lib/houdini_form";
|
2018-07-12 11:39:28 -05:00
|
|
|
import ReactInput from "./form/ReactInput";
|
2018-10-01 15:27:58 -05:00
|
|
|
import ReactSelect from './form/ReactSelect';
|
|
|
|
import ReactTextarea from "./form/ReactTextarea";
|
2018-05-21 15:03:46 -05:00
|
|
|
|
|
|
|
|
2018-10-09 11:50:51 -05:00
|
|
|
export const BasicField = observer((props:{field:Field, placeholder?:string, label?:string, wrapperClassName?:string, inputClassNames?:string}) =>{
|
2018-06-29 12:42:56 -05:00
|
|
|
let field = props.field as HoudiniField
|
2018-05-21 15:03:46 -05:00
|
|
|
return <LabeledFieldComponent
|
2018-06-29 12:42:56 -05:00
|
|
|
inputId={props.field.id} labelText={field.label} inError={field.hasError} error={field.error}
|
|
|
|
inStickyError={field.hasServerError} stickyError={field.serverError}
|
|
|
|
className={props.wrapperClassName} >
|
2018-10-09 11:50:51 -05:00
|
|
|
<ReactInput field={field} label={props.label} placeholder={props.placeholder} className={`form-control ${props.inputClassNames || ''}`}/>
|
2018-05-21 15:03:46 -05:00
|
|
|
</LabeledFieldComponent>
|
2018-10-01 15:27:58 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
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 <LabeledFieldComponent
|
|
|
|
inputId={props.field.id} labelText={field.label} inError={field.hasError} error={field.error}
|
|
|
|
inStickyError={field.hasServerError} stickyError={field.serverError}
|
|
|
|
className={props.wrapperClassName} >
|
|
|
|
|
|
|
|
<ReactSelect field={field} label={props.label} placeholder={props.placeholder} className={`form-control ${props.inputClassNames}`} options={props.options}/>
|
|
|
|
|
|
|
|
</LabeledFieldComponent>
|
|
|
|
})
|
|
|
|
|
|
|
|
export const TextareaField = observer((props:{field:Field, placeholder?:string, label?:string, wrapperClassName?:string, inputClassNames?:string, rows?:number}) =>{
|
|
|
|
let field = props.field as HoudiniField
|
|
|
|
return <LabeledFieldComponent
|
|
|
|
inputId={props.field.id} labelText={field.label} inError={field.hasError} error={field.error}
|
|
|
|
inStickyError={field.hasServerError} stickyError={field.serverError}
|
|
|
|
className={props.wrapperClassName} >
|
|
|
|
|
|
|
|
<ReactTextarea field={field} label={props.label} placeholder={props.placeholder} className={`form-control ${props.inputClassNames}`} rows={props.rows}/>
|
|
|
|
|
|
|
|
</LabeledFieldComponent>
|
|
|
|
})
|
|
|
|
|
|
|
|
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 <LabeledFieldComponent
|
|
|
|
inputId={props.field.id} labelText={field.label} inError={field.hasError} error={field.error}
|
|
|
|
inStickyError={field.hasServerError} stickyError={field.serverError}
|
|
|
|
className={props.wrapperClassName} >
|
|
|
|
<div className="input-group">
|
|
|
|
<span className="input-group-addon" id={currencySymbolId}>{props.currencySymbol}</span>
|
|
|
|
<ReactInput field={field} label={props.label} placeholder={props.placeholder} className={`form-control ${props.inputClassNames}`} aria-describedby={currencySymbolId}/>
|
|
|
|
</div>
|
|
|
|
</LabeledFieldComponent>
|
|
|
|
|
|
|
|
|
|
|
|
});
|