"use client" import * as React from "react" import { editInV0 } from "@/actions/edit-in-v0" import { Loader2 } from "lucide-react" import { useFormStatus } from "react-dom" import { toast } from "sonner" import { cn } from "@/lib/utils" import { Button, ButtonProps } from "@/registry/new-york/ui/button" import { Tooltip, TooltipContent, TooltipTrigger, } from "@/registry/new-york/ui/tooltip" import { Block } from "@/registry/schema" import { Style } from "@/registry/styles" type Size = "default" | "icon" function V0Tooltip({ size, style = "default", children, }: React.PropsWithChildren<{ size: Size; style?: Style["name"] }>) { if (size === "default") { return <>{children}> } return ( {style === "new-york" ? ( {children} ) : ( <>{children}> )} {style === "new-york" ? ( <>Not available in New York> ) : ( <>Edit in v0> )} ) } export function V0Button({ block, size = "default", disabled, className, ...props }: { block: Pick size?: Size } & ButtonProps) { if (block.style === "new-york") { return ( { toast("New York not available.", { description: ( Only the Default style is available in{" "} . ), }) }} disabled={ block.style === "new-york" && size === "icon" ? true : disabled } {...props} > {size === "icon" ? ( ) : ( <> Edit in > )} ) } return ( { try { const result = await editInV0({ name: block.name, description: block.description || "", code: block.code, style: block.style, }) if (result?.error) { throw new Error(result.error) } if (result?.url) { const popupOpened = window.open(result.url, "_blank") if (!popupOpened) { toast.warning("Pop-up window blocked.", { description: "Click the pop-up button in your browser to continue.", duration: 5000, }) } } } catch (error) { if (error instanceof Error) { toast.error(error.message) } } }} > ) } function Form({ disabled, size = "default", className, ...props }: Omit, "block">) { const { pending } = useFormStatus() return ( {size === "icon" ? ( <> {pending ? ( ) : ( )} > ) : ( <> {pending && } Edit in > )} ) } export function V0Logo({ className, ...props }: React.ComponentProps<"svg">) { return ( ) }