import { __, _n, sprintf } from "@wordpress/i18n"; import { useTableStore } from "../../store"; import { getMatchingRowCount } from "../../search"; import { isProAvailable } from "../../pro-status"; export function SearchInput() { const isPro = isProAvailable(); const searchTerm = useTableStore(state => state.searchTerm); const setSearchTerm = useTableStore(state => state.setSearchTerm); const table = useTableStore(state => state.table); const cells = useTableStore(state => state.cells); const searchConfig = table.search; if (!isPro || !searchConfig?.enabled) { return null; } const placeholder = searchConfig.placeholder; const position = searchConfig.position || "left"; const matchingCount = searchTerm.trim() ? getMatchingRowCount(cells, table.rows, table.cols, table, searchTerm) : null; const handleClear = () => { setSearchTerm(""); }; return (
setSearchTerm(e.target.value)} /> {searchTerm && ( )}
{matchingCount !== null && ( {matchingCount === 0 ? __("No results found", "tableberg") : /* translators: %d is the number of matching rows */ sprintf( _n( "%d result", "%d results", matchingCount, "tableberg" ), matchingCount )} )}
); }