code-block
jolyui-ui/code-blockFreeComponent
jolyui/ui publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by jolyui/ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://jolyui.dev/r/code-block.jsonSource
1import {2 Check,3 Copy,4 Download,5 FileCode,6 Maximize2,7 Minimize2,8 Terminal,9 WrapText,10} from "lucide-react";11import { AnimatePresence, motion } from "motion/react";12import { Highlight, type Language, themes } from "prism-react-renderer";13import * as React from "react";14import { cn } from "@/lib/utils";1516type CodeBlockVariant =17 | "default"18 | "terminal"19 | "minimal"20 | "gradient"21 | "glass";22type AnimationType = "none" | "fadeIn" | "slideIn" | "typewriter" | "highlight";23type ThemeType =24 | "oneDark"25 | "dracula"26 | "github"27 | "nightOwl"28 | "oceanicNext"29 | "palenight"30 | "shadesOfPurple"31 | "synthwave84"32 | "vsDark"33 | "vsLight";3435// Theme mapping36const themeMap: Record<ThemeType, typeof themes.oneDark> = {37 oneDark: themes.oneDark,38 dracula: themes.dracula,39 github: themes.github,40 nightOwl: themes.nightOwl,41 oceanicNext: themes.oceanicNext,42 palenight: themes.palenight,43 shadesOfPurple: themes.shadesOfPurple,44 synthwave84: themes.synthwave84,45 vsDark: themes.vsDark,46 vsLight: themes.vsLight,47};4849// Supported languages list50const supportedLanguages = [51 "javascript",52 "typescript",53 "jsx",54 "tsx",55 "python",56 "bash",57 "shell",58 "css",59 "scss",60 "html",61 "json",62 "yaml",63 "markdown",64 "sql",65 "graphql",66 "rust",67 "go",68 "java",69 "c",70 "cpp",71 "csharp",72 "php",73 "ruby",74 "swift",75 "kotlin",76 "scala",77 "r",78 "lua",79 "perl",80 "haskell",81 "elixir",82 "clojure",83 "dockerfile",84 "toml",85 "ini",86 "xml",87 "diff",88 "makefile",89 "regex",90] as const;9192interface CodeBlockProps {93 code: string;94 language?: Language | string;95 title?: string;96 showLineNumbers?: boolean;97 highlightLines?: number[];98 addedLines?: number[];99 removedLines?: number[];100 variant?: CodeBlockVariant;101 animation?: AnimationType;102 animationDelay?: number;103 className?: string;104 copyable?: boolean;105 downloadable?: boolean;106 downloadFileName?: string;107 maxHeight?: string;108 theme?: ThemeType;109 wrapLongLines?: boolean;110 showLanguage?: boolean;111 collapsible?: boolean;112 defaultCollapsed?: boolean;113 startingLineNumber?: number;114 caption?: string;115}116117// Copy button component118const CopyButton = ({119 code,120 className,121}: {122 code: string;123 className?: string;124}) => {125 const [copied, setCopied] = React.useState(false);126127 const handleCopy = async () => {128 try {129 await navigator.clipboard.writeText(code);130 setCopied(true);131 setTimeout(() => setCopied(false), 2000);132 } catch (err) {133// … truncated
What it pulls in
npm packages
Files it writes
More from jolyui/ui
All 199 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ai-prompt-boxai-prompt-box | jolyui/ui | Components | Free | 4 deps | |
| animated-beamanimated-beam | jolyui/ui | Components | Free | 1 dep | |
| animated-tableanimated-table | jolyui/ui | Components | Free | 2 deps | |
| animated-theme-toggleanimated-theme-toggle | jolyui/ui | Components | Free | 2 deps | |
| animated-toastanimated-toast | jolyui/ui | Components | Free | 2 deps | |
| animated-tooltipanimated-tooltip | jolyui/ui | Components | Free | 1 dep | |
| bento-gridbento-grid | jolyui/ui | Components | Free | no deps | |
| buttonbutton | jolyui/ui | Components | Free | 3 deps |
