react-tree-file-system
A basic tree file system that allows customisation
- custom CSS and classNames
- drag and drop available
- demo available
1 Demo
Version 1.1.0
Version 1.0.6
You can also try out here
2 Get Started
# To download, either npm install --save react-tree-file-system# or yarn add react-tree-file-system
In your code
; // import stylesheet;
Uncontrolled component
- you can toggle folder to open or close by using recursion
const recursiveSetState = { const dupTree= tree; const getIndex = indexescurrIndex; if currIndex === indexeslength - 1 dupTreegetIndexkey = value; return tree; dupTreegetIndexchildren = ; return dupTree;} // ... Component { superprops; thisstate = treeValue: title: 'folder name' type: 'folder' children: title: 'child 1' title: 'child 2' title: 'child 3' } { return // ... <Tree value=thisstatetreeValue folderOnClick= { this; } /> // ... }
- you can support on drag with recursion
const recursivelySetChild = { const dupTree= tree; const getIndex = toIndexescurrIndex; if currIndex === toIndexeslength - 1 dupTreegetIndexchildren; return tree; dupTreegetIndexchildren = ; return dupTree;} const getRecursiveItem = { const dupTree = tree; const getIndex = fromIndexescurrIndex; ifcurrIndex === fromIndexeslength - 1 const child = dupTree; return child0; return ;} const popRecursiveItem = { const dupTree = tree; const getIndex = fromIndexescurrIndex; ifcurrIndex === fromIndexeslength - 1 const filtered = dupTree; return filtered; const children = ; dupTreegetIndexchildren = children; return dupTree;} // ... Component { superprops; thisstate = treeValue: title: 'folder name' type: 'folder' children: title: 'child 1' title: 'child 2' title: 'child 3' } { return // ... <Tree value=thisstatetreeValue onDrag= { this } /> // ... }
4 Tree Structure
// Nodeinterface Node title: string isOpen?: boolean // isLocked?: boolean, // No support yet // isHidden?: boolean, // No support yet children?: Node folderIcon?: ReactElement fileIcon?: ReactElement style?: ReactCSSProperties className?: string // able to add anything here // Example title: 'main' // what is displayed isOpen: false // optional type: 'folder' folderIcon: <FolderIcon /> // optional children: title: 'Child 1' title: 'Readme.md' fileIcon: <FileIcon /> // optional text: 'demo text' // ... repeat Node
5 API
Property | Description | Type | Default |
---|---|---|---|
value | The Tree structure given in point 4 | Node[] | undefined |
fileOnClick | Called when file is clicked | (event, indexes: number[], value: Node) => void | undefined |
folderOnClick | Called when folder is clicked | (event, indexes: number[], state: boolean, value: Node) => void | undefined |
onDrop | Called when something is dragged on folder [Replace onDrag] | (event, fromIndexes, toIndexes) => void | undefined |
onDrag | Called when something is dragged on folder [Depreciated] | (event, fromIndexes, toIndexes) => void | undefined |
folderIcon | Replace the default folder icon | JSX.Element | undefined |
fileIcon | Replace the default file icon | JSX.Element | undefined |
style | customize the general style | React.CSSProperties | undefined |
isDraggable | customize the general style | React.CSSProperties | false |
selected | Enable highlighting of cell clicked. Basically just store the indexes as indexes.join(',') | string | undefined |
selectedClassName | customize the highlighted style with your own className | string | undefined |