houdini/javascripts/src/components/common/LabeledFieldComponent.tsx

42 lines
1.4 KiB
TypeScript
Raw Normal View History

// License: LGPL-3.0-or-later
import * as React from 'react';
import StandardFieldComponent from "./StandardFieldComponent";
2018-06-29 13:13:31 -05:00
import {observer} from 'mobx-react';
import {InjectedIntl, injectIntl} from 'react-intl';
export interface LabeledFieldComponentProps
{
inputId: string
labelText: string
inError:boolean
error?:string
2018-06-29 12:42:56 -05:00
inStickyError?:boolean
stickyError?:string
className?:string
2019-04-18 13:53:11 -05:00
style?:React.CSSProperties
}
@observer
export default class LabeledFieldComponent extends React.Component<LabeledFieldComponentProps, {}> {
render() {
2018-06-29 12:42:56 -05:00
let classNames:string[] = []
if (this.props.className)
classNames.push(this.props.className)
let inError = this.props.inError && this.props.error !== null && this.props.error !== "";
let inStickyError = this.props.inStickyError && this.props.stickyError !== null && this.props.stickyError !== ""
classNames.push("form-group")
if(inError || inStickyError){
classNames.push("has-error")
}
2019-04-18 13:53:11 -05:00
return <fieldset className={classNames.join(" ")} style={this.props.style}><label htmlFor={this.props.inputId} className="control-label">{this.props.labelText}</label>
2018-06-29 12:42:56 -05:00
<StandardFieldComponent inError={inError} error={this.props.error} inStickyError={inStickyError} stickyError={this.props.stickyError}>{this.props.children}</StandardFieldComponent>
</fieldset>;
}
}