Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | 19x 19x 19x 1x 1x | import { useSearchParams } from "react-router-dom";
import { useSetAtom } from "jotai";
import { Button, Icon } from "@canonical/react-components";
import type { PrimitiveAtom } from "jotai";
type Props = {
state: PrimitiveAtom<string>;
label: string;
placeholder: string;
};
function Filter({ state, label, placeholder }: Props): React.JSX.Element {
const [searchParams, setSearchParams] = useSearchParams();
const setFilter = useSetAtom(state);
return (
<div className="p-search-box">
<label className="u-off-screen" htmlFor="search">
{label}
</label>
<input
required
type="search"
id="search"
name="search"
className="p-search-box__input"
placeholder={placeholder}
autoComplete="off"
value={searchParams.get("filter") || ""}
onChange={(e) => {
if (e.target.value) {
setSearchParams({ filter: e.target.value });
setFilter(e.target.value);
} else {
setSearchParams();
setFilter("");
}
}}
/>
<Button
type="reset"
className="p-search-box__reset"
onClick={() => {
setSearchParams();
setFilter("");
}}
>
<Icon name="close">Clear filter</Icon>
</Button>
<Button type="submit" className="p-search-box__button">
<Icon name="search">Search</Icon>
</Button>
</div>
);
}
export default Filter;
|