MUI blog template example - DAV-1000/react-material GitHub Wiki

Created: 7/31/2025 16:56
Updated: 7/31/2025 17:02
Exported: 8/14/2025 11:13
Link: https://chatgpt.com/c/688b9235-0b74-8001-8c5c-a3bd92cf96f3

Prompt:

Give me an example of using the Material UI Blog template in React

Response:

Sure! Here's a working example of how to use the Material UI (MUI) Blog template in a React app. Material UI provides a Blog template as part of its official template gallery, and you can customize it as needed.

βœ… Steps:

  1. Set up your React app
    npx create-react-app mui-blog
    cd mui-blog
    npm install @mui/material @emotion/react @emotion/styled @mui/icons-material
  2. Replace App.js with the Blog template code

Below is a simplified version of the MUI Blog template in one file (App.js). For a more modular structure, you'd break it up into components.


πŸ“ App.js

import React from 'react';
import {
  AppBar, Toolbar, Typography, CssBaseline, Container, Grid, Card, CardContent, CardMedia, Link, Box
} from '@mui/material';

const featuredPosts = [
  {
    title: 'Post One',
    date: 'Jul 31',
    description: 'This is a wider card with supporting text below.',
    image: 'https://source.unsplash.com/random?tech',
  },
  {
    title: 'Post Two',
    date: 'Jul 30',
    description: 'This is another card with supporting text.',
    image: 'https://source.unsplash.com/random?nature',
  },
];

function Header() {
  return (
    <AppBar position="static" color="default" elevation={0}>
      <Toolbar>
        <Typography variant="h6" color="inherit" noWrap>
          My Blog
        </Typography>
      </Toolbar>
    </AppBar>
  );
}

function MainFeaturedPost() {
  return (
    <Box sx={{ bgcolor: 'grey.200', p: 6, mb: 4 }}>
      <Typography variant="h3" gutterBottom>
        Welcome to My Blog
      </Typography>
      <Typography variant="h6" paragraph>
        Explore insightful articles on tech, development, and design.
      </Typography>
    </Box>
  );
}

function FeaturedPost({ post }) {
  return (
    <Grid item xs={12} md={6}>
      <Card sx={{ display: 'flex', flexDirection: 'column' }}>
        <CardMedia
          component="img"
          image={post.image}
          alt={post.title}
          height="200"
        />
        <CardContent>
          <Typography component="h2" variant="h5">
            {post.title}
          </Typography>
          <Typography variant="subtitle1" color="text.secondary">
            {post.date}
          </Typography>
          <Typography variant="subtitle1" paragraph>
            {post.description}
          </Typography>
          <Link href="#">Continue reading...</Link>
        </CardContent>
      </Card>
    </Grid>
  );
}

export default function App() {
  return (
    <>
      <CssBaseline />
      <Header />
      <Container maxWidth="lg">
        <MainFeaturedPost />
        <Grid container spacing={4}>
          {featuredPosts.map((post) => (
            <FeaturedPost key={post.title} post={post} />
          ))}
        </Grid>
      </Container>
    </>
  );
}

πŸ–Ό Result:

This will render:

  • A header bar with "My Blog"
  • A main featured section with an intro
  • Two blog post cards (you can add more by extending featuredPosts)

πŸ”§ Tips:

  • You can modularize components like Header, FeaturedPost, and MainFeaturedPost into separate files.
  • To match the full template from MUI's site, you'd also add:
    • Footer component
    • Sidebar with recent posts or archives
    • Routing with React Router if needed

Would you like a version with routing or Markdown post support?

Prompt:

My react app is in typescript

Response:

Great! If your React app is using TypeScript, here's how you can adapt the Material UI Blog template to work with TypeScript.


βœ… Step-by-Step Guide

1. Create a React + TypeScript app

npx create-react-app mui-blog-ts --template typescript
cd mui-blog-ts
npm install @mui/material @emotion/react @emotion/styled @mui/icons-material

🧩 TypeScript-Compatible Blog Template

Here's a modular version of the Blog using TypeScript components.

1. App.tsx

import React from 'react';
import CssBaseline from '@mui/material/CssBaseline';
import Container from '@mui/material/Container';
import Grid from '@mui/material/Grid';

import Header from './components/Header';
import MainFeaturedPost from './components/MainFeaturedPost';
import FeaturedPost from './components/FeaturedPost';

const featuredPosts = [
  {
    title: 'Post One',
    date: 'Jul 31',
    description: 'This is a wider card with supporting text below.',
    image: 'https://source.unsplash.com/random?tech',
  },
  {
    title: 'Post Two',
    date: 'Jul 30',
    description: 'This is another card with supporting text.',
    image: 'https://source.unsplash.com/random?nature',
  },
];

function App() {
  return (
    <>
      <CssBaseline />
      <Header title="My Blog" />
      <Container maxWidth="lg">
        <MainFeaturedPost />
        <Grid container spacing={4}>
          {featuredPosts.map((post) => (
            <FeaturedPost key={post.title} post={post} />
          ))}
        </Grid>
      </Container>
    </>
  );
}

export default App;

2. components/Header.tsx

import React from 'react';
import AppBar from '@mui/material/AppBar';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';

interface HeaderProps {
  title: string;
}

const Header: React.FC<HeaderProps> = ({ title }) => (
  <AppBar position="static" color="default" elevation={0}>
    <Toolbar>
      <Typography variant="h6" color="inherit" noWrap>
        {title}
      </Typography>
    </Toolbar>
  </AppBar>
);

export default Header;

3. components/MainFeaturedPost.tsx

import React from 'react';
import { Box, Typography } from '@mui/material';

const MainFeaturedPost: React.FC = () => (
  <Box sx={{ bgcolor: 'grey.200', p: 6, mb: 4 }}>
    <Typography variant="h3" gutterBottom>
      Welcome to My Blog
    </Typography>
    <Typography variant="h6" paragraph>
      Explore insightful articles on tech, development, and design.
    </Typography>
  </Box>
);

export default MainFeaturedPost;

4. components/FeaturedPost.tsx

import React from 'react';
import {
  Card,
  CardContent,
  CardMedia,
  Grid,
  Typography,
  Link,
} from '@mui/material';

interface Post {
  title: string;
  date: string;
  description: string;
  image: string;
}

interface FeaturedPostProps {
  post: Post;
}

const FeaturedPost: React.FC<FeaturedPostProps> = ({ post }) => (
  <Grid item xs={12} md={6}>
    <Card sx={{ display: 'flex', flexDirection: 'column' }}>
      <CardMedia component="img" image={post.image} alt={post.title} height="200" />
      <CardContent>
        <Typography component="h2" variant="h5">
          {post.title}
        </Typography>
        <Typography variant="subtitle1" color="text.secondary">
          {post.date}
        </Typography>
        <Typography variant="subtitle1" paragraph>
          {post.description}
        </Typography>
        <Link href="#">Continue reading...</Link>
      </CardContent>
    </Card>
  </Grid>
);

export default FeaturedPost;

πŸ“ File Structure

mui-blog-ts/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ Header.tsx
β”‚   β”‚   β”œβ”€β”€ MainFeaturedPost.tsx
β”‚   β”‚   └── FeaturedPost.tsx
β”‚   β”œβ”€β”€ App.tsx
β”‚   └── index.tsx

βœ… TypeScript Benefits Here

  • Strong typing for post objects.
  • Reusable, modular components.
  • Easy to scale into a full blog (with routing, markdown, CMS, etc).

Let me know if you’d like to add:

  • Routing with react-router-dom
  • Markdown rendering for blog content
  • Blog posts fetched from an API or local .md files

Prompt:

The instructions in the blog readme.md are : 1. Copy these folders (blog and shared-theme) into your project 2. Make sure your project has the required dependencies: @mui/material, @mui/icons-material, @emotion/styled, @emotion/react, markdown-to-jsx. 3. Import and use the Blog component.

Response:

Thanks for the clarification! You're referring to the official Material UI Blog Template from the MUI GitHub repo, which is structured around two folders: blog/ and shared-theme/.

Let's walk through how to integrate it in your TypeScript React app.


βœ… Step-by-Step Setup

1. Download blog/ and shared-theme/

Go to the GitHub repository:

πŸ“ MUI Blog Template on GitHub

Download or copy these two folders into your project’s src/ directory:

src/
β”œβ”€β”€ blog/
β”œβ”€β”€ shared-theme/

Make sure the *.js or *.jsx files are renamed to *.tsx, and adjust types accordingly if needed.


2. Install Required Dependencies

npm install @mui/material @mui/icons-material @emotion/react @emotion/styled markdown-to-jsx

For TypeScript support (optional but recommended):

npm install --save-dev @types/react @types/react-dom

3. Update Imports if Needed

In the files inside blog/ and shared-theme/, update any .js or .jsx extensions in imports to .tsx or remove the extension if using modern module resolution.

Also, in some cases you'll want to add types like this:

// Example in blog/components/Main.tsx
const Main: React.FC<{ posts: Post[] }> = ({ posts }) => {
  // ...
};

4. Use the Blog Component

In your App.tsx (or a route/page component), simply use:

import React from 'react';
import Blog from './blog/Blog'; // Adjust path if needed

function App() {
  return <Blog />;
}

export default App;

βœ… File Structure After Setup

src/
β”œβ”€β”€ App.tsx
β”œβ”€β”€ blog/
β”‚   └── [all blog components like Blog.tsx, Main.tsx, Sidebar.tsx etc.]
β”œβ”€β”€ shared-theme/
β”‚   └── [theme/index.ts, branding etc.]

🧠 Optional Improvements

  • Convert all .js to .ts or .tsx with types.
  • Add typing for blog posts (Post interface).
  • Modularize content with Markdown files or an API later.

Would you like me to give you the full TypeScript version of the Blog.tsx with all necessary types included?


Powered by ChatGPT Exporter

⚠️ **GitHub.com Fallback** ⚠️