npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@open-react-hub/code-block

v1.0.8

Published

A feature-rich, customizable code block component for React applications with syntax highlighting, line numbers, and themes

Readme

@open-react-hub/code-block

A feature-rich, customizable code block component for React applications with support for syntax highlighting, line numbers, command-line interface simulation, and themes.

Features

  • 🎨 Syntax highlighting for multiple programming languages
  • 📝 Optional line numbers with toggle functionality
  • 🌙 Light and dark theme support
  • 💻 Command-line interface simulation
  • 📋 One-click code copying
  • 🎯 Customizable prompts and styling
  • ⚡ Built with performance in mind
  • 🎯 TypeScript support out of the box

Installation

npm install @open-react-hub/code-block
# or
yarn add @open-react-hub/code-block
# or 
pnpm add @open-react-hub/code-block

Dependencies

This package requires the following peer dependencies:

{
  "react": "^18.0.0",
  "react-dom": "^18.0.0",
  "lucide-react": "^0.263.1",
  "prismjs": "^1.29.0"
}

Basic Usage

import { CodeBlock } from '@open-react-hub/code-block';

function App() {
  const code = `function hello() {
  console.log("Hello, World!");
}`;

  return (
    <CodeBlock 
      code={code} 
      language="javascript"
    />
  );
}

Command-Line Mode

import { CodeBlock } from '@open-react-hub/code-block';

function Terminal() {
  const commands = `$ npm install @open-react-hub/code-block
Installing dependencies...
✓ Done!
$ npm start`;

  return (
    <CodeBlock 
      code={commands}
      isCommandLine={true}
      commandLine={{
        user: "dev",
        host: "localhost",
        path: "~/project"
      }}
    />
  );
}

API Reference

Props

| Prop | Type | Default | Description | |------|------|---------|-------------| | code | string | Required | The code or text content to display | | language | string | 'typescript' | Programming language for syntax highlighting | | showLineNumbers | boolean | true | Show/hide line numbers | | showCopyButton | boolean | true | Show/hide copy button | | showLanguageLabel | boolean | true | Show/hide language label | | theme | 'light' | 'dark' | 'dark' | Color theme | | className | string | '' | Additional CSS classes | | isCommandLine | boolean | false | Enable command-line interface mode | | commandLine | CommandLineConfig | See below | Command-line configuration |

CommandLineConfig Interface

interface CommandLineConfig {
  user?: string;          // Username in prompt
  host?: string;          // Hostname in prompt
  path?: string;          // Current path in prompt
  basePrompt?: string;    // Custom base prompt
  continuationPrompt?: string;  // Prompt for continued lines
  lines?: LineConfig[];   // Pre-configured lines
}

interface LineConfig {
  content: string;        // Line content
  isOutput?: boolean;     // Is this line command output?
  isContinuation?: boolean;  // Is this a continuation line?
  customPrompt?: string;  // Custom prompt for this line
}

Supported Languages

The component supports syntax highlighting for the following languages out of the box:

  • TypeScript
  • JavaScript
  • JSX/TSX
  • CSS
  • Python
  • Java
  • JSON
  • Bash
  • Markdown
  • Shell Session

Styling

The component uses Tailwind CSS classes internally and can be customized using the className prop. The component respects dark/light mode and automatically adjusts its appearance.

Theme Customization

<CodeBlock
  code={code}
  theme="light"
  className="my-8 shadow-lg"
/>

Command-Line Mode Examples

Basic Terminal

<CodeBlock
  code="$ ls -la
total 24
drwxr-xr-x  5 user  group  160 Jan 14 10:00 ."
  isCommandLine={true}
/>

Custom Prompt

<CodeBlock
  code="$ npm start"
  isCommandLine={true}
  commandLine={{
    basePrompt: "➜",
    continuationPrompt: "→"
  }}
/>

Best Practices

  1. Language Specification: Always specify the correct language for proper syntax highlighting:
<CodeBlock code={code} language="python" />
  1. Theme Consistency: Match the theme with your application's color scheme:
<CodeBlock code={code} theme={isDarkMode ? 'dark' : 'light'} />
  1. Command-Line Configuration: When using command-line mode, provide meaningful prompt information:
<CodeBlock
  code={commands}
  isCommandLine={true}
  commandLine={{
    user: "dev",
    host: "server",
    path: "/var/www"
  }}
/>

Performance Considerations

  • The component uses React's useState and useEffect hooks efficiently
  • Syntax highlighting is performed using Prism.js
  • Line numbers are virtualized for better performance with large code blocks

Accessibility

  • Proper ARIA labels and roles are implemented
  • Keyboard navigation support for copy functionality
  • High contrast ratios for better readability
  • Screen reader friendly content structure

Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

License

MIT © OpenReactHub