-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSearchBox.tsx
More file actions
72 lines (65 loc) · 1.93 KB
/
Copy pathSearchBox.tsx
File metadata and controls
72 lines (65 loc) · 1.93 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
import React from "react";
import { ProgressAnimation } from "../UtilComponents/ProgressAnimation";
import InputSupper from "../UtilComponents/InputSupper";
import { SuggestedField } from "../../types/SuggestedFields";
interface InputSupperHandle {
focus(): void;
select(): void;
}
export interface SearchBoxProps {
q: string;
isSearchInProgress: boolean;
updateVisibleText: (text: string) => void;
resetQuery: (e: React.MouseEvent<HTMLButtonElement>) => void;
suggestedFields?: SuggestedField[];
updateSearchText: () => void;
}
export default class SearchBox extends React.Component<SearchBoxProps> {
searchInput: InputSupperHandle | null = null;
focus = () => {
this.searchInput?.focus();
};
select = () => {
this.searchInput?.select();
};
render() {
const spinner = this.props.isSearchInProgress ? (
<ProgressAnimation />
) : (
false
);
return (
<div>
<div className="search-box">
<InputSupper
ref={(s: InputSupperHandle | null) => (this.searchInput = s)}
className="search-box__input"
value={this.props.q}
chips={this.props.suggestedFields}
onChange={this.props.updateVisibleText}
updateSearchText={this.props.updateSearchText}
/>
<div className="search__actions">{spinner}</div>
<div className={"search__buttons"}>
<button
className="btn"
title="Search"
onClick={this.props.updateSearchText}
disabled={this.props.isSearchInProgress}
>
Search
</button>
<button
className="btn"
title="Clear search query and filters"
onClick={this.props.resetQuery}
disabled={this.props.isSearchInProgress}
>
Clear
</button>
</div>
</div>
</div>
);
}
}