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 {
// 确保 dirPath 以 / 结尾,用于前缀匹配
const dirPathPrefix = dirPath.endsWith('/') ? dirPath : dirPath + '/';
const dirPathPrefix = dirPath.endsWith("/") ? dirPath : dirPath + "/";
return currentPath.startsWith(dirPathPrefix);
}
@ -25,7 +25,9 @@ export const FileTreeNode: Component<{
const isDir = !!props.node.children;
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 = () => {
if (isDir) {
@ -112,16 +114,21 @@ export const HeadingNode: Component<{
return (
<div>
<div class="flex flex-row">
<span class={`cursor-pointer mr-1 text-gray-400 text-xs w-3 flex-shrink-0`}
style={{ "margin-left": `${indent + 8}px` }}
onClick={handleExpand}
<span
class={`cursor-pointer mr-1 text-gray-400 text-xs w-3 shrink-0`}
style={{ "margin-left": `${indent + 8}px` }}
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>
<a
href={href}
class="inline-flex items-center py-0.5 px-2 text-sm text-gray-600 hover:text-gray-900 hover:bg-gray-50 rounded truncate cursor-pointer"
onClick={handleClick}
href={href}
class="inline-flex items-center py-0.5 px-2 text-sm text-gray-600 hover:text-gray-900 hover:bg-gray-50 rounded truncate cursor-pointer"
onClick={handleClick}
>
{props.node.title}
</a>