Code Tabs
Tabbed code display with syntax highlighting and copy functionality. Perfect for React applications requiring multi-variant code examples with Next.js integration and TypeScript support.
Powered by
Installation
npx shadcn@latest add https://www.shadcn.io/registry/code-tabs.json
npx shadcn@latest add https://www.shadcn.io/registry/code-tabs.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/code-tabs.json
bunx shadcn@latest add https://www.shadcn.io/registry/code-tabs.json
Features
- Multi-tab code display with smooth transitions between different code variants
- Syntax highlighting using Shiki for accurate language-specific highlighting
- Copy functionality with built-in copy button for each code snippet
- TypeScript support with complete type definitions and IntelliSense
- Theme-aware highlighting automatically adapts to light/dark themes using next-themes
- Customizable languages supporting all Shiki language definitions
Examples
Package Manager Commands
Display installation commands for different package managers with automatic syntax highlighting.
Without Copy Button
Show code comparisons across frameworks without the copy functionality.
Use Cases
This free open source React component works well for:
- Documentation sites - Display code examples for multiple platforms or languages built with Next.js
- API documentation - Show request examples in different programming languages using TypeScript and Tailwind CSS
- Tutorial content - Present alternative implementations or framework-specific code
- Configuration examples - Display setup instructions for various environments with shadcn/ui integration
API Reference
CodeTabs
Prop | Type | Default | Description |
---|---|---|---|
codes | Record<string, string> | required | Object with tab names as keys and code content as values |
lang | string | "bash" | Language for syntax highlighting |
themes | { light: string; dark: string } | { light: 'github-light', dark: 'github-dark' } | Shiki themes for light and dark modes |
copyButton | boolean | true | Whether to show the copy button |
onCopy | (content: string) => void | - | Callback when code is copied |
defaultValue | string | First key in codes | Initially selected tab |
value | string | - | Controlled selected tab value |
onValueChange | (value: string) => void | - | Callback when tab selection changes |
Supported Languages
The component supports all languages available in Shiki, including:
javascript
,typescript
,jsx
,tsx
- JavaScript ecosystempython
,ruby
,go
,rust
- Popular languagesbash
,shell
,powershell
- Shell scriptingjson
,yaml
,toml
- Configuration formatshtml
,css
,scss
- Web technologies- And many more...
Implementation Notes
- Requires
next-themes
for theme detection - Code highlighting is performed asynchronously on mount
- The component gracefully falls back to plain text if highlighting fails
- Tab selection can be controlled or uncontrolled
- Copy button uses the shadcn/ui CopyButton component
Code Editor
Animated code editor component for React and Next.js applications. Built with TypeScript support, Tailwind CSS styling, and shadcn/ui design featuring syntax highlighting, typing animations, and customizable themes.
Sandbox
Interactive code playground with live preview and debugging capabilities. Perfect for React component testing requiring isolated environments with Next.js integration and TypeScript support.