mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
33c5f0651c
* Allow sort by more than one key * created custom tooltip component * remove unused code * fixed style for more layouts * added tooltip to query side panel * tooltips added to setting form * finished settings form * added tooltip for perf impact table headers * tooltip for pack table and user form * tooltip on manage policies page * tooltip for manage schedules * tooltip for automations; spacing for form input * tooltip for automations modal * user form; fixed input with icon component * more user form tooltips * tooltip for homepage; style fixes * replaced many more tooltips with new version * added story for tooltip * added position prop * fixed tests * re-work how we click react-select dropdowns * forcing the update button click * trying a blur * fixed typo * trying blur on another element * temp check-in * replaced tooltip from host details software * more consolidation of tooltip use for software * fixed settings flow test Co-authored-by: Tomas Touceda <chiiph@gmail.com>
83 lines
1.5 KiB
TypeScript
83 lines
1.5 KiB
TypeScript
import React from "react";
|
|
import classnames from "classnames";
|
|
import { isEmpty } from "lodash";
|
|
|
|
import TooltipWrapper from "components/TooltipWrapper";
|
|
|
|
const baseClass = "form-field";
|
|
|
|
export interface IFormFieldProps {
|
|
children: JSX.Element;
|
|
className: string;
|
|
error: string;
|
|
hint: Array<any> | JSX.Element | string;
|
|
label: Array<any> | JSX.Element | string;
|
|
name: string;
|
|
type: string;
|
|
tooltip?: string;
|
|
}
|
|
|
|
const FormField = ({
|
|
children,
|
|
className,
|
|
error,
|
|
hint,
|
|
label,
|
|
name,
|
|
type,
|
|
tooltip,
|
|
}: IFormFieldProps): JSX.Element => {
|
|
const renderLabel = () => {
|
|
const labelWrapperClasses = classnames(`${baseClass}__label`, {
|
|
[`${baseClass}__label--error`]: !isEmpty(error),
|
|
});
|
|
|
|
if (!label) {
|
|
return false;
|
|
}
|
|
|
|
return (
|
|
<label
|
|
className={labelWrapperClasses}
|
|
htmlFor={name}
|
|
data-has-tooltip={!!tooltip}
|
|
>
|
|
{error ||
|
|
(tooltip ? (
|
|
<TooltipWrapper tipContent={tooltip}>
|
|
{label as string}
|
|
</TooltipWrapper>
|
|
) : (
|
|
<>{label}</>
|
|
))}
|
|
</label>
|
|
);
|
|
};
|
|
|
|
const renderHint = () => {
|
|
if (hint) {
|
|
return <span className={`${baseClass}__hint`}>{hint}</span>;
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
const formFieldClass = classnames(
|
|
baseClass,
|
|
{
|
|
[`${baseClass}--${type}`]: !isEmpty(type),
|
|
},
|
|
className
|
|
);
|
|
|
|
return (
|
|
<div className={formFieldClass}>
|
|
{renderLabel()}
|
|
{children}
|
|
{renderHint()}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default FormField;
|