Components
Show more
Opens the rest of a list cut short, and closes it again.
- Senior Backend Engineer · Brightline Insurance
- Backend Engineer · Octopus Parcel
'use client'
import { useId, useState } from 'react'
import { ShowMore } from '@dex/shared/components/show-more'
const ROLES = [
'Senior Backend Engineer · Brightline Insurance',
'Backend Engineer · Octopus Parcel',
'Software Engineer · Cleo',
'Graduate Engineer · BJSS',
'Engineering Intern · Monzo',
]
const SHOWN = 2
export function ShowMoreDefault() {
const [isExpanded, setIsExpanded] = useState(false)
const listId = useId()
const hidden = ROLES.length - SHOWN
return (
<div className="flex w-full max-w-md flex-col gap-4">
<ul className="flex flex-col gap-2 text-sm" id={listId}>
{(isExpanded ? ROLES : ROLES.slice(0, SHOWN)).map((role) => (
<li key={role}>{role}</li>
))}
</ul>
<ShowMore
aria-controls={listId}
expanded={isExpanded}
onClick={() => setIsExpanded((expanded) => !expanded)}
>
{isExpanded ? 'Show less' : `Show ${hidden} more`}
</ShowMore>
</div>
)
}
Skills
- Python
- Go
- PostgreSQL
- Kafka
'use client'
import { useId, useState } from 'react'
import { ShowMore } from '@dex/shared/components/show-more'
const SKILLS = ['Python', 'Go', 'PostgreSQL', 'Kafka', 'Kubernetes', 'AWS', 'Terraform', 'gRPC']
const SHOWN = 4
export function ShowMorePlain() {
const [isExpanded, setIsExpanded] = useState(false)
const listId = useId()
return (
<div className="flex w-full max-w-md flex-col gap-4 rounded-lg border-hairline bg-card p-5">
<p className="text-sm font-bold">Skills</p>
<ul className="flex flex-wrap gap-2 text-sm text-muted-foreground" id={listId}>
{(isExpanded ? SKILLS : SKILLS.slice(0, SHOWN)).map((skill) => (
<li key={skill}>{skill}</li>
))}
</ul>
<ShowMore
aria-controls={listId}
expanded={isExpanded}
onClick={() => setIsExpanded((expanded) => !expanded)}
variant="plain"
>
{isExpanded ? 'Show less' : `Show ${SKILLS.length - SHOWN} more`}
</ShowMore>
</div>
)
}
- Use it for one long list cut short, such as a candidate's jobs. Show the first few, usually two to five, and open the rest under them. For pages of the same data use pagination; for a section a reader may not need at all, an accordion.
- Say how many are hidden: "Show 3 more", then "Show less". Sentence case, and the caller writes the words.
rule, the default, runs a hairline out to each side, marking where the list was cut. Useplainwhere something already marks the edge, such as the foot of a card.- Keep what it opens in the page, not fetched on the press, so it opens at once and find-in-page reaches it.
- Point
aria-controlsat the list it opens. It setsaria-expandeditself.