Socket
Socket
Sign inDemoInstall

@react-md/tree

Package Overview
Dependencies
17
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @react-md/tree

A package for creating an accessible tree component following the tree role.


Version published
Weekly downloads
1K
increased by2.94%
Maintainers
1
Install size
3.55 MB
Created
Weekly downloads
 

Changelog

Source

5.1.6 (2023-12-11)

Bug Fixes

  • @react-md/chip: add overflow to support font icons (da44bbd), closes #1432
  • select: port fixed positioning fixes back from v6.0.0 (feb9ec6), closes #1461

Documentation

  • react-md.dev: update blog to include additional releases (b305882)

Readme

Source

@react-md/tree

Create accessible tree widgets following the tree view specifications using the material design styles and fairly customizable renderers and styles and reasonable defaults.

Installation

npm install --save @react-md/tree

It is also recommended to install these other packages as they work hand-in-hand with this package:

npm install --save @react-md/theme \
  @react-md/typography \
  @react-md/icon \
  @react-md/material-icons \
  @react-md/list

Documentation

You should check out the full documentation for live examples and more customization information, but an example usage is shown below.

Usage

The main export from this package is the Tree component which allows you to render a tree from TreeData which is really a lookup of Record<TreeItemId, TreeItem>. The Tree component is fully controlled and requires you to provide the selection and logic expansion with a few props. You can use the useTreeItemExpansion and useTreeItemSelection hooks to get pretty reasonable support out of the box including multi-select behavior.

If you are a Typescript user, this package also exports a decent amount of types to help out such as the TreeData, BaseTreeItem, and TreeItemSorter.

Here's a quick example:

import type { ReactElement, ReactNode } from "react";
import { render } from "react-dom";
import {
  Tree,
  TreeData,
  BaseTreeItem,
  useTreeItemExpansion,
  useTreeItemSelection,
} from "@react-md/tree";

interface MyTreeItem extends BaseTreeItem {
  name: string;
}

const data: TreeData<MyTreeItem> = {
  "item-1-id": {
    name: "Root Node",
    itemId: " item-1-id",
    parentId: null,
  },
  "item-2-id": {
    name: "Child 1",
    itemId: "item-2-id",
    parentId: "item-1-id",
  },
  "item-3-id": {
    name: "Child 2",
    itemId: "item-3-id",
    parentId: "item-1-id",
  },
};

export default function Example(): ReactElement {
  const selection = useTreeItemSelection([], false);
  const expansion = useTreeItemExpansion([]);

  return (
    <Tree
      id="example-tree"
      aria-label="Tree"
      data={data}
      {...selection}
      {...expansion}
    />
  );
}

Keywords

FAQs

Last updated on 11 Dec 2023

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc