27 lines
832 B
TypeScript
27 lines
832 B
TypeScript
|
|
import * as UI from "@/ui";
|
||
|
|
import * as LabelPrimitive from "@radix-ui/react-label";
|
||
|
|
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) => {
|
||
|
|
const _hint = hint ? hint : required ? "obligatorio" : undefined;
|
||
|
|
return (
|
||
|
|
<UI.FormLabel ref={ref} className="flex justify-between" {...props}>
|
||
|
|
<span className="block font-semibold">{label}</span>
|
||
|
|
{_hint && <span className="font-normal">{_hint}</span>}
|
||
|
|
</UI.FormLabel>
|
||
|
|
);
|
||
|
|
});
|
||
|
|
|
||
|
|
FormLabel.displayName = "FormLabel";
|