81 Pro components and page blocks

Get Pro

Code Block

New

Preview

Customize

Install tabs

Installation

npx shadcn@latest add https://uibrik.com/r/code-block.json
Adds the files to components/uibrik/code-block and installs motion and shiki. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/code-block.

Usage

import { CodeBlock } from "@/components/uibrik/code-block/code-block";​const tabs = [  { label: "npm", code: "npm install motion react-use-measure", lang: "bash" },  { label: "pnpm", code: "pnpm add motion react-use-measure", lang: "bash" },  // …2 more];​<CodeBlock  lineNumbers  wrap={false}  copyable  code=""  lang="tsx"  tabs={tabs}  syncKey="pm"  diff={false}  // title="…"  // value="…"  // defaultValue="…"  // onValueChange={(label) => {}}  // highlightLines={[0]}/>

Props

CodeBlock
lineNumbers
Type boolean
true
A gutter of line numbers. Copying never picks them up.
wrap
Type boolean
false
Wrap long lines instead of scrolling sideways.
collapseAfter
Type number
15
Fold longer snippets behind Show all. 0 never folds.
copyable
Type boolean
true
The copy button. A diff copies the code after the change.
code / lang
Type string / "tsx" | "jsx" | "ts" | "js" | "bash" | "json" | "css" | "html" | "python" | "text"
"tsx"
A single snippet and its language.
tabs
Type { label; code; lang? }[]
–
Several snippets, one per tab.
title
Type string
–
File name or caption for a single snippet.
value / defaultValue / onValueChange
Type string / string / (label) => void
–
Selected tab, controlled or not.
syncKey
Type string
–
Blocks with the same key switch tabs together and remember the choice in this browser.
highlightLines
Type number[]
–
1-based lines to mark.
diff
Type boolean
false
Lines starting with + or - show as added or removed.
className
Type string
–
Classes for the frame.