style(file-tree): Reformat JSX and fix class name
This commit is contained in:
parent
53c8ce0677
commit
9794184e98
|
|
@ -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,16 +114,21 @@ 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
|
||||||
style={{ "margin-left": `${indent + 8}px` }}
|
class={`cursor-pointer mr-1 text-gray-400 text-xs w-3 shrink-0`}
|
||||||
onClick={handleExpand}
|
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>
|
</span>
|
||||||
<a
|
<a
|
||||||
href={href}
|
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"
|
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}
|
onClick={handleClick}
|
||||||
>
|
>
|
||||||
{props.node.title}
|
{props.node.title}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue