mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 13:37:30 +00:00
* add prettier and have it format all js code except website: : * trying running prettier check in CI * fix runs on in CI * change CI job name * fix prettier erros and fix CI
75 lines
1.5 KiB
JavaScript
75 lines
1.5 KiB
JavaScript
import React, { Component } from "react";
|
|
import PropTypes from "prop-types";
|
|
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,
|
|
PropTypes.node,
|
|
]),
|
|
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;
|