Skip to content

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

Merged
merged 2 commits into from
Jul 31, 2025

Conversation

brettkolodny
Copy link
Collaborator

Copy link

vercel bot commented Jul 31, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 31, 2025 8:33pm

Copy link
Member

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a few bits of feedback, but nothing worth blocking over

</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">
Copy link
Member

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 and p) inside it is going to make the HTML invalid

Two things come to mind:

  1. We might be able to switch the markup around. So:
    1. Get rid of the div and move the classes to the trigger
    2. Swap the p for a span
  2. I don't know how if there are any edge cases, but you might be able to use asChild to merge the trigger into first immediate child. But even then, you'd want to swap the div for a button

Comment on lines +109 to +111
({ name, label, icon: Icon, snippet }, index) => (
<DropdownMenuItem
key={index}
Copy link
Member

@Parkreiner Parkreiner Jul 31, 2025

Choose a reason for hiding this comment

The 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 index, and use some combination of the name and label as the render key. If neither are guaranteed to be fully unique on their own, we could also concatenate them to make a compound key

Comment on lines +124 to +130
<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>
Copy link
Member

Choose a reason for hiding this comment

The 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]) => {
Copy link
Member

@Parkreiner Parkreiner Jul 31, 2025

Choose a reason for hiding this comment

The 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 Object.entries makes an array in a deterministic order. The v8 engine does, but I don't know about other engines (I would expect them to follow v8's lead, though)

What this means is that without a .sort call, there's a risk that the elements could get scrambled up during re-renders. The stable keys will mean that the state won't get mixed up, but there's a risk the list item order will

@brettkolodny brettkolodny merged commit acde4ee into main Jul 31, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Playground: move examples closer to the editor
2 participants