Presupuestador_web/client/src/components/Forms/FormLabel.tsx

31 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-06-06 11:05:54 +00:00
import * as UI from "@/ui";
import * as LabelPrimitive from "@radix-ui/react-label";
2024-08-12 10:52:11 +00:00
import { t } from "i18next";
2024-06-06 11:05:54 +00:00
import React from "react";
import { FormInputProps } from "./FormProps";
export interface FormLabelProps {
label: string;
hint?: string;
}
export const FormLabel = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
FormLabelProps &
Pick<FormInputProps, "required">
>(({ label, hint, required, ...props }, ref) => {
2024-07-03 15:15:52 +00:00
const { error } = UI.useFormField();
2024-08-12 10:52:11 +00:00
const _hint = hint ? hint : required ? t("common.required") : undefined;
2024-07-03 15:15:52 +00:00
const _hintClassName = error ? "text-destructive font-semibold" : "";
2024-06-06 11:05:54 +00:00
return (
2024-06-29 19:39:25 +00:00
<UI.FormLabel ref={ref} className='flex justify-between text-sm' {...props}>
2024-07-03 15:15:52 +00:00
<span className={`block font-semibold ${_hintClassName}`}>{label}</span>
{_hint && <span className={`text-sm font-medium ${_hintClassName} `}>{_hint}</span>}
2024-06-06 11:05:54 +00:00
</UI.FormLabel>
);
});
FormLabel.displayName = "FormLabel";