Syntax Highlighted Code Block
This code block
Import
To use the Code component in your project, import it as follows:
import { CodeBlock } from "@purrfect-ui/components";
If you are using VITE:
vite.config.js
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
optimizeDeps: {
include: ["react-syntax-highlighter", "lowlight"], // Include dependencies
},
build: {
commonjsOptions: {
transformMixedEsModules: true, // Allows transforming mixed modules (CommonJS/ESM)
},
},
});
Usage
The Code component is designed to make embedding and presenting code snippets easy. Below is an example of its basic usage:
Basic Usage
import React from "react";
import { CodeBlock } from "@purrfect-ui/components";
export function CodeBlockDemo() {
return (
<CodeBlock lang="typescript" code="import React from 'react';"/>
);
}
export default CodeBlockDemo;
Key Features
-
Syntax Highlighting: Automatic language detection for improved readability.
-
Customizable Themes: Supports multiple themes for styling code blocks.
-
Responsive Design: Scales perfectly across all devices.
-
Easy Integration: Works right out of the box with minimal configuration required.
-
Lightweight: Designed to be fast and efficient in performance.