@bravostudioai/react 0.1.28 → 0.1.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +589 -0
- package/package.json +1 -1
- package/src/codegen/generator.ts +74 -0
- package/src/codegen/parser.ts +47 -707
- package/src/codegen/propQualification.ts +284 -0
- package/src/components/EncoreApp.tsx +92 -540
- package/src/components/EncoreContextProviders.tsx +60 -0
- package/src/hooks/useFontLoader.ts +84 -0
- package/src/hooks/usePusherUpdates.ts +14 -23
- package/src/hooks/useRepeatingContainers.ts +147 -0
- package/src/index.ts +4 -1
- package/src/lib/dataPatching.ts +78 -0
- package/src/lib/dynamicModules.ts +8 -9
- package/src/lib/fetcher.ts +2 -9
- package/src/lib/logger.ts +53 -0
- package/src/lib/moduleRegistry.ts +3 -1
- package/src/stores/useEncoreState.ts +62 -2
- package/src/version.ts +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,589 @@
|
|
|
1
|
+
# @bravostudioai/react
|
|
2
|
+
|
|
3
|
+
> Stream your Figma designs directly into production-ready, type-safe React components for your MCP apps.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@bravostudioai/react)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://reactjs.org/)
|
|
8
|
+
|
|
9
|
+
**The Figma → React Pipeline:**
|
|
10
|
+
- 🎨 Design in Figma → Stream to typed React components
|
|
11
|
+
- 🤖 Perfect for MCP (Model Context Protocol) apps
|
|
12
|
+
- 🔒 100% TypeScript with full IntelliSense support
|
|
13
|
+
- 🚀 Zero configuration, instant productivity
|
|
14
|
+
- 📝 Auto-generated documentation for every component
|
|
15
|
+
- 🎯 Human-readable prop names, not cryptic IDs
|
|
16
|
+
|
|
17
|
+
**At a Glance:**
|
|
18
|
+
|
|
19
|
+
| Feature | Included |
|
|
20
|
+
|---------|----------|
|
|
21
|
+
| TypeScript Interfaces | ✅ Yes |
|
|
22
|
+
| Form Handling | ✅ Yes |
|
|
23
|
+
| Event Handlers | ✅ Yes |
|
|
24
|
+
| List/Array Props | ✅ Yes |
|
|
25
|
+
| Dropdown Controls | ✅ Yes |
|
|
26
|
+
| Auto Documentation | ✅ Yes |
|
|
27
|
+
| Production Bundles | ✅ Yes |
|
|
28
|
+
| Live Updates | ✅ Yes (via Pusher) |
|
|
29
|
+
|
|
30
|
+
## Table of Contents
|
|
31
|
+
|
|
32
|
+
- [What is Bravo Studio AI?](#what-is-bravo-studio-ai)
|
|
33
|
+
- [Perfect For](#perfect-for)
|
|
34
|
+
- [Installation](#installation)
|
|
35
|
+
- [Quick Start](#quick-start)
|
|
36
|
+
- [What Gets Generated](#what-gets-generated)
|
|
37
|
+
- [Real-World Examples](#real-world-examples)
|
|
38
|
+
- [How It Works](#how-it-works)
|
|
39
|
+
- [CLI Commands](#cli-commands)
|
|
40
|
+
- [Advanced Features](#advanced-features)
|
|
41
|
+
- [Package Exports](#package-exports)
|
|
42
|
+
- [Troubleshooting](#troubleshooting)
|
|
43
|
+
- [Support](#support)
|
|
44
|
+
|
|
45
|
+
## Why This Matters
|
|
46
|
+
|
|
47
|
+
Stop manually translating Figma designs into code. Stop writing boilerplate. Stop maintaining prop interfaces that fall out of sync with your designs.
|
|
48
|
+
|
|
49
|
+
With `@bravostudioai/react`, you design in Figma and Bravo Studio AI streams them into:
|
|
50
|
+
|
|
51
|
+
- **Type-safe React components** with full TypeScript interfaces
|
|
52
|
+
- **Intelligent prop detection** that understands your data bindings, forms, buttons, and interactive elements
|
|
53
|
+
- **Human-readable APIs** with clean, semantic prop names (not cryptic IDs)
|
|
54
|
+
- **Automatic event handlers** for clicks, form submissions, and state changes
|
|
55
|
+
- **Self-documenting code** with README files for every component
|
|
56
|
+
- **Zero manual configuration** - the generator understands your design intent
|
|
57
|
+
|
|
58
|
+
## What is Bravo Studio AI?
|
|
59
|
+
|
|
60
|
+
**Bravo Studio AI** is a Figma-to-React pipeline that transforms your designs into production-ready components. Design in Figma, and Bravo Studio AI automatically generates type-safe React components with intelligent prop detection, form handling, and event routing.
|
|
61
|
+
|
|
62
|
+
### The Perfect MCP Companion
|
|
63
|
+
|
|
64
|
+
This package is optimized for **MCP (Model Context Protocol) applications**, where AI agents need to interact with real, functional UI components. By streaming Figma designs into typed React components, you can:
|
|
65
|
+
|
|
66
|
+
- Rapidly prototype AI-powered interfaces
|
|
67
|
+
- Let designers iterate without code changes
|
|
68
|
+
- Build MCP apps with production-ready UI in minutes
|
|
69
|
+
- Maintain type safety across your entire AI app stack
|
|
70
|
+
|
|
71
|
+
## Perfect For
|
|
72
|
+
|
|
73
|
+
✅ **MCP app developers** building AI-powered applications with real UI
|
|
74
|
+
✅ **Design teams** who want to iterate in Figma and see changes instantly
|
|
75
|
+
✅ **Full-stack developers** building prototypes or MVPs at lightning speed
|
|
76
|
+
✅ **Product teams** validating designs with real functionality
|
|
77
|
+
✅ **Agencies** shipping client projects with tight deadlines
|
|
78
|
+
✅ **Startups** optimizing for speed without sacrificing code quality
|
|
79
|
+
|
|
80
|
+
**Not ideal for:**
|
|
81
|
+
❌ Projects without Figma designs processed through Bravo Studio AI
|
|
82
|
+
❌ Teams needing 100% custom, hand-coded components
|
|
83
|
+
|
|
84
|
+
## Installation
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm install @bravostudioai/react
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Requirements:**
|
|
91
|
+
- Node.js 16+
|
|
92
|
+
- React 18.2.0+ or 19.0.0+
|
|
93
|
+
- TypeScript (recommended)
|
|
94
|
+
|
|
95
|
+
## Quick Start
|
|
96
|
+
|
|
97
|
+
### The Figma → React Workflow
|
|
98
|
+
|
|
99
|
+
1. **Design in Figma** - Create your interface with your team
|
|
100
|
+
2. **Process through Bravo Studio AI** - Your designs get app/page IDs
|
|
101
|
+
3. **Generate React components** - Stream them into your codebase
|
|
102
|
+
4. **Use in your MCP app** - Import and use with full type safety
|
|
103
|
+
|
|
104
|
+
### Generate Components from Your Bravo Studio AI App
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Generate all pages from an app
|
|
108
|
+
npx @bravostudioai/react generate <appId> ./src/components
|
|
109
|
+
|
|
110
|
+
# Generate a specific page
|
|
111
|
+
npx @bravostudioai/react generate <appId> <pageId> ./src/components
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
This creates a folder structure like:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
src/components/
|
|
118
|
+
YourApp/
|
|
119
|
+
PageName/
|
|
120
|
+
index.tsx # Type-safe React component
|
|
121
|
+
README.md # Complete documentation
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Use Your Generated Component
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
import { PageName } from './components/YourApp/PageName';
|
|
128
|
+
|
|
129
|
+
function MCPApp() {
|
|
130
|
+
return (
|
|
131
|
+
<PageName
|
|
132
|
+
headline="Welcome to our app"
|
|
133
|
+
items={[
|
|
134
|
+
{ title: "Item 1", image: "https://..." },
|
|
135
|
+
{ title: "Item 2", image: "https://..." }
|
|
136
|
+
]}
|
|
137
|
+
onSubmitClick={() => console.log('Submitted!')}
|
|
138
|
+
/>
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
That's it. No configuration files. No manual prop mapping. Just clean, typed React components streamed from Figma.
|
|
144
|
+
|
|
145
|
+
## What Gets Generated
|
|
146
|
+
|
|
147
|
+
### 1. Type-Safe Component Interfaces
|
|
148
|
+
|
|
149
|
+
Every data binding, form input, and interactive element in your design becomes a typed prop:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
export interface SalaryCalculatorProps {
|
|
153
|
+
// Data bindings from your design
|
|
154
|
+
estimatedCost?: string;
|
|
155
|
+
|
|
156
|
+
// Dropdown controls
|
|
157
|
+
contractType?: string;
|
|
158
|
+
contractTypeOptions?: Array<string | { value: string; label: string }>;
|
|
159
|
+
onContractTypeChange?: (value: string) => void;
|
|
160
|
+
|
|
161
|
+
// Button actions
|
|
162
|
+
onBookButtonClick?: () => void;
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 2. Smart List/Repeater Support
|
|
167
|
+
|
|
168
|
+
Repeating containers become typed array props:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
export interface TimelineItem {
|
|
172
|
+
title: string;
|
|
173
|
+
description: string;
|
|
174
|
+
image: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export interface PageProps {
|
|
178
|
+
timeline: TimelineItem[];
|
|
179
|
+
timelineCurrentIndex?: number;
|
|
180
|
+
onTimelineIndexChange?: (index: number) => void;
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Use it like this:
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
<Page
|
|
188
|
+
timeline={[
|
|
189
|
+
{ title: "Step 1", description: "...", image: "..." },
|
|
190
|
+
{ title: "Step 2", description: "...", image: "..." }
|
|
191
|
+
]}
|
|
192
|
+
timelineCurrentIndex={currentSlide}
|
|
193
|
+
onTimelineIndexChange={setCurrentSlide}
|
|
194
|
+
/>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### 3. Complete Form Handling
|
|
198
|
+
|
|
199
|
+
Forms get typed interfaces and submission callbacks:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
export interface ContactFormData {
|
|
203
|
+
name: string;
|
|
204
|
+
email: string;
|
|
205
|
+
message: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface PageProps {
|
|
209
|
+
onContactFormSubmit?: (formData: ContactFormData) => void;
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
Your form handler receives clean, typed data:
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
<Page
|
|
217
|
+
onContactFormSubmit={(data) => {
|
|
218
|
+
console.log(data.name); // Type-safe!
|
|
219
|
+
console.log(data.email); // Type-safe!
|
|
220
|
+
console.log(data.message); // Type-safe!
|
|
221
|
+
}}
|
|
222
|
+
/>
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### 4. Comprehensive Documentation
|
|
226
|
+
|
|
227
|
+
Every component includes a README with:
|
|
228
|
+
|
|
229
|
+
- Complete prop documentation
|
|
230
|
+
- Type information for every prop
|
|
231
|
+
- Usage examples
|
|
232
|
+
- Component metadata (App ID, Page ID)
|
|
233
|
+
|
|
234
|
+
## Real-World Examples
|
|
235
|
+
|
|
236
|
+
### Example 1: Interactive Salary Calculator
|
|
237
|
+
|
|
238
|
+
A salary calculator with multiple dropdowns and a submit button:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
export interface DeelSalaryCalculatorProps {
|
|
242
|
+
estimatedCost?: string;
|
|
243
|
+
|
|
244
|
+
// Three interconnected dropdowns
|
|
245
|
+
contractTypeSelectInput?: string;
|
|
246
|
+
contractTypeSelectInputOptions?: Array<string | { value: string; label: string }>;
|
|
247
|
+
onContractTypeSelectInputChange?: (value: string) => void;
|
|
248
|
+
|
|
249
|
+
contractCountrySelectInput?: string;
|
|
250
|
+
contractCountrySelectInputOptions?: Array<string | { value: string; label: string }>;
|
|
251
|
+
onContractCountrySelectInputChange?: (value: string) => void;
|
|
252
|
+
|
|
253
|
+
contractSalarySelectInput?: string;
|
|
254
|
+
contractSalarySelectInputOptions?: Array<string | { value: string; label: string }>;
|
|
255
|
+
onContractSalarySelectInputChange?: (value: string) => void;
|
|
256
|
+
|
|
257
|
+
onBookButtonClick?: () => void;
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Using it in your app:**
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
function SalaryCalculator() {
|
|
265
|
+
const [contractType, setContractType] = useState('full-time');
|
|
266
|
+
const [country, setCountry] = useState('US');
|
|
267
|
+
const [salary, setSalary] = useState('100000');
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<DeelSalaryCalculator
|
|
271
|
+
contractTypeSelectInput={contractType}
|
|
272
|
+
contractTypeSelectInputOptions={['full-time', 'contractor', 'part-time']}
|
|
273
|
+
onContractTypeSelectInputChange={setContractType}
|
|
274
|
+
contractCountrySelectInput={country}
|
|
275
|
+
contractCountrySelectInputOptions={['US', 'UK', 'CA', 'AU']}
|
|
276
|
+
onContractCountrySelectInputChange={setCountry}
|
|
277
|
+
contractSalarySelectInput={salary}
|
|
278
|
+
contractSalarySelectInputOptions={['50000', '75000', '100000', '150000']}
|
|
279
|
+
onContractSalarySelectInputChange={setSalary}
|
|
280
|
+
onBookButtonClick={() => console.log('Booking consultation')}
|
|
281
|
+
/>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Example 2: Content Sections with Data Bindings
|
|
287
|
+
|
|
288
|
+
A simple layout with text content:
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
export interface ContentSectionProps {
|
|
292
|
+
headline?: string;
|
|
293
|
+
topline?: string;
|
|
294
|
+
line1?: string;
|
|
295
|
+
line2?: string;
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**Using it in your app:**
|
|
300
|
+
|
|
301
|
+
```tsx
|
|
302
|
+
<ContentSection
|
|
303
|
+
headline="Transform Your Business"
|
|
304
|
+
topline="Introducing Our New Platform"
|
|
305
|
+
line1="Built for modern teams"
|
|
306
|
+
line2="Scales with your growth"
|
|
307
|
+
/>
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Simple, clean props that map directly to your design's data bindings.
|
|
311
|
+
|
|
312
|
+
## How It Works
|
|
313
|
+
|
|
314
|
+
Bravo Studio AI processes your Figma designs and the generator:
|
|
315
|
+
|
|
316
|
+
1. **Detects data bindings** - Components tagged in Figma become typed props
|
|
317
|
+
2. **Identifies repeating containers** - Lists and sliders become array props with typed items
|
|
318
|
+
3. **Finds forms** - Input groups become typed form data interfaces
|
|
319
|
+
4. **Discovers interactive elements** - Buttons, selects, and inputs get event handlers
|
|
320
|
+
5. **Generates human-readable names** - Component names become `headline`, not `component_01ABC123`
|
|
321
|
+
6. **Streams updates** - Optional live updates when Figma designs change
|
|
322
|
+
|
|
323
|
+
## CLI Commands
|
|
324
|
+
|
|
325
|
+
### Generate Components
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
# Generate all pages from an app
|
|
329
|
+
npx @bravostudioai/react generate <appId> <outputPath>
|
|
330
|
+
|
|
331
|
+
# Generate a specific page
|
|
332
|
+
npx @bravostudioai/react generate <appId> <pageId> <outputPath>
|
|
333
|
+
|
|
334
|
+
# Generate with bundled production data (offline mode)
|
|
335
|
+
npx @bravostudioai/react generate <appId> <pageId> <outputPath> --production
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
### Download Raw Data
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
# Download page data for inspection
|
|
342
|
+
npx @bravostudioai/react download <appId> <pageId> <targetPath>
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Environment Variables
|
|
346
|
+
|
|
347
|
+
Configure the Bravo Studio AI API endpoint:
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
APPS_SERVICE_URL=https://your-custom-endpoint.com
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
Or use in your `.env` file:
|
|
354
|
+
|
|
355
|
+
```env
|
|
356
|
+
VITE_APPS_SERVICE_URL=https://your-custom-endpoint.com
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
## Advanced Features
|
|
360
|
+
|
|
361
|
+
### Controlled vs Uncontrolled Components
|
|
362
|
+
|
|
363
|
+
Sliders and repeating containers support both modes:
|
|
364
|
+
|
|
365
|
+
```tsx
|
|
366
|
+
// Uncontrolled (component manages its own state)
|
|
367
|
+
<Page items={myItems} />
|
|
368
|
+
|
|
369
|
+
// Controlled (you control the current slide)
|
|
370
|
+
<Page
|
|
371
|
+
items={myItems}
|
|
372
|
+
itemsCurrentIndex={currentIndex}
|
|
373
|
+
onItemsIndexChange={setCurrentIndex}
|
|
374
|
+
/>
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Production Mode
|
|
378
|
+
|
|
379
|
+
Bundle your app/page definitions directly into components for offline usage:
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
npx @bravostudioai/react generate <appId> <pageId> ./src/components --production
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
This creates a `data.json` file with all necessary data baked in.
|
|
386
|
+
|
|
387
|
+
### Page Metadata
|
|
388
|
+
|
|
389
|
+
Every component exports metadata about the original design:
|
|
390
|
+
|
|
391
|
+
```typescript
|
|
392
|
+
export const PageMeta = {
|
|
393
|
+
width: 375,
|
|
394
|
+
height: 812,
|
|
395
|
+
aspectRatio: 0.46,
|
|
396
|
+
};
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
Use this for responsive layouts or aspect ratio containers.
|
|
400
|
+
|
|
401
|
+
## Package Exports
|
|
402
|
+
|
|
403
|
+
```typescript
|
|
404
|
+
// Main component
|
|
405
|
+
import { EncoreApp } from '@bravostudioai/react';
|
|
406
|
+
|
|
407
|
+
// All components
|
|
408
|
+
import * from '@bravostudioai/react/components';
|
|
409
|
+
|
|
410
|
+
// Hooks
|
|
411
|
+
import { useFontLoader } from '@bravostudioai/react/hooks/useFontLoader';
|
|
412
|
+
import { usePusherUpdates } from '@bravostudioai/react/hooks/usePusherUpdates';
|
|
413
|
+
|
|
414
|
+
// State management
|
|
415
|
+
import { useEncoreState } from '@bravostudioai/react/stores/useEncoreState';
|
|
416
|
+
|
|
417
|
+
// Version info
|
|
418
|
+
import { VERSION } from '@bravostudioai/react/version';
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
## TypeScript Support
|
|
422
|
+
|
|
423
|
+
Full TypeScript support out of the box. Every generated component includes:
|
|
424
|
+
|
|
425
|
+
- Exported interfaces for component props
|
|
426
|
+
- Exported interfaces for list item types
|
|
427
|
+
- Exported interfaces for form data
|
|
428
|
+
- Complete type safety for all callbacks
|
|
429
|
+
|
|
430
|
+
## Requirements
|
|
431
|
+
|
|
432
|
+
- React 18.2.0+ or 19.0.0+
|
|
433
|
+
- React DOM 18.2.0+ or 19.0.0+
|
|
434
|
+
- TypeScript (recommended but not required)
|
|
435
|
+
|
|
436
|
+
## Developer Experience
|
|
437
|
+
|
|
438
|
+
This isn't just code generation - it's a complete Figma → React pipeline:
|
|
439
|
+
|
|
440
|
+
1. **Design in Figma** - Work with your design team in their native tool
|
|
441
|
+
2. **Process through Bravo Studio AI** - Designs get structured and tagged
|
|
442
|
+
3. **Run the generator** - One command streams your components
|
|
443
|
+
4. **Import and use** - Type-safe components with IntelliSense support
|
|
444
|
+
5. **Iterate quickly** - Regenerate anytime Figma designs change
|
|
445
|
+
|
|
446
|
+
The generated code is clean, readable, and maintainable. You can read it, understand it, and even modify it if needed.
|
|
447
|
+
|
|
448
|
+
### Why This Matters for MCP Apps
|
|
449
|
+
|
|
450
|
+
MCP applications need real UI components that AI agents can reason about and manipulate. By streaming Figma designs into typed React components, you get:
|
|
451
|
+
|
|
452
|
+
- **Type safety** - AI agents work with strongly-typed interfaces
|
|
453
|
+
- **Rapid iteration** - Designers update Figma, you regenerate
|
|
454
|
+
- **Production quality** - Not prototypes, but real components
|
|
455
|
+
- **Developer-friendly** - Clean code that developers can read and extend
|
|
456
|
+
|
|
457
|
+
## Example Output
|
|
458
|
+
|
|
459
|
+
Here's what the generator creates for a real-world salary calculator:
|
|
460
|
+
|
|
461
|
+
**Generated TypeScript Interface:**
|
|
462
|
+
```typescript
|
|
463
|
+
export interface DeelSalaryCalculatorProps {
|
|
464
|
+
estimatedCost?: string;
|
|
465
|
+
contractTypeSelectInput?: string;
|
|
466
|
+
contractTypeSelectInputOptions?: Array<string | { value: string; label: string }>;
|
|
467
|
+
onContractTypeSelectInputChange?: (value: string) => void;
|
|
468
|
+
// ... and more typed props
|
|
469
|
+
}
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
**Generated Component:**
|
|
473
|
+
```typescript
|
|
474
|
+
export function DeelSalaryCalculator(props: DeelSalaryCalculatorProps) {
|
|
475
|
+
const handleAction = (payload: any) => {
|
|
476
|
+
// Automatically generated event routing
|
|
477
|
+
if (action?.action === "select-change") {
|
|
478
|
+
if (nodeId === "..." && props.onContractTypeSelectInputChange) {
|
|
479
|
+
props.onContractTypeSelectInputChange(value);
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
return (
|
|
486
|
+
<EncoreApp
|
|
487
|
+
appId="..."
|
|
488
|
+
pageId="..."
|
|
489
|
+
data={{ /* auto-mapped props */ }}
|
|
490
|
+
onAction={handleAction}
|
|
491
|
+
/>
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
**Generated README.md:**
|
|
497
|
+
Complete documentation with prop descriptions, types, and usage examples.
|
|
498
|
+
|
|
499
|
+
## Why Developers Love This
|
|
500
|
+
|
|
501
|
+
**"Figma to code in seconds, not days"**
|
|
502
|
+
Your designers iterate in Figma while you work with production-ready components. No translation layer.
|
|
503
|
+
|
|
504
|
+
**"Perfect for MCP apps"**
|
|
505
|
+
AI agents need typed interfaces. This gives you exactly that, streamed from design files.
|
|
506
|
+
|
|
507
|
+
**"Type safety everywhere"**
|
|
508
|
+
Catch errors at compile time, not runtime. IntelliSense shows you every available prop.
|
|
509
|
+
|
|
510
|
+
**"Self-documenting components"**
|
|
511
|
+
Every component includes documentation. No need to ask "what props does this take?"
|
|
512
|
+
|
|
513
|
+
**"Zero configuration"**
|
|
514
|
+
No webpack configs, no babel plugins, no setup guides. Just `npm install` and `generate`.
|
|
515
|
+
|
|
516
|
+
**"Actually readable code"**
|
|
517
|
+
The generated code looks like code you'd write by hand. Clean, idiomatic React.
|
|
518
|
+
|
|
519
|
+
## Troubleshooting
|
|
520
|
+
|
|
521
|
+
### Common Issues
|
|
522
|
+
|
|
523
|
+
**Q: The generated component shows "Failed to load"**
|
|
524
|
+
- Ensure your `appId` and `pageId` are correct
|
|
525
|
+
- Check that you have network access to the Bravo Studio AI API
|
|
526
|
+
- For offline use, use `--production` flag during generation
|
|
527
|
+
|
|
528
|
+
**Q: TypeScript errors in generated code**
|
|
529
|
+
- Make sure you have `@types/react` installed
|
|
530
|
+
- Verify your TypeScript version is 5.0+
|
|
531
|
+
- Try regenerating the component with the latest package version
|
|
532
|
+
|
|
533
|
+
**Q: Props not updating the component**
|
|
534
|
+
- Remember that data bindings need to be properly tagged in your Figma design
|
|
535
|
+
- Check the generated README.md for the exact prop names
|
|
536
|
+
- Verify the component is receiving props correctly using React DevTools
|
|
537
|
+
|
|
538
|
+
**Q: How do I get my App ID and Page ID?**
|
|
539
|
+
- Contact your Bravo Studio AI team for access credentials
|
|
540
|
+
- IDs are provided when your Figma designs are processed through Bravo Studio AI
|
|
541
|
+
|
|
542
|
+
**Q: Can I use this with regular Figma files?**
|
|
543
|
+
- Figma files must be processed through Bravo Studio AI first
|
|
544
|
+
- This adds the necessary metadata and structure for component generation
|
|
545
|
+
|
|
546
|
+
### Best Practices
|
|
547
|
+
|
|
548
|
+
1. **Regenerate components when designs change** - Keep your code in sync
|
|
549
|
+
2. **Read the generated README** - Each component documents its own API
|
|
550
|
+
3. **Use TypeScript** - Get the full benefit of type safety
|
|
551
|
+
4. **Version control generated code** - Treat it like any other source code
|
|
552
|
+
5. **Customize carefully** - Remember that regeneration will overwrite changes
|
|
553
|
+
|
|
554
|
+
## Support
|
|
555
|
+
|
|
556
|
+
For questions, issues, or feature requests, please contact the Bravo Studio team.
|
|
557
|
+
|
|
558
|
+
Package: `@bravostudioai/react`
|
|
559
|
+
|
|
560
|
+
## Version & Updates
|
|
561
|
+
|
|
562
|
+
Check your installed version:
|
|
563
|
+
|
|
564
|
+
```bash
|
|
565
|
+
npm list @bravostudioai/react
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
Or programmatically:
|
|
569
|
+
|
|
570
|
+
```typescript
|
|
571
|
+
import { VERSION } from '@bravostudioai/react/version';
|
|
572
|
+
console.log(VERSION);
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
**Updating to the latest version:**
|
|
576
|
+
|
|
577
|
+
```bash
|
|
578
|
+
npm update @bravostudioai/react
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
## Keywords
|
|
582
|
+
|
|
583
|
+
`react`, `typescript`, `code-generation`, `design-to-code`, `figma`, `figma-to-react`, `bravo-studio`, `bravo-studio-ai`, `component-generator`, `type-safe`, `mcp`, `model-context-protocol`, `ai-apps`, `design-streaming`, `design-system`, `ui-components`, `figma-plugin`
|
|
584
|
+
|
|
585
|
+
---
|
|
586
|
+
|
|
587
|
+
**Stream Figma designs directly into your MCP apps. Start with @bravostudioai/react.**
|
|
588
|
+
|
|
589
|
+
Made with ❤️ by the Bravo Studio AI team
|
package/package.json
CHANGED
package/src/codegen/generator.ts
CHANGED
|
@@ -12,12 +12,51 @@ import {
|
|
|
12
12
|
sanitizePropName,
|
|
13
13
|
} from "./parser";
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Metadata extracted from generated component
|
|
17
|
+
*/
|
|
15
18
|
export interface ComponentMetadata {
|
|
19
|
+
/** List of prop names */
|
|
16
20
|
props: string[];
|
|
21
|
+
/** List of event handler names */
|
|
17
22
|
events: string[];
|
|
23
|
+
/** Example JSX usage string */
|
|
18
24
|
jsx: string;
|
|
19
25
|
}
|
|
20
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Generates React component wrapper code for an Encore page
|
|
29
|
+
*
|
|
30
|
+
* Creates a TypeScript React component that wraps EncoreApp with typed props
|
|
31
|
+
* for all data-bound components, sliders, forms, and interactive elements.
|
|
32
|
+
*
|
|
33
|
+
* @param appId - Encore app ID
|
|
34
|
+
* @param pageId - Encore page ID
|
|
35
|
+
* @param componentName - Name for the generated component
|
|
36
|
+
* @param sliders - Slider/list metadata from parser
|
|
37
|
+
* @param standaloneComponents - Standalone component metadata
|
|
38
|
+
* @param inputGroups - Input group metadata
|
|
39
|
+
* @param forms - Form metadata
|
|
40
|
+
* @param selectInputs - Select input metadata
|
|
41
|
+
* @param actionButtons - Action button metadata
|
|
42
|
+
* @param isProduction - Whether to include bundled data for production
|
|
43
|
+
* @param pageMeta - Optional page dimensions and aspect ratio
|
|
44
|
+
* @returns TypeScript component source code
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const code = generateComponentCode(
|
|
48
|
+
* "01ABC123",
|
|
49
|
+
* "01DEF456",
|
|
50
|
+
* "MyPage",
|
|
51
|
+
* sliders,
|
|
52
|
+
* components,
|
|
53
|
+
* inputGroups,
|
|
54
|
+
* forms,
|
|
55
|
+
* selectInputs,
|
|
56
|
+
* actionButtons
|
|
57
|
+
* );
|
|
58
|
+
* fs.writeFileSync("MyPage.tsx", code);
|
|
59
|
+
*/
|
|
21
60
|
export function generateComponentCode(
|
|
22
61
|
appId: string,
|
|
23
62
|
pageId: string,
|
|
@@ -453,6 +492,25 @@ export const PageMeta = {
|
|
|
453
492
|
`;
|
|
454
493
|
}
|
|
455
494
|
|
|
495
|
+
/**
|
|
496
|
+
* Generates README documentation for a generated component
|
|
497
|
+
*
|
|
498
|
+
* Creates comprehensive Markdown documentation explaining all props,
|
|
499
|
+
* events, and usage examples for the generated wrapper component.
|
|
500
|
+
*
|
|
501
|
+
* @param appId - Encore app ID
|
|
502
|
+
* @param pageId - Encore page ID
|
|
503
|
+
* @param appName - Human-readable app name
|
|
504
|
+
* @param pageName - Human-readable page name
|
|
505
|
+
* @param componentName - Generated component name
|
|
506
|
+
* @param sliders - Slider/list metadata
|
|
507
|
+
* @param standaloneComponents - Component metadata
|
|
508
|
+
* @param inputGroups - Input group metadata
|
|
509
|
+
* @param forms - Form metadata
|
|
510
|
+
* @param selectInputs - Select input metadata
|
|
511
|
+
* @param actionButtons - Action button metadata
|
|
512
|
+
* @returns Markdown documentation string
|
|
513
|
+
*/
|
|
456
514
|
export function generateReadme(
|
|
457
515
|
appId: string,
|
|
458
516
|
pageId: string,
|
|
@@ -811,6 +869,22 @@ ${controlExample}
|
|
|
811
869
|
`;
|
|
812
870
|
}
|
|
813
871
|
|
|
872
|
+
/**
|
|
873
|
+
* Extracts component metadata for programmatic use
|
|
874
|
+
*
|
|
875
|
+
* Generates a simplified metadata object listing all props and events
|
|
876
|
+
* without the full code generation.
|
|
877
|
+
*
|
|
878
|
+
* @param _appName - App name (currently unused)
|
|
879
|
+
* @param pageName - Page name for component naming
|
|
880
|
+
* @param sliders - Slider metadata
|
|
881
|
+
* @param standaloneComponents - Component metadata
|
|
882
|
+
* @param inputGroups - Input group metadata
|
|
883
|
+
* @param forms - Form metadata
|
|
884
|
+
* @param selectInputs - Select input metadata
|
|
885
|
+
* @param actionButtons - Action button metadata
|
|
886
|
+
* @returns Component metadata object
|
|
887
|
+
*/
|
|
814
888
|
export function generateComponentMetadata(
|
|
815
889
|
_appName: string,
|
|
816
890
|
pageName: string,
|