Overview
A guide for configuring the Cerberus theming system.
Architecture
The Cerberus theming system is built around the API of Panda CSS.
Here's a quick overview of how the system is structured to provide a performant and extensible styling system:
- Define the styling system configuration using the
createCerberusConfig
function - Create the styling engine using the
makeSystemConfig
function - Pass the styling engine to the
CerberusProvider
component
1'use client'2
3import {4 CerberusProvider,5 defineIcons,6 makeSystemConfig,7} from '@cerberus-design/react'8import {9 Calendar,10 Checkmark,11 CheckmarkOutline,12 ChevronDown,13 ChevronLeft,14 ChevronRight,15 Close,16 CloudUpload,17 Information,18 Restart,19 TrashCan,20 UserFilled,21 Warning,22 WarningAlt,23 WarningFilled,24} from '@carbon/icons-react'25import type { PropsWithChildren } from 'react'26
27const icons = defineIcons({28 accordionIndicator: ChevronDown,29 avatar: UserFilled,30 calendar: Calendar,31 calendarPrev: ChevronLeft,32 calendarNext: ChevronRight,33 close: Close,34 confirmModal: Information,35 delete: TrashCan,36 promptModal: Information,37 waitingFileUploader: CloudUpload,38 infoNotification: Information,39 successNotification: CheckmarkOutline,40 warningNotification: WarningAlt,41 dangerNotification: WarningFilled,42 invalid: WarningFilled,43 invalidAlt: Warning,44 redo: Restart,45 selectArrow: ChevronDown,46 selectChecked: Checkmark,47 toggleChecked: Checkmark,48})49
50const config = makeSystemConfig({51 icons,52})53
54export default function CerberusConfig(props: PropsWithChildren<{}>) {55 return <CerberusProvider config={config}>{props.children}</CerberusProvider>56}
Config
The Cerberus system is configured using the createCerberusConfig
function. This function accepts a configuration object that allows you to customize the styling system's behavior.
After a config is defined, the makeSystemConfig
function creates internal options for Cerberus components to utilize when needed.
cssVarRoot
cssVarRoot
is the root element where the token CSS variables will be applied.
1export default createCerberusConfig({2 cssVarRoot: ":where(:root, :host)",3})
globalCss
globalCss
is used to apply global styles to the system. This will not be atomized, and will be applied to the root element.
1export default createCerberusConfig({2 globalCss: {3 "html, body": {4 margin: 0,5 padding: 0,6 },7 },8})
preflight
preflight
is used to apply css reset styles to the system.
1export default createCerberusConfig({2 preflight: false,3})
Alternatively, you can use the preflight
config property to apply css reset
styles to the system. This is useful if you want to apply css reset styles to a
specific element.
1export default createCerberusConfig({2 preflight: {3 scope: ".custom-reset",4 },5})
theme
Use the theme
config property to define the system theme. This property
accepts the following properties:
breakpoints
: for defining breakpointskeyframes
: for defining css keyframes animationstokens
: for defining primitive tokenssemanticTokens
: for defining semantic tokens (which consume primitive tokens)textStyles
: for defining typography styleslayerStyles
: for defining layer stylesanimationStyles
: for defining animation stylesrecipes
: for defining component recipesslotRecipes
: for defining component slot recipes
1export default createCerberusConfig({2 theme: {3 breakpoints: {4 sm: "320px",5 md: "768px",6 lg: "960px",7 xl: "1200px",8 },9 tokens: {10 colors: {11 red: "#EE0F0F",12 },13 },14 semanticTokens: {15 colors: {16 customRed: { value: "{colors.red}" },17 },18 },19 keyframes: {20 spin: {21 from: { transform: "rotate(0deg)" },22 to: { transform: "rotate(360deg)" },23 },24 },25 },26})
conditions
Use the conditions
config property to define custom selectors and media query
conditions for applying conditional styles in the system.
1export default createCerberusConfig({2 conditions: {3 cqSm: "@container(min-width: 320px)",4 child: "& > *",5 },6})
Sample usage:
1<Box mt="40px" _cqSm={{ mt: "0px" }}>2 <Text>Hello World</Text>3</Box>
strictTokens
Use the strictTokens
config property to enforce the usage of only design
tokens. This will throw a TS error if you try to use a token that is not defined
in the theme.
1export default createCerberusConfig({2 strictTokens: true,3})
1// ❌ This will throw a TS error2<Box color="#4f343e">Hello World</Box>3
4// ✅ This will work5<Box color="red.400">Hello World</Box>
TypeScript
When you configure the system properties (like colors
, space
, fonts
,
etc.), the Panda CLI can be used to generate type definitions for them.
1npm panda codegen
This will update the internal types in the styled-system
directory, and make
sure they are in sync with the theme. Providing a type-safe API and delightful
experience for developers.
System
After a config is defined, it is passed to the makeSystemConfig
function to create low level options that become internally available to components.
1const icons = defineIcons({...})2const config = makeSystemConfig({3 icons,4})
The system includes the following properties:
icons
The token function is used to create a mapping of icon names to their respective icon components. This allows you to easily reference and use custom icons throughout your application for the Cerberus components that depend on rendering icons for their functionality.
1import { defineIcons } from '@cerberus-design/react'2import { Calendar, Checkmark } from '@carbon/icons-react'3
4const icons = defineIcons({5 calendar: Calendar,6 checkmark: Checkmark,7})
Tokens
To learn more about tokens, please refer to the tokens section.
Recipes
To learn more about recipes, please refer to the recipes section.
On this page