LabelCell.mjs (2007B)
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 5 import { Component } from "resource://devtools/client/shared/vendor/react.mjs"; 6 import * as dom from "resource://devtools/client/shared/vendor/react-dom-factories.mjs"; 7 import PropTypes from "resource://devtools/client/shared/vendor/react-prop-types.mjs"; 8 9 /** 10 * Render the default cell used for toggle buttons 11 */ 12 class LabelCell extends Component { 13 // See the TreeView component for details related 14 // to the 'member' object. 15 static get propTypes() { 16 return { 17 title: PropTypes.string, 18 member: PropTypes.object.isRequired, 19 renderSuffix: PropTypes.func, 20 }; 21 } 22 23 render() { 24 const title = this.props.title; 25 const member = this.props.member; 26 const level = member.level || 0; 27 const renderSuffix = this.props.renderSuffix; 28 29 const iconClassList = ["treeIcon"]; 30 if (member.hasChildren && member.loading) { 31 iconClassList.push("devtools-throbber"); 32 } else if (member.hasChildren) { 33 iconClassList.push("theme-twisty"); 34 } 35 if (member.open) { 36 iconClassList.push("open"); 37 } 38 39 return dom.td( 40 { 41 className: "treeLabelCell", 42 title, 43 style: { 44 // Compute indentation dynamically. The deeper the item is 45 // inside the hierarchy, the bigger is the left padding. 46 "--tree-label-cell-indent": `${level * 16}px`, 47 }, 48 key: "default", 49 role: "presentation", 50 }, 51 dom.span({ 52 className: iconClassList.join(" "), 53 role: "presentation", 54 }), 55 dom.span( 56 { 57 className: "treeLabel " + member.type + "Label", 58 title, 59 "data-level": level, 60 }, 61 member.name 62 ), 63 renderSuffix && renderSuffix(member) 64 ); 65 } 66 } 67 68 // Exports from this module 69 export default LabelCell;