Overview
Layout components provide the structural foundation for CryptoDash. They handle navigation, branding, responsive behavior, and global controls like theme switching.Sidebar
The main navigation sidebar with responsive mobile drawer behavior.Props
Controls sidebar visibility. On mobile, this toggles the drawer open/closed. On desktop (md+), the sidebar is always visible.
Callback function invoked when the sidebar should close. Called when:
- User clicks the close button
- User clicks the overlay backdrop
- User presses the Escape key
- User navigates to a new page
Features
Responsive Behavior- Mobile: Slide-out drawer with backdrop overlay
- Desktop: Fixed sidebar, always visible
- Smooth transitions with
duration-300
- Escape key closes the mobile menu
- Body scroll locked when mobile menu is open
- Uses
NavLinkfrom React Router for active state - Active links have bright green background (
#2bee79) - Hover states with smooth transitions
- Material icons with scale animation on hover
- App logo with “CryptoDash” title
- “Pro Terminal” subtitle
- Fixed at bottom of sidebar
- Pro plan upgrade prompt with i18n support
Usage Example
Navigation Configuration
Navigation items are defined in/src/constants/navigation.js:
useTranslations() hook:
Styling Highlights
Active Navigation ItemAccessibility
- Close button includes
aria-label="Close menu" - Overlay has
aria-hidden="true" - Keyboard navigation fully supported
- Focus management on open/close
TopBar
The application header displaying market stats, user controls, and mobile menu trigger.Props
Formatted total market capitalization (e.g., “$2.4T”)
24-hour market cap change percentage (e.g., “+2.4%”)
Whether market cap change is positive. Controls color: green for true, red for false.
Formatted 24-hour trading volume (e.g., “$86.7B”)
Callback invoked when hamburger menu button is clicked (mobile only)
Features
Market Statistics Display- Real-time market cap with 24h change indicator
- 24h trading volume (hidden on very small screens)
- Color-coded trend indicators (green/red arrows)
- Responsive text sizing
- Theme toggle (light/dark mode)
- Language selector (EN/ES)
- User profile display with avatar
- Only visible on mobile (
md:hidden) - Opens sidebar drawer
- Material hamburger icon
Usage Example
Context Integration
TopBar usesSettingsContext for theme and language controls:
Responsive Design
Hamburger Menu- Visible:
< 768px(mobile) - Hidden:
≥ 768px(desktop)
- Mobile: Market cap only, minimal labels
- Small: Market cap with change, volume hidden
- Desktop: Full stats with labels
- Name/title hidden on small screens
- Avatar always visible
Styling Details
Header ContainerInternationalization
All text uses theuseTranslations() hook:
Accessibility
- Hamburger button includes
aria-label="Open menu" - Theme toggle has dynamic title based on current theme
- Language toggle has dynamic title
- Semantic
<header>element
DashboardLayout
Wrapper component that combines Sidebar, TopBar, and ToastContainer.Implementation
Data Flow
useDashboardData()fetches market data- Data passed to TopBar for display
- Full dashboard data passed to child routes via
<Outlet context={...}> - Child pages access data with
useOutletContext()
Mobile Menu State Management
Best Practices
Layout Component Usage
- Always use DashboardLayout as the parent route wrapper
- Pass formatted data to TopBar, not raw values
- Handle mobile menu state at the layout level
- Use Outlet context to share data with child routes
Responsive Considerations
- Test mobile menu at
< 768px - Verify sidebar visibility at
≥ 768px - Check stat visibility at different breakpoints
- Ensure touch targets are
≥ 44px
Performance
- Sidebar uses CSS transforms for smooth animations
- Backdrop blur is GPU-accelerated
- Mobile menu locks body scroll to prevent double scrolling
- Event listeners cleaned up on unmount
Related Documentation
- Common Components - ToastContainer and other utilities
- Component Overview - Architecture patterns
