Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.1 KB
Raw Blame
import { cva } from 'cva'
import { HTMLAttributes, LabelHTMLAttributes, forwardRef } from 'react'

import { cn } from 'lib/utils/css-classes'

const labelVariants = cva({
    base: 'font-semibold',
    variants: {
        intent: {
            menu: 'text-tertiary uppercase font-semibold text-[0.6875rem] leading-5 tracking-[0.075em]',
        },
    },
})

export interface LabelProps extends LabelHTMLAttributes<HTMLLabelElement> {
    intent?: 'menu'
}

export const Label = forwardRef<HTMLLabelElement, LabelProps>(({ className, intent, htmlFor, ...props }, ref) => {
    if (!htmlFor) {
        // When rendering as div, exclude label-specific props
        const { form, ...divProps } = props as LabelHTMLAttributes<HTMLLabelElement>
        return (
            <div
                className={cn(labelVariants({ intent }), className)}
                ref={ref as React.Ref<HTMLDivElement>}
                {...(divProps as HTMLAttributes<HTMLDivElement>)}
            />
        )
    }
    return <label className={cn(labelVariants({ intent }), className)} htmlFor={htmlFor} ref={ref} {...props} />
})

Label.displayName = 'Label'