Polski

Tutorial · MUI (Material UI) · React

MUI 7 in practice – theming, dark mode, custom components and DataGrid without the "default Material" look

We build a dumpling shop's kitchen dashboard in Material UI 7 – design tokens and a CSS-variables theme, flicker-free dark mode, custom components and variants, client- and server-side DataGrid, and a form with react-hook-form and Zod. The code also runs on MUI 9.

By · · 23 min read

MUI is the most popular React component library, but it has an image problem: apps built "on the defaults" all look the same – a blue app bar, upper-case buttons, a shadow under every card. In this guide you'll build a kitchen dashboard for a dumpling shop that uses everything MUI is good at (accessibility, ready-made components, DataGrid) but looks like a product with its own design system.

Prerequisites: React with hooks and TypeScript at the level of the TypeScript guide. Knowing react-hook-form and TanStack Query from the React guide helps, but isn't required.

7 → 9
MUI versions – the same code runs on both
3
colour modes – light, dark, system
240
DataGrid rows – sorting, filters and actions with no custom code
1
tokens file – the whole brand in one place

Step 1. Installation

npm create vite@latest pierogi-admin -- --template react-ts
cd pierogi-admin
npm install @mui/material @mui/icons-material @emotion/react @emotion/styled @mui/x-data-grid @fontsource-variable/inter
npm install react-hook-form @hookform/resolvers zod @tanstack/react-query

MUI uses Emotion as its styling engine, hence the two @emotion/* packages. The Inter font is installed locally via Fontsource – no requests to Google Fonts and no layout shift when a web font arrives late.

Project configuration

package.json
{
  "name": "pierogi-admin-mui",
  "private": true,
  "version": "0.1.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc --noEmit && vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "@emotion/react": "^11.14.0",
    "@emotion/styled": "^11.14.1",
    "@fontsource-variable/inter": "^5.3.0",
    "@hookform/resolvers": "^7.0.9",
    "@mui/icons-material": "^7.3.11",
    "@mui/material": "^7.3.11",
    "@mui/x-data-grid": "^9.18.0",
    "@tanstack/react-query": "^5.108.4",
    "react": "^19.3.1",
    "react-dom": "^19.3.1",
    "react-hook-form": "^7.92.0",
    "zod": "^4.6.7"
  },
  "devDependencies": {
    "@types/react": "^19.3.0",
    "@types/react-dom": "^19.3.0",
    "@vitejs/plugin-react": "^6.3.0",
    "typescript": "~7.0.2",
    "vite": "^8.4.0"
  }
}
tsconfig.json
{
  "compilerOptions": {
    "target": "es2023",
    "lib": ["ES2023", "DOM", "DOM.Iterable"],
    "module": "esnext",
    "moduleResolution": "bundler",
    "types": ["vite/client"],
    "jsx": "react-jsx",
    "noEmit": true,
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "skipLibCheck": true,
    "noUncheckedIndexedAccess": true
  },
  "include": ["src", "vite.config.ts"]
}
vite.config.ts
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [react()],
});
index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Pierogarnia · Kitchen admin</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>

Step 2. Design tokens and the theme

Design tokens are named decisions: "brand colour 700", "medium radius", "sans-serif font". The MUI theme is just one of their consumers – the same tokens can be exported to emails, charts or a mobile app.

Diagram: From tokens to components: one source of decisions, no colours hard-coded in components

Three theme files: the tokens, the type declarations (module augmentation) and the theme itself:

Tokens, types and theme

src/theme/tokens.ts
// Design tokens: the single source of brand decisions. The MUI theme only maps them.
export const tokens = {
  font: {
    sans: '"Inter Variable", system-ui, -apple-system, "Segoe UI", sans-serif',
  },
  radius: { sm: 6, md: 10, lg: 14 },
  // "Beetroot" brand scale instead of the default Material blue.
  brand: { 50: "#fff0f6", 100: "#ffdeeb", 300: "#faa2c1", 500: "#e64980", 700: "#c2255c", 900: "#a61e4d" },
  neutral: {
    0: "#ffffff", 50: "#f8f9fa", 100: "#f1f3f5", 200: "#e9ecef", 300: "#dee2e6",
    500: "#868e96", 700: "#495057", 800: "#2b2f36", 900: "#1d2026", 950: "#141619",
  },
  status: {
    light: { placed: "#1971c2", cooking: "#d9480f", delivering: "#6741d9", delivered: "#2b8a3e", cancelled: "#868e96" },
    dark: { placed: "#74c0fc", cooking: "#ffa94d", delivering: "#b197fc", delivered: "#8ce99a", cancelled: "#adb5bd" },
  },
} as const;

export type OrderStatus = keyof typeof tokens.status.light;
src/theme/mui.d.ts
import type { OrderStatus } from "./tokens.ts";

// Module augmentation: teach MUI's types about our custom theme parts.
declare module "@mui/material/styles" {
  // We always enable CSS variables, so `theme.vars` is never undefined.
  interface CssThemeVariables {
    enabled: true;
  }
  interface Palette {
    status: Record<OrderStatus, string>;
  }
  interface PaletteOptions {
    status?: Record<OrderStatus, string>;
  }
}

declare module "@mui/material/Button" {
  interface ButtonPropsVariantOverrides {
    soft: true;
  }
}
src/theme/theme.ts
import { createTheme } from "@mui/material/styles";
import { tokens } from "./tokens.ts";

const { brand, neutral, radius, status } = tokens;

export const theme = createTheme({
  // CSS variables + a class on <html> switch light/dark without re-rendering React.
  cssVariables: { colorSchemeSelector: "class" },
  colorSchemes: {
    light: {
      palette: {
        primary: { main: brand[700], light: brand[500], dark: brand[900], contrastText: "#fff" },
        background: { default: neutral[50], paper: neutral[0] },
        text: { primary: neutral[900], secondary: neutral[700] },
        divider: neutral[200],
        status: status.light,
      },
    },
    dark: {
      palette: {
        primary: { main: brand[300], light: brand[100], dark: brand[500], contrastText: neutral[950] },
        background: { default: neutral[950], paper: neutral[900] },
        text: { primary: neutral[100], secondary: neutral[500] },
        divider: "rgba(255, 255, 255, 0.10)",
        status: status.dark,
      },
    },
  },
  shape: { borderRadius: radius.md },
  typography: {
    fontFamily: tokens.font.sans,
    h1: { fontSize: "1.75rem", fontWeight: 700, letterSpacing: "-0.02em" },
    h2: { fontSize: "1.25rem", fontWeight: 650, letterSpacing: "-0.01em" },
    overline: { fontWeight: 600, letterSpacing: "0.06em" },
    button: { textTransform: "none", fontWeight: 600 }, // no SHOUTING buttons
  },
  components: {
    MuiButtonBase: { defaultProps: { disableRipple: true } },
    MuiButton: {
      defaultProps: { disableElevation: true },
      styleOverrides: {
        root: ({ theme }) => ({
          borderRadius: radius.sm,
          "&.Mui-focusVisible": { outline: `2px solid ${theme.vars.palette.primary.main}`, outlineOffset: 2 },
          // Custom variant registered in mui.d.ts: <Button variant="soft">
          variants: [
            {
              props: { variant: "soft" },
              style: {
                color: theme.vars.palette.primary.main,
                backgroundColor: theme.alpha(theme.vars.palette.primary.main, 0.12),
                "&:hover": { backgroundColor: theme.alpha(theme.vars.palette.primary.main, 0.2) },
              },
            },
          ],
        }),
      },
    },
    MuiPaper: { defaultProps: { elevation: 0 }, styleOverrides: { root: { backgroundImage: "none" } } },
    MuiCard: { defaultProps: { variant: "outlined" } },
    MuiAppBar: {
      defaultProps: { elevation: 0, color: "inherit", position: "sticky" },
      styleOverrides: { root: ({ theme }) => ({ borderBottom: `1px solid ${theme.vars.palette.divider}` }) },
    },
    MuiTextField: { defaultProps: { size: "small", fullWidth: true } },
    MuiChip: { styleOverrides: { root: { fontWeight: 600, borderRadius: radius.sm } } },
    MuiTooltip: { defaultProps: { arrow: true } },
  },
});

What's going on:

  • cssVariables: { colorSchemeSelector: "class" } – MUI generates CSS variables (--mui-palette-primary-main) and switches the scheme with a .dark class on <html>. Components reference the variables, so changing the mode is just a class change, with no React re-render.
  • colorSchemes.light / colorSchemes.dark – two palettes built from the same tokens. In dark mode the primary colour is lighter (brand[300]) to keep the contrast.
  • theme.vars.palette… in overrides instead of theme.palette… – the CSS variable, not a fixed light-theme colour. Thanks to the CssThemeVariables { enabled: true } augmentation TypeScript knows theme.vars always exists.
  • components – default props and style overrides for every instance of a component. This is where shadows, ripples and upper-case labels disappear.
  • A custom soft variant – register it in ButtonPropsVariantOverrides and add its style in styleOverrides.root.variants. From then on <Button variant="soft"> is typed and autocompleted.
MUI defaultIn this projectWhere
blue #1976d2a "beetroot" brand scale from the tokenscolorSchemes.*.palette.primary
RobotoInter Variable via Fontsourcetypography.fontFamily
upper-case BUTTONtextTransform: "none", weight 600typography.button
shadows (elevation 1–24)1 px borders, elevation: 0MuiPaper, MuiCard, MuiAppBar
ripple on clicka clear 2 px focus ringMuiButtonBase, MuiButton
medium inputssmall inputs – a denser panelMuiTextField.defaultProps

Step 3. Dark mode without the flash

With a CSS-variables theme, dark mode needs three things: ThemeProvider with defaultMode, CssBaseline enableColorScheme (scrollbars and native inputs go dark too) and a switch built on useColorScheme().

Colour scheme switch

src/components/ThemeModeToggle.tsx
import DarkModeOutlined from "@mui/icons-material/DarkModeOutlined";
import LightModeOutlined from "@mui/icons-material/LightModeOutlined";
import SettingsBrightnessOutlined from "@mui/icons-material/SettingsBrightnessOutlined";
import ToggleButton from "@mui/material/ToggleButton";
import ToggleButtonGroup from "@mui/material/ToggleButtonGroup";
import { useColorScheme } from "@mui/material/styles";

export function ThemeModeToggle() {
  const { mode, setMode } = useColorScheme(); // "light" | "dark" | "system", persisted in localStorage
  if (!mode) return null; // not resolved yet on the very first render

  return (
    <ToggleButtonGroup
      size="small"
      exclusive
      value={mode}
      onChange={(_, next: typeof mode | null) => next && setMode(next)}
      aria-label="Colour scheme"
    >
      <ToggleButton value="light" aria-label="Light">
        <LightModeOutlined fontSize="small" />
      </ToggleButton>
      <ToggleButton value="system" aria-label="System">
        <SettingsBrightnessOutlined fontSize="small" />
      </ToggleButton>
      <ToggleButton value="dark" aria-label="Dark">
        <DarkModeOutlined fontSize="small" />
      </ToggleButton>
    </ToggleButtonGroup>
  );
}

The rest of this article is for members

Create a free account or sign in to read it all. Still ahead:

  • Step 4. Custom components: styled, sx and a status palette
  • Step 5. DataGrid: client-side and server-side tables
  • Step 6. A form: react-hook-form + MUI components
  • Step 7. Putting the panel together
  • Avoiding the "default Material" look – a checklist
  • Common mistakes
  • Check yourself
  • What next

Create a free account · Sign in