Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: move accordion to one level #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions src/components/scope/scope-item.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Scope, Variable, Reference } from "eslint-scope";
import { TreeEntry } from "../tree-entry";
import type { FC } from "react";
import {
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/components/ui/accordion";
import { TreeEntry } from "../tree-entry";
import type { FC } from "react";
} from "../ui/accordion";

type ScopeItemProperties = {
isArray: boolean;
Expand Down Expand Up @@ -41,25 +41,48 @@ export const ScopeItem: FC<ScopeItemProperties> = ({
([name]) => !name.startsWith("__"),
);

if (path.length === 1) {
return (
<AccordionItem
value={path + "." + index + "." + key}
className="border border-card rounded-lg overflow-hidden"
>
<AccordionTrigger className="text-sm bg-card px-4 py-3 capitalize">
{isArray && `${Math.max(index, 0)}.`} {key}
</AccordionTrigger>
<AccordionContent className="p-4 border-t">
<div className="space-y-1">
{properties.map((item, index) => (
<TreeEntry
key={item[0]}
data={item}
path={path + "." + index}
/>
))}
</div>
</AccordionContent>
</AccordionItem>
);
}

return (
<AccordionItem
value={path + "." + index + "." + key}
className="border border-card rounded-lg overflow-hidden"
>
<AccordionTrigger className="text-sm bg-card px-4 py-3 capitalize">
<div className="border border-card rounded-lg overflow-hidden">
<button className="flex items-center font-medium text-sm bg-card px-4 py-3 capitalize w-full">
{isArray && `${Math.max(index, 0)}.`} {key}
</AccordionTrigger>
<AccordionContent className="p-4 border-t">
<div className="space-y-1">
{properties.map((item, index) => (
<TreeEntry
key={item[0]}
data={item}
path={path + "." + index}
/>
))}
</button>
<div className="overflow-hidden text-sm">
<div className="p-4 border-t">
<div className="space-y-1">
{properties.map((item, index) => (
<TreeEntry
key={item[0]}
data={item}
path={path + "." + index}
/>
))}
</div>
</div>
</AccordionContent>
</AccordionItem>
</div>
</div>
);
};