feat: add getTreeLinePrefix utility for tree connector line#324
Open
rayshoo wants to merge 1 commit intobrimdata:mainfrom
Open
feat: add getTreeLinePrefix utility for tree connector line#324rayshoo wants to merge 1 commit intobrimdata:mainfrom
rayshoo wants to merge 1 commit intobrimdata:mainfrom
Conversation
Add a utility function that generates tree-line prefix strings
(├, └, │) for nodes, similar to the Unix `tree` command output.
This enables users to render visual tree connectors in their
custom node renderers without implementing the parent-traversal
logic themselves.
Features:
- Generates correct connector lines by traversing ancestor nodes
- Customizable characters via TreeLineChars option
- Works with any tree depth
- Exported from package root for easy access
Styling note:
The prefix uses Box Drawing characters which require a monospace
font for correct alignment. Wrap the prefix in a <span> with
fontFamily: "monospace" and use a consistent fontSize (e.g. 14-16px).
Inherited line-height or font-size from parent elements can cause
misalignment.
Usage:
```tsx
import { getTreeLinePrefix } from "react-arborist";
function MyNode({ node, style }) {
const icon = node.isLeaf ? "📄" : node.isOpen ? "📂" : "📁";
return (
<div style={style}>
<span style={{ fontFamily: "monospace", fontSize: 16 }}>
{getTreeLinePrefix(node)}
</span>
{icon} {node.data.name}
</div>
);
}
```
4e6e473 to
52cea54
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a
getTreeLinePrefix()utility function that generates tree connector line prefixes (├,└,│) for nodes, similar to the Unixtreecommand output.Currently, react-arborist does not provide a built-in way to render tree connector lines. Users have to implement the parent-traversal logic themselves in custom node renderers. This utility solves that.
Features
TreeLineCharsoptionUsage