Files

27 lines
926 B
TypeScript
Raw Permalink Normal View History

2023-06-09 18:21:18 +10:00
import * as React from 'react';
import * as LabelPrimitive from '@radix-ui/react-label';
2025-01-02 15:33:37 +11:00
import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority';
2023-06-09 18:21:18 +10:00
import { cn } from '../lib/utils';
const labelVariants = cva(
'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
);
const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
2023-09-20 13:48:30 +10:00
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants> & { required?: boolean }
>(({ className, children, required, ...props }, ref) => (
<LabelPrimitive.Root ref={ref} className={cn(labelVariants(), className)} {...props}>
{children}
{required && <span className="text-destructive ml-1 inline-block font-medium">*</span>}
</LabelPrimitive.Root>
2023-06-09 18:21:18 +10:00
));
Label.displayName = LabelPrimitive.Root.displayName;
export { Label };