UNPKG

react-win7-treeview

Version:

A Windows 7 styled TreeView component for React with animated expand/collapse, line connectors, and RTL support.

100 lines (75 loc) β€’ 5.41 kB
## 🌳 react-win7-treeview – Windows Explorer Style (7.css - wrapper) [![NPM](https://img.shields.io/npm/v/react-win7-treeview.svg)](https://www.npmjs.com/package/react-win7-treeview) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com) A flexible **Windows Explorer–style TreeView** component for React, built with **styled-components** and **framer-motion**. Supports nested nodes, animated expand/collapse, connector lines, keyboard navigation, and RTL. --- ### πŸš€ Live Demo πŸ‘‰ [Codesandbox](https://codesandbox.io/p/sandbox/pd9mvl) --- ### πŸ“¦ Installation ```bash npm install react-win7-treeview ``` --- ### πŸ›  Usage ```tsx import TreeView, { TreeViewItem } from "react-win7-treeview"; export default function App() { return ( <TreeView showBorder lineType="rounded" lineColor="#999"> <TreeViewItem label="Root Folder" defaultOpen> <TreeViewItem label="Child 1" /> <TreeViewItem label="Child 2" defaultOpen> <TreeViewItem label="Grandchild A" /> <TreeViewItem label="Grandchild B" /> </TreeViewItem> </TreeViewItem> </TreeView> ); } ``` --- ### βš™οΈ `<TreeView>` Props | Prop | Type | Default | Description | | ------------ | -------------------------------------------------- | ---------- | -------------------------------------------------- | | `showBorder` | `boolean` | `false` | Shows a Windows-style border around the whole tree | | `isCollapse` | `boolean` | `false` | Enables `<details>/<summary>` built-in collapse UI | | `lineType` | `"none"` \| `"solid"` \| `"dotted"` \| `"rounded"` | `"dotted"` | Connector line style between parent & children | | `lineColor` | `string` | `"#000"` | Color of connector lines | | `children` | `React.ReactNode` | β€” | One or more `<TreeViewItem>` nodes | | `className` | `string` | β€” | Custom class for the outer `<ul>` | --- ### βš™οΈ `<TreeViewItem>` Props | Prop | Type | Default | Description | | --------------- | ------------------------------------------ | --------- | --------------------------------------------------- | | `label` | `React.ReactNode` | β€” | Label text or custom node | | `value` | `any` | β€” | Value passed to `onSelect` and `onToggle` callbacks | | `defaultOpen` | `boolean` | `false` | Whether the node is open by default (uncontrolled) | | `expanded` | `boolean` | β€” | Controlled open/close state | | `onToggle` | `(expanded: boolean, value?: any) => void` | β€” | Called when node toggles | | `toggleMode` | `"row"` \| `"label"` | `"label"` | Toggle by clicking the whole row or just the label | | `direction` | `"ltr"` \| `"rtl"` | `"ltr"` | Text direction (RTL support) | | `controlBox` | `(open: boolean) => React.ReactNode` | β€” | Custom expand/collapse control | | `expandIcon` | `React.ReactNode` | β€” | Custom icon when collapsed | | `collapseIcon` | `React.ReactNode` | β€” | Custom icon when expanded | | `indent` | `number` | `20` | Left padding for nested lists (px) | | `showIcon` | `boolean` | `true` | Whether to show the expand/collapse icon | | `selected` | `boolean` | `false` | Mark this node as selected | | `onSelect` | `(value?: any) => void` | β€” | Called when the node is selected | | `disabled` | `boolean` | `false` | Disable interactions | | `onDoubleClick` | `(value?: any) => void` | β€” | Fired on double click | | `children` | `React.ReactNode` | β€” | Nested `<TreeViewItem>` nodes | | `className` | `string` | β€” | Custom class for the node | --- ### ✨ Features - **Windows 7 / Explorer-style UI** - **Animated** expand & collapse using **framer-motion** - Keyboard navigation (ArrowRight, ArrowLeft, Enter) - Supports **LTR / RTL** layouts - Flexible connector line types (none, solid, dotted, rounded) - Custom icons, control box, and selection modes - Optional double-click events and disabled state --- ### πŸ“‹ License MIT / Delpi