This document describes the Panda CSS integration for the Isolate UI component library.
Panda CSS is integrated as a zero-runtime styling engine that uses the design tokens from Style Dictionary. The integration provides type-safe styling with automatic mapping to CSS variables.
libs/shared/tokens/ → Style Dictionary tokens (source of truth)
├── src/tokens.json → Token definitions
└── gen/
├── ts/tokens.ts → TypeScript tokens
└── css/variables.css → CSS variables (--isolate-*)
panda.config.ts → Panda CSS configuration
styled-system/ → Generated Panda CSS styling engine (shared)
The panda.config.ts automatically transforms Style Dictionary tokens into Panda CSS theme tokens:
- Colors:
colors.primary.500→var(--isolate-color-primary-500) - Spacing:
spacing.4→var(--isolate-spacing-4) - Typography:
fonts.sans→var(--isolate-typography-font-family-sans)fontSizes.base→var(--isolate-typography-font-size-base)fontWeights.semibold→var(--isolate-typography-font-weight-semibold)lineHeights.normal→var(--isolate-typography-line-height-normal)
The configuration enables strictPropertyValues: true and strictTokens: true to encourage token usage for design-critical properties (colors, spacing, fonts).
Type Safety: Panda CSS provides TypeScript autocomplete and type-checking for token values:
// ✅ Valid - using tokens
css({ color: 'primary.500', padding: '4' });
// ✅ Valid - using escape hatch for edge cases
css({ color: '[#ff0000]' });
// ❌ TypeScript will suggest valid tokens
// (arbitrary values require bracket notation)import { css } from 'styled-system/css';export function Button({ children }: ButtonProps) {
return (
<button
className={css({
backgroundColor: 'primary.500',
color: 'neutral.0',
padding: '4',
borderRadius: '2',
fontWeight: 'semibold',
fontSize: 'base',
})}
>
{children}
</button>
);
}The CSS variables need to be imported in your application's entry point:
// src/main.tsx or src/index.tsx
import '@isolate-ui/tokens/gen/css/variables.css';# Generate styled-system for all libraries
pnpm exec panda codegen
# Generate via Nx for a specific library
pnpm nx codegen react-buttonThe styled-system is automatically regenerated when:
- Post-install: Running
pnpm installtriggerspreparescript - Via Nx cache: The
codegentarget is configured with outputs inproject.json
Add the codegen target to your library's project.json:
{
"targets": {
"codegen": {
"executor": "nx:run-commands",
"options": {
"command": "pnpm exec panda codegen",
"cwd": "{workspaceRoot}"
},
"outputs": ["{workspaceRoot}/styled-system"]
}
}
}Allow styled-system imports in your library's eslint.config.mjs:
export default [
...baseConfig,
{
files: ['**/*.ts', '**/*.tsx'],
rules: {
'@nx/enforce-module-boundaries': [
'error',
{
allow: ['^styled-system/'],
},
],
},
},
];The styled-system directory provides:
styled-system/css: Core styling functionstyled-system/tokens: Token utilities and typesstyled-system/patterns: Layout patternsstyled-system/jsx: Styled JSX elements (React)
TypeScript types are automatically generated and provide:
- Autocomplete for token values
- Type-safe color, spacing, and typography tokens
- Proper inference for responsive values and conditions
- Use semantic tokens: Prefer
primary.500over arbitrary colors - Escape hatch when needed: Use
[value]syntax for one-off values - Leverage patterns: Use Panda's layout patterns for common layouts
- Responsive design: Use Panda's responsive syntax for breakpoints