forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeader.js
More file actions
87 lines (77 loc) · 2.38 KB
/
Copy pathHeader.js
File metadata and controls
87 lines (77 loc) · 2.38 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
const React = require("react");
const { Component, createFactory } = React;
const PropTypes = require("prop-types");
const dom = require("react-dom-factories");
const constants = require("../constants");
const QuickLinks = createFactory(require("./QuickLinks"));
require("./Header.css");
class Header extends Component {
static get propTypes() {
return {
addInput: PropTypes.func.isRequired,
changeCurrentInput: PropTypes.func.isRequired,
clearResultsList: PropTypes.func.isRequired,
currentInputValue: PropTypes.string,
evaluate: PropTypes.func.isRequired,
navigateInputHistory: PropTypes.func.isRequired
};
}
constructor(props) {
super(props);
this.onSubmitForm = this.onSubmitForm.bind(this);
this.onInputChange = this.onInputChange.bind(this);
this.onInputKeyDown = this.onInputKeyDown.bind(this);
this.onClearButtonClick = this.onClearButtonClick.bind(this);
}
onSubmitForm(e) {
e.preventDefault();
const data = new FormData(e.target);
const expression = data.get("expression");
this.props.addInput(expression);
}
onInputChange(e) {
this.props.changeCurrentInput(e.target.value);
}
onInputKeyDown(e) {
if (["ArrowUp", "ArrowDown"].includes(e.key)) {
this.props.navigateInputHistory(
e.key === "ArrowUp" ? constants.DIR_BACKWARD : constants.DIR_FORWARD
);
}
}
onClearButtonClick(e) {
this.props.clearResultsList();
}
render() {
const { currentInputValue, evaluate } = this.props;
return dom.header(
{ className: "console-header" },
dom.form(
{ onSubmit: this.onSubmitForm },
dom.h1({}, "Reps"),
dom.input({
type: "text",
placeholder: "Enter an expression",
name: "expression",
value: currentInputValue || "",
autoFocus: true,
onChange: this.onInputChange,
onKeyDown: this.onInputKeyDown
}),
dom.button(
{
className: "clear-button",
type: "button",
onClick: this.onClearButtonClick
},
"Clear"
)
),
QuickLinks({ evaluate })
);
}
}
module.exports = Header;