mxyhi/ok-skills / ai-elements
ai-elements
VerifiedBuild AI chat interfaces using ai-elements components — conversations, messages, tool displays, prompt inputs, and more. Use when the user wants to build a chatbot, AI assistant UI, or any AI-powered chat interface.
scripts/code-block.tsx
View on GitHub"use client";
import {
CodeBlock,
CodeBlockActions,
CodeBlockCopyButton,
CodeBlockFilename,
CodeBlockHeader,
CodeBlockLanguageSelector,
CodeBlockLanguageSelectorContent,
CodeBlockLanguageSelectorItem,
CodeBlockLanguageSelectorTrigger,
CodeBlockLanguageSelectorValue,
CodeBlockTitle,
} from "@/components/ai-elements/code-block";
import { FileIcon } from "lucide-react";
import { useCallback, useState } from "react";
import type { BundledLanguage } from "shiki";
const codeExamples = {
go: {
code: `package main
import "fmt"
func greet(name string) string {
return fmt.Sprintf("Hello, %s!", name)
}
func main() {
fmt.Println(greet("World"))
}`,
filename: "greet.go",
},
python: {
code: `def greet(name: str) -> str:
return f"Hello, {name}!"
print(greet("World"))`,
filename: "greet.py",
},
rust: {
code: `fn greet(name: &str) -> String {
format!("Hello, {}!", name)
}
fn main() {
println!("{}", greet("World"));
}`,
filename: "greet.rs",
},
typescript: {
code: `function greet(name: string): string {
return \`Hello, \${name}!\`;
}
console.log(greet("World"));`,
filename: "greet.ts",
},
} as const;
type Language = keyof typeof codeExamples;
const languages: { value: Language; label: string }[] = [
{ label: "TypeScript", value: "typescript" },
{ label: "Python", value: "python" },
{ label: "Rust", value: "rust" },
{ label: "Go", value: "go" },
];
const handleCopy = () => {
console.log("Copied code to clipboard");
};
const handleCopyError = () => {
console.error("Failed to copy code to clipboard");
};
const Example = () => {
const [language, setLanguage] = useState<Language>("typescript");
const { code, filename } = codeExamples[language];
const handleLanguageChange = useCallback((value: string) => {
setLanguage(value as Language);
}, []);
return (
<CodeBlock code={code} language={language as BundledLanguage}>
<CodeBlockHeader>
<CodeBlockTitle>
<FileIcon size={14} />
<CodeBlockFilename>{filename}</CodeBlockFilename>
</CodeBlockTitle>
<CodeBlockActions>
<CodeBlockLanguageSelector
onValueChange={handleLanguageChange}
value={language}
>
<CodeBlockLanguageSelectorTrigger>
<CodeBlockLanguageSelectorValue />
</CodeBlockLanguageSelectorTrigger>
<CodeBlockLanguageSelectorContent>
{languages.map((lang) => (
<CodeBlockLanguageSelectorItem
key={lang.value}
value={lang.value}
>
{lang.label}
</CodeBlockLanguageSelectorItem>
))}
</CodeBlockLanguageSelectorContent>
</CodeBlockLanguageSelector>
<CodeBlockCopyButton onCopy={handleCopy} onError={handleCopyError} />
</CodeBlockActions>
</CodeBlockHeader>
</CodeBlock>
);
};
export default Example;
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |