"use client"; import { Button } from "@openstatus/ui/components/ui/button"; import { Separator } from "@openstatus/ui/components/ui/separator"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@openstatus/ui/components/ui/tooltip"; import { cn } from "@openstatus/ui/lib/utils"; import type { Table } from "@tanstack/react-table"; import { Loader, X } from "lucide-react"; import * as React from "react"; import * as ReactDOM from "react-dom"; export interface DataTableActionBarProps< TData, > extends React.ComponentProps<"div"> { table: Table; visible?: boolean; container?: Element | DocumentFragment | null; } function DataTableActionBar({ table, visible: visibleProp, container: containerProp, children, className, ...props }: DataTableActionBarProps) { const [mounted, setMounted] = React.useState(false); React.useLayoutEffect(() => { setMounted(true); }, []); React.useEffect(() => { function onKeyDown(event: KeyboardEvent) { if (event.key === "Escape") { table.toggleAllRowsSelected(false); } } window.addEventListener("keydown", onKeyDown); return () => window.removeEventListener("keydown", onKeyDown); }, [table]); const container = containerProp ?? (mounted ? globalThis.document?.body : null); if (!container) return null; const visible = visibleProp ?? table.getFilteredSelectedRowModel().rows.length > 0; return ReactDOM.createPortal(
{visible && (
{children}
)}
, container, ); } interface DataTableActionBarActionProps extends React.ComponentProps< typeof Button > { tooltip?: string; isPending?: boolean; } function DataTableActionBarAction({ size = "sm", tooltip, isPending, disabled, className, children, ...props }: DataTableActionBarActionProps) { const trigger = ( ); if (!tooltip) return trigger; return ( {trigger}

{tooltip}

); } interface DataTableActionBarSelectionProps { table: Table; } function DataTableActionBarSelection({ table, }: DataTableActionBarSelectionProps) { const onClearSelection = React.useCallback(() => { table.toggleAllRowsSelected(false); }, [table]); return (
{table.getFilteredSelectedRowModel().rows.length} selected

Clear selection

Esc
); } export { DataTableActionBar, DataTableActionBarAction, DataTableActionBarSelection, };