Dashboard Responsive Design

Complete guide to making dashboards fully responsive for mobile, tablet, and desktop devices.

Contents

Overview

The responsive dashboard system provides:

Files:

Breakpoints

DeviceWidthGrid ColumnsSidebar
Desktop> 1024px3 (configured)Visible
Tablet768px - 1024px2Visible
Mobile480px - 768px2Burger menu
Small Mobile< 480px1Burger menu
/// CSS Variables for breakpoints
:root {
    --mobile-breakpoint         : 768px;
    --tablet-breakpoint         : 1024px;
    --small-mobile-breakpoint   : 480px;
}

Components

TResponsiveManager

Main component that handles responsive behavior.

TYPE
   TDeviceMode = (dmDesktop, dmTablet, dmMobile, dmSmallMobile);

   TResponsiveManager = CLASS(TComponent)
      PUBLIC
         PROCEDURE Initialize;
         PROCEDURE OpenSidebar;
         PROCEDURE CloseSidebar;
         PROCEDURE ToggleSidebar;
         PROCEDURE CheckDeviceMode;
         
         FUNCTION IsMobile: Boolean;
         FUNCTION IsTablet: Boolean;
         FUNCTION IsDesktop: Boolean;
         FUNCTION GetResponsiveColumns: Integer;
         
         PROPERTY CurrentMode: TDeviceMode READ FCurrentMode;
         PROPERTY SidebarOpen: Boolean READ FSidebarOpen;
         
      PUBLISHED
         PROPERTY LayoutContainer: TCoreDiv;
         PROPERTY Sidebar: TControl;
         PROPERTY Canvas: TControl;
         PROPERTY ReadOnlyOnMobile: Boolean DEFAULT True;
         PROPERTY MobileBreakpoint: Integer DEFAULT 768;
         PROPERTY TabletBreakpoint: Integer DEFAULT 1024;
         PROPERTY SmallMobileBreakpoint: Integer DEFAULT 480;
         PROPERTY OnDeviceModeChanged: TDeviceModeChangedEvent;
   END;

Key Features

CSS Files

Dashboard.Responsive.css

Include this CSS file in your application for responsive styles.

Key CSS Classes

ClassPurpose
.dashboard-layoutMain container - add to parent of sidebar + canvas
.mobile-modeAdded automatically when on mobile
.dashboard-sidebarSidebar container
.sidebar-openShows sidebar on mobile
.burger-menu-btnHamburger menu button
.sidebar-overlayDark overlay when menu open
.dashboard-readonlyDisables editing controls

Grid Responsive Rules

/// Tablet: Force 2 columns
@media screen and (max-width: 1024px) {
    .dashboard-container {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/// Mobile: 2 columns, padding for burger
@media screen and (max-width: 768px) {
    .dashboard-container {
        grid-template-columns: repeat(2, 1fr) !important;
        padding: 60px 10px 10px 10px;
    }
    
    /// Cards span single column only
    .dashboard-card {
        grid-column: span 1 !important;
    }
}

/// Small Mobile: Single column
@media screen and (max-width: 480px) {
    .dashboard-container {
        grid-template-columns: 1fr !important;
    }
}

Usage Guide

Step 1: Include CSS

Add the responsive CSS to your HTML:

<link rel="stylesheet" href="Dashboard.Responsive.css">

Step 2: Setup HTML Structure

<div class="dashboard-layout">
    <div class="dashboard-sidebar">
        <!-- TSideBar component here -->
    </div>
    <div class="dashboard-main-content">
        <div class="dashboard-container">
            <!-- TDashboardCanvas component here -->
        </div>
    </div>
</div>

Step 3: Create ResponsiveManager

PROCEDURE TMainForm.WebFormCreate(Sender: TObject);
BEGIN
   FResponsiveManager := TResponsiveManager.Create(Self);
   FResponsiveManager.LayoutContainer := pnlMain;      /// Main container div
   FResponsiveManager.Sidebar := pnlSidebar;           /// Sidebar panel
   FResponsiveManager.Canvas := DashboardCanvas;       /// Dashboard canvas
   FResponsiveManager.ReadOnlyOnMobile := True;        /// Disable editing on mobile
   FResponsiveManager.OnDeviceModeChanged := HandleModeChanged;
   FResponsiveManager.Initialize;
END;

Step 4: Handle Mode Changes (Optional)

PROCEDURE TMainForm.HandleModeChanged(Sender: TObject; NewMode: TDeviceMode);
BEGIN
   CASE NewMode OF
      dmDesktop:
         Console.log('Switched to desktop mode');
      dmTablet:
         Console.log('Switched to tablet mode');
      dmMobile, dmSmallMobile:
         Console.log('Switched to mobile mode');
   END;
END;

Read-Only Mode

When ReadOnlyOnMobile is True (default), the following is disabled on mobile:

CSS Classes for Read-Only

.dashboard-readonly .card-resize-handle {
    display: none !important;
}

.dashboard-readonly .dashboard-card {
    cursor: default !important;
}

.dashboard-readonly .btn-expand,
.dashboard-readonly .btn-shrink,
.dashboard-readonly .btn-delete {
    display: none !important;
}

Programmatic Control

/// Check if currently mobile
IF ResponsiveManager.IsMobile THEN
   ShowMessage('You are on a mobile device');
   
/// Get recommended columns for current mode
Columns := ResponsiveManager.GetResponsiveColumns;
DashboardCanvas.SpanAcross := Columns;
Important: The responsive CSS uses !important flags to override inline styles set by JavaScript. This ensures the responsive grid rules take precedence on mobile devices.