Fold
Long text behind one row, with a Show more link. Opens in place, no popup.
Builder notes12 lines, written by the builder
import { Fold } from "@dapplelight/signet-ui/components/fold"
const notes = `Changed **packages/ui** only.
- Added the Fold component and its tests
- Reused Markdown for the body`
export function Demo() {
return (
<Fold title="Builder notes" detail="12 lines, written by the builder">
{notes}
</Fold>
)
}Installation
npm i @dapplelight/signet-uiThe body is rendered by Markdown, so Fold needs its optional peers (react-markdown, remark-gfm, remark-parse, unified, github-slugger). That is why it is imported from components/fold and not the barrel.
Usage
import { Fold } from "@dapplelight/signet-ui/components/fold"
<Fold title="Builder notes" detail="12 lines, written by the builder">
{markdown}
</Fold>The toggle is a real button: Enter and Space work, aria-expanded announces open or closed, and aria-controls points at the text. The text is capped at about 66 characters wide.
Examples
Open at first
Builder notes12 lines, written by the builder
Changed packages/ui only.
- Added the Fold component and its tests
- Reused
Markdownfor the body, so links and lists render safely - Left every existing component as it was
Run bun run test in packages/ui to check it.
<Fold title="Builder notes" detail="12 lines, written by the builder" defaultOpen>
{markdown}
</Fold>Your own words and styles
Release noteswritten by the team
<Fold
title="Release notes"
detail="written by the team"
showMoreLabel="Read on"
showLessLabel="Fold up"
classNames={{ detail: "italic" }}
>
{markdown}
</Fold>Customising
- Tokens: it uses theme utilities only, so a theme change restyles it.
- Words:
showMoreLabel/showLessLabel, orshowMore/showLessonce for the app throughLabelsProvider. - Classes and state:
className,classNamesper part (header,title,detail,toggle,body,markdown) anddata-state="open|closed". - Parts:
FoldRoot,FoldHeader,FoldTitle,FoldDetail,FoldToggle,FoldBodyto build your own row (a badge in the header, plain text in the body). - Own the code:
signet add foldcopies the file in.
API Reference
Fold
| Prop | Type | Default | Description |
|---|---|---|---|
| title | ReactNode | - | The row's title. |
| detail | ReactNode | - | Muted text beside the title. |
| children | string | - | The long text, as Markdown. |
| open | boolean | - | Controlled state. |
| defaultOpen | boolean | false | Start open. |
| onOpenChange | (open: boolean) => void | - | Called when the link is used. |
| showMoreLabel | string | "Show more" | Link text while closed. |
| showLessLabel | string | "Show less" | Link text while open. |
| markdown | Omit<MarkdownProps, "children"> | - | Passed to the Markdown renderer. |
| classNames | { header?; title?; detail?; toggle?; body?; markdown? } | - | Class per part. |