Spaces:
Running
Running
File size: 11,058 Bytes
ec936d5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# User Story 003: Interactive React Demo
## Story
**As a** potential lerobot.js user exploring the library capabilities
**I want** an interactive web demo with a modern, polished UI
**So that** I can easily test robot calibration features and understand the library's potential before integrating it into my own projects
## Background
While lerobot.js provides platform-agnostic robotics functionality, we need a compelling demo interface to showcase its web capabilities. The current development setup uses Vite with basic HTML/CSS, but lacks the polish needed to demonstrate professional robotics applications.
The Python lerobot ecosystem includes various visualization tools and demos. For lerobot.js, we need a modern web demo that:
1. Showcases the existing web calibration functionality from User Story 002
2. Provides an intuitive UI for robot setup and calibration
3. Demonstrates real-time robot interaction capabilities
4. Serves as a reference implementation for web integration
**Critical Requirement**: React, Tailwind, and shadcn/ui should be **development dependencies only** - the core lerobot library must remain framework-agnostic so users can integrate it with any frontend framework or vanilla JavaScript.
## Acceptance Criteria
### Core Demo Features
- [ ] **Robot Calibration Interface**: Modern UI for SO-100 follower/leader calibration
- [ ] **Port Selection**: Intuitive Web Serial API port selection with visual feedback
- [ ] **Calibration Progress**: Real-time progress indicators during calibration procedures
- [ ] **Configuration Display**: View and manage saved calibration configurations
- [ ] **Error Handling**: User-friendly error messages and recovery suggestions
- [ ] **Responsive Design**: Works on desktop, tablet, and mobile devices
### UI/UX Requirements
- [ ] **Modern Design**: Clean, professional interface using Tailwind 4 and shadcn/ui
- [ ] **Brand Consistency**: Consistent with Hugging Face design language
- [ ] **Accessibility**: WCAG 2.1 AA compliant interface
- [ ] **Dark/Light Mode**: Theme switching support
- [ ] **Loading States**: Smooth loading and transition animations
- [ ] **Visual Feedback**: Clear status indicators for connection, calibration, and errors
### Technical Requirements
- [ ] **Framework Isolation**: React used only for demo, core library remains framework-agnostic
- [ ] **Development Only**: React/Tailwind/shadcn as devDependencies, not regular dependencies
- [ ] **Vite Integration**: Seamless integration with existing Vite development setup
- [ ] **TypeScript**: Full type safety throughout React components
- [ ] **Build Separation**: Demo build separate from library build
- [ ] **Tree Shaking**: Demo dependencies excluded from library builds
### Library Integration
- [ ] **Web API Usage**: Demonstrates proper usage of lerobot web APIs
- [ ] **Error Boundaries**: Robust error handling that doesn't break the demo
- [ ] **Performance**: Smooth interaction without blocking the UI thread
- [ ] **Real Hardware**: Demo works with actual SO-100 hardware via Web Serial API
## Expected User Flow
### Development Experience
```bash
# Install demo dependencies (includes React, Tailwind, shadcn/ui as devDependencies)
$ pnpm install
# Start development server with React demo
$ pnpm run dev
# Opens modern React interface at http://localhost:5173
```
### Demo Interface Flow
1. **Landing Page**: Clean introduction to lerobot.js with call-to-action buttons
2. **Robot Setup**: Card-based interface for selecting robot type (SO-100 follower/leader)
3. **Port Connection**:
- Click "Connect Robot" button
- Browser shows Web Serial API port selection dialog
- Visual feedback shows connection status
4. **Calibration Interface**:
- Step-by-step calibration wizard
- Progress indicators and instructions
- Real-time motor position feedback (if applicable)
5. **Results Display**:
- Success confirmation with visual feedback
- Option to download configuration file
- Suggestions for next steps
### Error Handling Flow
- **No Web Serial Support**: Clear message with browser compatibility info
- **Connection Failed**: Troubleshooting steps with visual aids
- **Calibration Errors**: Descriptive error messages with retry options
- **Permission Denied**: Guide user through browser permission setup
## Implementation Details
### Project Structure Changes
```
lerobot.js/
βββ src/
β βββ demo/ # Demo-specific React components (new)
β β βββ components/
β β β βββ ui/ # shadcn/ui components
β β β βββ CalibrationWizard.tsx
β β β βββ RobotCard.tsx
β β β βββ ConnectionStatus.tsx
β β β βββ ErrorBoundary.tsx
β β βββ pages/
β β β βββ Home.tsx
β β β βββ Setup.tsx
β β β βββ Calibrate.tsx
β β βββ hooks/
β β β βββ useRobotConnection.ts
β β β βββ useCalibration.ts
β β βββ App.tsx
β β βββ main.tsx
β βββ lerobot/ # Core library (unchanged)
β β βββ web/
β β βββ node/
β βββ main.ts # Original Vite entry (unchanged)
βββ index.html # Updated to load React demo
βββ demo.html # New: Vanilla JS demo option
βββ lib.html # New: Library-only demo
```
### Package.json Changes
```json
{
"scripts": {
"dev": "vite --mode demo", // Runs React demo
"dev:vanilla": "vite --mode vanilla", // Runs vanilla demo
"dev:lib": "vite --mode lib", // Library-only mode
"build": "tsc && vite build --mode lib", // Library build (no React)
"build:demo": "tsc && vite build --mode demo" // Demo build (with React)
},
"devDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"tailwindcss": "^4.0.0",
"@tailwindcss/typography": "^0.5.0",
"autoprefixer": "^10.4.0",
"postcss": "^8.4.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"tailwind-merge": "^2.0.0",
"lucide-react": "^0.400.0"
}
}
```
### Vite Configuration
```typescript
// vite.config.ts
export default defineConfig(({ mode }) => {
const baseConfig = {
plugins: [typescript()],
build: {
lib: {
entry: "src/main.ts",
name: "LeRobot",
fileName: "lerobot",
},
},
};
if (mode === "demo") {
return {
...baseConfig,
plugins: [...baseConfig.plugins, react()],
css: {
postcss: {
plugins: [tailwindcss, autoprefixer],
},
},
build: {
// Demo-specific build configuration
outDir: "dist/demo",
rollupOptions: {
input: {
main: "index.html",
},
},
},
};
}
return baseConfig; // Library-only build
});
```
### Key Dependencies
#### Demo-Only Dependencies (devDependencies)
- **React 18**: Latest stable React with concurrent features
- **Tailwind CSS 4**: Latest Tailwind with modern CSS features
- **shadcn/ui**: High-quality React component library
- **Lucide React**: Modern icon library
- **class-variance-authority**: For component variant management
- **clsx + tailwind-merge**: For conditional class management
#### Build Tools
- **@vitejs/plugin-react**: React support for Vite
- **PostCSS**: CSS processing for Tailwind
- **Autoprefixer**: CSS vendor prefixing
### React Components Architecture
#### Core Demo Components
```typescript
// Demo-specific React hooks
function useRobotConnection() {
// Wraps lerobot web APIs in React-friendly hooks
// Manages connection state, error handling
}
function useCalibration() {
// Wraps lerobot calibration APIs
// Provides progress tracking, status updates
}
// Main calibration wizard component
function CalibrationWizard({ robotType }: { robotType: string }) {
const { connect, disconnect, status } = useRobotConnection();
const { calibrate, progress, error } = useCalibration();
// Multi-step wizard UI using shadcn/ui components
}
```
#### shadcn/ui Integration
- **Button**: Primary actions (Connect, Calibrate, Retry)
- **Card**: Robot selection, status displays, results
- **Progress**: Calibration progress indicators
- **Alert**: Error messages and warnings
- **Badge**: Status indicators (Connected, Calibrating, Error)
- **Dialog**: Confirmation dialogs and detailed error information
- **Toast**: Success/error notifications
### Technical Considerations
#### Framework Isolation Strategy
1. **Separate Entry Points**: Demo uses React, library uses vanilla TypeScript
2. **Build Modes**: Vite modes for demo vs library builds
3. **Dependency Isolation**: React in devDependencies, excluded from library bundle
4. **Type Safety**: Shared types between demo and library, but no runtime dependencies
#### Tailwind 4 Integration
- **New CSS Engine**: Leverage Tailwind 4's improved performance
- **Container Queries**: Responsive components using container queries
- **Modern CSS**: CSS Grid, flexbox, custom properties integration
- **Optimization**: Automatic unused CSS elimination
#### Performance Considerations
- **Code Splitting**: Lazy load calibration components
- **Bundle Size**: Demo bundle separate from library bundle
- **Web Serial API**: Non-blocking serial communication
- **Error Boundaries**: Prevent component crashes from breaking entire demo
#### Accessibility
- **Keyboard Navigation**: Full keyboard support for all interactions
- **Screen Readers**: Proper ARIA labels and descriptions
- **Color Contrast**: WCAG AA compliant color schemes
- **Focus Management**: Proper focus handling during async operations
## Testing Strategy
### Integration Testing
- **Library Integration**: Verify demo correctly uses lerobot APIs
- **Build Testing**: Ensure library builds don't include React
- **Browser Compatibility**: Test Web Serial API across supported browsers
## Definition of Done
- [ ] **Functional Demo**: Interactive React demo showcases robot calibration
- [ ] **Modern UI**: Professional interface using Tailwind 4 and shadcn/ui
- [ ] **Framework Isolation**: React isolated to demo only, library remains framework-agnostic
- [ ] **Build Separation**: Library builds exclude React dependencies
- [ ] **Browser Compatibility**: Works in Chrome, Edge, and other Chromium browsers
- [ ] **Responsive Design**: Works across desktop, tablet, and mobile devices
- [ ] **Accessibility**: WCAG 2.1 AA compliant interface
- [ ] **Error Handling**: Graceful error handling with user-friendly messages
- [ ] **Documentation**: Demo usage documented in README
- [ ] **Performance**: Smooth interactions, fast loading times
- [ ] **Type Safety**: Full TypeScript coverage for demo components
- [ ] **Real Hardware**: Successfully calibrates actual SO-100 hardware via Web Serial API
|