Components
Label
Names a form control, and focuses it when pressed.
import { Input } from '@dex/shared/components/input'
import { Label } from '@dex/shared/components/label'
export function LabelDefault() {
return (
<div className="grid w-full max-w-sm gap-2">
<Label htmlFor="label-github">GitHub username</Label>
<Input id="label-github" placeholder="e.g. samokafor" />
</div>
)
}
An email when Dex finds a match.
import { Label } from '@dex/shared/components/label'
import { Switch } from '@dex/shared/components/switch'
export function LabelWithASwitch() {
return (
<div className="flex w-full max-w-sm items-center gap-4">
<div className="min-w-0 flex-1">
<Label htmlFor="label-new-roles">New role emails</Label>
<p className="mt-0.5 text-sm text-muted-foreground">An email when Dex finds a match.</p>
</div>
<Switch id="label-new-roles" defaultChecked />
</div>
)
}
import { Checkbox } from '@dex/shared/components/checkbox'
import { Label } from '@dex/shared/components/label'
export function LabelAroundACheckbox() {
return (
<Label className="items-start gap-3 font-normal">
<Checkbox defaultChecked />
<span>I currently work here</span>
</Label>
)
}
import { Field, FieldControl, FieldLabel } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function LabelInAField() {
return (
<Field className="max-w-sm">
<FieldLabel>Current company</FieldLabel>
<FieldControl>
<Input placeholder="e.g. Northwind" />
</FieldControl>
</Field>
)
}
import { Field, FieldControl, FieldLabel } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function LabelOptional() {
return (
<Field className="max-w-sm">
<FieldLabel optional>Preferred name</FieldLabel>
<FieldControl>
<Input />
</FieldControl>
</Field>
)
}
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { FieldLegend, FieldSet } from '@dex/shared/components/field'
export function LabelForAGroup() {
return (
<FieldSet>
<FieldLegend>How do you want to work?</FieldLegend>
<ChipGroup type="multiple" defaultValue={['hybrid']}>
<Chip value="remote">Remote</Chip>
<Chip value="hybrid">Hybrid</Chip>
<Chip value="office">In the office</Chip>
</ChipGroup>
</FieldSet>
)
}
import { Field, FieldControl, FieldLabel } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function LabelDisabled() {
return (
<Field disabled className="max-w-sm">
<FieldLabel>Current company</FieldLabel>
<FieldControl>
<Input defaultValue="Northwind" disabled />
</FieldControl>
</Field>
)
}
Fieldholds one control with its label and message. It owns the ids that connect them. PasscontrolIdwhen the control needs an id you know elsewhere, andinvalidordisabledfor the whole field.FieldLabelis the label. It points at the field's control without anhtmlFor.FieldControlwraps the one control. It passes on the field's id, its error state and the id of the message.FieldMessagetakes the helper text asdescriptionand the error aserror, and shows the error in the helper text's place while there is one.FieldSetandFieldLegenddo the same for a group of options, such as chips, radios or choice cards.invalidon theFieldSetturns every option's border red.
- Every control has a label. In a form, that is a
FieldLabelin aField. UseLabelon its own for a control outside a field, such as a switch in a settings row. - Join a
Labelto its control withhtmlFor, or wrap the control in it. WithhtmlFor, the cursor becomes a pointer over the label. - A label names one control. For one question with several options, use a
FieldLegendin aFieldSet. - Mark a field that can be left empty with
optional. - The label keeps its colour when the field has an error. Only the control's border and the message turn red.