style(file-tree): Reformat JSX and fix class name

This commit is contained in:
hyper 2026-06-30 20:26:11 +08:00
parent 53c8ce0677
commit 9794184e98
1 changed files with 16 additions and 9 deletions

View File

@ -7,7 +7,7 @@ import { useNavigate } from "@solidjs/router";
*/ */
function isPathInDir(currentPath: string, dirPath: string): boolean { function isPathInDir(currentPath: string, dirPath: string): boolean {
// 确保 dirPath 以 / 结尾,用于前缀匹配 // 确保 dirPath 以 / 结尾,用于前缀匹配
const dirPathPrefix = dirPath.endsWith('/') ? dirPath : dirPath + '/'; const dirPathPrefix = dirPath.endsWith("/") ? dirPath : dirPath + "/";
return currentPath.startsWith(dirPathPrefix); return currentPath.startsWith(dirPathPrefix);
} }
@ -25,7 +25,9 @@ export const FileTreeNode: Component<{
const isDir = !!props.node.children; const isDir = !!props.node.children;
const isActive = createMemo(() => props.currentPath === props.node.path); const isActive = createMemo(() => props.currentPath === props.node.path);
// 默认收起,除非当前文件在该文件夹内 // 默认收起,除非当前文件在该文件夹内
const [isExpanded, setIsExpanded] = createSignal(isDir && isPathInDir(props.currentPath, props.node.path)); const [isExpanded, setIsExpanded] = createSignal(
isDir && isPathInDir(props.currentPath, props.node.path),
);
const handleClick = () => { const handleClick = () => {
if (isDir) { if (isDir) {
@ -112,11 +114,16 @@ export const HeadingNode: Component<{
return ( return (
<div> <div>
<div class="flex flex-row"> <div class="flex flex-row">
<span class={`cursor-pointer mr-1 text-gray-400 text-xs w-3 flex-shrink-0`} <span
class={`cursor-pointer mr-1 text-gray-400 text-xs w-3 shrink-0`}
style={{ "margin-left": `${indent + 8}px` }} style={{ "margin-left": `${indent + 8}px` }}
onClick={handleExpand} onClick={handleExpand}
> >
<span class={`${hasChildren ? "" : "invisible" } ${isExpanded() ? "rotate-90" : ""} mt-1 inline-block transition-transform `}></span> <span
class={`${hasChildren ? "" : "invisible"} ${isExpanded() ? "rotate-90" : ""} mt-1 inline-block transition-transform `}
>
</span>
</span> </span>
<a <a
href={href} href={href}