Commit 52cea54
committed
feat: add getTreeLinePrefix utility for tree connector lines
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>
);
}
```1 parent c851c6f commit 52cea54
2 files changed
Lines changed: 83 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
176 | 257 | | |
177 | 258 | | |
178 | 259 | | |
| |||
0 commit comments