# Page header

An app page's header bar: menu button on small screens, the page title and its actions.

- Family: navigation
- Import: `import { PageHeader, PageHeaderBar, PageHeaderProvider } from "@senvenli/react/navigation";`
- Page: https://design.senvenli.com/docs/components/page-header
- JSON: https://design.senvenli.com/docs/components/page-header.json

## Example: A page's title and actions

On its own, the header renders in place at the top of the page.

```tsx
import { Button } from "@senvenli/react/action";
import { Input } from "@senvenli/react/form";
import { PageHeader } from "@senvenli/react/navigation";

export default function Example() {
  return (
    <PageHeader
      title="Orders"
      description="1,204 orders, 18 awaiting payment."
      actions={
        <>
          <Input type="search" aria-label="Search orders" placeholder="Order number or customer" size="small" />
          <Button variant="primary" iconBefore="plus">
            Create order
          </Button>
        </>
      }
    />
  );
}
```

## Examples

### A detail page

Breadcrumbs above the title say where the page sits.

```tsx
import { Button } from "@senvenli/react/action";
import { PageHeader } from "@senvenli/react/navigation";

export default function Example() {
  return (
    <PageHeader
      breadcrumbs={[{ label: "Orders", href: "#" }, { label: "ORD-1040" }]}
      title="Order ORD-1040"
      description="Ada Lovelace · placed March 18"
      actions={
        <>
          <Button>Refund</Button>
          <Button variant="primary">Mark as shipped</Button>
        </>
      }
    />
  );
}
```

### In the shell's bar

Under a provider, the page's header shows in PageHeaderBar, outside the content that scrolls.

```tsx
import { Button } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";
import { PageHeader, PageHeaderBar, PageHeaderProvider } from "@senvenli/react/navigation";
import { toast } from "@senvenli/react/overlay";

function CustomersPage() {
  return (
    <>
      <PageHeader title="Customers" actions={<Button variant="primary">Add customer</Button>} />
      <Text tone="subtle">The page's content scrolls under the bar. The menu button shows under 1024px and opens the Sidebar.</Text>
    </>
  );
}

export default function Example() {
  return (
    <PageHeaderProvider>
      <div className="flex h-56 flex-col overflow-hidden rounded-ds-large border border-ds-border">
        <PageHeaderBar menuLabel="Open menu" onMenuPress={() => toast("Menu opened")} />
        <div className="flex-1 overflow-y-auto p-ds-300">
          <CustomersPage />
        </div>
      </div>
    </PageHeaderProvider>
  );
}
```

## Guidelines

### When to use it

- Titling a page inside an app shell with a sidebar.

### Use something else when

- [navbar](https://design.senvenli.com/docs/components/navbar.md): A public site needs brand, links and actions in one top bar.
- [heading](https://design.senvenli.com/docs/components/heading.md): A title alone, without actions or a menu button.

## Accessibility

Built in:

- The menu button is named "Open menu" and opens the sidebar panel.

You provide:

- A page title.

## API reference

### PageHeader

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| title | `React.ReactNode` |  | yes | The page's name; the page's one h1. |
| description | `React.ReactNode` |  | no | One line under the title. |
| breadcrumbs | `readonly BreadcrumbItem[]` |  | no | Where the page sits, above the title (a detail page under its list). |
| actions | `React.ReactNode` |  | no | The page's actions: filters, a search field, one primary button. |

### PageHeaderBar

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| menuLabel | `string` |  | yes | The menu button's name ("Open menu"); it opens the Sidebar, which is a panel under 1024px. |
| onMenuPress | `() => void` |  | yes |  |

### PageHeaderProvider

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| children | `React.ReactNode` |  | yes |  |

### Tokens it reads

`--ds-border`, `--ds-border-focused`, `--ds-icon-subtle`, `--ds-radius-small`, `--ds-space-025`, `--ds-space-050`, `--ds-space-100`, `--ds-space-150`, `--ds-space-200`, `--ds-space-300`, `--ds-space-400`, `--ds-surface`, `--ds-text`, `--ds-text-subtle`

## Related

- [sidebar](https://design.senvenli.com/docs/components/sidebar.md)
