Skip to content

Commit 3f2eb81

Browse files
committed
feat: renderTree add options listClassName, listInnerClassName
1 parent 0489b89 commit 3f2eb81

4 files changed

Lines changed: 4116 additions & 3085 deletions

File tree

docs/v1/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ The main function of this library. React hook. The arguments are as follows:
6666
The return of `useHeTree` is an object, including some states and methods. **Note**, this object will change every time. Do not rely on this object, but you can rely on the properties of this object. The properties are as follows:
6767
| Name | Type | Description |
6868
| ------------------------- | ------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------|
69-
|renderTree<a id="rendertree"/>|`(options?: { className?: string, style?: React.CSSProperties }): ReactNode`|Tree render. Options can be passed in `className` and `style` to control the style of the root element.|
69+
|renderTree<a id="rendertree"/>|`(options?: { className?: string, style?: React.CSSProperties, listClassName?: string, listInnerClassName?: string }): ReactNode`|Tree render. Options can be passed in `className` and `style` to control the style of the root element. `listClassName` is for virtual list root element, `listInnerClassName` is for virtual list inner element.|
7070
|getStat<a id="getstat"/>|`(idOrNodeOrStat)=>stat`|Get stat by id, or node data, or stat object.|
7171
|allIds<a id="allids"/>|Array|The ids of all nodes.|
7272
|rootIds<a id="rootids"/>|Array|The ids of all root nodes|

lib/HeTree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ export function useHeTree<T extends Record<string, any>>(
658658
const { visibleIds, attrsList, onDragOverRoot, onDropToRoot, onDragEndOnRoot, scrollToNode } = cacheForVisible
659659
const persistentIndices = useMemo(() => draggingStat ? [visibleIds.indexOf(draggingStat.id)] : [], [draggingStat, visibleIds]);
660660
// render
661-
const renderTree = (options?: { className?: string, style?: React.CSSProperties }): ReactNode => {
661+
const renderTree = (options?: { className?: string, style?: React.CSSProperties, listClassName?: string, listInnerClassName?: string }): ReactNode => {
662662
let renderNodeBox = props.renderNodeBox!
663663
if (!renderNodeBox) {
664664
const placeholder = <div className="he-tree-drag-placeholder" style={{ minHeight: '20px', border: '1px dashed blue' }}></div>
@@ -668,7 +668,7 @@ export function useHeTree<T extends Record<string, any>>(
668668
}
669669
return (
670670
<div className={`he-tree ${options?.className || ''}`} style={options?.style} ref={rootRef} onDragOver={onDragOverRoot} onDrop={onDropToRoot} onDragEnd={onDragEndOnRoot}>
671-
<VirtualList<Id> ref={virtualListRef} items={visibleIds} virtual={props.virtual} persistentIndices={persistentIndices} style={{ height: '100%' }}
671+
<VirtualList<Id> ref={virtualListRef} className={options?.listClassName || ''} innerClassName={options?.listInnerClassName || ''} items={visibleIds} virtual={props.virtual} persistentIndices={persistentIndices} style={{ height: '100%' }}
672672
renderItem={(id, index) => renderNodeBox({
673673
stat: getStat(id)!, attrs: attrsList[index], isPlaceholder: id === placeholderId
674674
})}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "he-tree-react",
3-
"version": "1.1.4",
3+
"version": "1.2.0",
44
"license": "MIT",
55
"author": "phphe <phphe@outlook.com> (https://github.com/phphe)",
66
"description": "React draggable sortable tree component.",
@@ -41,7 +41,7 @@
4141
},
4242
"dependencies": {
4343
"helper-js": "^3.1.5",
44-
"react-base-virtual-list": "^1.0.0"
44+
"react-base-virtual-list": "^1.1.0"
4545
},
4646
"peerDependencies": {
4747
"react": "^18",
@@ -85,4 +85,4 @@
8585
]
8686
}
8787
}
88-
}
88+
}

0 commit comments

Comments
 (0)