mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 09:18:59 +00:00
ee6832c743
* AppSettingsPage at /admin/settings * Adds App Settings to site nav items * SMTP not configured warning * Creates AppConfigForm * Avatar preview * API client to update app config * Creates OrgLogoIcon component * Hide username/password when no auth type
64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
import React, { Component, PropTypes } from 'react';
|
|
import classnames from 'classnames';
|
|
|
|
const baseClass = 'form-field';
|
|
|
|
class FormField extends Component {
|
|
static propTypes = {
|
|
children: PropTypes.node,
|
|
className: PropTypes.string,
|
|
error: PropTypes.string,
|
|
hint: PropTypes.oneOfType([PropTypes.array, PropTypes.node, PropTypes.string]),
|
|
label: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
|
|
name: PropTypes.string,
|
|
type: PropTypes.string,
|
|
};
|
|
|
|
renderLabel = () => {
|
|
const { error, label, name } = this.props;
|
|
const labelWrapperClasses = classnames(
|
|
`${baseClass}__label`,
|
|
{ [`${baseClass}__label--error`]: error }
|
|
);
|
|
|
|
if (!label) {
|
|
return false;
|
|
}
|
|
|
|
return (
|
|
<label className={labelWrapperClasses} htmlFor={name}>
|
|
{error || label}
|
|
</label>
|
|
);
|
|
}
|
|
|
|
renderHint = () => {
|
|
const { hint } = this.props;
|
|
|
|
if (hint) {
|
|
return <span className={`${baseClass}__hint`}>{hint}</span>;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
render () {
|
|
const { renderLabel, renderHint } = this;
|
|
const { children, className, type } = this.props;
|
|
|
|
const formFieldClass = classnames(baseClass, {
|
|
[`${baseClass}--${type}`]: type,
|
|
}, className);
|
|
|
|
return (
|
|
<div className={formFieldClass}>
|
|
{renderLabel()}
|
|
{children}
|
|
{renderHint()}
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default FormField;
|