Ai Artifact
elements/artifactFreeComponent
TODO: Add description
Install it
npx shadcn@latest add https://www.tryelements.dev/r/artifact.jsonSource
1"use client";23import * as React from "react";45import {6 Check,7 Copy,8 Download,9 FileCode,10 Play,11 RefreshCw,12 Share2,13 X,14} from "lucide-react";1516import { cn } from "@/lib/utils";1718interface AiArtifactContextValue {19 onClose?: () => void;20}2122const AiArtifactContext = React.createContext<AiArtifactContextValue | null>(23 null,24);2526function useArtifactContext() {27 const context = React.useContext(AiArtifactContext);28 if (!context) {29 throw new Error("AiArtifact components must be used within <AiArtifact>");30 }31 return context;32}3334interface AiArtifactProps {35 onClose?: () => void;36 children?: React.ReactNode;37 className?: string;38}3940function AiArtifact({ onClose, children, className }: AiArtifactProps) {41 const contextValue = React.useMemo(() => ({ onClose }), [onClose]);4243 return (44 <AiArtifactContext.Provider value={contextValue}>45 <div46 data-slot="ai-artifact"47 className={cn(48 "rounded-lg border border-border bg-card text-card-foreground shadow-lg overflow-hidden flex flex-col",49 className,50 )}51 >52 {children}53 </div>54 </AiArtifactContext.Provider>55 );56}5758interface AiArtifactHeaderProps {59 children?: React.ReactNode;60 className?: string;61}6263function AiArtifactHeader({ children, className }: AiArtifactHeaderProps) {64 return (65 <div66 data-slot="ai-artifact-header"67 className={cn(68 "flex items-center justify-between gap-4 border-b border-border px-4 py-3",69 className,70 )}71 >72 <div className="flex items-center gap-3 min-w-0">73 <div className="flex size-8 shrink-0 items-center justify-center rounded-md bg-muted">74 <FileCode className="size-4 text-muted-foreground" />75 </div>76 <div className="min-w-0">{children}</div>77 </div>78 </div>79 );80}8182interface AiArtifactTitleProps {83 children?: React.ReactNode;84 className?: string;85}8687function AiArtifactTitle({ children, className }: AiArtifactTitleProps) {88 return (89 <h390 data-slot="ai-artifact-title"91 className={cn("font-semibold text-sm truncate", className)}92 >93 {children}94 </h3>95 );96}9798interface AiArtifactDescriptionProps {99 children?: React.ReactNode;100 className?: string;101}102103function AiArtifactDescription({104 children,105 className,106}: AiArtifactDescriptionProps) {107 return (108 <p109 data-slot="ai-artifact-description"110 className={cn("text-xs text-muted-foreground truncate", className)}111 >112// … truncated
Files it writes
More from elements
All 359 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Ably Logoably-logo | elements | Components | Free | no deps | |
| AI Agent Contextagent-context | elements | Components | Free | 2 deps | |
| AI Agent Rosteragent-roster | elements | Components | Free | 1 dep | |
| AI Agent Statusagent-status | elements | Components | Free | 1 dep | |
| Algolia Logoalgolia-logo | elements | Components | Free | no deps | |
| Amp Logoamp-logo | elements | Components | Free | no deps | |
| Anthropic Logoanthropic-logo | elements | Components | Free | no deps | |
| Antigravity Logoantigravity-logo | elements | Components | Free | no deps |
