forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchInput.js
More file actions
138 lines (123 loc) · 2.75 KB
/
SearchInput.js
File metadata and controls
138 lines (123 loc) · 2.75 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import { DOM as dom, Component } from "react";
import { isEnabled } from "devtools-config";
import Svg from "./Svg";
import classnames from "classnames";
import CloseButton from "./Button/Close";
import "./SearchInput.css";
const arrowBtn = (onClick, type, className, tooltip) => {
return dom.button(
{
onClick,
type,
className,
title: tooltip,
key: type
},
Svg(type)
);
};
class SearchInput extends Component {
displayName: "SearchInput";
props: {
query: string,
count: number,
placeholder: string,
summaryMsg: string,
onChange: () => void,
handleClose: () => void,
showErrorEmoji: boolean,
onKeyUp: () => void,
onKeyDown: () => void,
onFocus: () => void,
onBlur: () => void,
size: string,
handleNext: () => void,
handlePrev: () => void
};
static defaultProps: Object;
shouldShowErrorEmoji() {
const { count, query, showErrorEmoji } = this.props;
return count === 0 && query.trim() !== "" && !showErrorEmoji;
}
renderSvg() {
if (this.shouldShowErrorEmoji()) {
return Svg("sad-face");
}
return Svg("magnifying-glass");
}
renderArrowButtons() {
const { handleNext, handlePrev } = this.props;
return [
arrowBtn(
handleNext,
"arrow-down",
classnames("nav-btn", "next"),
L10N.getFormatStr("editor.searchResults.nextResult")
),
arrowBtn(
handlePrev,
"arrow-up",
classnames("nav-btn", "prev"),
L10N.getFormatStr("editor.searchResults.prevResult")
)
];
}
renderNav() {
if (!isEnabled("searchNav")) {
return;
}
const { count, handleNext, handlePrev } = this.props;
if ((!handleNext && !handlePrev) || (!count || count == 1)) {
return;
}
return dom.div(
{ className: "search-nav-buttons" },
this.renderArrowButtons()
);
}
render() {
const {
query,
placeholder,
summaryMsg,
onChange,
onKeyDown,
onKeyUp,
onFocus,
onBlur,
handleClose,
size
} = this.props;
return dom.div(
{
className: `search-field ${size}`
},
this.renderSvg(),
dom.input({
className: classnames({
empty: this.shouldShowErrorEmoji()
}),
onChange,
onKeyDown,
onKeyUp,
onFocus,
onBlur,
placeholder,
value: query,
spellCheck: false,
ref: "input"
}),
dom.div({ className: "summary" }, summaryMsg || ""),
this.renderNav(),
CloseButton({
handleClick: handleClose,
buttonClass: size
})
);
}
}
SearchInput.defaultProps = {
size: "",
showErrorEmoji: true
};
export default SearchInput;