0.0.6 • Published 2 years ago

@roo-app/react-code-block v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

React Code Block

npm version

Installation

Install with your favorite package manager

# yarn
yarn add @roo-app/react-code-block
# pnpm
pnpm i @roo-app/react-code-block
# npm
npm i @roo-app/react-code-block

Usage

In order to use CodeBlock, simply import and use in a component:

import CodeBlock from "@roo-app/react-code-block";
import { themes } from "prism-react-renderer";

const codeBlock = `
const GroceryItem: React.FC<GroceryItemProps> = ({ item }) => {
  return (
    <div>
      <h2>{item.name}</h2>
      <p>Price: {item.price}</p>
      <p>Quantity: {item.quantity}</p>
    </div>
  );
}
`;
function ReactCodeBlockExample() {
  return (
    <CodeBlock
      code={codeBlock}
      theme={themes.vsDark}
      language="tsx"
      onCopy={(value) => {
        console.log(value);
      }}
    />
  );
}

export default ReactCodeBlockExample;

Props

CodeBlock properties extends HighlightProps from prism-react-renderer. Outside of the existing properties we expose:

Prop nameTypeDescriptionExampleRequired
highlightLinesArray<number>The line numbers you want to highlight1,5,7No
filenamestringThe filename to show at the top of the code blockMyFile.tsxNo
showLineNumbersbooleanTo show line number or notfalseNo
showFileIconbooleanTo show the icon left of the filename - must have filenamefalseNo
onCopy(value: string) => voidCallback if user taps on the copy logoNo

Icons

We support a handful of filetype icons. Here is the current list:

  • jsx
  • tsx
  • swift
  • kotlin
  • objectivec
  • rust
  • graphql
  • go
  • markdown
  • python

Demo

You can find a demo on my website or go to the example/ directory and run it there.

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago