ef-tree / ef-tree-item

Generic data-driven tree component. The building block used by ef-hierarchy.

ef-tree is a general-purpose tree view driven by a .items array. ef-hierarchy is built on top of it. Use ef-tree directly when you need a collapsible tree for non-composition data.

AttributeReact propTypeDefaultDescription
expand-allexpandAllbooleantrueExpands all items by default.
headerheaderstring""Header text shown above the tree (when `show-header`).
selected-idselectedIdstring | nullID of the currently selected item.
show-headershowHeaderbooleanfalseWhether to show the header row.
<ef-tree show-header header="Files"></ef-tree>

<script>
  const tree = document.querySelector('ef-tree');
  tree.items = [
    {
      id: 'src',
      label: 'src',
      children: [
        { id: 'index', label: 'index.ts' },
        { id: 'app', label: 'app.ts' },
      ],
    },
    { id: 'package', label: 'package.json' },
  ];

  tree.addEventListener('tree-select', (e) => {
    console.log('selected:', e.detail.id);
  });
</script>

TreeItem shape:

interface TreeItem {
  id: string;
  label: string;
  icon?: string;       // optional icon HTML/text
  children?: TreeItem[];
}

Events:

EventDetailDescription
tree-select{ id: string | null; item: TreeItem | null }Fires when the user clicks a row.

CSS Custom Properties

PropertyDefaultDescription
--tree-bgBackground color of the tree container.
--tree-borderBorder color.
--tree-hover-bgRow background color on hover.
--tree-selected-bgRow background color when selected.
--tree-textText color.

Each row is rendered by an internal ef-tree-item:

PropertyDefaultDescription
--tree-expand-icon-size1remSize of the expand/collapse chevron icon.
--tree-icon-gap0.25remGap between the icon and label.
--tree-indent1remIndent width per nesting level.
--tree-item-font-size0.75remRow label font size.
--tree-item-height1.5remRow height.
--tree-item-padding-left0.5remRow left padding.
--tree-item-padding-right0.5remRow right padding.

CSS Parts

PartDescription
containerOuter tree wrapper.
emptyEmpty-state message.
headerOptional header (when `show-header`).
PartDescription
childrenWrapper around nested child items (receives `data-collapsed`).
expand-iconExpand/collapse chevron.
iconOptional item icon.
labelItem label text.
rowItem row (receives `data-selected`).