Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Morden React Tree component library with virtualization, search, and Tailwind CSS support.

License

NotificationsYou must be signed in to change notification settings

fireangle/rstree

Repository files navigation

RsTree Logo

npm versionBuild StatusTypeScriptMIT License

A Morden React tree component library with virtualization, search, and Tailwind CSS support.Demo

Another choice for React tree components.Tree component screenshot

Features

  • Virtual scrolling for large datasets (1000+ nodes)
  • Fuzzy search with highlighting and auto-expansion
  • Full customization of icons and nodes
  • Responsive design for all screen sizes
  • TypeScript support with complete type definitions
  • Multiple selection modes - single/multi-select, checkboxes, disabled states
  • Tailwind CSS integration - works with or without Tailwind
  • Tree utilities - connecting lines, click-to-toggle, auto-expand

Installation

npm install rstree-ui

Peer Dependencies

npm install react react-dom

Tailwind CSS Support (Optional)

Works with Tailwind CSS v3+ and v4+, or as a standalone component.

Quick Start

Option 1: With Tailwind CSS v4

Add to your CSS file:

@import"tailwindcss";@source"../node_modules/rstree-ui";

Option 2: With Tailwind CSS v3

Add the library path to yourtailwind.config.js:

module.exports={content:["./src/**/*.{js,ts,jsx,tsx}","./node_modules/rstree-ui/**/*.{js,ts,jsx,tsx}",],// ... other config}

Option 3: Standalone CSS

Import the pre-compiled styles:

import'rstree-ui/style.css'

Basic Usage

import{RsTree}from'rstree-ui'constdata=[{id:'1',label:'Documents',children:[{id:'1-1',label:'Resume.pdf'},{id:'1-2',label:'Cover Letter.docx'}]},{id:'2',label:'Pictures'}]functionApp(){const[selectedIds,setSelectedIds]=useState([])return(<RsTreedata={data}selectedIds={selectedIds}onSelect={setSelectedIds}showIcons={true}/>)}

API Reference

RsTree Props

Core Props

PropTypeDefaultDescription
dataTreeNode[]requiredTree data structure
selectedIdsstring[][]Array of selected node IDs
onSelect(ids: string[]) => void-Selection change callback
multiSelectbooleanfalseEnable multi-selection

Expansion Control

PropTypeDefaultDescription
expandedIdsstring[][]Array of expanded node IDs
onExpand(ids: string[]) => void-Expansion change callback
clickToTogglebooleanfalseClick anywhere on node to toggle

Checkbox Support

PropTypeDefaultDescription
checkablebooleanfalseEnable checkboxes
checkedIdsstring[][]Array of checked node IDs
onCheck(ids: string[]) => void-Check state change callback

Visual Customization

PropTypeDefaultDescription
showIconsbooleantrueShow folder/file icons
showTreeLinesbooleanfalseShow connecting lines
disabledbooleanfalseDisable all interactions
classNamestring''Additional CSS classes for container
treeLineClassNamestring''Custom CSS classes for tree lines
treeNodeClassNamestring''Custom CSS classes for tree nodes

Custom Icons

PropTypeDefaultDescription
expandIconReact.ReactNode<ChevronRight />Custom expand icon
collapseIconReact.ReactNode<ChevronDown />Custom collapse icon
folderIconReact.ReactNode<Folder />Custom folder icon
fileIconReact.ReactNode<File />Custom file icon

Search Features

PropTypeDefaultDescription
searchTermstring''Search query string
autoExpandSearchbooleantrueAuto-expand search results
onSearchMatch(id: string | null) => void-Best match callback

Performance & Layout

PropTypeDefaultDescription
virtualizeEnabledbooleantrueEnable virtual scrolling
heightnumber400Fixed height in pixels
itemHeightnumber32Height per item
autoHeightbooleanfalseAuto-adjust height
maxHeightnumber400Maximum height
minHeightnumber100Minimum height

Advanced Customization

PropTypeDescription
renderNode(node: TreeNode, props: TreeNodeRenderProps) => React.ReactNodeCustom node renderer
onNodeClick(node: TreeNode, event: React.MouseEvent) => voidNode click handler

TreeNode Interface

interfaceTreeNode{id:string// Unique identifierlabel:string// Display textchildren?:TreeNode[]// Child nodesdisabled?:boolean// Disable this nodeicon?:React.ComponentType<{className?:string}>|ReactNode// Custom icon for this nodemetadata?:Record<string,unknown>// Additional metadatadata?:any// Additional custom data}

Examples

Multi-Select Tree

<RsTreedata={data}multiSelect={true}selectedIds={selectedIds}onSelect={setSelectedIds}/>

Checkable Tree

<RsTreedata={data}checkable={true}checkedIds={checkedIds}onCheck={setCheckedIds}/>

Search with Auto-Expand

<RsTreedata={data}searchTerm={searchTerm}autoExpandSearch={true}virtualizeEnabled={true}/>

Custom Icons

constMyExpandIcon=<span></span>constMyCollapseIcon=<span></span><RsTreedata={data}expandIcon={MyExpandIcon}collapseIcon={MyCollapseIcon}showIcons={true}/>

Large Dataset with Virtualization

<RsTreedata={largeDataset}height={500}virtualizeEnabled={true}itemHeight={36}/>

Custom Styling

// Custom tree lines and node styling<RsTreedata={data}showTreeLines={true}treeLineClassName="border-blue-300 border-dashed"treeNodeClassName="rounded-lg shadow-sm hover:shadow-md"className="border border-gray-200 rounded-md"/>// Dark theme styling example<RsTreedata={data}showTreeLines={true}treeLineClassName="border-gray-600"treeNodeClassName="text-gray-100 hover:bg-gray-800 bg-gray-900"className="bg-gray-900 border border-gray-700"/>

Custom Node Renderer

The library automatically handles layout structure (indentation, tree lines, expand icons, checkboxes) while allowing you to customize the content area:

// Rich project management tree with custom metadataconstprojectData=[{id:"project-1",label:"React Dashboard",data:{type:"project",status:"active",priority:"high",lastModified:"2 hours ago"},children:[{id:"src",label:"src",data:{type:"folder",fileCount:12,size:"298 KB"}},{id:"app.tsx",label:"App.tsx",data:{type:"file",language:"typescript",size:"12.5 KB",lines:340}},]}];constcustomRenderer=(node,props)=>{const{ data}=node;if(data?.type==="project"){return(<divclassName="flex items-center gap-3 py-1 w-full min-w-0"><divclassName="flex items-center gap-2 flex-1 min-w-0"><spanclassName="font-semibold text-gray-100">{node.label}</span><spanclassName={`px-2 py-0.5 text-xs rounded-full${data.status==='active' ?'bg-green-500/20 text-green-400' :'bg-blue-500/20 text-blue-400'}`}>{data.status}</span><divclassName="w-2 h-2 rounded-full bg-red-500"></div><spanclassName="text-xs text-gray-400">{data.priority}</span></div><spanclassName="text-xs text-gray-400">📅{data.lastModified}</span></div>);}if(data?.type==="file"){return(<divclassName="flex items-center gap-3 py-1 w-full min-w-0"><divclassName="flex items-center gap-2 flex-1 min-w-0"><spanclassName="w-6 h-6 bg-gray-700 text-gray-300 rounded text-xs flex items-center justify-center font-mono">{data.language==='typescript' ?'TS' :'JS'}</span><spanclassName="text-gray-200">{node.label}</span></div><divclassName="flex items-center gap-3 text-xs text-gray-500"><span>{data.lines} lines</span><span>{data.size}</span></div></div>);}return<span>{node.label}</span>;};<RsTreedata={projectData}renderNode={customRenderer}showTreeLines={true}multiSelect={true}/>

Key Features:

  • Automatic Layout: Indentation, tree lines, and controls are handled automatically
  • Rich Content: Display badges, icons, metadata, and custom styling
  • Responsive Design: Content adapts to available space with proper text truncation
  • Interaction Support: Maintain full tree functionality (select, expand, check)

Note: Your custom content is automatically wrapped in the standard tree layout structure, so you don't need to handle indentation, tree lines, or control elements yourself. Just focus on the node content.

Development

Install Dependencies

npm install

Development

npm run dev# Watch modenpm run build# Build librarynpm runtest# Run testsnpm run lint# Lint code

Build

npm run build

Testing

npm runtest

Contributing

Contributions are welcome!

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Open a Pull Request

License

This project is licensed under the MIT License - see theLICENSE file for details.

Support

About

A Morden React Tree component library with virtualization, search, and Tailwind CSS support.

Topics

Resources

License

Contributing

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp