A step-by-step guide to install Cerberus
For a better developer experience, we recommend using either Deno or pnPm as your package manager which has first class support for JSR packages.
You can still use NPM, it will just require a bit more configuration.
Before you can use the Cerberus, you need to have Panda CSS installed and setup in your project. This is the preferred style engine for Cerberus.
Head over to the Panda CSS installation guide to get started.
Now that Panda is installed, you need to install the Cerberus preset package. We publish as many packages to JSR as possible to ensure a better experience for developers.
npx jsr add @cerberus/panda-presetpnpm add jsr:@cerberus/panda-presetdeno add jsr:@cerberus/panda-presetbunx jsr add @cerberus/panda-presetNext, update your PandaCSS config to utilize the Cerberus helpers:
import {
createCerberusConfig,
createCerberusPreset,
} from '@cerberus/panda-preset'
export default createCerberusConfig({
presets: [createCerberusPreset()],
include: [
'./app/**/*.{ts,tsx}'
],
exclude: [],
})The createCerberusConfig function adds the required Cerberus config settings
to PandaCSS along with any additional settings you pass into it.
The createCerberusPreset function does the same except on the preset level.
The core preset comes with the base "cerberus" theme and PandaCSS presets built in:
The Cerberus core preset includes a set of font helpers. In order to utilize them, your project needs to have your preferred fonts assigned to the following CSS variables:
--font-display: Any display heading text-style--font-sans: Any other text style--font-mono: Any monospace text styleIf using NextJS fonts, you can simply import and assign these with the fonts package:
import { Poppins, Recursive } from 'next/font/google'
const poppins = Poppins({
display: 'swap',
subsets: ['latin'],
weight: ['400', '600', '700'],
variable: '--font-sans',
})
const recursive = Recursive({
display: 'swap',
subsets: ['latin'],
weight: ['400'],
variable: '--font-mono',
})Because Cerberus provides multiple themes and modes out of the box, you need to initialize your root layout to trigger the default options you want to use.
To connect the Cerberus theme, add the required data attributes to your root html tag.
function RootLayout({ children }) {
return (
<html lang="en" data-panda-theme="cerberus" data-color-mode="light">
<body>{children}</body>
</html>
)
}Important: This is a good point to run the panda codegen command to
generate the Cerberus related additions.
Once this has been run, you can start using Cerberus styles and themes in your project. If you are interested in using the React library, continue
To add the React library to your project, continue in the guide.
Cerberus React assumes the baseUrl is setup to the root location in your tsconfig.json file.
If you do not, or use a different location, you should include a path alias for
the styled-system/* location. Not doing so will result in build errors.
// tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
// ...your config options
}
}Now that your base path is setup, you can install Cerberus React.
npm install @cerberus/react@npm:@cerberus-design/reactpnpm add @cerberus/react@npm:@cerberus-design/reactdeno add npm:@cerberus-design/reactbun add @cerberus/react@npm:@cerberus-design/reactpanda.config.tsAdd the build config to the include array so Panda can generate the styles.
import { createCerberusConfig, createCerberusPreset } from "@cerberus/panda-preset";
export default createCerberusConfig({
// ...your previous settings
include: [
"./node_modules/@cerberus/react/dist/panda.buildinfo.json",
"./app/**/*.{ts,tsx,js,jsx}",
],
});In order for components to have access to icons, you must wrap your application with the CerberusProvider context.
At this point, you are ready to start using Cerberus React.
React comes built in with the Carbon Icons set. However, if you prefer a different icon library, you can register it with Cerberus Context Provider.
Learn how to register custom icons with the Cerberus Context Provider
If you want to support multiple themes, you can use the presetAcheronTheme and getThemeName helpers to configure your theme.
import { createCerberusConfig, createCerberusPreset } from "@cerberus/panda-preset";
import { presetAcheronTheme, getThemeName } from "@cerberus/preset-acheron-theme";
export default createCerberusConfig({
clean: true,
preflight: true,
presets: [createCerberusPreset(), presetAcheronTheme],
include: [
"./node_modules/@cerberus/react/dist/panda.buildinfo.json",
"./app/**/*.{ts,tsx,js,jsx}",
],
staticCss: {
themes: ["cerberus", getThemeName()],
},
});To help make maintaining a breeze, add these scripts to your package.json to
use when you need to upgrade Cerberus:
"scripts": {
"up:cerby:npm-deps": "pnpm install @cerberus/react@npm:@cerberus-design/react@latest",
"up:cerby:jsr-deps": "pnpm add jsr:@cerberus/panda-preset && pnpm add jsr:@cerberus/preset-acheron-theme",
"up:cerberus": "pnpm run up:cerby:npm-deps && pnpm run up:cerby:jsr-deps && pnpm up @pandacss/dev@latest"
}Now you can update Cerberus and PandaCSS with a single command:
npm run up:cerberuspnpm run up:cerberusdeno run npm:up:cerberusbun run up:cerberusOn this page
'use client'
import { CerberusProvider } from '@cerberus/react'
import { type PropsWithChildren } from 'react'
export function CerberusConfig(props: PropsWithChildren) {
return <CerberusProvider>{props.children}</CerberusProvider>
}