Browse and insert prompt templates. Click a prompt to copy it to clipboard (or insert directly when used with PromptInput).
Installation
pnpm dlx shadcn@latest add https://cult-ui.com/r/prompt-library.json
Usage
Use PromptLibrary with prompts, onPromptsChange, and onSelect. Compose PromptLibraryTrigger, PromptLibraryContent (with PromptLibrarySearch, PromptLibraryList, PromptLibraryEmpty, PromptLibraryGroup, PromptLibraryItem), PromptLibraryFooter, PromptLibraryCreateTrigger, and PromptLibraryCreateDialog for the full experience.
Basic example
import { useState } from "react"
import {
PromptLibrary,
PromptLibraryTrigger,
PromptLibraryContent,
PromptLibrarySearch,
PromptLibraryList,
PromptLibraryEmpty,
PromptLibraryGroup,
PromptLibraryItem,
PromptLibraryFooter,
PromptLibraryCreateTrigger,
PromptLibraryCreateDialog,
type Prompt,
} from "@/registry/default/ui/prompt-library"
const prompts: Prompt[] = [
{
id: "code-review",
title: "Code Review",
description: "Review code for best practices",
prompt: "Please review this code for best practices and potential issues.",
category: "Development",
},
]
export default function Example() {
const [promptsState, setPromptsState] = useState(prompts)
const [lastSelected, setLastSelected] = useState<Prompt | null>(null)
return (
<PromptLibrary
prompts={promptsState}
onPromptsChange={setPromptsState}
onSelect={setLastSelected}
>
<PromptLibraryTrigger />
<PromptLibraryContent>
<PromptLibrarySearch />
<PromptLibraryList>
<PromptLibraryEmpty />
<PromptLibraryGroup heading="Development">
{promptsState
.filter((p) => p.category === "Development")
.map((prompt) => (
<PromptLibraryItem key={prompt.id} prompt={prompt} />
))}
</PromptLibraryGroup>
</PromptLibraryList>
<PromptLibraryFooter>
<PromptLibraryCreateTrigger />
</PromptLibraryFooter>
</PromptLibraryContent>
<PromptLibraryCreateDialog />
</PromptLibrary>
)
}Features
- Categories: Group prompts with
PromptLibraryGroupand optionalheading - Custom prompts: Add and remove custom prompts via
onPromptsChange,PromptLibraryCreateTrigger, andPromptLibraryCreateDialog - Copy or insert: Selecting a prompt copies to clipboard; when used with PromptInput, can insert directly
- Search:
PromptLibrarySearchfilters the list - Compound API: PromptLibrary, PromptLibraryTrigger, PromptLibraryContent, PromptLibrarySearch, PromptLibraryList, PromptLibraryEmpty, PromptLibraryGroup, PromptLibraryItem, PromptLibraryFooter, PromptLibraryCreateTrigger, PromptLibraryCreateDialog