Selection bar
“3 selected”, the × that clears, the actions as buttons and the rest behind ⋯.
import { SelectionBar, useActions } from "@forgeron/ui";import {
ArrowRight02Icon,
Delete02Icon,
Download01Icon,
Link01Icon,
StarIcon,
UserAdd01Icon,
} from "@forgeron/icons";
import { SelectionBar } from "@forgeron/ui";
export default function Default() {
return (
<div style={{ width: "100%", maxWidth: 640 }}>
<SelectionBar
count={3}
onClear={() => {}}
inline={5}
iconOnly={["star", "trash"]}
actions={[
{ id: "share", label: "Share", icon: UserAdd01Icon },
{ id: "download", label: "Download", icon: Download01Icon },
{ id: "move", label: "Move", icon: ArrowRight02Icon },
{ id: "star", label: "Star", icon: StarIcon },
{ id: "trash", label: "Move to trash", icon: Delete02Icon, danger: true },
{ id: "link", label: "Copy link", icon: Link01Icon },
]}
/>
</div>
);
}// In the trash the selection offers other actions: restore, or delete for good.
import { Delete02Icon, Undo02Icon } from "@forgeron/icons";
import { Button, SelectionBar } from "@forgeron/ui";
import { useState } from "react";
export default function Trash() {
const [count, setCount] = useState(2);
const [said, setSaid] = useState("");
return (
<div style={{ display: "grid", gap: 8, width: "100%", maxWidth: 520 }}>
<SelectionBar
count={count}
onClear={() => setCount(0)}
actions={[
{ id: "restore", label: "Restore", icon: Undo02Icon, run: () => setSaid("Restored") },
{
id: "purge",
label: "Delete forever",
icon: Delete02Icon,
danger: true,
run: () => setSaid("Deleted forever"),
},
]}
/>
{count === 0 ? (
<Button size="sm" onClick={() => setCount(2)}>
Select 2 items
</Button>
) : null}
<span style={{ color: "var(--ink-dim)", font: "400 11px/16px var(--font-mono)" }}>
{said}
</span>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
count | number | — | How many are selected; nothing at 0. |
onClear | () => void | — | The × and Escape. |
actions | Action[] | — | The same list as useActions: run, icon, danger, disabled, sub-actions. |
inline | number | 4 | How many actions show as buttons before the ⋯. |
iconOnly | string[] | — | Ids of the actions drawn as an icon alone, the label as a tooltip. |
onAction | (id) => void | — | After the action's own run. |
className | string | — | Extra classes. |