# Toolbar

A row of controls above a list or table; BulkBar shows actions for the selected rows.

- Family: layout
- Import: `import { Toolbar, ToolbarSpacer, BulkBar } from "@senvenli/react/layout";`
- Page: https://design.senvenli.com/docs/components/toolbar
- JSON: https://design.senvenli.com/docs/components/toolbar.json

## Example: Tools above a list

Compact controls in one Tab stop; arrow keys move between them. The spacer pushes the rest to the end.

```tsx
import { Button } from "@senvenli/react/action";
import { Input } from "@senvenli/react/form";
import { Toolbar, ToolbarSpacer } from "@senvenli/react/layout";
import { Select } from "@senvenli/react/selection";

export default function Example() {
  return (
    <Toolbar aria-label="Order tools">
      <Input type="search" aria-label="Search orders" placeholder="Order number or customer" size="small" />
      <Select
        aria-label="Status"
        size="small"
        placeholder="All statuses"
        items={[
          { id: "open", label: "Open" },
          { id: "paid", label: "Paid" },
          { id: "overdue", label: "Overdue" },
        ]}
      />
      <ToolbarSpacer />
      <Button size="small" iconBefore="download">
        Export
      </Button>
    </Toolbar>
  );
}
```

## Examples

### BulkBar

Appears while rows are selected, with their count and the actions for them.

```tsx
import { Button } from "@senvenli/react/action";
import { Stack } from "@senvenli/react/layout";
import { BulkBar } from "@senvenli/react/layout";
import { toast } from "@senvenli/react/overlay";
import { Checkbox, CheckboxGroup } from "@senvenli/react/selection";
import { useState } from "react";

const ORDERS = ["ORD-1040", "ORD-1039", "ORD-1038", "ORD-1037"];

export default function Example() {
  const [selected, setSelected] = useState(["ORD-1040", "ORD-1038"]);
  return (
    <Stack space="space-200">
      <CheckboxGroup label="Orders awaiting payment" value={selected} onChange={setSelected}>
        {ORDERS.map((order) => (
          <Checkbox key={order} value={order}>
            {order}
          </Checkbox>
        ))}
      </CheckboxGroup>
      {selected.length > 0 && (
        <BulkBar
          aria-label="Selected orders"
          selectedCount={selected.length}
          onClear={() => setSelected([])}
          actions={
            <>
              <Button size="small" iconBefore="mail" onPress={() => toast.success("Reminders sent")}>
                Send reminder
              </Button>
              <Button size="small" iconBefore="download">
                Export
              </Button>
            </>
          }
        />
      )}
    </Stack>
  );
}
```

## Guidelines

### When to use it

- Filters, search and actions above a list.
- Actions on selected rows (BulkBar).

### Use something else when

- [button-group](https://design.senvenli.com/docs/components/button-group.md): Two or three related buttons, not a full row of controls.
- [menu](https://design.senvenli.com/docs/components/menu.md): The actions fit under one button.

## Accessibility

Keyboard:

- Arrow keys: Moves between controls.

Built in:

- One tab stop for the toolbar.

You provide:

- A name for the toolbar.

## API reference

### Toolbar

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| children | `React.ReactNode` |  | yes | Compact (32px) controls acting on the view below: search, filters, date range, view switch, export. |
| aria-label | `string` |  | yes | Names the toolbar ("Order tools"). |

### BulkBar

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| selectedCount | `number` |  | yes | How many rows are selected; announced as it changes. |
| actions | `React.ReactNode` |  | yes | The bulk actions (compact Buttons): "Send reminder", "Export". |
| onClear | `() => void` |  | yes | Clears the selection; the bar goes with it. |
| aria-label | `string` |  | yes | Names the bar ("Selected orders"). |

### Tokens it reads

`--ds-background-neutral-bold`, `--ds-background-neutral-pressed`, `--ds-radius-large`, `--ds-shadow-raised`, `--ds-space-100`, `--ds-space-150`, `--ds-surface-raised`, `--ds-text`, `--ds-text-inverse`

## Related

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