A component that draws connector lines for nested lists such as file trees. This is a custom component with no Base UI primitive. Devie adds the variant prop.
Here is the component implementation code that you can copy to your project:
// https://devie-ui.com/components/tree-line
import clsx from "clsx";
import type React from "react";
import styles from "./TreeLine.module.scss";
type TreeLineVariant =
| "horizontal"
| "vertical"
| "corner-top-left"
| "corner-top-right"
| "corner-bottom-left"
| "corner-bottom-right"
| "branch-right"
| "branch-left"
| "branch-down"
| "branch-up";
function TreeLine({ variant, className, ...props }: TreeLine.Props) {
return (
<div
className={clsx(
styles.treeLine,
variant === "horizontal" && styles.variantHorizontal,
variant === "vertical" && styles.variantVertical,
variant === "corner-top-left" && styles.variantCornerTopLeft,
variant === "corner-top-right" && styles.variantCornerTopRight,
variant === "corner-bottom-left" && styles.variantCornerBottomLeft,
variant === "corner-bottom-right" && styles.variantCornerBottomRight,
variant === "branch-right" && styles.variantBranchRight,
variant === "branch-left" && styles.variantBranchLeft,
variant === "branch-down" && styles.variantBranchDown,
variant === "branch-up" && styles.variantBranchUp,
className,
)}
{...props}
/>
);
}
namespace TreeLine {
export type Variant = TreeLineVariant;
export interface Props extends React.ComponentProps<"div"> {
variant: Variant;
}
}
export default TreeLine;Build each row from TreeLine cells: vertical continues a parent line, branch-right connects an item, and corner-bottom-left ends the last one.
Set variant to horizontal or vertical for a straight line, or to a corner: corner-top-left, corner-top-right, corner-bottom-left, or corner-bottom-right. For a branch, use branch-right, branch-left, branch-down, or branch-up.