Code Block
iconiq-ui/code-blockFreeComponent
Editor-style code block with a filename tab, a top-right spring-crossfade copy button, a bottom status bar with language and line count, line numbers, built-in theme-aware syntax highlighting, and line emphasis.
Live preview
live · rendered by the registry
Rendered by Iconiq UI on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.iconiqui.com/r/code-block.jsonSource
1"use client";23import { Check, Copy } from "lucide-react";4import { AnimatePresence, motion, useReducedMotion } from "motion/react";5import { useCallback, useMemo, useRef, useState } from "react";67import { cn } from "@/lib/utils";89const COPY_RESET_MS = 2000;1011/** Transform-only spring for the copy icon swap — stays off the layout thread. */12const ICON_SPRING = {13 type: "spring",14 stiffness: 600,15 damping: 30,16 mass: 0.6,17} as const;1819type TokenKind =20 | "call"21 | "comment"22 | "keyword"23 | "number"24 | "operator"25 | "plain"26 | "property"27 | "punctuation"28 | "string"29 | "tag"30 | "type";3132type Token = {33 kind: TokenKind;34 value: string;35};3637const KEYWORDS = new Set([38 "abstract",39 "as",40 "async",41 "await",42 "break",43 "case",44 "catch",45 "class",46 "const",47 "continue",48 "def",49 "default",50 "delete",51 "do",52 "elif",53 "else",54 "enum",55 "export",56 "extends",57 "false",58 "finally",59 "fn",60 "for",61 "from",62 "function",63 "if",64 "implements",65 "import",66 "in",67 "instanceof",68 "interface",69 "let",70 "match",71 "new",72 "None",73 "not",74 "null",75 "of",76 "pass",77 "private",78 "protected",79 "public",80 "readonly",81 "return",82 "satisfies",83 "static",84 "struct",85 "switch",86 "this",87 "throw",88 "true",89 "try",90 "type",91 "typeof",92 "undefined",93 "var",94 "void",95 "while",96 "yield",97]);9899const WHITESPACE_RE = /^\s+/;100const BLOCK_COMMENT_RE = /^\/\*[\s\S]*?(?:\*\/|$)/;101const LINE_COMMENT_RE = /^(?:\/\/|#)[^\n]*/;102const TEMPLATE_STRING_RE = /^`(?:\\.|[\s\S])*?`/;103const DOUBLE_QUOTED_STRING_RE = /^"(?:\\.|[^"\\])*"/;104const SINGLE_QUOTED_STRING_RE = /^'(?:\\.|[^'\\])*'/;105const TAG_RE = /^<\/?[A-Za-z][\w.-]*|^\/?>/;106const ATTRIBUTE_RE = /^[A-Za-z_$][\w$-]*(?==)/;107const PROPERTY_RE = /^[A-Za-z_$][\w$-]*(?=\s*:)/;108const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*/;109const TYPE_IDENTIFIER_RE = /^[A-Z]/;110const NUMBER_RE = /^-?\d+(?:\.\d+)?/;111const OPERATOR_RE =112 /^(?:=>|===|!==|==|!=|<=|>=|\+\+|--|\|\||&&|\?\?|\.\.\.|[=<>+\-*/%!?&|])/;113const PUNCTUATION_RE = /^[{}()[\],.;:]/;114115const STATIC_MATCHERS: { kind: TokenKind; regex: RegExp }[] = [116 { kind: "plain", regex: WHITESPACE_RE },117 { kind: "comment", regex: BLOCK_COMMENT_RE },118 { kind: "comment", regex: LINE_COMMENT_RE },119 { kind: "string", regex: TEMPLATE_STRING_RE },120 { kind: "string", regex: DOUBLE_QUOTED_STRING_RE },121 { kind: "string", regex: SINGLE_QUOTED_STRING_RE },122 { kind: "tag", regex: TAG_RE },123 { kind: "property", regex: ATTRIBUTE_RE },124// … truncated
What it pulls in
npm packages
Files it writes
More from Iconiq UI
All 119 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | Iconiq UI | Components | Free | 2 deps | |
| AI Inputai-input | Iconiq UI | Components | Free | 3 deps | |
| Alertalert | Iconiq UI | Components | Free | 2 deps | |
| Avataravatar | Iconiq UI | Components | Free | 3 deps | |
| Accordion (Base UI)b-accordion | Iconiq UI | Components | Free | 2 deps | |
| Alert Dialog (Base UI)b-alert-dialog | Iconiq UI | Components | Free | 3 deps | |
| Autocomplete (Base UI)b-autocomplete | Iconiq UI | Components | Free | 3 deps | |
| Avatar (Base UI)b-avatar | Iconiq UI | Components | Free | 2 deps |
