bulk-operate-bar.tsx


Overview

bulk-operate-bar.tsx defines a React functional component called BulkOperateBar that renders a user interface element for performing bulk operations on a selected list of items (typically files). It displays the count of selected items, a visual icon, and a set of actionable buttons corresponding to different bulk operations (e.g., delete, move, copy). The component visually distinguishes destructive actions like "delete" by highlighting them and wraps these actions with a confirmation dialog to prevent accidental triggers.

This component is intended for use in applications where users select multiple items and then apply one or more bulk operations to them in a streamlined, visually clear manner.


Detailed Explanation

Types

BulkOperateItemType

A type that defines the shape of each bulk operation item.

Property

Type

Description

id

string

Unique identifier for the bulk operation (e.g., "delete", "move")

label

ReactNode

Text or element displayed as the operation's label on the button

icon

ReactNode

Icon displayed alongside the label on the button

onClick

() => void

Callback function invoked when the operation is triggered


Props

BulkOperateBarProps

Property

Type

Required

Description

list

BulkOperateItemType[]

Yes

Array of bulk operation items to render as buttons

count

number

Yes

Number of selected files/items

className

string

No

Optional additional CSS classes for the root container


Component: BulkOperateBar

function BulkOperateBar({
  list,
  count,
  className,
}: BulkOperateBarProps): JSX.Element

Purpose

Renders a card UI showing the number of selected files and a list of bulk operation buttons. It visually distinguishes the "delete" action by coloring it with an error state and wrapping it in a confirmation dialog.

Parameters

Behavior

Usage Example

import { BulkOperateBar, BulkOperateItemType } from './bulk-operate-bar';
import { Trash2, Edit3 } from 'lucide-react';

const operations: BulkOperateItemType[] = [
  {
    id: 'delete',
    label: 'Delete',
    icon: <Trash2 />,
    onClick: () => console.log('Delete confirmed'),
  },
  {
    id: 'rename',
    label: 'Rename',
    icon: <Edit3 />,
    onClick: () => console.log('Rename clicked'),
  },
];

function Example() {
  return <BulkOperateBar list={operations} count={3} />;
}

Implementation Details


Interaction with Other System Parts


Mermaid Diagram: Component Structure and Workflow

componentDiagram
    BulkOperateBar <|-- ConfirmDeleteDialog
    BulkOperateBar --> Button
    BulkOperateBar --> Card
    BulkOperateBar --> CardContent
    BulkOperateBar --> Separator
    BulkOperateBar --> BrushCleaningIcon

    BulkOperateBar : +list: BulkOperateItemType[]
    BulkOperateBar : +count: number
    BulkOperateBar : +className?: string
    BulkOperateBar : +isDeleteItem(id: string): boolean
    BulkOperateBar : +render()

    ConfirmDeleteDialog : +hidden: boolean
    ConfirmDeleteDialog : +onOk: () => void

    Button : +variant: string
    Button : +onClick: () => void

Summary

The BulkOperateBar component presents a user-friendly interface for applying operations to multiple selected items with visual clarity and safety measures (confirmation dialogs for deletes). It is modular, reusable, and integrates seamlessly with the app's design system and confirmation dialog pattern. Its clear API and separation of concerns make it easy to extend with additional bulk operations as needed.