MCPcopy Create free account
hub / github.com/anomalyco/opencode / FileTreeNode

Function FileTreeNode

packages/app/src/components/file-tree.tsx:110–191  ·  view source on GitHub ↗
(
  p: ParentProps &
    ComponentProps<"div"> &
    ComponentProps<"button"> & {
      node: FileNode
      level: number
      active?: string
      nodeClass?: string
      draggable: boolean
      kinds?: ReadonlyMap<string, Kind>
      marks?: Set<string>
      as?: "div" | "button"
    },
)

Source from the content-addressed store, hash-verified

108}
109
110const FileTreeNode = (
111 p: ParentProps &
112 ComponentProps<"div"> &
113 ComponentProps<"button"> & {
114 node: FileNode
115 level: number
116 active?: string
117 nodeClass?: string
118 draggable: boolean
119 kinds?: ReadonlyMap<string, Kind>
120 marks?: Set<string>
121 as?: "div" | "button"
122 },
123) => {
124 const [local, rest] = splitProps(p, [
125 "node",
126 "level",
127 "active",
128 "nodeClass",
129 "draggable",
130 "kinds",
131 "marks",
132 "as",
133 "children",
134 "class",
135 "classList",
136 ])
137 const kind = () => visibleKind(local.node, local.kinds, local.marks)
138 const active = () => !!kind() && !local.node.ignored
139 const color = () => {
140 const value = kind()
141 if (!value) return
142 return kindTextColor(value)
143 }
144
145 return (
146 <Dynamic
147 component={local.as ?? "div"}
148 classList={{
149 "w-full min-w-0 h-6 flex items-center justify-start gap-x-1.5 rounded-md px-1.5 py-0 text-left hover:bg-surface-raised-base-hover active:bg-surface-base-active transition-colors cursor-pointer": true,
150 "bg-surface-base-active": local.node.path === local.active,
151 ...local.classList,
152 [local.class ?? ""]: !!local.class,
153 [local.nodeClass ?? ""]: !!local.nodeClass,
154 }}
155 style={`padding-left: ${Math.max(0, 8 + local.level * 12 - (local.node.type === "file" ? 24 : 4))}px`}
156 draggable={local.draggable}
157 onDragStart={(event: DragEvent) => {
158 if (!local.draggable) return
159 event.dataTransfer?.setData("text/plain", `file:${local.node.path}`)
160 event.dataTransfer?.setData("text/uri-list", pathToFileUrl(local.node.path))
161 if (event.dataTransfer) event.dataTransfer.effectAllowed = "copy"
162 withFileDragImage(event)
163 }}
164 {...rest}
165 >
166 {local.children}
167 <span

Callers

nothing calls this directly

Calls 8

pathToFileUrlFunction · 0.85
withFileDragImageFunction · 0.85
kindTextColorFunction · 0.85
kindDotColorFunction · 0.85
activeFunction · 0.70
colorFunction · 0.70
kindFunction · 0.70
kindLabelFunction · 0.70

Tested by

no test coverage detected