Consume with Panda
Point an app at a design system with one config field.
If your app runs Panda too, it can build on top of a design system instead of just loading its CSS. You get the design
system's tokens and recipes in your own css() calls, can extend its theme, and ship one stylesheet that covers both.
(Not running Panda in the app? See Consume without Panda.)
It takes one config field. Install the package and point designSystem at it:
panda.config.ts
export default defineConfig({
designSystem: '@acme/ds',
include: ['src/**/*.{ts,tsx}']
})From there, Panda loads the design system's theme and reuses the styles it already extracted, so its source isn't
scanned again. Imports from @acme/ds and from your local styled-system are both recognized.
The preset, importMap, and build info all come from the package. You don't need to add them yourself:
panda.config.ts
export default defineConfig({
designSystem: '@acme/ds',
presets: ['@acme/ds/preset'], // ❌ already loaded
importMap: '@acme/ds', // ❌ already resolved
include: ['src/**/*.{ts,tsx}', '@acme/ds'] // ❌ errors: design_system_in_include
})Add the dependency
package.json
{
"dependencies": {
"@acme/ds": "workspace:*"
},
"devDependencies": {
"@pandacss/dev": "^2.0.0",
"@pandacss/vite": "^2.0.0"
}
}Outside the monorepo, use the published version ("@acme/ds": "^1.0.0").
Extend the theme
Extend it like any preset:
panda.config.ts
import { defineConfig } from '@pandacss/dev'
export default defineConfig({
designSystem: '@acme/ds',
include: ['src/**/*.{ts,tsx}'],
outdir: 'styled-system',
theme: {
extend: {
tokens: {
spacing: {
6: { value: '1.5rem' }
}
}
}
}
})If @acme/ds also defines spacing.6, yours wins. Panda reports design_system_token_conflict (info).
Your additions type-check in the design system
The design system's types accept what you add, with nothing to set up:
import type { SystemStyleObject } from '@acme/ds/types'
import { css } from '../styled-system/css'
const styles: SystemStyleObject = css.raw({ padding: '6' }) // `spacing.6` is yours- The design system needs a
./typesexport.panda libwrites it. - Use
designSystem. Importing its config as a preset doesn't share types. - Don't rename or remove tokens it uses. Its components follow your types.
- Type-check one app per
tsconfig. Two apps in one program conflict (TS2717).
Wire up the bundler
Add the Panda plugin. It generates CSS for your app and the design system's components:
vite.config.ts
import pandacss from '@pandacss/vite'
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
export default defineConfig({
plugins: [pandacss(), react()]
})Or with PostCSS:
postcss.config.mjs
import pandacss from '@pandacss/postcss'
export default {
plugins: [pandacss()]
}styled-system must exist before the bundler's first run:
package.json
{
"scripts": {
"predev": "panda codegen",
"prebuild": "panda codegen"
}
}Add the entry CSS
Declare the layer order. The plugin injects the CSS itself:
src/index.css
@layer reset, base, tokens, recipes, utilities;src/main.tsx
import { createRoot } from 'react-dom/client'
import { App } from './app'
import './index.css'
createRoot(document.getElementById('root')!).render(<App />)Import components and css
src/app.tsx
import { Button } from '@acme/ds'
import { css } from '../styled-system/css'
export function App() {
return (
<main className={css({ color: 'brand', p: '6' })}>
<Button>Welcome</Button>
</main>
)
}Import css from your local styled-system when the app extends the theme, so it's typed against both. With no
additions, @acme/ds/css works too.
What the app generates
Your styled-system re-exports the design system's runtime instead of shipping a second copy:
styled-system/css/index.js
export * from '@acme/ds/css/css'
export * from '@acme/ds/css/cva'
export * from '@acme/ds/css/cx'
// …What stays re-exported depends on what the app adds:
- Nothing, or only recipes and patterns: the design system's runtime is re-exported. Your own recipes and patterns are generated next to it.
- Tokens, utilities, conditions, or breakpoints: the full tree is generated locally. The design system's recipes
call its
css(), so they can't be re-exported oncecss()is local. jsxFramework,jsxStyleProps,syntax, or a nested design system: the full tree is generated locally.
Add your own recipes
panda.config.ts
export default defineConfig({
designSystem: '@acme/ds',
theme: {
extend: {
recipes: {
panel: {
className: 'panel',
base: { display: 'flex', flexDirection: 'column', gap: '3', p: '3' }
}
}
}
}
})src/app.tsx
import { Button } from '@acme/ds'
import { panel } from '../styled-system/recipes'
export function App() {
return (
<div className={panel()}>
<Button>Welcome</Button>
</div>
)
}The generated recipes index mixes both:
styled-system/recipes/index.js
export * from '@acme/ds/recipes/button'
export * from './panel'Name a recipe the design system already ships and yours wins. Panda warns with design_system_artifact_conflict.
Isolate styles with a prefix
An app and an embedded widget can ship different versions of the design system. Both emit .button and --colors-brand
with different rules, and the cascade keeps one. Set prefix in the design system, keyed to its major version:
packages/ds/panda.config.ts
export default defineConfig({
prefix: 'acme-ds-v1' // .button → .acme-ds-v1-button
})Apps inherit it through designSystem. Leave prefix, hash, and separator unset in the app: the design system's
components are built with its prefix, so overriding it leaves them unstyled. Panda warns with
design_system_option_mismatch.
This works for one Panda build per page. With Module Federation, each app needs its own prefix, so designSystem
doesn't fit. See Module Federation.
More on prefixes: Style isolation.
Nested design systems
A design system can extend another. Point at the leaf package:
panda.config.ts
export default defineConfig({
designSystem: '@acme/marketing-ds'
})Panda merges the parent chain root-first. The app generates a full local styled-system.
To ship CSS only for the components you import, turn on tree-shaking:
panda.config.ts
export default defineConfig({
designSystem: '@acme/marketing-ds',
optimize: { treeshakeDesignSystem: true }
})Parent components a selected component depends on are kept. Namespace and side-effect imports keep everything.
You can't point designSystem at two unrelated packages. If the second only consumes the first, put it in include.
Building the child package? See Extend another design system.
Troubleshooting
| Code | What to do |
|---|---|
design_system_manifest_not_found / design_system_manifest_not_exported | The package has no ./panda/* export. The author runs panda lib and republishes. Then reinstall. |
design_system_export_missing | A styled-system subpath (./css, ./recipes) is missing. Same fix. |
design_system_peer_range_unsatisfied | This app's Panda major does not match the package. Upgrade them together. |
design_system_in_include | Move the package from include to designSystem. |
design_system_buildinfo_stale | Panda re-extracted fallback files. Styles stay correct. If it persists, the author republishes. |
design_system_token_conflict / design_system_artifact_conflict | Expected when you override on purpose. |
More cases: Troubleshooting.
Example
npx degit chakra-ui/panda-examples/examples/panda-app my-appA Next.js app using a published design system (source (opens in a new tab)).