"use client" import type { Option } from "@/types/table" import type { Column } from "@tanstack/react-table" import { Check, PlusCircle } from "lucide-react" import { cn } from "@/lib/utils" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, } from "@/components/ui/command" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { Separator } from "@/components/ui/separator" interface DataTableFacetedFilterProps { column?: Column title?: string options: Option[] } export function DataTableFacetedFilter({ column, title, options, }: DataTableFacetedFilterProps) { const unknownValue = column?.getFilterValue() const selectedValues = new Set( Array.isArray(unknownValue) ? unknownValue : [] ) return ( No results found. {options.map((option) => { const isSelected = selectedValues.has(option.value) return ( { if (isSelected) { selectedValues.delete(option.value) } else { selectedValues.add(option.value) } const filterValues = Array.from(selectedValues) column?.setFilterValue( filterValues.length ? filterValues : undefined ) }} >
{option.icon && (
) })}
{selectedValues.size > 0 && ( <> column?.setFilterValue(undefined)} className="justify-center text-center" > Clear filters )}
) }