Components
State rules
Every control moves through the same states, drawn with the same tokens.
A control's border carries most of its state. It is the foreground colour at one of three strengths, and each state is one step along.
- Rest. A 1px
control-border-subtleborder, 25% of foreground, on acardfill. Every control starts here. - Hover. The border steps up to
control-border, 50%. Nothing fills and nothing moves. A selected item does not change on hover. - Focus. The border steps up again to
control-border-strong, 75%. It shows for the keyboard only, and nothing is drawn outside the control. - Selected.
primary. Small things fill with it and choice cards take a primary border. Selected has the patterns. - Invalid. A
destructiveborder on the control, or on every option in a group, with a message under it. Errors has the patterns and the wording. - Disabled. The whole field at 50%, with the rest border and a
mutedfill, and no hover. A selected or on control keepsprimary, so it still shows its value. - Read-only. Fields only. A
mutedfill, full-contrast text, a lock, and helper text saying where the value came from.
A new control that follows these rules fits the set.
import { Checkbox } from '@dex/shared/components/checkbox'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { ChoiceCardRadio, ChoiceCardRadioGroup } from '@dex/shared/components/choice-card'
import { Input } from '@dex/shared/components/input'
import { RadioGroup, RadioGroupItem } from '@dex/shared/components/radio-group'
import { Switch } from '@dex/shared/components/switch'
export function StateRulesRestHoverFocus() {
return (
<>
<Input aria-label="City" placeholder="London" className="w-44" />
<Checkbox aria-label="Open to relocating" />
<RadioGroup aria-label="Notice period">
<RadioGroupItem value="1-month" aria-label="1 month" />
</RadioGroup>
<Switch aria-label="Open to new roles" />
<ChipGroup type="single" aria-label="Way of working" className="w-fit">
<Chip value="remote">Remote</Chip>
</ChipGroup>
<ChoiceCardRadioGroup aria-label="Level" className="w-44">
<ChoiceCardRadio value="senior" title="Senior" description="5–8 yrs" />
</ChoiceCardRadioGroup>
</>
)
}
import { Checkbox } from '@dex/shared/components/checkbox'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { ChoiceCardRadio, ChoiceCardRadioGroup } from '@dex/shared/components/choice-card'
import { RadioGroup, RadioGroupItem } from '@dex/shared/components/radio-group'
import { Switch } from '@dex/shared/components/switch'
export function StateRulesSelected() {
return (
<>
<Checkbox aria-label="Open to relocating" defaultChecked />
<RadioGroup aria-label="Notice period" defaultValue="1-month">
<RadioGroupItem value="1-month" aria-label="1 month" />
</RadioGroup>
<Switch aria-label="Open to new roles" defaultChecked />
<ChipGroup type="single" defaultValue="remote" aria-label="Way of working" className="w-fit">
<Chip value="remote">Remote</Chip>
</ChipGroup>
<ChoiceCardRadioGroup defaultValue="senior" aria-label="Level" className="w-44">
<ChoiceCardRadio value="senior" title="Senior" description="5–8 yrs" />
</ChoiceCardRadioGroup>
</>
)
}
import { Checkbox } from '@dex/shared/components/checkbox'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { ChoiceCardRadio, ChoiceCardRadioGroup } from '@dex/shared/components/choice-card'
import { Input } from '@dex/shared/components/input'
import { RadioGroup, RadioGroupItem } from '@dex/shared/components/radio-group'
export function StateRulesInvalid() {
return (
<>
<Input aria-label="City" placeholder="London" aria-invalid className="w-44" />
<Checkbox aria-label="Accept the terms" aria-invalid />
<RadioGroup aria-label="Notice period" aria-invalid>
<RadioGroupItem value="1-month" aria-label="1 month" />
</RadioGroup>
<ChipGroup type="single" aria-label="Way of working" aria-invalid className="w-fit">
<Chip value="remote">Remote</Chip>
</ChipGroup>
<ChoiceCardRadioGroup aria-label="Level" aria-invalid className="w-44">
<ChoiceCardRadio value="senior" title="Senior" description="5–8 yrs" />
</ChoiceCardRadioGroup>
</>
)
}
import { Checkbox } from '@dex/shared/components/checkbox'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { ChoiceCardRadio, ChoiceCardRadioGroup } from '@dex/shared/components/choice-card'
import { Input } from '@dex/shared/components/input'
import { RadioGroup, RadioGroupItem } from '@dex/shared/components/radio-group'
import { Switch } from '@dex/shared/components/switch'
export function StateRulesDisabled() {
return (
<>
<Input aria-label="City" defaultValue="London" disabled className="w-44" />
<Checkbox aria-label="Open to relocating" disabled />
<Checkbox aria-label="Open to contract roles" disabled defaultChecked />
<RadioGroup aria-label="Notice period" defaultValue="1-month" disabled className="flex">
<RadioGroupItem value="immediately" aria-label="Immediately" />
<RadioGroupItem value="1-month" aria-label="1 month" />
</RadioGroup>
<Switch aria-label="Weekly digest" disabled />
<Switch aria-label="Open to new roles" disabled defaultChecked />
<ChipGroup
type="single"
defaultValue="remote"
disabled
aria-label="Way of working"
className="w-fit"
>
<Chip value="hybrid">Hybrid</Chip>
<Chip value="remote">Remote</Chip>
</ChipGroup>
<ChoiceCardRadioGroup defaultValue="senior" aria-label="Level" className="w-44">
<ChoiceCardRadio value="senior" title="Senior" description="5–8 yrs" disabled />
</ChoiceCardRadioGroup>
</>
)
}
From your LinkedIn profile.
import { Field, FieldControl, FieldLabel, FieldMessage } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function StateRulesReadOnly() {
return (
<Field className="max-w-sm">
<FieldLabel>Current employer</FieldLabel>
<FieldControl>
<Input readOnly defaultValue="Northwind Robotics" />
</FieldControl>
<FieldMessage description="From your LinkedIn profile." />
</Field>
)
}
Focus is always a darker 1px edge, and only for the keyboard (focus-visible). There is no halo: nothing is drawn outside the control, so focus never collides with a neighbour or a popover. How the edge is drawn depends on what the control already has. The class strings are in @dex/shared/styles/focus-ring.
- Bordered controls take
focusBorder: the border itself steps up tocontrol-border-strong. Inputs, selects, checkboxes, radios, switches and chips. - Borderless things take
focusRing: the same edge as a 1px inset ring, which sits where a border would and shifts nothing. Ghost and link buttons, tabs, accordion rows and calendar days. - Text with no padding round it takes
focusOutline: a 1px outline 2px out, because an inset would cut into the letters. Inline links and collapsible section headers. - Filled things keep their primary edge and draw a 1px line in their foreground colour just inside it. A ticked box, a selected radio, chip or calendar cell, a switch that is on, and a solid button.
- An invalid control keeps its red border, and a 1px red inset doubles it. Focus never hides an error.
- A group wrapping a field, such as the file dropzone or the chat composer, takes
focusBorderWithin: its border steps up while the field inside has focus. Buttons inside the group keep their ownfocusRing. - A choice card marks the card, not the radio or checkbox inside it. A selected card doubles its primary border with a 1px primary inset.
- A slider marks the thumb, not the track. The thumb already has a primary edge, so a 1px primary inset doubles it.
Give an element one of these, not two.
Text with no padding, like
import { Button } from '@dex/shared/components/button'
import { Checkbox } from '@dex/shared/components/checkbox'
import { Input } from '@dex/shared/components/input'
import { TextLink } from '@dex/shared/components/text-link'
export function StateRulesFocus() {
return (
<>
<Input aria-label="City" placeholder="A bordered control" className="w-52" />
<Button variant="ghost">A borderless control</Button>
<p className="text-sm text-muted-foreground">
Text with no padding, like <TextLink variant="inline">this link</TextLink>
</p>
<Button>A filled control</Button>
<Checkbox aria-label="A ticked box" defaultChecked />
<Input
aria-label="Work email"
defaultValue="An invalid control"
aria-invalid
className="w-52"
/>
</>
)
}