Label

The name of a control, on Radix Label: htmlFor points it at the control, so a click on it reaches the control.

import { Input } from "@produkto/ui/Input";
import { Label } from "@produkto/ui/Label";

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-2">
    <Label htmlFor="label-preview">Label</Label>
    <Input id="label-preview" placeholder="Placeholder" />
  </div>
);

export default Example;

Usage

import { Label } from "@produkto/ui/Label";
<Label htmlFor="email">Label</Label>

Examples

Sizes

size sets its text: sm 12px, base 14px (the default) or lg 16px.

import { Input } from "@produkto/ui/Input";
import { Label, type LabelSize } from "@produkto/ui/Label";

const variants: { size: LabelSize; label: string }[] = [
  { size: "sm", label: "Small" },
  { size: "base", label: "Base" },
  { size: "lg", label: "Large" },
];

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    {variants.map((variant) => (
      <div className="flex flex-col gap-2" key={variant.size}>
        <Label htmlFor={`label-size-${variant.size}`} size={variant.size}>
          {variant.label}
        </Label>
        <Input id={`label-size-${variant.size}`} placeholder="Placeholder" />
      </div>
    ))}
  </div>
);

export default Example;

With icon

An Icon goes inside the Label as a child, before its text.

import { Tag01Icon } from "@hugeicons/core-free-icons";
import { Icon } from "@produkto/ui/Icon";
import { Input } from "@produkto/ui/Input";
import { Label } from "@produkto/ui/Label";

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-2">
    <Label htmlFor="label-icon">
      <Icon icon={Tag01Icon} />
      Label
    </Label>
    <Input id="label-icon" placeholder="Placeholder" />
  </div>
);

export default Example;

Required

required adds a mark after the text, hidden from screen readers, which hear required on the input instead, beside a label as it is by default.

import { Input } from "@produkto/ui/Input";
import { Label } from "@produkto/ui/Label";

const Example = () => (
  <div className="flex w-full max-w-xs flex-col gap-4">
    <div className="flex flex-col gap-2">
      <Label htmlFor="label-optional">Label</Label>
      <Input id="label-optional" placeholder="Placeholder" />
    </div>
    <div className="flex flex-col gap-2">
      <Label htmlFor="label-required" required>
        Label
      </Label>
      <Input id="label-required" placeholder="Placeholder" required />
    </div>
  </div>
);

export default Example;

API Reference

Label

LabelProps · components/Label/Label.types.ts
PropTypeDefault
sizeLabelSize"sm" | "base" | "lg""base"
requiredboolean-
infoReactNode-

It also takes the props of Radix Label.Root.