chrome-devtools-frontend
Version:
Chrome DevTools UI
62 lines (54 loc) • 2.12 kB
text/typescript
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as FrontendHelpers from '../../../../testing/EnvironmentHelpers.js';
import * as Lit from '../../../lit/lit.js';
import * as ComponentHelpers from '../../helpers/helpers.js';
import * as TreeOutline from '../../tree_outline/tree_outline.js';
const {html} = Lit;
await ComponentHelpers.ComponentServerSetup.setup();
await FrontendHelpers.initializeGlobalVars();
interface TreeNodeData {
cssProperty: string;
cssValue: string;
}
const data: TreeOutline.TreeOutline.TreeOutlineData<TreeNodeData> = {
defaultRenderer: (node, state) => {
const {cssProperty, cssValue} = node.treeNodeData;
const valueStyles = Lit.Directives.styleMap({
paddingLeft: '10px',
fontStyle: 'italic',
color: 'var(--sys-color-token-property-special)',
});
return html`<code>${cssProperty}</code>:${
state.isExpanded ? Lit.nothing : html`<code style=${valueStyles}>${cssValue}</code>`}`;
},
tree: [
{
treeNodeData: {cssProperty: 'border', cssValue: '1px solid red'},
id: '1',
},
{
treeNodeData: {cssProperty: 'font-size', cssValue: '20px'},
id: '2',
},
{
treeNodeData: {cssProperty: 'margin', cssValue: '10px 5px'},
id: '3',
async children(): Promise<Array<TreeOutline.TreeOutlineUtils.TreeNode<TreeNodeData>>> {
return [
{treeNodeData: {cssProperty: 'margin-left', cssValue: '5px'}, id: '4'},
{treeNodeData: {cssProperty: 'margin-right', cssValue: '5px'}, id: '5'},
{treeNodeData: {cssProperty: 'margin-top', cssValue: '10px'}, id: '6'},
{treeNodeData: {cssProperty: 'margin-bottom', cssValue: '10px'}, id: '7'},
];
},
},
],
};
const component = new TreeOutline.TreeOutline.TreeOutline<TreeNodeData>();
component.data = data;
document.getElementById('container')?.appendChild(component);
document.getElementById('recursively-expand')?.addEventListener('click', () => {
void component.expandRecursively();
});