-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add examples dropdown also in code editor panel #50
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ import { | |
CheckIcon, | ||
ChevronDownIcon, | ||
CopyIcon, | ||
ExternalLinkIcon, | ||
FileJsonIcon, | ||
NotebookPenIcon, | ||
PlusIcon, | ||
UsersIcon, | ||
ZapIcon, | ||
} from "lucide-react"; | ||
|
@@ -22,6 +25,7 @@ import { useEditor } from "@/client/contexts/editor"; | |
import { useTheme } from "@/client/contexts/theme"; | ||
import { Users } from "@/client/editor/Users"; | ||
import { type SnippetFunc, snippets } from "@/client/snippets"; | ||
import { examples } from "@/examples"; | ||
import type { ParameterWithSource } from "@/gen/types"; | ||
import type { User } from "@/user"; | ||
import { cn } from "@/utils/cn"; | ||
|
@@ -89,31 +93,63 @@ export const Editor: FC<EditorProps> = ({ | |
<Tabs.Trigger icon={UsersIcon} label="Users" value="users" /> | ||
</div> | ||
|
||
<DropdownMenu> | ||
<DropdownMenuTrigger className="flex w-fit min-w-[140px] cursor-pointer items-center justify-between rounded-md border bg-surface-primary px-2 py-1.5 text-content-secondary transition-colors hover:text-content-primary data-[state=open]:text-content-primary"> | ||
<div className="flex items-center justify-center gap-2"> | ||
<ZapIcon width={18} height={18} /> | ||
<p className="text-xs">Snippets</p> | ||
</div> | ||
<ChevronDownIcon width={18} height={18} /> | ||
</DropdownMenuTrigger> | ||
|
||
<DropdownMenuPortal> | ||
<DropdownMenuContent align="start"> | ||
{snippets.map( | ||
({ name, label, icon: Icon, snippet }, index) => ( | ||
<DropdownMenuItem | ||
key={index} | ||
onClick={() => onAddSnippet(name, snippet)} | ||
> | ||
<Icon size={24} /> | ||
{label} | ||
</DropdownMenuItem> | ||
), | ||
)} | ||
</DropdownMenuContent> | ||
</DropdownMenuPortal> | ||
</DropdownMenu> | ||
<div className="flex items-center gap-2"> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger className="flex w-fit min-w-[140px] cursor-pointer items-center justify-between rounded-md border bg-surface-primary px-2 py-1.5 text-content-secondary transition-colors hover:text-content-primary data-[state=open]:text-content-primary"> | ||
<div className="flex items-center justify-center gap-2"> | ||
<ZapIcon width={18} height={18} /> | ||
<p className="text-xs">Snippets</p> | ||
</div> | ||
<PlusIcon width={18} height={18} /> | ||
</DropdownMenuTrigger> | ||
|
||
<DropdownMenuPortal> | ||
<DropdownMenuContent align="start"> | ||
{snippets.map( | ||
({ name, label, icon: Icon, snippet }, index) => ( | ||
<DropdownMenuItem | ||
key={index} | ||
Comment on lines
+109
to
+111
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a guarantee that each snippet will be unique? In that case, I think we should get rid of the |
||
onClick={() => onAddSnippet(name, snippet)} | ||
> | ||
<Icon size={24} /> | ||
{label} | ||
</DropdownMenuItem> | ||
), | ||
)} | ||
</DropdownMenuContent> | ||
</DropdownMenuPortal> | ||
</DropdownMenu> | ||
|
||
<DropdownMenu> | ||
<DropdownMenuTrigger className="flex w-fit min-w-[140px] cursor-pointer items-center justify-between rounded-md border bg-surface-primary px-2 py-1.5 text-content-secondary transition-colors hover:text-content-primary data-[state=open]:text-content-primary"> | ||
<div className="flex items-center justify-center gap-2"> | ||
<NotebookPenIcon width={18} height={18} /> | ||
<p className="text-xs">Examples</p> | ||
</div> | ||
<ChevronDownIcon width={18} height={18} /> | ||
</DropdownMenuTrigger> | ||
Comment on lines
+124
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same feedback for the trigger above applies here |
||
|
||
<DropdownMenuPortal> | ||
<DropdownMenuContent> | ||
{Object.entries(examples).map(([slug, title]) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Realistically this isn't a huge deal, but I think that even now, the JS spec doesn't guarantee that What this means is that without a |
||
const href = `${window.location.origin}/parameters/example/${slug}`; | ||
return ( | ||
<DropdownMenuItem key={slug} asChild={true}> | ||
<a href={href} target="_blank" rel="noreferrer"> | ||
<span className="sr-only"> | ||
{" "} | ||
(link opens in new tab) | ||
</span> | ||
<ExternalLinkIcon /> | ||
{title} | ||
</a> | ||
</DropdownMenuItem> | ||
); | ||
})} | ||
</DropdownMenuContent> | ||
</DropdownMenuPortal> | ||
</DropdownMenu> | ||
</div> | ||
</div> | ||
</Tabs.List> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to say that the default output for a Radix trigger is a
button
element, so putting two elements that are semantically block-based (div
andp
) inside it is going to make the HTML invalidTwo things come to mind:
div
and move the classes to the triggerp
for aspan
asChild
to merge the trigger into first immediate child. But even then, you'd want to swap thediv
for abutton