From 8bce12bda388e2ce98ff6d9c2c729fdc51d5f969 Mon Sep 17 00:00:00 2001 From: Adebesin Tolulope Date: Fri, 14 Aug 2026 10:05:31 +0100 Subject: [PATCH 1/3] docs: add agent guides and a Panda reference per example Coding agents kept guessing at Panda and mixing up the three setups. Each example now ships an AGENTS.md with wiring for that setup and a PANDA.md with the authoring API, the v2-beta facts these examples rely on, and the mistakes to avoid. PANDA.md and AGENTS.md are copied into every example folder so a single folder pulled with degit stays complete. The root AGENTS.md points to both and notes the copies are kept in sync. --- AGENTS.md | 6 ++ PANDA.md | 167 ++++++++++++++++++++++++++++++ examples/monorepo/AGENTS.md | 49 +++++++++ examples/monorepo/PANDA.md | 167 ++++++++++++++++++++++++++++++ examples/panda-app/AGENTS.md | 24 +++++ examples/panda-app/PANDA.md | 167 ++++++++++++++++++++++++++++++ examples/standalone-app/AGENTS.md | 24 +++++ examples/standalone-app/PANDA.md | 167 ++++++++++++++++++++++++++++++ 8 files changed, 771 insertions(+) create mode 100644 PANDA.md create mode 100644 examples/monorepo/AGENTS.md create mode 100644 examples/monorepo/PANDA.md create mode 100644 examples/panda-app/AGENTS.md create mode 100644 examples/panda-app/PANDA.md create mode 100644 examples/standalone-app/AGENTS.md create mode 100644 examples/standalone-app/PANDA.md diff --git a/AGENTS.md b/AGENTS.md index 6250085..77be7b9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,6 +10,12 @@ Panda CSS examples. Each folder under `examples/` is a standalone project you ca The design system source is `examples/monorepo/packages/ds/src` — tokens in `theme/`, one folder per component. +## Writing Panda + +Read [PANDA.md](PANDA.md) before writing styles. It covers the authoring API (`css()`, conditions, recipes, patterns, tokens), the v2-beta facts these examples rely on, and the mistakes to avoid. Each example also has its own `AGENTS.md` with wiring for that setup. + +Because each example is a standalone folder (people pull one with `degit`), every example carries its own copy of `PANDA.md` and `AGENTS.md`. They're duplicates on purpose. When you edit the copy here, update the ones under `examples/*/` too. + ## Conventions - Examples are **standalone**: pinned dependency versions, no `workspace:*` (except the `monorepo` example, which is itself a workspace). diff --git a/PANDA.md b/PANDA.md new file mode 100644 index 0000000..fd2c218 --- /dev/null +++ b/PANDA.md @@ -0,0 +1,167 @@ +# How to write Panda in these examples + +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 . For the beta specifics, see the [v2 migration guide](https://github.com/chakra-ui/panda/blob/main/V2_MIGRATION.md). + +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. + +## Where to import from + +| You want | Import from | +| --- | --- | +| `css`, `cx`, `cva`, `sva` | local `styled-system/css` | +| patterns (`stack`, `hstack`, `grid`, …) | local `styled-system/patterns` | +| pattern JSX (``, ``) | local `styled-system/jsx` | +| generated recipe functions | local `styled-system/recipes` | +| the `token()` helper | local `styled-system/tokens` | + +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. + +## Writing styles with css() + +```ts +css({ + display: 'flex', + px: '4', py: '2', // shorthands; '4' is a spacing token + bg: 'primary', // token dot-path (a semantic token) + color: 'red.400', // token dot-path (a scale token) + rounded: 'md', + width: '760px', // arbitrary value, just a string + background: 'var(--colors-frame-brand)', // a raw CSS var when you need one +}) +``` + +Token names resolve to CSS vars; arbitrary values pass straight through. To read a token in JS, use `token('colors.primary')`. + +## Conditions: pseudo, state, and selectors + +Underscore keys are conditions. String keys with `&` are raw selectors. + +```ts +css({ + color: 'ink', + _hover: { color: 'brand' }, + _focusVisible: { boxShadow: '0 0 0 3px …' }, + _disabled: { opacity: 0.5 }, + _dark: { color: 'white' }, + '& svg': { flexShrink: 0 }, + '&[data-state=open]': { bg: 'card' }, +}) +``` + +Dark mode here is class-based. The configs set `conditions: { extend: { dark: '.dark &' } }`, so `_dark` means "somewhere under a `.dark` ancestor". Toggle `.dark` on ``, and semantic tokens apply their `_dark` values on their own. + +## Responsive styles + +Mobile-first, keyed by breakpoint (`base`, `sm`, `md`, `lg`, `xl`, `2xl`): + +```ts +css({ paddingInline: { base: '5', md: '8' }, fontSize: { base: 'sm', lg: 'md' } }) +``` + +The array form `['5', '8']` maps to breakpoints in order. Prefer the object form; it says what it means. + +## Combining classes with cx() + +`cx()` joins class strings and resolves atomic conflicts, last one wins. Reach for it in any component that takes a `className`: + +```ts +cx(button({ variant, size }), css({ mt: '2' }), className) +``` + +## Recipes for a single element + +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`: + +```ts +export const button = defineRecipe({ + className: 'btn', + jsx: ['Button'], + base: { display: 'inline-flex', rounded: 'md' }, + variants: { + variant: { default: { bg: 'primary' }, ghost: { bg: 'transparent' } }, + size: { sm: { h: '8' }, md: { h: '9' } }, + }, + compoundVariants: [{ variant: 'ghost', size: 'sm', css: { px: '2' } }], + defaultVariants: { variant: 'default', size: 'md' }, +}) +``` + +The generated function returns a class string: + +```tsx +import { button } from '../../styled-system/recipes' +