Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(library): move Open in v0 into the page header (#50371)

Saxon Fletcher3253595fe471
diff --git a/apps/ui-library/app/(app)/docs/[[...slug]]/page.tsx b/apps/ui-library/app/(app)/docs/[[...slug]]/page.tsx
index 0d61133aa5d..60489518fce 100644
--- a/apps/ui-library/app/(app)/docs/[[...slug]]/page.tsx
+++ b/apps/ui-library/app/(app)/docs/[[...slug]]/page.tsx
@@ -11,6 +11,7 @@ import { allDocs } from '@/.velite'
import { metadata as mainMetadata } from '@/app/layout'
import { FrameworkSelector } from '@/components/framework-selector'
import { Mdx } from '@/components/mdx-components'
+import { OpenInV0Button } from '@/components/open-in-v0-button'
import { SourcePanel } from '@/components/source-panel'
import { DashboardTableOfContents } from '@/components/toc'
import { getTableOfContents } from '@/lib/toc'
@@ -96,7 +97,10 @@ export default async function DocPage(props: DocPageProps) {
</p>
)}
</div>
- <FrameworkSelector />
+ <div className="flex items-center gap-2">
+ <FrameworkSelector />
+ {doc.v0Name && <OpenInV0Button name={doc.v0Name} />}
+ </div>
</div>
<SourcePanel doc={doc} />
<div className="pb-12">
diff --git a/apps/ui-library/components/block-item.tsx b/apps/ui-library/components/block-item.tsx
index 058438feef6..7cf1561e483 100644
--- a/apps/ui-library/components/block-item.tsx
+++ b/apps/ui-library/components/block-item.tsx
@@ -2,7 +2,6 @@
import dynamic from 'next/dynamic'
-import { OpenInV0Button } from '@/components/open-in-v0-button'
import type { ShadcnFramework } from '@/lib/install-command'
//The dynamic import is to prevent the command component from being rendered on the server and cause hydration errors
@@ -10,15 +9,13 @@ const Command = dynamic(() => import('./command').then((mod) => mod.Command), {
interface BlockItemProps {
name: string
- showOpenInV0?: boolean
framework?: ShadcnFramework
}
-export const BlockItem = ({ name, showOpenInV0 = true, framework = 'react' }: BlockItemProps) => {
+export const BlockItem = ({ name, framework = 'react' }: BlockItemProps) => {
return (
<div className="mt-4">
<Command name={name} highlight framework={framework} />
- {showOpenInV0 && <OpenInV0Button name={name} className="w-fit shrink-0 mt-4" />}
</div>
)
}
diff --git a/apps/ui-library/components/open-in-v0-button.tsx b/apps/ui-library/components/open-in-v0-button.tsx
index a9d6f439145..d7fe6a4db46 100644
--- a/apps/ui-library/components/open-in-v0-button.tsx
+++ b/apps/ui-library/components/open-in-v0-button.tsx
@@ -1,42 +1,37 @@
-import { Button_Shadcn_ } from 'ui'
+import { Button } from 'ui'
import { cn } from '@/lib/utils'
-export function OpenInV0Button({
- name,
- className,
-}: { name: string } & React.ComponentProps<typeof Button_Shadcn_>) {
+function V0Logo() {
return (
- <Button_Shadcn_
- aria-label="Open in v0"
- className={cn(
- 'h-7 gap-1 rounded-lg shadow-none bg-black px-3 text-xs text-white hover:bg-black hover:text-white dark:bg-white dark:text-black',
- className
- )}
+ <svg viewBox="0 0 40 20" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
+ <path
+ d="M23.3919 0H32.9188C36.7819 0 39.9136 3.13165 39.9136 6.99475V16.0805H36.0006V6.99475C36.0006 6.90167 35.9969 6.80925 35.9898 6.71766L26.4628 16.079C26.4949 16.08 26.5272 16.0805 26.5595 16.0805H36.0006V19.7762H26.5595C22.6964 19.7762 19.4788 16.6139 19.4788 12.7508V3.68923H23.3919V12.7508C23.3919 12.9253 23.4054 13.0977 23.4316 13.2668L33.1682 3.6995C33.0861 3.6927 33.003 3.68923 32.9188 3.68923H23.3919V0Z"
+ fill="currentColor"
+ />
+ <path
+ d="M13.7688 19.0956L0 3.68759H5.53933L13.6231 12.7337V3.68759H17.7535V17.5746C17.7535 19.6705 15.1654 20.6584 13.7688 19.0956Z"
+ fill="currentColor"
+ />
+ </svg>
+ )
+}
+
+export function OpenInV0Button({ name, className }: { name: string; className?: string }) {
+ return (
+ <Button
asChild
+ variant="default"
+ size="medium"
+ className={cn('w-[38px] rounded-full px-0', className)}
+ icon={<V0Logo />}
>
<a
href={`https://v0.dev/chat/api/open?url=https://supabase.com${process.env.NEXT_PUBLIC_BASE_PATH ?? ''}/r/${name}.json`}
target="_blank"
rel="noreferrer"
- >
- Open in{' '}
- <svg
- viewBox="0 0 40 20"
- fill="none"
- xmlns="http://www.w3.org/2000/svg"
- className="h-5 w-5 text-current"
- >
- <path
- d="M23.3919 0H32.9188C36.7819 0 39.9136 3.13165 39.9136 6.99475V16.0805H36.0006V6.99475C36.0006 6.90167 35.9969 6.80925 35.9898 6.71766L26.4628 16.079C26.4949 16.08 26.5272 16.0805 26.5595 16.0805H36.0006V19.7762H26.5595C22.6964 19.7762 19.4788 16.6139 19.4788 12.7508V3.68923H23.3919V12.7508C23.3919 12.9253 23.4054 13.0977 23.4316 13.2668L33.1682 3.6995C33.0861 3.6927 33.003 3.68923 32.9188 3.68923H23.3919V0Z"
- fill="currentColor"
- ></path>
- <path
- d="M13.7688 19.0956L0 3.68759H5.53933L13.6231 12.7337V3.68759H17.7535V17.5746C17.7535 19.6705 15.1654 20.6584 13.7688 19.0956Z"
- fill="currentColor"
- ></path>
- </svg>
- </a>
- </Button_Shadcn_>
+ aria-label="Open in v0"
+ />
+ </Button>
)
}
diff --git a/apps/ui-library/velite.config.js b/apps/ui-library/velite.config.js
index 0cc7e05fcc6..865215ba61a 100644
--- a/apps/ui-library/velite.config.js
+++ b/apps/ui-library/velite.config.js
@@ -21,6 +21,18 @@ const NestedProperties = s.object({
reactAccessibleTreeview: s.boolean().optional(),
})
+// The MDX is the only reliable source for which registry item v0 can open: doc
+// slugs don't map onto registry names, and pages that install a client first
+// list it as an extra BlockItem that opts out. Take the first item still opted in.
+const getV0RegistryName = (raw) => {
+ for (const [, attributes] of raw.matchAll(/<BlockItem\b([^>]*?)\/?>/g)) {
+ if (/showOpenInV0=\{false\}/.test(attributes)) continue
+ const name = attributes.match(/name="([^"]+)"/)
+ if (name) return name[1]
+ }
+ return undefined
+}
+
const docs = s
.object({
title: s.string(),
@@ -45,6 +57,7 @@ const docs = s
...data,
slug: `/${flattenedPath}`,
slugAsParams: flattenedPath.split('/').slice(1).join('/'),
+ v0Name: getV0RegistryName(data.raw),
}))
export default defineConfig({