Label
A label for a form control.
Also uses Checkbox.
label-demo.tsx
import { Checkbox } from './ui/checkbox.tsx'
import { Label } from './ui/label.tsx'
export default () => (
<div style="display: flex; align-items: center; gap: 0.5rem">
<Checkbox id="label-terms" />
<Label for="label-terms">Accept terms and conditions</Label>
</div>
)
Installation
dui add labelOr copy ui/label.tsx and ui/label.css into your project, with lib/jsx/jsx-runtime.ts, lib/jsx/jsx-dev-runtime.ts, lib/css.d.ts, and lib/theme.css.
Examples
Around its control
Also uses Switch.
label-wrapping.tsx
import { Label } from './ui/label.tsx'
import { Switch } from './ui/switch.tsx'
// A label around its control needs no id, and looks disabled when the control is.
export default () => (
<div style="display: grid; gap: 1rem">
<Label>
<Switch /> Wi-Fi
</Label>
<Label>
<Switch disabled /> Bluetooth
</Label>
</div>
)
Compared to shadcn/ui
- A plain
<label>instead of Radix's Label. - It looks disabled when its control is: one inside it, or one just before it (shadcn's
peer-disabled).