| title | Prerequisites | |
|---|---|---|
| description | Libraries required to create custom Code Block component. | |
| category |
|
To create your own custom Code Block component, make sure you have the following prerequisites:
- Node.js v20 or higher.
- Typescript v5 or higher.
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:
- Create a new React app:
- Install the following dependencies:
- 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));
}You'll need to install @base-ui/react to use the Blocks components:
- Install the package:
- 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 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.
If you don't have a components.json file yet, initialize it by running:
Then, add the registries section to your components.json file:
{
"registries": {
"@code-blocks": "https://code-blocks.pheralb.dev/r/{name}.json"
}
}All the utilities are built using TypeScript. You'll only need install the highlighter library you choose to use: