import * as React from "react" import { ChevronDownIcon } from "lucide-react" import { ActionMenu, type ActionMenuItem, type ActionMenuProps, } from "@/components/actions/action-menu" import { Button } from "@/components/ui/button" import { cn } from "@/lib/utils" export type DataTableBulkAction = Omit & { onSelect?: (rows: TData[]) => void | Promise } export type DataTableBulkActionsProps = Omit< ActionMenuProps, "actions" | "trigger" > & { rows: TData[] actions: DataTableBulkAction[] label?: React.ReactNode selectedLabel?: (count: number) => React.ReactNode clearLabel?: React.ReactNode onClearSelection?: () => void hideWhenEmpty?: boolean triggerClassName?: string } function DataTableBulkActions({ rows, actions, label = "Bulk actions", selectedLabel = (count) => `${count} selected`, clearLabel = "Clear", onClearSelection, hideWhenEmpty = true, triggerClassName, disabled, ...props }: DataTableBulkActionsProps) { const count = rows.length if (hideWhenEmpty && count === 0) { return null } const resolvedActions: ActionMenuItem[] = actions.map((action) => ({ ...action, disabled: action.disabled || count === 0, onSelect: action.onSelect ? () => action.onSelect?.(rows) : undefined, })) return (
{selectedLabel(count)} } {...props} /> {onClearSelection && count > 0 && ( )}
) } export { DataTableBulkActions }