Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 36 ยท Projects and Practice

Project: Admin Dashboard

Build an admin dashboard with Material UI: responsive layout, stat cards, a themed chart-free bar graph, recent orders table and a dark mode switch, with a runnable stand-in.

In this project you will put the chapter together: a theme, a responsive shell, a grid of stat cards, a simple bar chart and a table of recent orders. It is the screen almost every business app starts with, so the structure is worth knowing by heart.

Material UI cannot run in the live editors on this site. Each step shows the real MUI code read-only, and the runnable preview at the end is a stand-in built from plain React and CSS that has the same structure, so you can try the layout, the data flow and the dark switch.

What you will build

flowchart TD
  A["ThemeProvider + CssBaseline"] --> B["Shell: AppBar + Drawer"]
  B --> C["Dashboard page"]
  C --> D["StatCard x4 (Grid)"]
  C --> E["RevenueBars (Card)"]
  C --> F["RecentOrders (Table)"]

One provider at the top, one shell, and a page made of small components that each take plain data as props.

Step 1: data and types first

Keep the data separate from the UI. The page receives plain objects, so you can later swap the sample data for an API call.

TSX
// Real Material UI + TypeScript, read-only: src/data.ts
export type Stat = { id: string; label: string; value: string; change: number };
export type Order = { id: number; customer: string; total: number; status: 'Paid' | 'Pending' | 'Refunded' };

export const stats: Stat[] = [
  { id: 'revenue', label: 'Revenue', value: '$48,200', change: 12.5 },
  { id: 'orders', label: 'Orders', value: '1,284', change: 4.1 },
  { id: 'customers', label: 'New customers', value: '312', change: -2.3 },
  { id: 'refunds', label: 'Refunds', value: '27', change: -8.0 },
];

Step 2: the StatCard

A stat card shows one number and its trend. It should be a small, reusable component: a Card with a label, a big value and a Chip that is green for growth and red for decline. Note the color is not the only signal: the arrow and the sign carry the same information.

TSX
// Real Material UI, read-only: src/StatCard.tsx
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import Chip from '@mui/material/Chip';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import ArrowUpward from '@mui/icons-material/ArrowUpward';
import ArrowDownward from '@mui/icons-material/ArrowDownward';
import type { Stat } from './data';

export function StatCard({ label, value, change }: Omit<Stat, 'id'>) {
  const up = change >= 0;
  return (
    <Card variant="outlined" sx={{ height: '100%' }}>
      <CardContent>
        <Typography variant="body2" color="text.secondary">{label}</Typography>
        <Stack direction="row" alignItems="center" justifyContent="space-between" sx={{ mt: 1 }}>
          <Typography variant="h4" component="p">{value}</Typography>
          <Chip
            size="small"
            color={up ? 'success' : 'error'}
            icon={up ? <ArrowUpward /> : <ArrowDownward />}
            label={`${up ? '+' : ''}${change}%`}
          />
        </Stack>
      </CardContent>
    </Card>
  );
}

Step 3: the grid

Grid (v7 API) lays out the cards. Four across on large screens, two on tablets, one on phones:

TSX
// Real Material UI, read-only: src/Dashboard.tsx
import Grid from '@mui/material/Grid';
import Container from '@mui/material/Container';
import Typography from '@mui/material/Typography';
import { StatCard } from './StatCard';
import { RevenueBars } from './RevenueBars';
import { RecentOrders } from './RecentOrders';
import { stats, orders, revenueByMonth } from './data';

export default function Dashboard() {
  return (
    <Container maxWidth="xl" sx={{ py: 3 }}>
      <Typography variant="h4" component="h1" gutterBottom>Overview</Typography>
      <Grid container spacing={2}>
        {stats.map(({ id, ...stat }) => (
          <Grid key={id} size={{ xs: 12, sm: 6, lg: 3 }}>
            <StatCard {...stat} />
          </Grid>
        ))}
        <Grid size={{ xs: 12, lg: 7 }}>
          <RevenueBars data={revenueByMonth} />
        </Grid>
        <Grid size={{ xs: 12, lg: 5 }}>
          <RecentOrders rows={orders} />
        </Grid>
      </Grid>
    </Container>
  );
}

spacing={2} is 16px between items. The size prop takes the number of columns out of 12 per breakpoint. With height: '100%' on each Card, cards in a row stay equally tall.

Step 4: a chart without a chart library

For a handful of bars you do not need a charting package. Use Box with heights computed from the data, and an accessible text alternative (a table or a summary) for screen readers:

TSX
// Real Material UI, read-only: src/RevenueBars.tsx
import Box from '@mui/material/Box';
import Card from '@mui/material/Card';
import CardContent from '@mui/material/CardContent';
import CardHeader from '@mui/material/CardHeader';

export function RevenueBars({ data }: { data: { month: string; value: number }[] }) {
  const max = Math.max(...data.map((d) => d.value));
  return (
    <Card variant="outlined" sx={{ height: '100%' }}>
      <CardHeader title="Revenue by month" subheader="Last six months, in thousands of dollars" />
      <CardContent>
        <Box role="img" aria-label={data.map((d) => `${d.month}: ${d.value}k`).join(', ')}
          sx={{ display: 'flex', alignItems: 'flex-end', gap: 1.5, height: 180 }}>
          {data.map((d) => (
            <Box key={d.month} sx={{ flex: 1, textAlign: 'center' }}>
              <Box sx={{ height: `${(d.value / max) * 150}px`, bgcolor: 'primary.main', borderRadius: 1 }} />
              <Box component="span" sx={{ typography: 'caption', color: 'text.secondary' }}>{d.month}</Box>
            </Box>
          ))}
        </Box>
      </CardContent>
    </Card>
  );
}

For real analytics (tooltips, zoom, many series) use MUI X Charts or another chart library; keep the chart in a lazy-loaded chunk.

Step 5: recent orders

The orders table reuses what you learned in Tables, Pagination and Data Grid: a Table inside a TableContainer, numeric columns right-aligned and the status as a color-coded Chip (with text, not color only).

Step 6: the shell and dark mode

The shell is the AppBar and Drawer from App Bar and Drawer Navigation. Add a toggle that uses useColorScheme (see Dark Mode and Color Schemes). All colors in the page come from the theme (primary.main, text.secondary, background.paper), which is why dark mode requires no changes in the dashboard components.

The runnable stand-in

This preview has the same structure: stat cards in a responsive grid (CSS grid with auto-fit), the bar chart with an accessible label, and the orders table. The theme switch uses CSS variables, like colorSchemes. Resize the preview to see the grid reflow.

Dashboard: stat cards, bars and orders

Improve it

Practice what you have learned by extending the project:

  1. Add a date range ToggleButtonGroup (7 days, 30 days, 12 months) that changes the data shown.
  2. Show Skeleton cards while the data loads, then reveal real values.
  3. Move the orders table to the sortable one from the tables lesson.
  4. Add a Snackbar "Report exported" after clicking an Export button.
  5. Lazy-load the chart section and check the bundle with an analyzer.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does Grid keep four stat cards in one row on large screens and one per row on phones?

    The size prop takes columns out of twelve per breakpoint, so 12 is full width, 6 is half and 3 is a quarter.
  2. 2. Why include a text sign and an arrow in the change Chip, not just a color?

    Information should never rely on color alone.
  3. 3. Why does dark mode need no changes inside StatCard or RecentOrders?

    Theme-aware values follow the active scheme, so the components stay unaware of it.
  4. 4. How can you make a hand-built bar chart accessible?

    A text alternative lets screen reader users get the same information.

Summary

  • Separate data from UI; keep components small and fed with plain props.
  • StatCard, RevenueBars and RecentOrders are reusable pieces; Grid with size handles the responsive layout.
  • Theme-aware colors make dark mode free.
  • Provide text alternatives for charts and do not rely on color alone.

Next: Project: Settings Form