5.3.0 • Published 3 years ago

@astrouxds/rux-tree v5.3.0

Weekly downloads
35
License
SEE LICENSE IN LI...
Repository
github
Last release
3 years ago

Tree

A Tree navigation element presents a hierarchical set of related items, and allow users to explore and select items within that hierarchy. Each item can have a number of subitems.

An item can be expanded to reveal subitems, if any exist, and collapsed to hide subitems.

Guidelines

Web Components Usage

1. Installation

Install the Astro UXDS Tree package via Command Line (Preferred Method)

npm i --save @astrouxds/rux-tree

You may use Yarn, NPM, or your Node package manager of choice. The --save flag adds this component as a dependency in your package.json file.

Alternatively, download the Astro Component Library source to your project.

Via CLI:

git clone https://github.com/RocketCommunicationsInc/astro-components.git

Or, download Astro Components as a .zip

2. Import the Astro Tree Web Component

This example assumes you're using the NPM package in node_modules. Otherwise, import the component using the path to the Astro Components directory in your project.

import { RuxTree } from '@astrouxds/rux-tree/rux-tree.js'

3. Render the Astro Tree Web Component

<rux-tree .data="${dataArray}"></rux-tree>

Properties

PropertyTypeDefaultRequiredDescription
dataArray[]yesAn array of objects defining the tree structure. See a sample object below.

Sample data object

[
 {
  label: "Option 1",
  status: "critical",
  expanded: true,
  children: [{
   label: "Option 1.1",
   status: "normal",
   selected: true,
   children: [ …] }]
 },
 {
  label: "Option 1.2",
  status: "normal",
  children: [ …]
 },
 {
  label: "Option 2",
  status: "normal",
 }
]

Object Properties

PropertyTypeRequiredDescription
labelStringyesThe label for the tree item
idStringnoAn optional property to help identify individual tree elements
selectedBooleannoIf set to true, this item shows a selected style. When a new item is selected by user click, all other selected items are unselected.
expandedBooleannoIf set to true, this item is expanded. Multiple items can be expanded at the same time.
statusStringnoAn optional property to assign status. See Astro Status for valid status options
childrenArraynoAn array of child elements. Children use the same structure as parents and may include their own children array to create nested elements

Component Events

Tree emits a tree-updated event whenever the selected tree item changes. Events contain a composed path to the element that triggered the event and two objects in the the detail property.

Sample Tree event

window.addEventListener('tree-updated', (event) => {
    // an array that reflects the current state of the tree
    console.log('Tree data', event.detail.data)

    // an object representing the currently selected tree item
    console.log('Selected tree item', event.detail.selected)
})

detail Properties

PropertyTypeDescription
dataArrayAn updated array reflecting the current state of the array
selectedObjectThe currently selected element

Revision History

4.0
  • Replaced Polymer 3 implementation with LitElement for improved speed and interoperability with JS Frameworks as well as simpler template declaration now available in vanilla JavaScript.
  • Tree supports multiple nested child tree element
  • Added keyboard support
  • Added support for assigning status to each tree item
3.0
  • Added a light theme
2.1
  • Converted to Web Component
Notes

RUX Tree is based on the industry standard WebComponents v1 spec.

Note: RUX Tree is available as a preview release and should not be used in production code.

5.3.0

3 years ago

5.0.1

3 years ago

5.0.0

3 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

4 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.0.0

6 years ago

2.0.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago