mirror of
https://github.com/fleetdm/fleet
synced 2026-05-16 05:28:38 +00:00
## Addresses #14519 - Applies anywhere there is a sort header, including the query results and query report tables https://github.com/fleetdm/fleet/assets/61553566/5bf0db8f-3d13-434d-b811-914fdded02df - [x] Changes file added for user-visible changes in `changes/` See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import React, { useState } from "react";
|
|
import { useDebouncedCallback } from "use-debounce";
|
|
import { IconNames } from "components/icons";
|
|
// @ts-ignore
|
|
import InputFieldWithIcon from "../InputFieldWithIcon";
|
|
|
|
const baseClass = "search-field";
|
|
|
|
export interface ISearchFieldProps {
|
|
placeholder: string;
|
|
defaultValue?: string;
|
|
onChange: (value: string) => void;
|
|
onClick?: (e: React.MouseEvent) => void;
|
|
icon?: IconNames;
|
|
}
|
|
|
|
const SearchField = ({
|
|
placeholder,
|
|
defaultValue = "",
|
|
onChange,
|
|
onClick,
|
|
icon = "search",
|
|
}: ISearchFieldProps): JSX.Element => {
|
|
const [searchQueryInput, setSearchQueryInput] = useState(defaultValue);
|
|
|
|
const debouncedOnChange = useDebouncedCallback((newValue: string) => {
|
|
onChange(newValue);
|
|
}, 500);
|
|
|
|
const onInputChange = (newValue: string): void => {
|
|
setSearchQueryInput(newValue);
|
|
debouncedOnChange(newValue);
|
|
};
|
|
|
|
return (
|
|
<InputFieldWithIcon
|
|
name={icon}
|
|
placeholder={placeholder}
|
|
value={searchQueryInput}
|
|
// inputWrapperClass={`${baseClass}__input-wrapper`}
|
|
onChange={onInputChange}
|
|
onClick={onClick}
|
|
iconPosition="start"
|
|
iconSvg={icon}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default SearchField;
|