Components
Button
Starts an action, such as saving a form or opening a dialog.
import { Button } from '@dex/shared/components/button'
export function ButtonVariants() {
return (
<>
<Button>Default</Button>
<Button variant="brand">Brand</Button>
<Button variant="secondary">Secondary</Button>
<Button variant="outline">Outline</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="destructive">Destructive</Button>
</>
)
}
import { Button } from '@dex/shared/components/button'
export function ButtonSizes() {
return (
<>
<Button size="sm">Small</Button>
<Button>Default</Button>
<Button size="lg">Large</Button>
<Button size="xl">Extra large</Button>
</>
)
}
import { ArrowRight, Mail, Plus } from 'lucide-react'
import { Button } from '@dex/shared/components/button'
export function ButtonWithIcon() {
return (
<>
<Button>
<Mail /> Send email
</Button>
<Button variant="outline">
<Plus /> Add role
</Button>
<Button variant="ghost">
Continue <ArrowRight />
</Button>
</>
)
}
import { Plus, Settings, X } from 'lucide-react'
import { Button } from '@dex/shared/components/button'
export function ButtonIconOnly() {
return (
<>
<Button size="icon-sm" variant="ghost" aria-label="Close">
<X />
</Button>
<Button size="icon" variant="outline" aria-label="Settings">
<Settings />
</Button>
<Button size="icon-lg" aria-label="Add">
<Plus />
</Button>
</>
)
}
Text button
A button’s height and padding with no shape, such as “Show more” under a list. Text with no padding round it, in a line of copy or a footer, is a text link.
import { Button } from '@dex/shared/components/button'
export function ButtonTextButton() {
return (
<>
<Button variant="link">Show 4 more</Button>
<Button variant="link" size="sm">
Show 4 more
</Button>
</>
)
}
import { Button } from '@dex/shared/components/button'
export function ButtonSignIn() {
return (
<>
<Button variant="linkedin" size="lg">
Continue with LinkedIn
</Button>
<Button variant="google" size="lg">
Continue with Google
</Button>
</>
)
}
'use client'
import { useState } from 'react'
import { Button } from '@dex/shared/components/button'
export function ButtonLoading() {
const [isSaving, setIsSaving] = useState(false)
const save = () => {
setIsSaving(true)
window.setTimeout(() => setIsSaving(false), 1500)
}
return (
<>
<Button loading={isSaving} onClick={save}>
Save changes
</Button>
<Button variant="outline" loading>
Saving
</Button>
</>
)
}
import { Button } from '@dex/shared/components/button'
export function ButtonDisabled() {
return (
<>
<Button disabled>Default</Button>
<Button variant="brand" disabled>
Brand
</Button>
<Button variant="outline" disabled>
Outline
</Button>
<Button variant="ghost" disabled>
Ghost
</Button>
</>
)
}
import Link from 'next/link'
import { Button } from '@dex/shared/components/button'
export function ButtonAsLink() {
return (
<Button variant="outline" render={<Link href="/components/button" />}>
Browse roles
</Button>
)
}
- One
defaultorbrandbutton per view, for the thing we most want done.brandis for the main conversion action only; everything else steps down tooutlineorghost. - Name what happens: "Save changes", "Apply", not "OK" or "Submit". Sentence case, no full stop.
- Pass
loadingwhile the action runs, instead of swapping in a spinner. It shows the spinner and stops a second press. - Keep a form's main button active and say what's missing when it's pressed, rather than leaving it disabled with no reason given.
- An icon-only button needs an
aria-label. - For navigation, render the button as a link with
render, so it is a real link to the browser and to assistive technology.