import React, { useEffect, useState } from 'react'; import type { RowData, Table } from '@tanstack/table-core'; import { useTranslation } from '#hooks'; import { SearchBar } from '../SearchBar/SearchBar.tsx'; import { useDataTableHandle, useDataTableStore } from './hooks.ts'; import type { DataTableSearchChangeHandler } from './types.ts'; export const DataTableControls = ({ onSearchChange, togglesComponent: Toggles }: { onSearchChange?: DataTableSearchChangeHandler; togglesComponent?: React.FC<{ table: Table }>; }) => { const table = useDataTableHandle('table'); const setGlobalFilter = useDataTableStore((store) => store.setGlobalFilter); const [searchValue, setSearchValue] = useState(''); const { t } = useTranslation(); useEffect(() => { if (onSearchChange) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument onSearchChange(searchValue, table); } else { setGlobalFilter(searchValue || undefined); } }, [onSearchChange, searchValue]); return (
{ setSearchValue(value); }} /> {Toggles && (
)}
); };