"use client"; import * as React from "react"; import type { Table } from "@tanstack/react-table"; import { Search, X } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { DataTableServerFacetedFilter, type DataTableServerFacetedFilterLabels, type FacetedFilterOption, } from "./data-table-server-faceted-filter"; import { DataTableViewOptions, type DataTableViewOptionsLabels, } from "./data-table-view-options"; export interface DataTableFilterOptions { title: string; options: FacetedFilterOption[]; multi?: boolean; } export interface DataTableServerToolbarLabels { search: string; reset: string; viewOptions: Partial; facetedFilter: Partial; } const DEFAULT_LABELS: DataTableServerToolbarLabels = { search: "Search", reset: "Reset", viewOptions: {}, facetedFilter: {}, }; interface DataTableServerToolbarProps { table: Table; addButton?: React.ReactNode; q?: string; onSearchChange?: (q: string) => void; f?: TFilter | ""; onFilterChange?: (f: TFilter | "") => void; filterOptions?: DataTableFilterOptions; labels?: Partial; } interface DataTableSearchControlsProps { initialQuery: string; onSearchChange: (query: string) => void; searchLabel: string; resetLabel: string; } interface DataTableSearchResetProps { label: string; onReset: () => void; } function DataTableSearchReset({ label, onReset }: DataTableSearchResetProps) { return ( ); } function DataTableSearchControls({ initialQuery, onSearchChange, searchLabel, resetLabel, }: DataTableSearchControlsProps) { const [qSearch, setQSearch] = React.useState(initialQuery); return (
setQSearch(event.target.value)} className="h-8 w-[150px] lg:w-[250px]" aria-label={searchLabel} /> {qSearch ? ( { setQSearch(""); onSearchChange(""); }} /> ) : null}
); } export function DataTableServerToolbar({ table, addButton, q, onSearchChange, f, onFilterChange, filterOptions, labels, }: DataTableServerToolbarProps) { const t = { ...DEFAULT_LABELS, ...labels }; return (
{onSearchChange ? ( ) : null} {onFilterChange && filterOptions ? ( ) : null}
{addButton}
); }