Components
Chips
Short, label-only answers to a question, where one or several can be chosen.
'use client'
import { useState } from 'react'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { FieldLegend, FieldSet } from '@dex/shared/components/field'
export function ChipsSingleChoice() {
const sizes = ['1–10', '11–50', '51–200', '201–1,000', '1,000+']
const [size, setSize] = useState('11–50')
return (
<FieldSet>
<FieldLegend>What size of company do you want to join?</FieldLegend>
<ChipGroup type="single" value={size} onValueChange={(value) => value && setSize(value)}>
{sizes.map((option) => (
<Chip key={option} value={option}>
{option}
</Chip>
))}
</ChipGroup>
</FieldSet>
)
}
'use client'
import { useState } from 'react'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { FieldLegend, FieldMessage, FieldSet } from '@dex/shared/components/field'
export function ChipsMultipleChoice() {
const areas = ['Backend', 'Frontend', 'Machine learning', 'Platform', 'Data']
const [chosen, setChosen] = useState(['Backend', 'Machine learning'])
return (
<FieldSet>
<FieldLegend>Which areas do you work in?</FieldLegend>
<ChipGroup type="multiple" value={chosen} onValueChange={setChosen}>
{areas.map((area) => (
<Chip key={area} value={area}>
{area}
</Chip>
))}
</ChipGroup>
<FieldMessage description="Choose all that apply." />
</FieldSet>
)
}
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
export function ChipsSmall() {
return (
<div className="flex w-full flex-col gap-4">
<ChipGroup type="single" chipSize="sm" defaultValue="1 month" aria-label="Notice period">
<Chip value="Immediately">Immediately</Chip>
<Chip value="1 month">1 month</Chip>
<Chip value="2 months">2 months</Chip>
<Chip value="3 months">3 months</Chip>
</ChipGroup>
<ChipGroup
type="multiple"
chipSize="sm"
defaultValue={['Hybrid']}
aria-label="Ways of working"
>
<Chip value="Remote">Remote</Chip>
<Chip value="Hybrid">Hybrid</Chip>
<Chip value="In the office">In the office</Chip>
</ChipGroup>
</div>
)
}
'use client'
import { useState } from 'react'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { FieldLegend, FieldSet } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
export function ChipsOtherRevealsInput() {
const sources = ['LinkedIn', 'A friend', 'Podcast', 'Other']
const [source, setSource] = useState('Other')
return (
<FieldSet className="w-full max-w-md">
<FieldLegend>How did you hear about Dex?</FieldLegend>
<ChipGroup type="single" value={source} onValueChange={(value) => value && setSource(value)}>
{sources.map((option) => (
<Chip key={option} value={option}>
{option}
</Chip>
))}
</ChipGroup>
{source === 'Other' && (
<Input aria-label="Where you heard about Dex" placeholder="Tell us where" />
)}
</FieldSet>
)
}
'use client'
import { useState } from 'react'
import { Chip, ChipAction, ChipGroup } from '@dex/shared/components/chip-group'
import { FieldLegend, FieldSet } from '@dex/shared/components/field'
import { Input } from '@dex/shared/components/input'
import { Popover, PopoverContent, PopoverTrigger } from '@dex/shared/components/popover'
export function ChipsActions() {
const popular = ['Python', 'TypeScript', 'Go', 'Rust']
const more = ['Kotlin', 'Scala', 'Elixir', 'Haskell', 'C++', 'Swift']
const [languages, setLanguages] = useState(['Python'])
const [isOwnAnswerOpen, setIsOwnAnswerOpen] = useState(false)
const shown = [...popular, ...languages.filter((language) => !popular.includes(language))]
return (
<FieldSet className="w-full">
<FieldLegend>Which languages do you work in?</FieldLegend>
<ChipGroup type="multiple" value={languages} onValueChange={setLanguages}>
{shown.map((language) => (
<Chip key={language} value={language}>
{language}
</Chip>
))}
<Popover>
<PopoverTrigger render={<ChipAction />}>More</PopoverTrigger>
<PopoverContent align="start" className="w-72">
<ChipGroup
type="multiple"
chipSize="sm"
aria-label="More languages"
value={languages}
onValueChange={setLanguages}
>
{more.map((language) => (
<Chip key={language} value={language}>
{language}
</Chip>
))}
</ChipGroup>
</PopoverContent>
</Popover>
<ChipAction
aria-expanded={isOwnAnswerOpen}
onClick={() => setIsOwnAnswerOpen((isOpen) => !isOpen)}
>
Something else
</ChipAction>
</ChipGroup>
{isOwnAnswerOpen && <Input aria-label="Another language" placeholder="e.g. OCaml" />}
</FieldSet>
)
}
'use client'
import { useState } from 'react'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { FieldLegend, FieldMessage, FieldSet } from '@dex/shared/components/field'
export function ChipsInvalid() {
const places = ['London', 'Manchester', 'Edinburgh', 'Remote, UK']
const [chosen, setChosen] = useState<string[]>([])
const isInvalid = chosen.length === 0
return (
<FieldSet invalid={isInvalid}>
<FieldLegend>Where do you want to work?</FieldLegend>
<ChipGroup type="multiple" value={chosen} onValueChange={setChosen}>
{places.map((place) => (
<Chip key={place} value={place}>
{place}
</Chip>
))}
</ChipGroup>
{isInvalid && <FieldMessage error="Choose at least one option." />}
</FieldSet>
)
}
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
export function ChipsDisabled() {
return (
<ChipGroup type="single" defaultValue="Senior" disabled aria-label="Level">
<Chip value="Mid">Mid</Chip>
<Chip value="Senior">Senior</Chip>
<Chip value="Staff">Staff</Chip>
<Chip value="Principal">Principal</Chip>
</ChipGroup>
)
}
Press a reply to send it.
'use client'
import { useState } from 'react'
import { ChipButton, ChipGroup } from '@dex/shared/components/chip-group'
export function ChipsQuickReplies() {
const replies = ['Tell me more about the role', "What's the tech stack?", 'How does equity work?']
const [sent, setSent] = useState<string | null>(null)
return (
<div className="flex w-full flex-col gap-3">
<p className="text-sm text-muted-foreground">
{sent ? `Sent: "${sent}"` : 'Press a reply to send it.'}
</p>
<ChipGroup type="single" role="group" chipSize="sm" aria-label="Quick replies">
{replies.map((reply) => (
<ChipButton key={reply} onClick={() => setSent(reply)}>
{reply}
</ChipButton>
))}
</ChipGroup>
</div>
)
}
Have you run Kubernetes in production before?
'use client'
import { PencilLine } from 'lucide-react'
import { useState } from 'react'
import { ChipButton, ChipGroup } from '@dex/shared/components/chip-group'
import { Input } from '@dex/shared/components/input'
export function ChipsStarters() {
const starters = ["Yes, I've run", "Not exactly, but I've", "No, I haven't"]
const [message, setMessage] = useState('')
return (
<div className="flex w-full max-w-xl flex-col gap-3">
<p className="text-sm">Have you run Kubernetes in production before?</p>
<ChipGroup type="single" role="group" chipSize="sm" aria-label="Starters">
{starters.map((starter) => (
<ChipButton key={starter} onClick={() => setMessage(`${starter} `)}>
{starter}
<PencilLine aria-hidden className="text-muted-foreground" />
</ChipButton>
))}
</ChipGroup>
<Input
aria-label="Message"
placeholder="Message Dex"
value={message}
onChange={(event) => setMessage(event.target.value)}
/>
</div>
)
}
- Use chips for short answers that need no explanation. An option that needs a sentence of explanation is a choice card.
- A chip is always a pill, so it never reads as a button.
- Use the default 40px chip in forms and the small 32px chip in chat.
- A chip group sits in a
FieldSetwith its question as theFieldLegend. Passoptionalto the legend of a group that can be skipped. Without a visible question, give the group anaria-label. - Set
invalidon theFieldSet, oraria-invalidon theChipGroup, and every chip and action in it turns red. One message goes under the group. - A chip that does something rather than being an answer is a
ChipButtonorChipAction, not aChip. It is a plain button, so it is never on and a screen reader does not announce it as an unpressed toggle.