"use client" import * as React from "react" import type { BulkAction } from "./hub-table" import { Button } from "../ui/button" import { Tip } from "../ui/tip" import { Kbd, KbdGroup } from "../ui/kbd" import { Shortcut } from "../ui/dropdown-menu" import { DataTable } from "../data-table" /** * The floating bulk bar's body. Typed `bulkActions` win over the older * `bulkActionsSlot` escape hatch when both are given. */ export function useHubBulkActions>({ bulkActions, bulkActionsSlot, getRowId, }: { bulkActions: BulkAction[] | undefined bulkActionsSlot: ((selected: Set) => React.ReactNode) | undefined getRowId: (row: TRow) => string | number }) { // ─── Bulk actions (structured > slot) ───────────────────────────────────── // When the consumer passes `bulkActions`, synthesize the floating bulk-bar // body from that typed array — resolving `onSelect` with the actual // selected `TRow` objects. The `bulkActionsSlot` escape hatch is still // honored when `bulkActions` is omitted, so existing call-sites (Library's // single-button Export slot, dashboards with bespoke chrome) keep working. // `bulkActions` wins when both are set, on the assumption that a hub // adopting the typed API does so intentionally. const effectiveBulkActionsSlot = React.useMemo(() => { if (bulkActions && bulkActions.length > 0) { return (selected: Set, dtRows: TRow[]) => { const selectedRows = dtRows.filter(r => selected.has(getRowId(r))) return ( <> {bulkActions.map(action => { const labelText = action.label.trim() const isIconOnly = !labelText && Boolean(action.icon) const aria = action.ariaLabel ?? labelText ?? action.id const tip = action.tooltip ?? labelText // Resolve to the actual DS Button variants. We never mint a // filled `default` button in the bar — `bulkActions` callers // either pick `"default"` → outline (the standard) or // `"destructive"` → destructive-solid on the selection bar. // Per `exxat-ux-principles` P3 the bar has no single primary product action. const buttonVariant: "outline" | "destructive-solid" = action.variant === "destructive" ? "destructive-solid" : "outline" // Labeled actions: Kbd inline at rest (discoverable without hover). // Icon-only: Tip carries the chord (button is too tight for bare Kbd). const shortcutKbd = ( {action.shortcut} ) const button = (