Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
f43e987
basic webpack setup, can run hello world html
shunjizhan Oct 14, 2020
8fffb00
remove dist folder
shunjizhan Oct 27, 2020
657150b
setup basic dev env, hot reloading works
shunjizhan Oct 27, 2020
20ca81b
updated dev server
shunjizhan Oct 27, 2020
b8a9440
restructure scripts and config
shunjizhan Oct 27, 2020
248f162
updated HMR that it clears console on each build
shunjizhan Oct 27, 2020
88ea443
Added Sandbox
shunjizhan Nov 5, 2020
db7750a
Added Icon to Public HTML
shunjizhan Nov 7, 2020
21c3461
Set Up FolderTree Skeleton
shunjizhan Nov 7, 2020
39894c1
Added Jest Framework
shunjizhan Nov 7, 2020
36c6754
Setup Eslint
shunjizhan Nov 8, 2020
d1961bb
added airbnb eslint rules and fixed lint errors
shunjizhan Nov 8, 2020
04f5020
Set Up Husky Pre-commit Pipeline
shunjizhan Nov 8, 2020
00ef2a8
run tests in precpush hook
shunjizhan Nov 10, 2020
708646e
More Eslint Setup
shunjizhan Nov 10, 2020
c2f5f41
folderTree can intialzie data with ids
shunjizhan Nov 11, 2020
b918048
clean up jest config
shunjizhan Nov 11, 2020
8bff19f
clean up jest config
shunjizhan Nov 11, 2020
6bcdf96
initialized data with checked status
shunjizhan Nov 11, 2020
eaf5eef
Merge branch 'v4-upgrade' of github.com:shunjizhan/React-Folder-Tree …
shunjizhan Nov 19, 2020
ae8ca10
able to integrate scss
shunjizhan Nov 28, 2020
9c8a0ea
able to render tree nodes
shunjizhan Nov 30, 2020
c41f324
update eslint to use babel
shunjizhan Dec 1, 2020
e4ee9ce
added and enabled optional chaining
shunjizhan Dec 5, 2020
e6ce2b2
Add Checkbox Component
shunjizhan Dec 5, 2020
b166c00
half check works!!!
shunjizhan Dec 5, 2020
ddf0fc0
set up jest and enzyme testing env
shunjizhan Dec 6, 2020
eb62089
added tests for CheckBox component
shunjizhan Dec 6, 2020
7802ea3
refactored code to pass shared util functions using context
shunjizhan Dec 6, 2020
44b49c2
adde script to create new component files
shunjizhan Dec 7, 2020
6c75247
added renameNode() function
shunjizhan Dec 7, 2020
0c8d183
added EditableName component
shunjizhan Dec 7, 2020
2233a1e
integrated EditableName component to TreeNode
shunjizhan Dec 7, 2020
00889a3
added deleteNode function
shunjizhan Dec 8, 2020
c6b8f59
integrated deleteNode function to folder tree
shunjizhan Dec 8, 2020
c757be9
solved a bug for computing state after deleting a node
shunjizhan Dec 8, 2020
93b0f47
added react-icons package
shunjizhan Dec 8, 2020
b995a5a
Integrated Icons
shunjizhan Dec 10, 2020
6db7af2
added functionality to add a node
shunjizhan Dec 10, 2020
2dd60ae
integrated addNode() to folder tree
shunjizhan Dec 10, 2020
a0b0bc4
group all scss to one file
shunjizhan Dec 10, 2020
896e719
massive icon UI updates
shunjizhan Dec 10, 2020
23bd2c2
added tree state viewer in sandbox
shunjizhan Dec 11, 2020
994ea4b
set up sandbox basic structure and envs
shunjizhan Dec 13, 2020
c4fac4c
added toggle open method in utils
shunjizhan Dec 14, 2020
aba5fe8
manage isOpen at the top level tree state
shunjizhan Dec 14, 2020
a5f5349
fix the path error for yarn build
shunjizhan Dec 15, 2020
43bfb7e
updated main entry in package json to use the production bundle
shunjizhan Dec 15, 2020
9ac4015
production ready
shunjizhan Dec 16, 2020
e42af86
slightly changed webpack setting for production
shunjizhan Jan 26, 2021
62e44e0
changed internal tree state to use _id instead of id
shunjizhan Jan 26, 2021
f8e44b5
final polish before publishing
shunjizhan Jan 30, 2021
ac03316
updated README for publishing
shunjizhan Jan 30, 2021
01867d8
fixed tests related to chaning id to _id
shunjizhan Jan 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-optional-chaining"
]
}
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/components/SandBox.jsx
src/components/SandBoxComponents/
69 changes: 69 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
module.exports = {
parser: 'babel-eslint', // use babel to parse
env: {
browser: true,
es6: true,
node: true, // for node globals, such as 'module'
jest: true, // for jest globals, such as 'test' and 'expect'
},
// 'plugins' section only 'activate' these plugins
// still need manually edit 'rules' to actually use them
// such as { react/xxx: 'error' }
plugins: [
'react',
],
// 'extends' section will extend these configs
// and they will take effect directly
extends: [
'eslint:recommended',
'plugin:react/recommended',
'airbnb',
'airbnb/hooks',
'plugin:react-hooks/recommended',
],
rules: {
indent: [2, 2, { SwitchCase: 1 }],
quotes: [2, 'single'],
semi: [2, 'always'],
'jsx-quotes': [2, 'prefer-single'],
'linebreak-style': [2, 'unix'],
'arrow-parens': [2, 'as-needed'],
'react/jsx-curly-spacing': [2, {
when: 'always',
spacing: { objectLiterals: 'never' },
}],
'no-restricted-syntax': [
'error',
'ForInStatement',
// 'ForOfStatement',
'LabeledStatement',
'WithStatement',
],

/* ---------- turned off ---------- */
'max-len': 0,
'react/jsx-filename-extension': 0,
'react/forbid-prop-types': 0,
'react/require-default-props': 0,
'no-underscore-dangle': 0,
'no-multi-spaces': 0,
'jsx-a11y/click-events-have-key-events': 0, // allow click handler on <div>
'jsx-a11y/no-static-element-interactions': 0, // allow click handler on <div>
'no-unused-expressions': [2, { allowShortCircuit: true }], // allow x && y()
'import/no-extraneous-dependencies': [2, { devDependencies: true }], // so can import enzyme, which is dev dependencies
},

// don't know what these are... generated by eslint --init
// TODO: do more research about these
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: 'module',
},
};
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dist/
notes.md

yarn-error.log
npm-debug.log
build
Expand Down
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

212 changes: 37 additions & 175 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,188 +1,50 @@
# Introduction
# React Folder Tree
A powerful and customizable react treeview library.

This is a folder tree written in ReactJS.

We can do:
## Core Features
- **Half Check** (indeterminate checkboxes): when some of the children nodes are checked, parent node automatically becomes half check.
- **Inline CRUD** operations: rename nodes, create new nodes, and delete nodes.
- **Customizable**: all icons are customizable, so you can build your favorite styles, as well as custom functionalities for user interactions.

- click each carat to expand/collapse the folder
- click the checkbox to (un)check each folder and file. (un)check each folder will automatically (un)check all sub-folders, including all the files in these folders. If part of the sub-folders or files in a folder are checked, this folder will display a half check.
- click the folder/file name to select it, and it will be hightlighted in blue
- click the pencil beside the folder/file to rename it
- click the delete button to delete the selected folder/file
- click the Add button to add new file in the selected folder/file. Adding a file-2 to a file-1 will change file-1 to a folder; if all sub folder/files of a folder are deleted, this folder will become a file. The new file's check status is same as its parent
## Quick Preview
![folder-tree-demo](/assets/folder-tree-demo.gif)

# Props
- data: initial data to construct the tree. Sample data can be found [below](#sample-data)
- onChange(data): It will call this function after any of these four actions: (un)check, add, delete, or rename. Where data is the object representing the tree of all selected files/folders (filtered out all unchecked files/folders).
- FileComponent & FolderComponent: you can inject your own components here. Default file/folder component is already provided.

# Sample Tree:
## Demos & Code Examples
[===== HERE =====](https://shunjizhan.github.io/react-folder-tree-demos/)
[===== HERE =====](https://shunjizhan.github.io/react-folder-tree-demos/)
[===== HERE =====](https://shunjizhan.github.io/react-folder-tree-demos/)

![](https://raw.githubusercontent.com/shunjizhan/React-Folder-Tree/master/folder-tree-demo.gif?raw=true)

## Basic Usage & Props
```tsx
import FolderTree, { testData } from 'react-folder-tree';

# To Install:
npm install --save react-folder-tree
const BasicTree = () => {
const onTreeStateChange = state => console.log('tree state: ', state);

# To Run:
return (
<FolderTree
data={ testData }
onChange={ onTreeStateChange }
/>
);
};

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
```

Remember to include the above link in your html page. Otherwise the icons won't show up.
| prop name | description | type | options |
|-------------------|-----------------------------------------|----------|------------------------------------------------|
| data | initial tree state data (required) | object | N/A |
| onChange | callback when tree state changes | function | console.log (default) |
| initCheckedStatus | initial check status of all nodes | string | 'unchecked' (default) \| 'checked' \| 'custom' |
| initOpenStatus | initial open status of all folder nodes | string | 'close' (default) \| 'open' \| 'custom' |
| iconComponents | custom icon components | object | N/A |
| indentPixels | ident pixels | number | 30 (default) |

import React from 'react';
import ReactDOM from 'react-dom';
import FolderTree from 'react-folder-tree';
## Note
After upgrading to `v4.0`, old versions are no compatible anymore, please try out new version or specify old version when installing!

const testData = YOUR DATA;

ReactDOM.render(
<FolderTree
data={testData}
/>,
document.getElementById('root')
)

# Data Format:

{
id: number,
filename: string,
children: array of *this* [optional]
}

# Sample Data:

const testData = {
"id": 1,
"filename": "All Categories",
"children": [
{
"id": 2,
"filename": "For Sale",
"children": [
{
"id": 3,
"filename": "Audio & Stereo",
"children": [
{
"id": 4,
"filename": "For Sale",
"children": [
{
"id": 5,
"filename": "Audio & Stereo",
},
{
"id": 6,
"filename": "Baby & Kids Stuff",
},
{
"id": 7,
"filename": "Music, Films, Books & Games",
}
]
},
{
"id": 8,
"filename": "Motors",
"children": [
{
"id": 9,
"filename": "Car Parts & Accessories",
},
{
"id": 10,
"filename": "Cars",
},
{
"id": 11,
"filename": "Motorbike Parts & Accessories",
}
]
},
{
"id": 12,
"filename": "Jobs",
"children": [
{
"id": 13,
"filename": "Accountancy",
},
{
"id": 14,
"filename": "Financial Services & Insurance",
},
{
"id": 15,
"filename": "Bar Staff & Management",
}
]
}
]
},
{
"id": 16,
"filename": "Baby & Kids Stuff",
},
{
"id": 17,
"filename": "Music, Films, Books & Games",
}
]
},
{
"id": 18,
"filename": "Motors",
"children": [
{
"id": 19,
"filename": "Car Parts & Accessories",
},
{
"id": 20,
"filename": "Cars",
},
{
"id": 21,
"filename": "Motorbike Parts & Accessories",
}
]
},
{
"id": 22,
"filename": "Jobs",
"children": [
{
"id": 23,
"filename": "Accountancy",
},
{
"id": 24,
"filename": "Financial Services & Insurance",
},
{
"id": 25,
"filename": "Bar Staff & Management",
}
]
}
]
}

# Resources

Testing data is from [here](http://codepen.io/anon/pen/Ftkln?editors=0010)

Icons are from [here](https://www.npmjs.com/package/react-fontawesome)

# Contribution
Any contributions are welcomed! Please upload issues or pull requests on the github page, thank you!

# TODO
- css modules of font awesome
- in editing mode the inputbox doesn't hover automatically
- press enter to confirm (now must click the confirm icon)
- fully test all funtionalities
- change structure: since now each Treenode has path, there should exist more concise way to handle check
- remove excessive dependencies
## Contributions
Welcome!
Binary file added assets/folder-tree-demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 0 additions & 36 deletions config/env.js

This file was deleted.

12 changes: 0 additions & 12 deletions config/jest/cssTransform.js

This file was deleted.

Loading