Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

1.0 KB
Raw Blame
import { ReactNode } from 'react';
import { Typography } from '@signozhq/ui/typography';
import { FieldError } from 'react-hook-form';

import FieldLabel from './FieldLabel';

import styles from './FormField.module.scss';

interface FormFieldProps {
	htmlFor: string;
	label: string;
	tooltip: string;
	required?: boolean;
	error?: FieldError;
	children: ReactNode;
}

/** A labelled setup drawer field with its validation message below the input. */
function FormField({
	htmlFor,
	label,
	tooltip,
	required,
	error,
	children,
}: FormFieldProps): JSX.Element {
	return (
		<div className={styles.drawerSection}>
			<FieldLabel
				htmlFor={htmlFor}
				label={label}
				tooltip={tooltip}
				required={required}
			/>
			{children}
			{error && (
				<Typography.Text
					as="span"
					size="small"
					role="alert"
					className={styles.fieldError}
				>
					{error.message}
				</Typography.Text>
			)}
		</div>
	);
}

FormField.defaultProps = {
	required: false,
	error: undefined,
};

export default FormField;