BulkActionBar
Appears when things are selected: how many, what can be done to all of them at once, and «Clear selection».
import { BulkActionBar } from '@sypnia/ui/react'
On this page
Two selected
Tick and untick people, or press «Clear selection».
2 selected
Code
import { useState } from 'react';
import { BulkActionBar, Button, Checkbox } from '@sypnia/ui/react';
const people = ['Laura Méndez', 'Diego Ruiz', 'Ana Castaño', 'Marco Silva'];
// Tick some people: the bar says how many and what can be done to all of them. With none ticked it is not drawn.
export default function Basic() {
const [picked, setPicked] = useState<string[]>(['Diego Ruiz', 'Ana Castaño']);
const toggle = (name: string, on: boolean) => setPicked((all) => (on ? [...all, name] : all.filter((n) => n !== name)));
return (
<div className="sy-stack">
<BulkActionBar count={picked.length} onClear={() => setPicked([])}>
<Button size="sm" icon="mail">Send a reminder</Button>
<Button size="sm" variant="danger" icon="trash">Remove</Button>
</BulkActionBar>
{people.map((p) => <Checkbox key={p} label={p} checked={picked.includes(p)} onChange={(e) => toggle(p, e.target.checked)} />)}
</div>
);
} When to use it
Use it when
- People pick several rows of a list to act on them together: mark as paid, send, delete.
- With
countat 0 it is not drawn, so it can always sit in the page. - In a DataTable, pass the buttons with
bulkActionsand it draws this bar by itself.
Do not use it when
- The action is for a single row: RowActions.
- The action is for the whole list, selected or not: TableToolbar.
For everyone
- The count is a status, so «2 selected» is announced as it changes.
- Something destructive (delete) still asks first, with a ConfirmDialog that says how many.
- On phones the buttons sit two by two.
Props
| BulkActionBar | Type | Default |
|---|---|---|
countrequiredHow many things are selected. With 0 the bar is not drawn. | number | |
childrenWhat can be done to all of them: buttons. | ReactNode | |
onClearWith it the bar shows «Clear selection». | (() => void) |