# Label
The visible name of a form control.
Source page: https://dinachi.dev/docs/components/label

## Installation
```bash
npx @dinachi/cli@latest add label
```
Adds to your project:
- `components/ui/label/label.tsx`
- `components/ui/label/index.ts`

## Usage
```tsx
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"

export function EmailField() {
  return (
    <div className="grid gap-1.5">
      <Label htmlFor="email">Email</Label>
      <Input id="email" type="email" />
    </div>
  )
}
```

## Examples

### Default
A label paired with an input.
```tsx
import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';

export function Example() {
  return (
    <div className="grid w-full max-w-sm items-center gap-1.5">
      <Label htmlFor="email">Email</Label>
      <Input type="email" id="email" placeholder="Email" />
    </div>
  );
}
```

### Disabled
A label beside a disabled input.
```tsx
import { Label } from '@/components/ui/label';
import { Input } from '@/components/ui/input';

export function Example() {
  return (
    <div className="grid w-full max-w-sm items-center gap-1.5">
      <Label htmlFor="disabled" className="peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
        Disabled
      </Label>
      <Input type="text" id="disabled" placeholder="Disabled" disabled className="peer" />
    </div>
  );
}
```

## Notes

### Disabled styling
The label dims through Tailwind's `peer-disabled:`, so it must come after a disabled control with the `peer` class.

### Inside a Field
Inside a `Field`, use `FieldLabel`. It wires the label to the control and its validation state.

## API reference

### Label
A styled native `label` element.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `htmlFor` | `string` | - | Id of the named control. Clicking the label focuses it. |
| `children` **agent** | `ReactNode` | - | The name, read by the agent as the control's label. |
| `className` | `string` | - | Merged with the default classes. |

## Accessibility
- A native label; its text is the control's accessible name.
- Link it with `htmlFor` and a matching id, or wrap the control inside it.
- The agent addresses a labelled field by its label text.

## Source
`components/ui/label/label.tsx`
```tsx
"use client"

import * as React from "react"
import { cn } from "@/lib/utils"

const Label = React.forwardRef<
  HTMLLabelElement,
  React.ComponentProps<"label">
>(({ className, ...props }, ref) => (
  <label
    ref={ref}
    data-slot="label"
    className={cn(
      "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
      className
    )}
    {...props}
  />
))
Label.displayName = "Label"

export { Label }
```
