You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rewrite the Panda guide around the errors agents actually make: dynamic
values that emit no CSS, Tailwind class strings, `var(--x)` instead of
token names, `:hover` instead of `_hover`, `md:` prefixes, and recipe
variant props that only emit defaultVariants. Each is a wrong-vs-right
pair with a one-line why.
This is what you need to write correct Panda here and stop guessing. The examples run Panda v2 (`2.0.0-beta.12`). The authoring API is the same as v1; what changed is the compiler and the way libraries ship and get consumed. Full docs are at <https://panda-css.com>. For the beta specifics, see the [v2 migration guide](https://github.com/chakra-ui/panda/blob/main/V2_MIGRATION.md).
3
+
Read this before you write a line of Panda in these examples. It's the API and, more to the point, the mistakes that trip up anyone coming from Tailwind or Panda v1. The examples run Panda v2 (`2.0.0-beta.12`). Full docs: <https://panda-css.com>. Beta specifics: the [v2 migration guide](https://github.com/chakra-ui/panda/blob/main/V2_MIGRATION.md).
4
4
5
-
Panda runs at build time. You write style objects, the CLI extracts them statically and generates atomic CSS plus a typed `styled-system/`. It can't see runtime values, so style with static ones.
5
+
## The one rule behind most mistakes: styles must be static
6
6
7
-
## Where to import from
7
+
Panda reads your code at build time and generates CSS from what it can see. It runs no JavaScript. If a style value isn't a literal it can read at the call site, it generates nothing, and you get a `className` with no CSS behind it. No error, just a missing style.
8
8
9
-
| You want | Import from |
10
-
| --- | --- |
11
-
|`css`, `cx`, `cva`, `sva`| local `styled-system/css`|
12
-
| patterns (`stack`, `hstack`, `grid`, …) | local `styled-system/patterns`|
13
-
| pattern JSX (`<Stack>`, `<Box>`) | local `styled-system/jsx`|
14
-
| generated recipe functions | local `styled-system/recipes`|
15
-
| the `token()` helper | local `styled-system/tokens`|
9
+
```tsx
10
+
// ❌ nothing is generated — the value isn't known at build time
11
+
css({ color: props.color })
12
+
css({ color: `red.${shade}` })
13
+
css({ color: colorByType[type] })
14
+
15
+
// ✅ literals, ternaries of literals, and same-file constants all work
16
+
const accent ='red.300'
17
+
css({ color: accent })
18
+
css({ color: isActive?'red.500':'red.600' }) // both classes emitted
19
+
```
16
20
17
-
Always the local `styled-system`, the one this app's `panda build` generated. Never from the `pandacn` package. The `standalone-app` example has no `styled-system` at all; see its AGENTS.md.
21
+
When a value is genuinely dynamic, pick one of these:
Use a raw `var(...)` only when you're deliberately holding a runtime value (see the static rule above). `token('colors.red.300')` reads a token in JS; `token.var('colors.red.300')` gives its var reference.
55
+
56
+
## The spacing scale: '4' is a token, '4px' is not
57
+
58
+
Quoted scale steps hit the token scale. A raw length bypasses it.
Dark mode here is class-based. The configs set `conditions: { extend: { dark: '.dark &' } }`, so `_dark` means "somewhere under a `.dark` ancestor". Toggle `.dark` on `<html>`, and semantic tokens apply their `_dark` values on their own.
52
-
53
-
## Responsive styles
80
+
Order matters: `_dark: { _backdrop: {…} }` is valid, the reverse isn't. Dark mode here is class-based: the configs set `dark: '.dark &'`, so `_dark` applies under a `.dark` ancestor. Toggle `.dark` on `<html>`; semantic tokens switch on their own.
54
81
55
-
Mobile-first, keyed by breakpoint (`base`, `sm`, `md`, `lg`, `xl`, `2xl`):
A recipe is variant-driven styling for one element. Author it with `defineRecipe`, register it in `panda.config.ts` under `theme.extend.recipes`, and Panda generates it into`styled-system/recipes`:
113
+
A recipe is variant-driven styling for one element. Author it with `defineRecipe`, register it in `panda.config.ts` under `theme.extend.recipes`, and consume the generated function from`styled-system/recipes`:
Inline `cva({...})` from `styled-system/css` works the same but is atomic, and it emits every variant. A config recipe is JIT: it only emits variants it sees used, so a dynamic prop like `button({ variant: someProp })` falls back to `defaultVariants` unless `staticCss` ships it. That's why these examples set `staticCss: { recipes: '*' }`. One more catch: `compoundVariants` turns off responsive and conditional variant props on a config recipe. The generated function also carries`.raw()`, `.variantKeys`, and `.splitVariantProps(props)`.
135
+
Fix a genuinely dynamic prop with `staticCss` on the recipe (`staticCss: ['*']`, or list the variants). These examples set `staticCss: { recipes: '*' }` in the config for exactly this reason. Two more catches: `compoundVariants` disables responsive variant props on a config recipe, and inline `cva({...})` from `styled-system/css` never supports responsive variant props (it does emit every variant, though). Recipe functions also carry`.raw()`, `.variantKeys`, and `.splitVariantProps(props)`.
97
136
98
-
## Recipes for multi-part components
137
+
## Multi-part components use slot recipes
99
138
100
-
For a component with several parts (a Card is root, header, title, and so on), use `defineSlotRecipe` and register it under `theme.extend.slotRecipes`. The generated function returns one class per slot:
139
+
For a component with parts (a Card is root, header, title), use `defineSlotRecipe` under `theme.extend.slotRecipes`. The generated function returns one class per slot:
Reference either by dot-path in `css()`: `bg: 'brand'`, `color: 'primary'`. A bare name resolves the token's `DEFAULT` key.
176
+
Then reference by dot-path in `css()`: `bg: 'brand'`, `color: 'primary'`. A bare name resolves the token's `DEFAULT` key.
140
177
141
-
## Composing styles across files with css.raw()
178
+
## Where to import from
142
179
143
-
`css.raw()` returns the style object instead of a class, so you can define styles in one file and compose them in another. v2 folds static named imports:
Always the local `styled-system`, the one this app's `panda build` generated. Never runtime helpers from the `pandacn` package. The `standalone-app` example has no `styled-system` at all; see its AGENTS.md.
150
190
151
191
## v2 beta gotchas
152
192
153
-
- ESM only, Node 22 or newer. No `require()`.`panda.config.ts` loads as ESM.
154
-
- Presets aren't auto-injected. A config needs `presets: ['@pandacss/preset-base', '@pandacss/preset-panda']`, or `designSystem`, which pulls them in. Without them you get a bare system: no `bg`/`color` utilities, no scales, no `_hover`. Both preset packages have to be installed.
155
-
-Re-run`panda build` after you change tokens, recipes, or patterns. These apps do it for you in `predev`/`prebuild`.
156
-
- Don't edit `styled-system/`. It's generated, and your changes are overwritten.
157
-
-`createStyleContext` is gone in v2. Use `createRecipeContext` for a `cva` recipe, `createSlotRecipeContext` for an `sva` one.
158
-
-Extraction is static at the call site. A prop renamed or forwarded through a wrapper (`<Button size={circleSize} />`) isn't tracked. Keep real prop names; for arbitrary ones, pass `css.raw({...})`.
159
-
-With `strictTokens` on, arbitrary values are rejected. Use the `[…]` escape hatch: `bg: '[#abc]'`, `fontSize: '[13px]'`. These examples don't turn it on.
193
+
- ESM only, Node 22 or newer. No `require()`.
194
+
- Presets aren't auto-injected. A config needs `presets: ['@pandacss/preset-base', '@pandacss/preset-panda']`, or `designSystem`, which pulls them in. Without them you get a bare system: no `bg`/`color`, no scales, no `_hover`. Both packages must be installed.
195
+
-Run`panda build` after changing tokens, recipes, or patterns, and before `styled-system` types exist. These apps do it in `predev`/`prebuild`.
196
+
- Don't edit `styled-system/`. It's generated and gets overwritten.
197
+
-`!important` is a suffix on the value: `css({ color: 'red!' })`.
198
+
-With `strictTokens` on, arbitrary values are rejected. Escape with brackets: `bg: '[#abc]'`, `fontSize: '[13px]'`. These examples don't turn it on.
199
+
-`createStyleContext` is gone. Use `createRecipeContext` (cva) or `createSlotRecipeContext` (sva).
160
200
161
201
## Shipping and consuming the design system
162
202
163
-
Here's how`pandacn` reaches the three apps. The `monorepo` example is the source.
203
+
How`pandacn` reaches the three apps. The `monorepo` example is the source.
164
204
165
-
-Shipping: `panda lib` builds `dist/panda/lib.json`, a `preset.mjs`, and build info, then syncs `package.json` exports. It bundles the whole system, every token, recipe, and variant, which is why the source sets `staticCss: { recipes: '*' }`.
166
-
-Consuming with Panda: the app sets `designSystem: 'pandacn'` in `panda.config.ts`. Panda resolves `pandacn/panda/lib.json`, merges its preset, and the app emits only its own additions. You import from the app's local `styled-system`.
167
-
-Consuming without Panda: import the prebuilt `pandacn/styles.css` and the React components. That's the `standalone-app` example.
205
+
-Ship: `panda lib` builds `dist/panda/lib.json`, a `preset.mjs`, and build info, then syncs `package.json` exports. It bundles every token, recipe, and variant, which is why the source sets `staticCss: { recipes: '*' }`.
206
+
-Consume with Panda: set `designSystem: 'pandacn'` in `panda.config.ts`. Panda merges its preset and the app emits only its own additions. Import from the app's local `styled-system`.
207
+
-Consume without Panda: import the prebuilt `pandacn/styles.css` and the React components. That's the `standalone-app` example.
0 commit comments