Bulk action bar

Playground

Usage

Pass the selection count and add action and clear-selection slots. Your app manages selection and updates the data.

'use client';
import { useRef, useState } from 'react';
import { BulkActionBar, Button, Checkbox } from '@mbsw/ui';

export default function Example({ onComplete }: { onComplete: () => void }) {
  const [selected, setSelected] = useState(true);
  const checkbox = useRef<HTMLButtonElement>(null);
  const bar = useRef<HTMLDivElement>(null);
  const clear = () => {
    if (bar.current?.contains(document.activeElement))
      checkbox.current?.focus();
    setSelected(false);
  };
  return (
    <>
      <label>
        <Checkbox
          ref={checkbox}
          checked={selected}
          onCheckedChange={(value) => setSelected(value === true)}
        />{' '}
        {"Item 1"}
      </label>
      {selected && (
        <BulkActionBar
          ref={bar}
          selectionLabel={"1 selected"}
          actions={
            <Button
              size="sm"
              onClick={() => {
                clear();
                onComplete();
              }}
            >
              {"Complete"}
            </Button>
          }
          clearAction={
            <Button size="sm" onClick={clear}>
              {"Clear selection"}
            </Button>
          }
        />
      )}
    </>
  );
}

The Playground Code tab includes the full example with your current settings. See Installation for the CSS imports.

Composition