List.js (1289B)
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 file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const { 8 Component, 9 } = require("resource://devtools/client/shared/vendor/react.mjs"); 10 const PropTypes = require("resource://devtools/client/shared/vendor/react-prop-types.mjs"); 11 const dom = require("resource://devtools/client/shared/vendor/react-dom-factories.js"); 12 13 /** 14 * Generic list component that takes another react component to represent 15 * the children nodes as `itemComponent`, and a list of items to render 16 * as that component with a click handler. 17 */ 18 class List extends Component { 19 static get propTypes() { 20 return { 21 itemComponent: PropTypes.any.isRequired, 22 onClick: PropTypes.func, 23 items: PropTypes.array.isRequired, 24 }; 25 } 26 27 render() { 28 const { items, onClick, itemComponent: Item } = this.props; 29 30 return dom.ul( 31 { className: "list" }, 32 ...items.map((item, index) => { 33 return Item( 34 Object.assign({}, this.props, { 35 key: index, 36 item, 37 index, 38 onClick: () => onClick(item), 39 }) 40 ); 41 }) 42 ); 43 } 44 } 45 46 module.exports = List;