Join our Discord community
Code

Snippet

Tabbed code display with one-click clipboard functionality and customizable content. Perfect for React documentation requiring code examples with Next.js integration and TypeScript support.

Loading component...

Installation

npx shadcn@latest add https://www.shadcn.io/registry/snippet.json
npx shadcn@latest add https://www.shadcn.io/registry/snippet.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/snippet.json
bunx shadcn@latest add https://www.shadcn.io/registry/snippet.json

Features

  • One-click clipboard functionality using native browser APIs with visual feedback and success indicators
  • Customizable tab system supporting unlimited tabs with flexible content and styling options
  • Multiple content support handling code snippets, command examples, and installation instructions
  • Accessible interface built on Radix UI Tabs primitive with full keyboard navigation and screen reader support
  • Flexible copy button with configurable timeout, custom callbacks, and success/error states
  • Custom tab triggers allowing personalized labels, icons, and interactive elements
  • Content customization supporting rich text, syntax highlighting, and formatted code blocks
  • TypeScript support with complete interface definitions for reliable integration
  • Responsive design adapting to mobile and desktop viewports with touch-friendly interactions

Examples

NPM packages

Loading component...

Use Cases

This free open source React component works well for:

  • Installation guides - Package manager commands and setup instructions built with Next.js
  • API documentation - Code examples and request/response snippets using TypeScript
  • Tutorial content - Step-by-step code examples with multiple language support
  • Command references - CLI commands and terminal examples using shadcn/ui design
  • Configuration examples - Environment variables and config file snippets
  • Code samples - Reusable code blocks for documentation using Tailwind CSS styling

API Reference

Snippet

PropTypeDefaultDescription
childrenReactNodeundefinedSnippetTab components or content
defaultValuestringundefinedDefault active tab value
classNamestringundefinedAdditional CSS classes for the container
onValueChangefunctionundefinedCallback when active tab changes

SnippetTab

PropTypeDefaultDescription
valuestringundefinedUnique identifier for the tab
labelstringundefinedDisplay label for the tab trigger
childrenReactNodeundefinedContent to display in the tab panel
copyTextstringundefinedText to copy when copy button is clicked
showCopyButtonbooleantrueWhether to show the copy button
copyTimeoutnumber2000Duration in ms to show copy success state
onCopyfunctionundefinedCallback when copy button is clicked
classNamestringundefinedAdditional CSS classes for tab content

Implementation Notes

  • Component built on Radix UI Tabs primitive ensuring accessibility and keyboard navigation
  • Copy functionality uses Clipboard API with fallback for older browsers
  • Tab system supports unlimited tabs with dynamic content and conditional rendering
  • Copy success feedback includes visual state changes and configurable timeout duration
  • Content supports both plain text and rich JSX elements for flexible display options
  • Responsive design adapts tab layout and copy button positioning across device sizes
  • Compatible with shadcn/ui design system and Tailwind CSS utility classes
  • Error handling includes clipboard permission checks and graceful fallbacks
  • Performance optimized with lazy loading and efficient re-rendering for large tab sets
  • TypeScript interfaces ensure type safety for tab configuration and callback functions