Design ↔ Code
Overview
Pencil enables a two-way workflow between design and code:
- Design → Code: Generate components from Pencil designs
- Code → Design: Import existing code into Pencil
Design → Code Workflow
Basic Export to Code
- Design in Pencil - Design your screens, layouts or individual UI components on the canvas
- Save the
.penfile in your project workspace - Open AI chat - Press
Cmd/Ctrl + K - Ask Pencil to generate code
Example Prompts
Component generation
Create a React component for this buttonGenerate TypeScript types for this formExport this card as a reusable componentFull pages
Generate a Next.js page from this designCreate a landing page component with Tailwind CSSExport this dashboard as a React componentWith specific libraries
Generate code using Shadcn UI componentsCreate this form using React Hook FormExport using Lucide icons instead of Material IconsCode → Design Workflow
Importing Existing Code
If you have existing components in your codebase, Pencil can recreate them visually.
Requirements:
- Keep the
.penfile in the same workspace as your code - The AI agent can access both files
Workflow:
- Open your
.penfile - Open AI chat - Press
Cmd/Ctrl + K - Ask to import code
Example Prompts
Recreate the Button component from src/components/Button.tsxImport the LoginForm from my codebase into this designAdd the Header component from src/layouts/Header.tsxWhat gets imported:
- Component structure and hierarchy
- Layout and positioning
- Styling (colors, typography, spacing)
Two-Way Sync
Keeping Design and Code in Sync
The most powerful workflow combines both directions:
- Start with code - Import existing components into Pencil
- Design improvements - Make visual changes in Pencil
- Update code - Ask AI to apply changes back to code
- Iterate - Repeat as needed
Variables & Design Tokens
CSS Variables ↔ Pencil Variables
Create a synchronized design token system:
Import CSS to Pencil:
- Have a
globals.cssor similar file with CSS variables - Ask the agent:
Create Pencil variables from my globals.cssImport design tokens from src/styles/tokens.cssExport Pencil to CSS:
- Define variables in Pencil
- Ask the agent:
Update globals.css with these Pencil variablesSync these design tokens to my CSSBest Practices
File Organization
Keep .pen files in your repo:
my-project/
├── src/
│ ├── components/
│ └── styles/
├── design.pen ← Design file
└── package.jsonBenefits:
- AI agent can see both design and code
- Version control tracks both together
- Easy to keep in sync
Workflow Recommendations
Start new features:
- Design in Pencil first
- Generate initial code
- Refine code implementation
- Update design if needed
Update existing features:
- Import component into Pencil
- Make design changes
- Sync changes back to code
Design system maintenance:
- Define variables in Pencil
- Sync to CSS
- Use variables in both design and code
- Update once, apply everywhere
Popular Stacks & Libraries
Pencil is not limited to a specific framework — you can ask the AI to generate code for any stack. Here are some commonly used options:
Frameworks:
- React (JavaScript or TypeScript), Next.js, Vue, Svelte, plain HTML/CSS
Styling:
- Tailwind CSS, CSS Modules, Styled Components, plain CSS
Component Libraries:
- shadcn/ui, Radix UI, Chakra UI, Material UI, or your own custom components
Specifying Your Stack
Mention your preferred technologies in the prompt so the AI generates code that fits your project:
Generate Next.js 14 code with Tailwind CSSCreate a Vue component using TypeScriptUse shadcn/ui components for this layoutIcon Libraries
Built-in vs Code Libraries
In Pencil:
- Pencil includes the following built-in icon libraries: Material Symbols (Outlined, Rounded, Sharp), Lucide Icons, Feather, and Phosphor.
- You can also import your own SVG icons the same way as individual images.
For code generation:
- Specify your preferred library in prompts
- Common options: Lucide, Heroicons, FontAwesome, React Icons
Example:
Generate this design using Lucide iconsReplace Material Icons with Heroicons in the code