MainToolbar.js (2097B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 "use strict"; 5 6 // React 7 const { 8 Component, 9 createFactory, 10 } = require("resource://devtools/client/shared/vendor/react.mjs"); 11 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 12 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs"); 13 const SearchBox = createFactory( 14 require("resource://devtools/client/shared/components/SearchBox.js") 15 ); 16 17 const { l10n } = require("resource://devtools/client/dom/content/utils.js"); 18 19 // Actions 20 const { 21 fetchProperties, 22 } = require("resource://devtools/client/dom/content/actions/grips.js"); 23 const { 24 setVisibilityFilter, 25 } = require("resource://devtools/client/dom/content/actions/filter.js"); 26 27 /** 28 * This template is responsible for rendering a toolbar 29 * within the 'Headers' panel. 30 */ 31 class MainToolbar extends Component { 32 static get propTypes() { 33 return { 34 object: PropTypes.any.isRequired, 35 dispatch: PropTypes.func.isRequired, 36 }; 37 } 38 39 constructor(props) { 40 super(props); 41 this.onRefresh = this.onRefresh.bind(this); 42 this.onSearch = this.onSearch.bind(this); 43 } 44 45 onRefresh() { 46 this.props.dispatch(fetchProperties(this.props.object)); 47 } 48 49 onSearch(value) { 50 this.props.dispatch(setVisibilityFilter(value)); 51 } 52 53 render() { 54 return dom.div( 55 { className: "devtools-toolbar devtools-input-toolbar" }, 56 SearchBox({ 57 key: "filter", 58 delay: 250, 59 onChange: this.onSearch, 60 placeholder: l10n.getStr("dom.filterDOMPanel"), 61 type: "filter", 62 }), 63 dom.span({ className: "devtools-separator" }), 64 dom.button({ 65 key: "refresh", 66 className: "refresh devtools-button", 67 id: "dom-refresh-button", 68 title: l10n.getStr("dom.refresh"), 69 onClick: this.onRefresh, 70 }) 71 ); 72 } 73 } 74 75 // Exports from this module 76 module.exports = MainToolbar;