- codegen: Low-code React app with JSON-driven component system - packagerepo: Schema-driven package repository with backend/frontend - postgres: Next.js app with Drizzle ORM and PostgreSQL Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
6.9 KiB
JSON Component Trees & Atomic Components - Implementation Summary
Overview
This iteration focused on expanding the atomic component library and creating JSON-driven component trees to make the application more declarative and maintainable.
New Atomic Components Created
General Purpose Components (src/components/atoms/)
-
TextHighlight - Inline highlighted text with variant support
- Variants: primary, accent, success, warning, error
- Use case: Highlighting important text inline
-
ActionCard - Interactive card for quick actions
- Features: Icon support, hover effects, disabled state
- Use case: Dashboard quick actions, feature navigation
-
InfoBox - Informational message boxes
- Types: info, warning, success, error
- Features: Auto-icon, title support
- Use case: Alerts, notifications, help text
-
ListItem - Flexible list item component
- Features: Icon support, end content, active state
- Use case: File lists, navigation menus, activity feeds
-
MetricDisplay - Display metrics with trends
- Features: Trend indicators (up/down), icon support, variants
- Use case: Dashboard KPIs, analytics displays
-
KeyValue - Key-value pair display
- Orientations: horizontal, vertical
- Use case: Property displays, form summaries
-
EmptyMessage - Empty state messaging
- Features: Icon, title, description, action button
- Use case: Empty lists, no data states
-
StepIndicator - Multi-step process indicator
- Features: Completed steps, current step highlighting, clickable
- Use case: Wizards, onboarding, progress tracking
JSON-UI Specific Components (src/components/atoms/json-ui/)
-
Panel - Structured panel with header
- Variants: default, bordered, elevated
- Features: Title, description, actions slot
- Use case: Grouping related content
-
GridLayout - Responsive grid layout
- Features: Breakpoint-specific columns, gap control
- Use case: Dashboard layouts, card grids
-
FlexLayout - Flexible box layout
- Features: Direction, alignment, justification, wrap
- Use case: Toolbar layouts, inline arrangements
-
DynamicText - Text with formatting
- Formats: text, number, currency, date, time, datetime, boolean
- Features: Locale support, currency formatting
- Use case: Dynamic data display
-
ConditionalWrapper - Conditional rendering wrapper
- Features: Condition-based rendering, fallback support
- Use case: Show/hide based on state
-
RepeatWrapper - List rendering wrapper
- Features: Empty message, gap control, key management
- Use case: Repeating patterns from arrays
JSON Component Tree Schemas Created
1. Project Settings (public/schemas/project-settings.json)
A complete settings page demonstrating:
- Form inputs with KV storage bindings
- Grid layouts for responsive form fields
- Label-input associations
- Multi-line text areas
2. File Manager (public/schemas/file-manager.json)
A file browsing interface showing:
- Search functionality with computed data sources
- Conditional rendering (empty state vs file grid)
- Repeat patterns for file cards
- Click event handling
3. Analytics Dashboard (public/schemas/analytics-dashboard.json)
A comprehensive dashboard demonstrating:
- Metric cards with trend indicators
- Multiple data sources (KV and computed)
- Recent activity feed with list items
- Quick action cards
- Complex layouts with gradients and styling
- Data binding transformations
Key Features
Data Binding
All JSON schemas support:
- Direct bindings:
{ source: 'dataSource', path: 'property' } - Computed transforms:
{ source: 'data', transform: '(d) => d.value * 2' } - Multiple binding targets: value, children, props, endContent
Event Handling
JSON components support event bindings:
"events": {
"onClick": "handlerName",
"onChange": "updateHandler"
}
Conditional Rendering
Components can be conditionally rendered:
"condition": "items.length > 0"
Repeat Patterns
Arrays can be rendered using repeat:
"repeat": {
"items": "dataSource",
"itemVar": "item",
"indexVar": "index"
}
Integration Points
Component Registry
All new atomic components are:
- Exported from
src/components/atoms/index.ts - Can be referenced by name in JSON schemas
- Support all standard React props
JSON Page Renderer
The existing JSONPageRenderer component can now render:
- All new atomic components
- All new JSON-UI layout components
- Complex nested structures
- Dynamic data bindings
Usage Example
To use a JSON component tree:
import { JSONPageRenderer } from '@/components/JSONPageRenderer'
import dashboardSchema from '@/public/schemas/analytics-dashboard.json'
function DashboardPage() {
return <JSONPageRenderer config={dashboardSchema} />
}
Benefits
- Declarative: UI structure defined in JSON
- Maintainable: Easy to update without touching React code
- Reusable: Atomic components used across schemas
- Type-safe: Schema validation ensures correctness
- Data-driven: Bindings connect UI to data sources
- Flexible: Mix JSON and React components as needed
Next Steps
- Expand Component Library: Add more atomic components for specific use cases
- Schema Editor: Build visual editor for creating JSON schemas
- Template Library: Create reusable schema templates
- Advanced Bindings: Support more complex data transformations
- Animation Support: Add transition/animation declarations in JSON
- Form Validation: Schema-based validation rules
- Component Composition: Allow custom component definitions in JSON
File Structure
src/
components/
atoms/
TextHighlight.tsx
ActionCard.tsx
InfoBox.tsx
ListItem.tsx
MetricDisplay.tsx
KeyValue.tsx
EmptyMessage.tsx
StepIndicator.tsx
json-ui/
Panel.tsx
GridLayout.tsx
FlexLayout.tsx
DynamicText.tsx
ConditionalWrapper.tsx
RepeatWrapper.tsx
index.ts
index.ts
public/
schemas/
project-settings.json
file-manager.json
analytics-dashboard.json
Testing Recommendations
- Test each atomic component in isolation
- Verify JSON schema validation
- Test data binding with various data types
- Verify conditional rendering logic
- Test responsive layouts at different breakpoints
- Validate event handlers fire correctly
- Test empty states and edge cases
Performance Considerations
- JSON schemas are parsed once and cached
- Atomic components are lightweight and optimized
- Data bindings use React's efficient re-rendering
- Large lists should use virtual scrolling (future enhancement)
- Consider lazy loading for heavy components
Status: ✅ Complete Components Created: 14 atomic components JSON Schemas Created: 3 complete page schemas Lines of Code: ~2,500 lines