import { Cross2Icon } from '@radix-ui/react-icons' import { type Table } from '@tanstack/react-table' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { DataTableFacetedFilter } from './faceted-filter' import { DataTableViewOptions } from './view-options' type DataTableToolbarProps = { table: Table searchPlaceholder?: string searchKey?: string filters?: { columnId: string title: string options: { label: string value: string icon?: React.ComponentType<{ className?: string }> }[] }[] } export function DataTableToolbar({ table, searchPlaceholder = 'Filter...', searchKey, filters = [], }: DataTableToolbarProps) { const isFiltered = table.getState().columnFilters.length > 0 || table.getState().globalFilter return (
{searchKey ? ( table.getColumn(searchKey)?.setFilterValue(event.target.value) } className='h-8 w-[150px] lg:w-[250px]' /> ) : ( table.setGlobalFilter(event.target.value)} className='h-8 w-[150px] lg:w-[250px]' /> )}
{filters.map((filter) => { const column = table.getColumn(filter.columnId) if (!column) return null return ( ) })}
{isFiltered && ( )}
) }