9.2 KiB
Claude's Learning Document - Chakra UI
Last Updated: September 30, 2025
Project Overview
Chakra UI is a comprehensive React component system for building accessible, high-quality web applications and design systems. It emphasizes speed, accessibility, and works seamlessly with modern frameworks like Next.js (including RSC support).
- Repository: https://github.com/chakra-ui/chakra-ui
- Author: Segun Adebayo
- License: MIT
- Version: 2.0.0
- Package Manager: pnpm 10.15.0
- Node Version: >=20.x
Project Structure
Root Directory
chakra-ui/
├── packages/ # Core packages
├── apps/ # Applications (www docs, mcp server)
├── sandbox/ # Testing environments
├── scripts/ # Build and utility scripts
├── .changeset/ # Changesets for versioning
└── package.json # Root package configuration
Key Packages
-
packages/react- Main React component library- Core system implementation
- Styled-system utilities
- Component recipes
- Type definitions
-
packages/cli- CLI tools for Chakra UI- Type generation
- Token management
-
packages/charts- Chart components -
packages/panda-preset- Panda CSS preset for Chakra
Apps
apps/www- Documentation website (https://chakra-ui.com)apps/mcp- MCP server for AI integrationsapps/compositions- Component compositions examples
Sandbox Environments
Multiple sandbox projects for testing in different environments:
next-app/,next-pages/- Next.js testingvite-ts/,vite-jsx/- Vite testingremix-ts/- Remix testingreact-router/- React Router testingstorybook-ts/- Storybook testingshadow-dom/- Shadow DOM testing
Styled System Architecture
The styled-system is the heart of Chakra UI's styling engine. Located in
packages/react/src/styled-system/:
Core Files
-
system.ts- Main system creation and configuration- Creates the Chakra system instance
- Integrates tokens, breakpoints, conditions, and utilities
- Provides CSS-in-JS functionality
-
cva.ts(Class Variance Authority) - Recipe creation- Handles variant-based styling
- Processes base styles, variants, and compound variants
- Recent Fix: Now properly handles bracket syntax for responsive styles in recipes
-
sva.ts(Slot Variance Authority) - Multi-slot recipe creation- For components with multiple parts (slots)
- Each slot can have its own variants
-
token-dictionary.ts- Token management- Token resolution and transformation
- Semantic token handling
- Color palette expansion
-
breakpoints.ts- Responsive breakpoint system- Converts breakpoint names to media queries
- Handles array syntax for responsive values
-
conditions.ts- Conditional styling- Pseudo-selectors (:hover, :focus, etc.)
- Data attributes
- Media queries
-
utility.ts- Utility function management- Property transformations
- CSS property mappings
-
calc.ts- CSS calc() utilities- Mathematical operations in CSS
Style Resolution Flow
- User defines styles (tokens, recipes, variants)
normalize()processes raw style objects- Breakpoint arrays
[value1, value2]→ responsive object{base: value1, sm: value2} - Tokens get resolved from token dictionary
- Conditions get applied (media queries, pseudo-selectors)
- CSS output is generated with proper layering
Recent Work: Recipe Bracket Syntax Fix
Problem
Array/bracket syntax for responsive styles wasn't working correctly in recipe variants:
const recipe = system.cva({
variants: {
variant: {
primary: {
color: ["red", "green"], // ❌ Wasn't converting to breakpoints
},
},
},
})
Solution
Enhanced the normalization process in the recipe system to handle bracket syntax properly. The fix ensures that:
- Base styles support bracket syntax
- Variant styles support bracket syntax
- Compound variants support bracket syntax
- Mixed bracket and object syntax works correctly
Modified Files
packages/react/src/styled-system/breakpoints.tspackages/react/src/styled-system/calc.tspackages/react/src/styled-system/conditions.tspackages/react/src/styled-system/cva.tspackages/react/src/styled-system/sva.tspackages/react/src/styled-system/system.tspackages/react/src/styled-system/token-dictionary.tspackages/react/src/styled-system/utility.tspackages/react/src/utils/entries.ts
Test Coverage
Created comprehensive tests in packages/react/__tests__/recipe.test.ts:
- ✅ Bracket syntax in recipe variants (original issue)
- ✅ Bracket syntax in base styles
- ✅ Object syntax as control test
- ✅ Multiple properties with bracket syntax
- ✅ Multiple breakpoints (3+ values)
- ✅ Compound variants with bracket syntax
- ✅ Mixed bracket and object syntax
- ✅ Partial breakpoint values
- ✅ Multiple variant options with bracket syntax
Changeset
Created .changeset/fix-recipe-bracket-syntax.md documenting the fix for
release notes.
Build Scripts
Core Commands
pnpm build # Build all packages
pnpm build:fast # Fast build (no type checking)
pnpm dev # Watch mode for all packages
pnpm test # Run Vitest tests
pnpm typecheck # TypeScript type checking
Token Generation
pnpm build:tokens # Generate TypeScript types from tokens
pnpm build:tokens-dev # Generate tokens locally
Package Management
pnpm react # Run commands in @chakra-ui/react
pnpm www # Run commands in docs site
pnpm mcp # Run commands in MCP server
Quality Assurance
pnpm lint # ESLint
pnpm format:check # Prettier check
pnpm format:write # Prettier format
Release Management
pnpm version # Create version with changesets
pnpm release # Publish to npm
pnpm version:dev # Create dev snapshot version
pnpm release:dev # Publish dev version
Key Technologies
- React 19.1.1 with Server Components support
- TypeScript 5.8.3 for type safety
- Vite 7.0.0 for bundling and dev server
- Vitest 3.2.4 for testing
- Panda CSS preset for styling
- Changesets for version management
- Rollup for package bundling
- Storybook 9.1.8 for component development
Testing Philosophy
- Unit tests with Vitest
- Accessibility tests with vitest-axe
- Component tests with @testing-library/react
- Integration tests in sandbox environments
- Storybook for visual testing
Key Design Principles
- Accessibility First - WCAG compliant components
- Type Safety - Full TypeScript support
- Performance - Optimized style resolution
- Developer Experience - Intuitive APIs
- Composability - Build complex UIs from simple primitives
- Responsive - Mobile-first design patterns
- Themeable - Customizable design tokens
Current Git Status
Staged Files (Recent Work)
.changeset/fix-recipe-bracket-syntax.md- Changeset for recipe fixpackages/react/__tests__/recipe.test.ts- New test suite- Multiple styled-system files (modified for bracket syntax support)
Recent Commits
96edd4393- docs: password input example5b2bc851f- fix(www): update showcase navigationc58b20530- docs: ai rulese59f66e19- docs: update focus ring451209e75- fix(table): ensure stickyHeader works with outline variant
Learning Insights
Responsive Style Patterns
Bracket Syntax (Array)
color: ["red", "green", "blue"]
// Maps to: base=red, sm=green, md=blue
Object Syntax
color: { base: 'red', sm: 'green', md: 'blue' }
Both are equivalent and should work interchangeably throughout the system.
Recipe System
CVA (Class Variance Authority) - Single component styling
const button = system.cva({
base: {
/* base styles */
},
variants: {
/* variants */
},
compoundVariants: [
/* combinations */
],
defaultVariants: {
/* defaults */
},
})
SVA (Slot Variance Authority) - Multi-part component styling
const card = system.sva({
slots: ["root", "header", "body", "footer"],
base: {
/* styles per slot */
},
variants: {
/* variants per slot */
},
})
Token System
- Semantic tokens reference base tokens
- Color palettes auto-expand (50-950 scales)
- Tokens can use CSS variables
- Token dictionary handles resolution and transformation
Next Steps / Areas to Explore
- Understanding the component architecture in
packages/react/src/components/ - Deep dive into the Panda CSS integration
- MCP server capabilities for AI integrations
- Documentation generation system
- CLI tooling for scaffolding and code generation
- Performance optimization strategies
- Build pipeline and bundle optimization
This document serves as a living knowledge base for Claude to maintain context about the Chakra UI project structure, recent changes, and architectural decisions.