Socket
Socket
Sign inDemoInstall

@hig/tree-view

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hig/tree-view

HIG Tree View


Version published
Weekly downloads
8
decreased by-11.11%
Maintainers
4
Weekly downloads
 
Created
Source

TreeView

The tree view component provides a way to view and manipulate a list of data, often with complex nested structures.

Read more about when and how to use the TreeView component on the internal wiki.

Getting started

Install the package

yarn add @hig/tree-view @hig/theme-context @hig/theme-data

Import the component

import TreeView, { TreeItem } from "@hig/tree-view";

Basic usage

<TreeView>
  <TreeItem label="Tree Item 1" id="tree-item-1">
    <TreeItem label="Tree Item 2" id="tree-item-2">
      <TreeItem label="Tree Item 3" id="tree-item-3">
        <TreeItem label="Tree Item 4" id="tree-item-4" />
        <TreeItem label="Tree Item 5" id="tree-item-5" />
        <TreeItem label="Tree Item 6" id="tree-item-6" />
      </TreeItem>
    </TreeItem>
  </TreeItem>
</TreeView>

Customization

Tree Node Object

const FileTreeCollection = {
  id: 1,
  index: 0,
  parentId: null,
  meta: {
    label: "Tree Item 1",
    collapsed: false,
    active: false,
    disabled: false,
    icon: <Calendar24 />,
  },
  children: [
    {
      id: 2,
      index: 1,
      parentId: 1,
      meta: {
        label: "Tree Item 2",
        collapsed: false,
        active: false,
        disabled: false,
        icon: null,
      },
    },
    {
      id: 3,
      index: 2,
      parentId: 1,
      meta: {
        label: "Tree Item 3",
        collapsed: false,
        active: false,
        icon: <Folder24 />,
      },
      children: [
        {
          id: 4,
          index: 3,
          parentId: 3,
          meta: {
            label: "Tree Item 4",
            collapsed: false,
            active: false,
            icon: null,
          },
        },
      ],
    },
  ],
};

Styling

Use the className prop to pass in a css class name to the outermost container of the component. The class name will also pass down to most of the other styled elements within the component.

TreeView also has a stylesheet prop that accepts a function wherein you can modify TreeView's styles. The original styles, props, current theme data and theme meta will be passed to your custom stylesheet function, and it should return an object with the same structure as the original styles. For instance:

function customStylesheet(styles, props, themeData) {
  return {
    ...styles,
    higTreeViewWrapper: {
      ...styles.higTreeViewWrapper,
      backgroundColor: "yellow"
    },
    higTreeView: {
      ...styles.higTreeView,
      backgroundColor: "black"
    },
    higTreeItem: {
      ...styles.higTreeItem,
      backgroundColor: themeData["basics.colors.green100"]
    },
    higTreeItemContentWrapper: {
      ...styles.higTreeItemContentWrapper,
      padding: 0
    },
    higTreeItemSubTreeViewWrapper: {
      ...styles.higTreeItemSubTreeViewWrapper,
      margin: 0
    },
    higTreeItemSubTreeView: {
      ...styles.higTreeItemSubTreeView,
      fontSize: "14px"
    },
    higTreeItemSubTreeViewLabelWrapper: {
      ...styles.shortcutWrapper,
      overflow: "hidden"
    },
    higTreeItemSubTreeViewLabelContentWrapper: {
      ...styles.higTreeItemSubTreeViewLabelContentWrapper,
      width: "100%"
    },
    higTreeItemSubTreeItem: {
      ...styles.higTreeItemSubTreeItem,
      textAlign: "center"
    },
    higTreeItemIndicatorWrapper: {
      ...styles.higTreeItemIndicatorWrapper,
      backgroundColor: "transparent"
    },
    higTreeItemIconWrapper: {
      ...styles.higTreeItemIconWrapper,
      height: "36px"
    },
    higTreeItemLabelWrapper: {
      ...styles.higTreeItemLabelWrapper,
      fontWeight: 900
    }
  };
}

<TreeView stylesheet={customStylesheet}>
  <TreeItem label="Tree Item 1" id="tree-item-1" stylesheet={customStylesheet}>
    <TreeItem label="Tree Item 2" id="tree-item-2">
      <TreeItem label="Tree Item 3" id="tree-item-3">
        <TreeItem label="Tree Item 4" id="tree-item-4" />
        <TreeItem label="Tree Item 5" id="tree-item-5" />
        <TreeItem label="Tree Item 6" id="tree-item-6" />
      </TreeItem>
    </TreeItem>
  </TreeItem>
</TreeView>;

FAQs

Package last updated on 18 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc