@llamaindex/ui
Version:
A comprehensive UI component library built with React, TypeScript, and Tailwind CSS for LlamaIndex applications
54 lines (51 loc) • 1.87 kB
JavaScript
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuCheckboxItem, DropdownMenuSeparator, DropdownMenuItem } from './chunk-MWBISAYH.mjs';
import { Button } from './chunk-NLLOGSY3.mjs';
import { cn } from './chunk-MG2ARK3A.mjs';
import { Filter } from 'lucide-react';
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
var ColumnFilter = ({
options,
selectedValues,
onFilterChange
}) => {
const handleToggleOption = (option, checked) => {
const newValues = checked ? [...selectedValues, option] : selectedValues.filter((value) => value !== option);
onFilterChange(newValues);
};
const handleClearAll = () => {
onFilterChange([]);
};
if (options.length === 0) {
return null;
}
return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
Button,
{
variant: "ghost",
size: "icon",
className: cn(
"h-6 w-6 p-0",
selectedValues.length > 0 ? "text-primary" : "text-muted-foreground"
),
children: /* @__PURE__ */ jsx(Filter, { className: "h-3 w-3" })
}
) }),
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "start", className: "w-48", children: [
options.map((option) => /* @__PURE__ */ jsx(
DropdownMenuCheckboxItem,
{
checked: selectedValues.includes(option),
onCheckedChange: (checked) => handleToggleOption(option, checked),
children: option
},
option
)),
selectedValues.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
/* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
/* @__PURE__ */ jsx(DropdownMenuItem, { onClick: handleClearAll, children: "Clear filters" })
] })
] })
] });
};
export { ColumnFilter };