/* Copyright 2026 Marimo. All rights reserved. */ "use no memo"; import type { Table } from "@tanstack/react-table"; import { useDebounce } from "@uidotdev/usehooks"; import { ChartSplineIcon, PanelRightIcon, SearchIcon, XIcon, } from "lucide-react"; import React, { useEffect, useState } from "react"; import useEvent from "react-use-event-hook"; import { cn } from "@/utils/cn"; import { PANEL_TYPES, type PanelType, } from "../editor/chrome/panels/context-aware-panel/context-aware-panel"; import { Spinner } from "../icons/spinner"; import { Button } from "../ui/button"; import { ColumnVisibilityDropdown } from "./column-visibility-dropdown"; import { type ExportActionProps, ExportActions } from "./export-actions"; const NOOP_ON_SEARCH = () => { /** no-op*/ }; interface TableTopBarProps extends Partial { table: Table; showSearch: boolean; searchQuery?: string; onSearchQueryChange?: (query: string) => void; reloading?: boolean; showChartBuilder?: boolean; isChartBuilderOpen?: boolean; toggleDisplayHeader?: () => void; showTableExplorer?: boolean; togglePanel?: (panelType: PanelType) => void; isAnyPanelOpen?: boolean; sizeBytes?: number | null; sizeBytesIsLoading?: boolean; } export const TableTopBar = ({ table, showSearch, searchQuery, onSearchQueryChange, reloading, showChartBuilder, isChartBuilderOpen, toggleDisplayHeader, showTableExplorer, togglePanel, isAnyPanelOpen, downloadAs, sizeBytes, sizeBytesIsLoading, }: TableTopBarProps) => { const [internalValue, setInternalValue] = useState(searchQuery || ""); const debouncedSearch = useDebounce(internalValue, 500); const onSearch = useEvent(onSearchQueryChange ?? NOOP_ON_SEARCH); const inputRef = React.useRef(null); useEffect(() => { onSearch(debouncedSearch); }, [debouncedSearch, onSearch]); return (
{onSearchQueryChange && showSearch && (
{ if (e.key === "Escape") { setInternalValue(""); inputRef.current?.blur(); } }} onChange={(e) => setInternalValue(e.target.value)} placeholder="Search..." /> {reloading && } {internalValue && ( )}
)}
{showChartBuilder && ( )} {showTableExplorer && togglePanel && ( )} {downloadAs && ( )}
); };