Skip to content

Commit b46ad36

Browse files
authored
Update snippets panel to use responsive layout based on panel context (#7755)
Uses our `usePanelOrientation` hook to automatically switch between vertical/horizontal layouts, matching the scratchpad behavior. The snippet contents were hidden by default otherwise.
1 parent 49aa79b commit b46ad36

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

frontend/src/components/editor/chrome/panels/snippets-panel.tsx

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { CommandList } from "cmdk";
44
import { BetweenHorizontalStartIcon, PlusIcon, XIcon } from "lucide-react";
55
import React from "react";
6+
import { Panel, PanelGroup, PanelResizeHandle } from "react-resizable-panels";
67
import {
78
Command,
89
CommandEmpty,
@@ -29,12 +30,15 @@ import { useTheme } from "@/theme/useTheme";
2930
import { cn } from "@/utils/cn";
3031
import { HideInKioskMode } from "../../kiosk-mode";
3132
import { ContributeSnippetButton } from "../components/contribute-snippet-button";
33+
import { usePanelOrientation, usePanelSection } from "./panel-context";
3234

3335
const extensions = [EditorView.lineWrapping];
3436

3537
const SnippetsPanel: React.FC = () => {
3638
const { readSnippets } = useRequestClient();
3739
const [selectedSnippet, setSelectedSnippet] = React.useState<Snippet>();
40+
const orientation = usePanelOrientation();
41+
const section = usePanelSection();
3842
const {
3943
data: snippets,
4044
error,
@@ -51,49 +55,60 @@ const SnippetsPanel: React.FC = () => {
5155
return <Spinner size="medium" centered={true} />;
5256
}
5357

58+
const isVertical = orientation === "vertical";
59+
5460
return (
55-
<div className="flex-1 overflow-hidden">
56-
<Command
57-
className={cn(
58-
"border-b rounded-none",
59-
selectedSnippet ? "h-1/3" : "h-full",
60-
)}
61-
>
62-
<div className="flex items-center w-full">
63-
<CommandInput
64-
placeholder="Search snippets..."
65-
className="h-6 m-1"
66-
rootClassName="flex-1 border-r"
67-
/>
68-
<ContributeSnippetButton>
69-
<button className="float-right border-b px-2 m-0 h-full hover:bg-accent hover:text-accent-foreground">
70-
<PlusIcon className="h-4 w-4" />
71-
</button>
72-
</ContributeSnippetButton>
73-
</div>
61+
<div className="flex-1 overflow-hidden h-full">
62+
<PanelGroup key={section} direction={orientation} className="h-full">
63+
{/* Snippet list panel */}
64+
<Panel defaultSize={40} minSize={20} maxSize={70}>
65+
<Command className="h-full rounded-none">
66+
<div className="flex items-center w-full border-b">
67+
<CommandInput
68+
placeholder="Search snippets..."
69+
className="h-6 m-1"
70+
rootClassName="flex-1 border-r"
71+
/>
72+
<ContributeSnippetButton>
73+
<button className="float-right px-2 m-0 h-full hover:bg-accent hover:text-accent-foreground">
74+
<PlusIcon className="h-4 w-4" />
75+
</button>
76+
</ContributeSnippetButton>
77+
</div>
7478

75-
<CommandEmpty>No results</CommandEmpty>
76-
<SnippetList
77-
onSelect={(snippet) => setSelectedSnippet(snippet)}
78-
snippets={snippets.snippets}
79-
/>
80-
</Command>
81-
<Suspense>
82-
<div className="h-2/3 snippet-viewer flex flex-col">
83-
{selectedSnippet ? (
84-
<SnippetViewer
85-
key={selectedSnippet.title}
86-
snippet={selectedSnippet}
87-
onClose={() => setSelectedSnippet(undefined)}
88-
/>
89-
) : (
90-
<PanelEmptyState
91-
title=""
92-
description="Click on a snippet to view its content."
79+
<CommandEmpty>No results</CommandEmpty>
80+
<SnippetList
81+
onSelect={(snippet) => setSelectedSnippet(snippet)}
82+
snippets={snippets.snippets}
9383
/>
84+
</Command>
85+
</Panel>
86+
<PanelResizeHandle
87+
className={cn(
88+
"bg-border hover:bg-primary/50 transition-colors",
89+
isVertical ? "h-1" : "w-1",
9490
)}
95-
</div>
96-
</Suspense>
91+
/>
92+
{/* Snippet viewer panel */}
93+
<Panel defaultSize={60} minSize={20}>
94+
<Suspense>
95+
<div className="h-full snippet-viewer flex flex-col overflow-hidden">
96+
{selectedSnippet ? (
97+
<SnippetViewer
98+
key={selectedSnippet.title}
99+
snippet={selectedSnippet}
100+
onClose={() => setSelectedSnippet(undefined)}
101+
/>
102+
) : (
103+
<PanelEmptyState
104+
title=""
105+
description="Click on a snippet to view its content."
106+
/>
107+
)}
108+
</div>
109+
</Suspense>
110+
</Panel>
111+
</PanelGroup>
97112
</div>
98113
);
99114
};

0 commit comments

Comments
 (0)