Skip to content

Commit 19536b4

Browse files
committed
added option to hide checkbox
1 parent bd8dc3c commit 19536b4

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ const BasicTree = () => {
3434

3535
```
3636

37-
| prop name | description | type | options |
37+
| prop | description | type | options |
3838
|-------------------|-----------------------------------------|----------|------------------------------------------------|
3939
| data | initial tree state data (required) | object | N/A |
4040
| onChange | callback when tree state changes | function | console.log (default) |
4141
| initCheckedStatus | initial check status of all nodes | string | 'unchecked' (default) \| 'checked' \| 'custom' |
42-
| initOpenStatus | initial open status of all folder nodes | string | 'open' (default) \| 'close' \| 'custom' |
42+
| initOpenStatus | initial open status of all treenodes | string | 'open' (default) \| 'close' \| 'custom' |
4343
| iconComponents | custom icon components | object | N/A |
44-
| indentPixels | ident pixels | number | 30 (default) |
44+
| indentPixels | ident pixels of 1x level treenode | number | 30 (default) |
45+
| showCheckbox | show check box? | bool | true (default) | false |
4546

4647
## Note
4748
After upgrading to `v4.0`, old versions are no compatible anymore, please try out new version or specify old version when installing!

src/components/FolderTree/FolderTree.jsx

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
addNode,
1818
} from '../../utils/utils';
1919
import TreeNode from '../TreeNode/TreeNode';
20-
import UtilsContext from './context';
20+
import ConfigContext from './context';
2121
import { testData } from '../../utils/testData';
2222

2323
import './FolderTree.scss';
@@ -28,6 +28,7 @@ const FolderTree = ({
2828
initCheckedStatus = 'unchecked',
2929
initOpenStatus = 'open',
3030
iconComponents = {},
31+
showCheckbox = true,
3132
indentPixels = 30,
3233
}) => {
3334
const [treeState, setTreeState] = useState(null);
@@ -109,18 +110,26 @@ const FolderTree = ({
109110
isOpen,
110111
} = treeState;
111112

113+
const configs = {
114+
handleCheck,
115+
handleRename,
116+
handleDelete,
117+
handleAddNode,
118+
handleToggleOpen,
119+
120+
iconComponents,
121+
indentPixels,
122+
showCheckbox,
123+
};
124+
125+
/* ----------
126+
- custom configs are passed down in context, which is same for each tree node
127+
- tree node specific data is passed recursively to each node, which is different for each node
128+
---------- */
112129
return (
113130
<div className='FolderTree'>
114-
<UtilsContext.Provider
115-
value={{
116-
handleCheck,
117-
handleRename,
118-
handleDelete,
119-
handleAddNode,
120-
handleToggleOpen,
121-
iconComponents,
122-
indentPixels,
123-
}}
131+
<ConfigContext.Provider
132+
value={ configs }
124133
>
125134
<TreeNode
126135
path={ [] }
@@ -130,7 +139,7 @@ const FolderTree = ({
130139
childrenData={ children }
131140
handleCheck={ handleCheck }
132141
/>
133-
</UtilsContext.Provider>
142+
</ConfigContext.Provider>
134143
</div>
135144
);
136145
};
@@ -154,6 +163,7 @@ FolderTree.propTypes = {
154163
CaretDownIcon: PropTypes.func,
155164
}),
156165
indentPixels: PropTypes.number,
166+
showCheckbox: PropTypes.bool,
157167
};
158168

159169
export { testData };

src/components/SandBox/SandBox.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const SandBox = () => {
99
<FolderTree
1010
data={ testData }
1111
onChange={ onTreeStateChange }
12+
showCheckbox={ false }
1213
/>
1314
</div>
1415
);

src/components/TreeNode/TreeNode.jsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from 'react-icons/ai';
1919

2020
import CheckBox from '../CheckBox/CheckBox';
21-
import UtilsContext from '../FolderTree/context';
21+
import ConfigContext from '../FolderTree/context';
2222
import EditableName from '../EditableName/EditableName';
2323
import {
2424
iconContainerClassName,
@@ -40,7 +40,8 @@ const TreeNode = ({
4040
handleToggleOpen,
4141
iconComponents,
4242
indentPixels,
43-
} = useContext(UtilsContext);
43+
showCheckbox,
44+
} = useContext(ConfigContext);
4445

4546
const isFolder = !!childrenData;
4647

@@ -171,10 +172,12 @@ const TreeNode = ({
171172
return (
172173
<>
173174
<div className='TreeNode' style={ treeNodeStyle }>
174-
<CheckBox
175-
status={ checked }
176-
onChange={ handleCheckBoxChange }
177-
/>
175+
{ showCheckbox && (
176+
<CheckBox
177+
status={ checked }
178+
onChange={ handleCheckBoxChange }
179+
/>
180+
)}
178181

179182
{ isFolder && folderCaret }
180183

0 commit comments

Comments
 (0)