To create your own custom Code Block component, make sure you have the following prerequisites:
- Node.js v20 or higher.
- Typescript v5 or higher.
Styling
All components uses Tailwind CSS v4 for styling. Make sure to have it installed and configured in your project.
For some colors, we use neutral theme from Tailwind CSS:
Components
- Create a new React app:
- Install the following dependencies:
pnpm i clsx tailwind-merge lucide-react @react-symbols/icons- Add
@alias to yourtsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}- Create the
cnutility:
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}Blocks
You'll need to install @base-ui/react to use the Blocks components:
- Install the package:
pnpm i @base-ui/react- Add
rootclass to global<body>tag:
<body>
<div className="root">{children}</div>
</body>- Add the following CSS to your global stylesheet:
.root {
isolation: isolate;
}shadcn/ui
shadcn/ui is a collection of accessible and customizable UI components styled with Tailwind CSS. It provides a CLI that you can use it to add components to your project using the components.json file.
Add registry
If you don't have a components.json file yet, initialize it by running:
pnpm dlx shadcn@latest initThen, add the registries section to your components.json file:
{
"registries": {
"@code-blocks": "https://code-blocks.pheralb.dev/r/{name}.json"
}
}Utilities
All the utilities are built using TypeScript. You'll only need install the highlighter library you choose to use: