Header
The bar on top of a dialog, a sheet or a panel: an action on each side and a title.
Usage
tsx
<Header>
<Header.Leading>
<Button aria-label="back" onClick={goBack}>
<Button.Icon><MdArrowBack /></Button.Icon>
</Button>
</Header.Leading>
<Header.Title>Release notes</Header.Title>
<Header.Trailing>
<Button aria-label="close" onClick={close}>
<Button.Icon><MdClose /></Button.Icon>
</Button>
</Header.Trailing>
</Header>Only some parts
Every part is optional. The trailing part stays on the right even without a title.
tsx
<Header>
<Header.Title>Invoices</Header.Title>
</Header>
<Header>
<Header.Leading>
<Button aria-label="back" onClick={goBack}>
<Button.Icon><MdArrowBack /></Button.Icon>
</Button>
</Header.Leading>
<Header.Trailing>
<Button aria-label="close" onClick={close}>
<Button.Icon><MdClose /></Button.Icon>
</Button>
</Header.Trailing>
</Header>Anything in between
Elements that aren't parts sit in the row after the title.
tsx
<Header>
<Header.Title>Invoice 0142</Header.Title>
<Chip active>overdue</Chip>
<Header.Trailing>
<Button aria-label="share" onClick={share}>
<Button.Icon><MdShare /></Button.Icon>
</Button>
<Button aria-label="delete" onClick={remove}>
<Button.Icon><MdDelete /></Button.Icon>
</Button>
</Header.Trailing>
</Header>overdue
Long titles
The title stops at two lines. Add items-start to keep the actions at the top.
tsx
<Header>
<Header.Leading>{back}</Header.Leading>
<Header.Title>{longTitle}</Header.Title>
<Header.Trailing>{close}</Header.Trailing>
</Header>
<Header className="items-start">
<Header.Leading>{back}</Header.Leading>
<Header.Title>{longTitle}</Header.Title>
<Header.Trailing>{close}</Header.Trailing>
</Header>Naming a dialog
tsx
<Header as="div" className="border-b-margo border-border">
<Header.Title id={titleId}>Delete invoice</Header.Title>
</Header>Reference
| prop | type | default | |
|---|---|---|---|
as? | ElementType | "header" | the element or component to render |
className? | string | — | added after the component's own class: what you set wins |
…rest | props of as | — | typed against the chosen element |
Header.Title
| prop | type | default | |
|---|---|---|---|
children | ReactNode | — | the title; clamped to two lines |
id? | string | — | for aria-labelledby |
className? | string | — | added after the part's own class: what you set wins |
Header.Leading and Header.Trailing
| prop | type | default | |
|---|---|---|---|
children? | ReactNode | — | what goes on that side |
className? | string | — | added after the part's own class: what you set wins |