ai-web-preview
dedevs-ui/ai-web-previewFreeComponent
AI web-preview component
See it running
Open the demo on dedevs-ui
ui.dedevs.com/components/ai-web-previewInstall it
npx shadcn@latest add https://ui.dedevs.com/r/ai-web-preview.jsonSource
1'use client';23import { ChevronDownIcon } from 'lucide-react';4import type { ComponentProps, ReactNode } from 'react';5import { createContext, useContext, useState } from 'react';6import { Button } from '@repo/shadcn-ui/components/ui/button';7import {8 Collapsible,9 CollapsibleContent,10 CollapsibleTrigger,11} from '@repo/shadcn-ui/components/ui/collapsible';12import { Input } from '@repo/shadcn-ui/components/ui/input';13import {14 Tooltip,15 TooltipContent,16 TooltipProvider,17 TooltipTrigger,18} from '@repo/shadcn-ui/components/ui/tooltip';19import { cn } from '@repo/shadcn-ui/lib/utils';2021export type AIWebPreviewContextValue = {22 url: string;23 setUrl: (url: string) => void;24 consoleOpen: boolean;25 setConsoleOpen: (open: boolean) => void;26};2728const AIWebPreviewContext = createContext<AIWebPreviewContextValue | null>(null);2930const useAIWebPreview = () => {31 const context = useContext(AIWebPreviewContext);32 if (!context) {33 throw new Error('AIWebPreview components must be used within a AIWebPreview');34 }35 return context;36};3738export type AIWebPreviewProps = ComponentProps<'div'> & {39 defaultUrl?: string;40 onUrlChange?: (url: string) => void;41};4243export const AIWebPreview = ({44 className,45 children,46 defaultUrl = '',47 onUrlChange,48 ...props49}: AIWebPreviewProps) => {50 const [url, setUrl] = useState(defaultUrl);51 const [consoleOpen, setConsoleOpen] = useState(false);5253 const handleUrlChange = (newUrl: string) => {54 setUrl(newUrl);55 onUrlChange?.(newUrl);56 };5758 const contextValue: AIWebPreviewContextValue = {59 url,60 setUrl: handleUrlChange,61 consoleOpen,62 setConsoleOpen,63 };6465 return (66 <AIWebPreviewContext.Provider value={contextValue}>67 <div68 className={cn('flex size-full flex-col rounded-lg border bg-card', className)}69 {...props}70 >71 {children}72 </div>73 </AIWebPreviewContext.Provider>74 );75};7677export type AIWebPreviewNavigationProps = ComponentProps<'div'>;7879export const AIWebPreviewNavigation = ({ className, children, ...props }: AIWebPreviewNavigationProps) => (80 <div className={cn('flex items-center gap-1 border-b p-2', className)} {...props}>81 {children}82 </div>83);8485export type AIWebPreviewNavigationButtonProps = ComponentProps<typeof Button> & {86 tooltip?: string;87};8889export const AIWebPreviewNavigationButton = ({90 onClick,91 disabled,92 tooltip,93 children,94 ...props95}: AIWebPreviewNavigationButtonProps) => (96 <TooltipProvider>97 <Tooltip>98// … truncated
Files it writes
More from dedevs-ui
All 30 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-branchai-branch | dedevs-ui | Components | Free | no deps | |
| ai-conversationai-conversation | dedevs-ui | Components | Free | no deps | |
| ai-inputai-input | dedevs-ui | Components | Free | no deps | |
| ai-messageai-message | dedevs-ui | Components | Free | no deps | |
| ai-reasoningai-reasoning | dedevs-ui | Components | Free | no deps | |
| ai-responseai-response | dedevs-ui | Components | Free | no deps | |
| ai-serverai-server | dedevs-ui | Components | Free | no deps | |
| ai-simpleai-simple | dedevs-ui | Components | Free | no deps |
