Components
Switch
Turns a setting on or off, and applies it straight away.
import { Label } from '@dex/shared/components/label'
import { Switch } from '@dex/shared/components/switch'
export function SwitchDefault() {
return (
<div className="flex items-center gap-3">
<Switch id="switch-open-to-roles" defaultChecked />
<Label htmlFor="switch-open-to-roles" className="font-normal">
Open to new roles
</Label>
</div>
)
}
Hide roles that need you in an office.
import { FieldDescription } from '@dex/shared/components/field'
import { Label } from '@dex/shared/components/label'
import { Switch } from '@dex/shared/components/switch'
export function SwitchWithDescription() {
return (
<div className="flex items-start gap-3">
<Switch id="switch-remote-only" />
<div className="flex flex-col gap-0.5">
<Label htmlFor="switch-remote-only">Remote only</Label>
<FieldDescription>Hide roles that need you in an office.</FieldDescription>
</div>
</div>
)
}
Hiring teams on Dex can find your profile.
'use client'
import { useState } from 'react'
import { FieldDescription } from '@dex/shared/components/field'
import { Label } from '@dex/shared/components/label'
import { Switch } from '@dex/shared/components/switch'
export function SwitchControlled() {
const [isVisible, setIsVisible] = useState(true)
return (
<div className="flex items-start gap-3">
<Switch id="switch-visible" checked={isVisible} onCheckedChange={setIsVisible} />
<div className="flex flex-col gap-0.5">
<Label htmlFor="switch-visible">Visible to companies</Label>
<FieldDescription>
{isVisible
? 'Hiring teams on Dex can find your profile.'
: 'Your profile is hidden from hiring teams.'}
</FieldDescription>
</div>
</div>
)
}
An email when a role matches your profile.
A Monday email with the week's new roles.
Always on while you have a live application.
import { FieldDescription } from '@dex/shared/components/field'
import { Label } from '@dex/shared/components/label'
import { Switch } from '@dex/shared/components/switch'
export function SwitchSettingsRows() {
return (
<div className="flex w-full max-w-md flex-col">
<div className="flex items-center justify-between gap-6 pb-3">
<div className="flex flex-col gap-0.5">
<Label htmlFor="switch-setting-matches">New role matches</Label>
<FieldDescription>An email when a role matches your profile.</FieldDescription>
</div>
<Switch id="switch-setting-matches" defaultChecked />
</div>
<div className="flex items-center justify-between gap-6 border-t-hairline py-3">
<div className="flex flex-col gap-0.5">
<Label htmlFor="switch-setting-digest">Weekly digest</Label>
<FieldDescription>A Monday email with the week's new roles.</FieldDescription>
</div>
<Switch id="switch-setting-digest" />
</div>
<div className="flex items-center justify-between gap-6 border-t-hairline pt-3 opacity-50">
<div className="flex flex-col gap-0.5">
<Label htmlFor="switch-setting-updates">Application updates</Label>
<FieldDescription>Always on while you have a live application.</FieldDescription>
</div>
<Switch
id="switch-setting-updates"
defaultChecked
disabled
className="disabled:opacity-100"
/>
</div>
</div>
)
}
import { Label } from '@dex/shared/components/label'
import { Switch } from '@dex/shared/components/switch'
export function SwitchDisabled() {
return (
<div className="flex flex-col gap-3">
<div className="flex items-center gap-3">
<Switch id="switch-disabled-off" disabled />
<Label htmlFor="switch-disabled-off" className="font-normal">
Open to contract roles
</Label>
</div>
<div className="flex items-center gap-3">
<Switch id="switch-disabled-on" disabled defaultChecked />
<Label htmlFor="switch-disabled-on" className="font-normal">
Open to permanent roles
</Label>
</div>
</div>
)
}
- Use a switch for a setting that applies straight away, such as profile visibility.
- A switch never errors, so it has no invalid state.
- Join the switch to its label with
idandhtmlFor. Beside a single setting the label sits 12px to the right of the switch. - In a list of settings, put the text on the left and the switch on the right, with a hairline between rows.
- A setting the person can't change is
disabledand drops to 50%. When it is on it keeps its fill, so it still shows the setting.