Skip to content

Commit

Permalink
[docs] Add CodeSandbox/Stackblitz to the rest of the templates (#43708)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored Oct 21, 2024
1 parent a7b7d9c commit 91d0d91
Show file tree
Hide file tree
Showing 177 changed files with 1,070 additions and 17,878 deletions.
69 changes: 15 additions & 54 deletions docs/data/material/getting-started/templates/blog/Blog.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,26 @@
import * as React from 'react';
import CssBaseline from '@mui/material/CssBaseline';
import Container from '@mui/material/Container';
import { createTheme, ThemeProvider } from '@mui/material/styles';
import AppAppBar from './components/AppAppBar';
import MainContent from './components/MainContent';
import Latest from './components/Latest';
import Footer from './components/Footer';
import TemplateFrame from './TemplateFrame';

import getBlogTheme from './theme/getBlogTheme';

export default function Blog() {
const [mode, setMode] = React.useState('light');
const [showCustomTheme, setShowCustomTheme] = React.useState(true);
const blogTheme = createTheme(getBlogTheme(mode));
const defaultTheme = createTheme({ palette: { mode } });
// This code only runs on the client side, to determine the system color preference
React.useEffect(() => {
// Check if there is a preferred mode in localStorage
const savedMode = localStorage.getItem('themeMode');
if (savedMode) {
setMode(savedMode);
} else {
// If no preference is found, it uses system preference
const systemPrefersDark = window.matchMedia(
'(prefers-color-scheme: dark)',
).matches;
setMode(systemPrefersDark ? 'dark' : 'light');
}
}, []);

const toggleColorMode = () => {
const newMode = mode === 'dark' ? 'light' : 'dark';
setMode(newMode);
localStorage.setItem('themeMode', newMode); // Save the selected mode to localStorage
};

const toggleCustomTheme = () => {
setShowCustomTheme((prev) => !prev);
};
import AppTheme from '../shared-theme/AppTheme';

export default function Blog(props) {
return (
<TemplateFrame
toggleCustomTheme={toggleCustomTheme}
showCustomTheme={showCustomTheme}
mode={mode}
toggleColorMode={toggleColorMode}
>
<ThemeProvider theme={showCustomTheme ? blogTheme : defaultTheme}>
<CssBaseline enableColorScheme />
<AppAppBar />
<Container
maxWidth="lg"
component="main"
sx={{ display: 'flex', flexDirection: 'column', my: 16, gap: 4 }}
>
<MainContent />
<Latest />
</Container>
<Footer />
</ThemeProvider>
</TemplateFrame>
<AppTheme {...props}>
<CssBaseline enableColorScheme />
<AppAppBar />
<Container
maxWidth="lg"
component="main"
sx={{ display: 'flex', flexDirection: 'column', my: 16, gap: 4 }}
>
<MainContent />
<Latest />
</Container>
<Footer />
</AppTheme>
);
}
69 changes: 15 additions & 54 deletions docs/data/material/getting-started/templates/blog/Blog.tsx
Original file line number Diff line number Diff line change
@@ -1,66 +1,27 @@
import * as React from 'react';
import CssBaseline from '@mui/material/CssBaseline';
import Container from '@mui/material/Container';
import { createTheme, ThemeProvider, PaletteMode } from '@mui/material/styles';
import AppAppBar from './components/AppAppBar';
import MainContent from './components/MainContent';
import Latest from './components/Latest';
import Footer from './components/Footer';
import TemplateFrame from './TemplateFrame';

import getBlogTheme from './theme/getBlogTheme';

export default function Blog() {
const [mode, setMode] = React.useState<PaletteMode>('light');
const [showCustomTheme, setShowCustomTheme] = React.useState(true);
const blogTheme = createTheme(getBlogTheme(mode));
const defaultTheme = createTheme({ palette: { mode } });
// This code only runs on the client side, to determine the system color preference
React.useEffect(() => {
// Check if there is a preferred mode in localStorage
const savedMode = localStorage.getItem('themeMode') as PaletteMode | null;
if (savedMode) {
setMode(savedMode);
} else {
// If no preference is found, it uses system preference
const systemPrefersDark = window.matchMedia(
'(prefers-color-scheme: dark)',
).matches;
setMode(systemPrefersDark ? 'dark' : 'light');
}
}, []);

const toggleColorMode = () => {
const newMode = mode === 'dark' ? 'light' : 'dark';
setMode(newMode);
localStorage.setItem('themeMode', newMode); // Save the selected mode to localStorage
};

const toggleCustomTheme = () => {
setShowCustomTheme((prev) => !prev);
};
import AppTheme from '../shared-theme/AppTheme';

export default function Blog(props: { disableCustomTheme?: boolean }) {
return (
<TemplateFrame
toggleCustomTheme={toggleCustomTheme}
showCustomTheme={showCustomTheme}
mode={mode}
toggleColorMode={toggleColorMode}
>
<ThemeProvider theme={showCustomTheme ? blogTheme : defaultTheme}>
<CssBaseline enableColorScheme />
<AppTheme {...props}>
<CssBaseline enableColorScheme />

<AppAppBar />
<Container
maxWidth="lg"
component="main"
sx={{ display: 'flex', flexDirection: 'column', my: 16, gap: 4 }}
>
<MainContent />
<Latest />
</Container>
<Footer />
</ThemeProvider>
</TemplateFrame>
<AppAppBar />
<Container
maxWidth="lg"
component="main"
sx={{ display: 'flex', flexDirection: 'column', my: 16, gap: 4 }}
>
<MainContent />
<Latest />
</Container>
<Footer />
</AppTheme>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<!-- #default-branch-switch -->

1. Copy the files into your project, or one of the [example projects](https://github.com/mui/material-ui/tree/master/examples).
1. Copy these folders (`blog` and `shared-theme`) into your project, or one of the [example projects](https://github.com/mui/material-ui/tree/master/examples).
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.

Expand Down
113 changes: 0 additions & 113 deletions docs/data/material/getting-started/templates/blog/TemplateFrame.js

This file was deleted.

Loading

0 comments on commit 91d0d91

Please sign in to comment.