mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { Description, Field, Label } from '@headlessui/react';
|
|
|
|
type FormFieldProps = React.InputHTMLAttributes<HTMLInputElement> & {
|
|
label: string;
|
|
error?: string;
|
|
hint?: string;
|
|
labelClassName?: string;
|
|
inputClassName?: string;
|
|
hintClassName?: string;
|
|
};
|
|
|
|
const FormField = ({
|
|
label,
|
|
error,
|
|
hint,
|
|
className,
|
|
labelClassName,
|
|
inputClassName,
|
|
hintClassName,
|
|
...inputProps
|
|
}: FormFieldProps) => {
|
|
return (
|
|
<Field className={className ?? 'space-y-1'}>
|
|
<Label
|
|
htmlFor={inputProps.id}
|
|
className={labelClassName ?? 'label text-sm font-semibold text-base-content'}
|
|
>
|
|
{label}
|
|
</Label>
|
|
|
|
<input
|
|
{...inputProps}
|
|
className={
|
|
inputClassName ?? `input h-11 w-full text-base ${error ? 'input-error' : ''}`
|
|
}
|
|
/>
|
|
|
|
{error ? (
|
|
<Description className={hintClassName ?? 'text-xs text-error'}>{error}</Description>
|
|
) : hint ? (
|
|
<Description className={hintClassName ?? 'text-xs text-[var(--color-muted)]'}>
|
|
{hint}
|
|
</Description>
|
|
) : null}
|
|
</Field>
|
|
);
|
|
};
|
|
|
|
export default FormField;
|