Components
Follow-ups
Questions that an answer opens, in a muted block under the question that opened them.
'use client'
import { useState } from 'react'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { FieldLegend, FieldSet } from '@dex/shared/components/field'
import { FollowUps } from '@dex/shared/components/follow-ups'
const OFFICE_DAYS = ['1 day', '2 days', '3 days', '4 days']
export function FollowUpsDefault() {
const [hybrid, setHybrid] = useState('yes')
const [days, setDays] = useState('')
const answerHybrid = (answer: string) => {
if (!answer) return
setHybrid(answer)
// The follow-up's answer goes when the block closes.
if (answer === 'no') setDays('')
}
return (
<div className="flex w-full max-w-md flex-col gap-3">
<FieldSet>
<FieldLegend>Open to hybrid?</FieldLegend>
<ChipGroup type="single" value={hybrid} onValueChange={answerHybrid}>
<Chip value="yes">Yes</Chip>
<Chip value="no">No</Chip>
</ChipGroup>
</FieldSet>
{hybrid === 'yes' && (
<FollowUps>
<FieldSet>
<FieldLegend>Up to how many days a week in the office?</FieldLegend>
<ChipGroup type="single" value={days} onValueChange={(next) => next && setDays(next)}>
{OFFICE_DAYS.map((option) => (
<Chip key={option} value={option}>
{option}
</Chip>
))}
</ChipGroup>
</FieldSet>
</FollowUps>
)}
</div>
)
}
'use client'
import { useState } from 'react'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import {
Field,
FieldControl,
FieldLabel,
FieldLegend,
FieldSet,
} from '@dex/shared/components/field'
import { FollowUps } from '@dex/shared/components/follow-ups'
import { Input } from '@dex/shared/components/input'
export function FollowUpsSeveralQuestions() {
const [relocating, setRelocating] = useState('yes')
const [city, setCity] = useState('Manchester')
const [support, setSupport] = useState('')
const answerRelocating = (answer: string) => {
if (!answer) return
setRelocating(answer)
if (answer === 'no') {
setCity('')
setSupport('')
}
}
return (
<div className="flex w-full max-w-md flex-col gap-3">
<FieldSet>
<FieldLegend>Open to relocating?</FieldLegend>
<ChipGroup type="single" value={relocating} onValueChange={answerRelocating}>
<Chip value="yes">Yes</Chip>
<Chip value="no">No</Chip>
</ChipGroup>
</FieldSet>
{relocating === 'yes' && (
<FollowUps>
<Field>
<FieldLabel>Where would you move to?</FieldLabel>
<FieldControl>
<Input
placeholder="e.g. Manchester"
value={city}
onChange={(event) => setCity(event.target.value)}
/>
</FieldControl>
</Field>
<FieldSet>
<FieldLegend>Do you need relocation support?</FieldLegend>
<ChipGroup
type="single"
value={support}
onValueChange={(next) => next && setSupport(next)}
>
<Chip value="yes">Yes</Chip>
<Chip value="no">No</Chip>
</ChipGroup>
</FieldSet>
</FollowUps>
)}
</div>
)
}
'use client'
import { useState } from 'react'
import { Field, FieldControl, FieldLabel } from '@dex/shared/components/field'
import { FollowUps } from '@dex/shared/components/follow-ups'
import { Input } from '@dex/shared/components/input'
import { TextLink } from '@dex/shared/components/text-link'
export function FollowUpsWithClose() {
const [isOpen, setIsOpen] = useState(false)
const [role, setRole] = useState('')
const close = () => {
setIsOpen(false)
setRole('')
}
if (!isOpen) {
return <TextLink onClick={() => setIsOpen(true)}>Not looking for engineering roles?</TextLink>
}
return (
<FollowUps className="w-full max-w-md" close={{ label: 'Close', onClick: close }}>
<Field>
<FieldLabel>What role are you looking for?</FieldLabel>
<FieldControl>
<Input
placeholder="e.g. Product designer"
value={role}
onChange={(event) => setRole(event.target.value)}
/>
</FieldControl>
</Field>
</FollowUps>
)
}
'use client'
import { useState } from 'react'
import { Chip, ChipGroup } from '@dex/shared/components/chip-group'
import { FieldLegend, FieldMessage, FieldSet } from '@dex/shared/components/field'
import { FollowUps } from '@dex/shared/components/follow-ups'
const OFFICE_DAYS = ['1 day', '2 days', '3 days', '4 days']
export function FollowUpsInvalid() {
const [hybrid, setHybrid] = useState('yes')
const [days, setDays] = useState('')
return (
<div className="flex w-full max-w-md flex-col gap-3">
<FieldSet>
<FieldLegend>Open to hybrid?</FieldLegend>
<ChipGroup type="single" value={hybrid} onValueChange={(next) => next && setHybrid(next)}>
<Chip value="yes">Yes</Chip>
<Chip value="no">No</Chip>
</ChipGroup>
</FieldSet>
{hybrid === 'yes' && (
<FollowUps>
<FieldSet invalid={!days}>
<FieldLegend>Up to how many days a week in the office?</FieldLegend>
<ChipGroup type="single" value={days} onValueChange={(next) => next && setDays(next)}>
{OFFICE_DAYS.map((option) => (
<Chip key={option} value={option}>
{option}
</Chip>
))}
</ChipGroup>
<FieldMessage
error={!days && 'Choose how many days a week you could be in the office.'}
/>
</FieldSet>
</FollowUps>
)}
</div>
)
}
- Put the block right under the question whose answer opened it, 12px below, and take it away when that answer changes.
- One block holds everything the answer opens, such as where someone would move to and whether they need support.
- Each question in the block is an ordinary
FieldorFieldSet, with its own label, states and message. Its controls keep their card fill on the muted block. - Clear the follow-up answers when the block closes. The component does not hold them, so this is the form's job.
- Use
closewhen a link or a button opened the block, rather than an answer. What closing clears is also the form's job.