Code Block
A clean code block that builds its entire theme from a single accent color. Pass code and a hex, it does the rest.
Dependencies
Interaction Type
Pick an accent swatch to re-shade the whole block from that color. Hit the copy button to see it spring into a check.
Props
Options you can pass to customize this component.
code*stringThe source code to render.
languagestringPrism language id, e.g. "tsx", "css", "json", "bash". Also shown as the tag in the header.
accent#F75001#1A73F2#FF3B30#34C759Any hex color. The whole theme is shades of it: the darkest shade is the background, tokens are tints of the accent, and the lightest text is always white.
mode"auto""dark""light"Color scheme. Auto follows the page theme (html dark/light class, data-theme, or OS preference). Pass dark or light to pin a palette: dark puts light tints of the accent on a dark surface, light flips the ramp.
filenamestringFilename or path shown on the left of the header. Falls back to the language id when omitted.
showFramebooleanToggles the outer layout — background, border, rounded corners, and header. Turn off to render nothing but the highlighted code.
showHeaderbooleanToggles the header bar. When hidden, the copy button floats over the top-right corner instead. Ignored when showFrame is off.
showLineNumbersbooleanToggles the line-number gutter.
showCopyButtonbooleanToggles the copy-to-clipboard button.
highlightLinesnumber[]Optional 1-based line numbers to highlight with a soft accent wash. Off when omitted.
classNamestringExtra classes merged onto the root element (data-slot="code-block") — use it for width and max-height.
Installation
npx shadcn add swamimalode07/rare-ui/code-blockHow to use
import CodeBlock from "@/components/ui/code-block"export function Demo() {return (<CodeBlockcode={`const greet = (name: string) => \`Hello, \${name}!\``}language="ts"accent="#F75001"filename="greet.ts"/>)}
Source Code
Click the code icon in the top-right corner to view the source code.
Keep in mind
Most components here are recreations of great work from around the web. I don't claim to be the original creator - this is my attempt to reverse-engineer, replicate, and often add a few extra features. I've tried to credit everyone; if I missed someone, let me know.
License & Usage
1
1import { useSpring, animated } from "motion/react";23type OrbitProps = {4 radius?: number;5 speed?: number;6};78export function Orbit({ radius = 120, speed = 1 }: OrbitProps) {9 const angle = useSpring(0, { stiffness: 80, damping: 20 });1011 const x = Math.cos(angle.get()) * radius;12 const y = Math.sin(angle.get()) * radius;1314 return (15 <animated.div16 style={{ x, y }}17 className="size-4 rounded-full bg-current"18 />19 );20}