# Platform-Specific UI Guide
## Overview
AeThex OS now supports platform-adaptive UI that automatically adjusts for mobile, desktop, and web environments while maintaining the same core functionality.
## Quick Start
### 1. Use the Platform Layout Hook
```typescript
import { usePlatformLayout, usePlatformClasses } from '@/hooks/use-platform-layout';
function MyComponent() {
const layout = usePlatformLayout();
const classes = usePlatformClasses();
return (
```
## Responsive Design Strategy
### 1. Layout Changes
- **Mobile**: Single column, bottom navigation, full-screen modals
- **Desktop**: Multi-column, top/side navigation, floating dialogs
- **Web**: Adaptive columns, sticky navigation, responsive dialogs
### 2. Typography
- **Mobile**: Larger base font (16px+) for readability
- **Desktop**: Standard font (14px) for information density
- **Web**: Medium font (15px) for balance
### 3. Spacing
- **Mobile**: Tighter spacing (12px-16px) to maximize screen space
- **Desktop**: Generous spacing (24px-32px) for clarity
- **Web**: Balanced spacing (16px-24px)
### 4. Touch Targets
- **Mobile**: Minimum 44px height for buttons and interactive elements
- **Desktop**: Standard 40px height
- **Web**: 40px height
## Example Implementation
See [PlatformAdaptiveExample.tsx](../client/src/components/PlatformAdaptiveExample.tsx) for a complete example showing:
- Platform-specific headers
- Adaptive grids
- Conditional navigation styles
- Touch-optimized controls
## Common Patterns
### Adaptive Navigation
```typescript
function Navigation() {
const { isMobile } = usePlatformLayout();
if (isMobile) {
return (
);
}
return (
);
}
```
### Responsive Cards
```typescript
function CardGrid() {
const { isMobile, isDesktop } = usePlatformLayout();
const columns = isMobile ? 'grid-cols-1' :
isDesktop ? 'grid-cols-4' :
'grid-cols-2';
return
{/* Cards */}
;
}
```
### Adaptive Forms
```typescript
function Form() {
const classes = usePlatformClasses();
return (
);
}
```
## Mobile-Specific Features
### Safe Area Support (iOS)
```css
/* In your CSS */
.mobile-container {
padding-top: env(safe-area-inset-top);
padding-bottom: env(safe-area-inset-bottom);
}
```
### Pull-to-Refresh
```typescript
import { isMobile } from '@/lib/platform';
if (isMobile()) {
// Enable pull-to-refresh gesture
window.addEventListener('touchstart', handlePullToRefresh);
}
```
### Native Gestures
```typescript
// Swipe navigation on mobile
if (isMobile()) {
}
```
## Desktop-Specific Features
### Window Controls
```typescript
import { isDesktop } from '@/lib/platform';
if (isDesktop()) {
// Custom title bar, minimize/maximize/close
}
```
### Keyboard Shortcuts
```typescript
if (isDesktop()) {
useEffect(() => {
// Ctrl+N for new item, etc.
const handler = (e: KeyboardEvent) => {
if (e.ctrlKey && e.key === 'n') {
createNew();
}
};
window.addEventListener('keydown', handler);
return () => window.removeEventListener('keydown', handler);
}, []);
}
```
## Testing Platform Variants
### In Development
```typescript
// Force platform detection for testing
if (import.meta.env.DEV) {
window.Capacitor = {}; // Test as mobile
// or
window.__TAURI__ = {}; // Test as desktop
}
```
### Chrome DevTools
- Open DevTools → Device Toolbar
- Select mobile device
- The app will detect as web but use mobile viewport
## Best Practices
1. **Design Mobile-First**: Start with mobile constraints, enhance for larger screens
2. **Use Touch-Friendly Sizes**: Minimum 44px tap targets on mobile
3. **Optimize Navigation**: Bottom tabs on mobile, top/side on desktop
4. **Adapt Typography**: Larger on mobile, more compact on desktop
5. **Test on Real Devices**: Emulators are good, but test on actual hardware
6. **Progressive Enhancement**: Core functionality works everywhere, enhancements per platform
## Migration Guide
To update existing components:
1. Import the hooks:
```typescript
import { usePlatformClasses } from '@/hooks/use-platform-layout';
```
2. Replace hardcoded classes:
```typescript
// Before