Tree Component

Hierarchical tree built on ul/li with states, shapes, densities, indent modes, node styles, checkboxes, notes, expand levels, and dynamic colors.

Notes

Basic usage

Default (collapsed)

  • A
    • A-1
    • A-2
  • B
  • C

Single branch expanded (.tree-expanded on node)

  • A
    • A-1
    • A-2
  • B
  • C

All expanded (.tree-expanded-all)

  • A
    • A-1
    • A-2
  • B
    • B-1
    • B-2
  • C
    • C-1
    • C-2

Expand levels (.tree-expanded-1 ~ .tree-expanded-3)

Level 1

  • A
    • A-1
    • A-2
  • B

Level 2

  • A
    • A-1
      • A-1-1
      • A-1-2
    • A-2
  • B

Level 3

  • A
    • A-1
      • A-1-1
        • A-1-1-1
        • A-1-1-2
      • A-1-2
    • A-2
  • B

States

Selected (.tree-selected) — colors the whole row

  • A
    • A-1
    • A-2
  • B
  • C

Active (.tree-active) — colors only the label

  • A
    • A-1
    • A-2
  • B
  • C

Disabled (.tree-disabled) — single node or root

  • A
    • A-1
    • A-2
  • B
  • C

Hoverable (.tree-hoverable)

  • A
    • A-1
    • A-2
  • B
  • C

Features

Edit mode — label replaced by <input>

    • A-1
    • A-2
  • B
  • C

Checkbox integration (label.check)

  • A
    • A-1
    • A-2
  • B
  • C

Note nodes (div[data-role="note"])

  • A
    This is apple
    • A-1
      This is apple-1
    • A-2
      This is apple-2
  • B
    This is banana
  • C
    This is cherry

Complex content (avatar, badge, spacer)

  • A 2 Apple
    • A-1
    • A-2
  • B
  • C

Arrow position (first child)

All data-role="node" elements should have a built-in data-role="arrow" child element to ensure consistent indentation.

  • A
    • A-1
    • A-2
  • B
    • B-1
    • B-2
  • C
    • C-1
    • C-2

Padded (.tree-padded)

  • A
    • A-1
    • A-2
  • B
  • C

Shapes

Default

  • A
  • B

Square (.tree-square)

  • A
  • B

Rounded (.tree-rounded)

  • A
  • B

Pill (.tree-pill)

  • A
  • B

Density

Tight (.tree-tight)

  • A
  • B

Snug (.tree-snug)

  • A
  • B

Compact (.tree-compact)

  • A
  • B

Relaxed (.tree-relaxed)

  • A
  • B

Loose (.tree-loose)

  • A
  • B

Indent modes

Cascading (.tree-indent-cascading) — default

  • A
    • A-1
    • A-2
  • B

Dedicated (.tree-indent-dedicated) — requires --tree-level and span[data-role="indent"]

  • A
    Apple note
    • A-1
      Apple-1 note
    • A-2
  • B
  • C

Node styles

Button style (.tree-btns)

  • A
    • A-1
    • A-2
  • B
  • C

List style (.tree-entries) — fully expanded, check icon on selected

  • A
    This is a custom node
    • A-1
    • A-2
  • B
    This is a custom node
  • C
    This is a custom node

Colors

Default (primary)

  • A
  • B

Primary (.tree-primary)

  • A
  • B

Success (.tree-success)

  • A
  • B

Warning (.tree-warning)

  • A
  • B

Error (.tree-error)

  • A
  • B

Color + entries style

  • A
  • B

Use cases

File explorer

  • 📁 src
    • 📁 components
      • 📄 Button.tsx
      • 📄 Tree.tsx
    • 📄 index.ts
    • 📄 utils.ts
  • 📁 public
    • 📄 index.html
  • 📄 package.json

Permission / category selector with checkboxes

  • User management
    • View users
    • Edit users
    • Delete users
  • Role management
    • View roles
    • Assign roles

Tag filter (btns style)

  • All
  • Frontend
  • Backend
  • DevOps
  • Design

Settings menu (entries style with colors)

  • General
    Language, region, appearance
  • Notifications
    Email, push, in-app alerts
  • Privacy
    Data sharing and cookies
  • Security
    Password, 2FA, sessions