Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Improve "Example projects" page design #37007

Merged
merged 6 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ You can find some example projects in the [GitHub repository](https://github.com

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

- [Next.js](https://github.com/mui/material-ui/tree/master/examples/material-next) ([TypeScript version](https://github.com/mui/material-ui/tree/master/examples/material-next-ts))
- [Create React App](https://github.com/mui/material-ui/tree/master/examples/material-cra) ([TypeScript version](https://github.com/mui/material-ui/tree/master/examples/material-cra-ts))
- [Remix](https://github.com/mui/material-ui/tree/master/examples/material-remix-ts)
- [Gatsby](https://github.com/mui/material-ui/tree/master/examples/material-gatsby)
- [Preact](https://github.com/mui/material-ui/tree/master/examples/material-preact)
- [CDN](https://github.com/mui/material-ui/tree/master/examples/material-via-cdn)
- [Express.js (server-rendered)](https://github.com/mui/material-ui/tree/master/examples/material-express-ssr)
- [Tailwind CSS](https://github.com/mui/material-ui/tree/master/examples/material-cra-tailwind-ts)
- [Vite.js](https://github.com/mui/material-ui/tree/master/examples/material-vite) ([TypeScript version](https://github.com/mui/material-ui/tree/master/examples/material-vite-ts))
- [Use styled-components as style engine](https://github.com/mui/material-ui/tree/master/examples/material-cra-styled-components) ([TypeScript version](https://github.com/mui/material-ui/tree/master/examples/material-cra-styled-components-ts))
- [Next.js + @mui/styles (v4 migration helper)](https://github.com/mui/material-ui/tree/master/examples/material-next-ts-v4-v5-migration)
{{"component": "docs/src/modules/components/ExampleCollection.js"}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update the rest of the docs to use the full import path?

Screenshot 2023-05-25 at 12 03 33

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You tell me! Is it better, code-wise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would imagine that

Suggested change
{{"component": "docs/src/modules/components/ExampleCollection.js"}}
{{"component": "modules/components/ExampleCollection.js"}}

in the docs page would have worked without the need to change the docs-infra: https://github.com/mui/material-ui/pull/37007/files#diff-8896d42292e63fa8530b9808a333b4770fee0e9fbe33d57e0b4ab5b3b723ed3dR223.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually, the location of the demo. This is now with the rest of the global component: docs/src/modules/components/. This folder is meant for global components.

If this component is only used on this page, I think we should move it, we can host it in the same folder as the docs docs/data/material/getting-started/example-projects/ so that if we ever refactor the page, we would remove this dead demo at the same time.

Shall we move the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll leave it up to @siriwatknp to decide on this one, then, as he pushed that commit on!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking back at this, I think one of the reasons to have it moved over to that global folder was so it could pick up the theme. Is there a way so that it sits locally with the markdown files but picking up the branding theme?


<br />

Create React App is an awesome project for learning React.
danilo-leal marked this conversation as resolved.
Show resolved Hide resolved
Have a look at [the alternatives available](https://github.com/facebook/create-react-app/blob/HEAD/README.md#popular-alternatives) to see which project best fits your needs.
Expand Down
3 changes: 3 additions & 0 deletions docs/public/static/images/examples/cra.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/static/images/examples/express.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions docs/public/static/images/examples/gatsby.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/public/static/images/examples/next.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions docs/public/static/images/examples/preact.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions docs/public/static/images/examples/remix.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/static/images/examples/styled.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/public/static/images/examples/tailwindcss.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/public/static/images/examples/vite.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
188 changes: 188 additions & 0 deletions docs/src/modules/components/ExampleCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Grid from '@mui/material/Unstable_Grid2';
import Card from '@mui/material/Card';
import Avatar from '@mui/material/Avatar';
import Typography from '@mui/material/Typography';
import Link from '@mui/material/Link';
import ChevronRightRoundedIcon from '@mui/icons-material/ChevronRightRounded';
import FilterDramaIcon from '@mui/icons-material/FilterDrama';

const examples = [
{
name: 'Next.js',
label: 'View JS example',
tsLabel: 'View TS example',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-next',
tsLink: 'https://github.com/mui/material-ui/tree/master/examples/material-next-ts',
src: '/static/images/examples/next.svg',
},
{
name: 'Create React App',
label: 'View JS example',
tsLabel: 'View TS example',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-cra',
tsLink: 'https://github.com/mui/material-ui/tree/master/examples/material-cra-ts',
src: '/static/images/examples/cra.svg',
},
{
name: 'Remix',
label: 'View example',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-remix-ts',
src: '/static/images/examples/remix.svg',
},
{
name: 'Tailwind CSS',
label: 'View example',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-cra-tailwind-ts',
src: '/static/images/examples/tailwindcss.svg',
},
{
name: 'Vite.js',
label: 'View JS example',
tsLabel: 'View TS example',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-vite',
src: '/static/images/examples/vite.svg',
},
{
name: 'styled-components',
label: 'View JS example',
tsLabel: 'View TS example',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-cra-styled-components',
tsLink:
'https://github.com/mui/material-ui/tree/master/examples/material-cra-styled-components-ts',
src: '/static/images/examples/styled.png',
},
{
name: 'Gatsby',
label: 'View example',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-gatsby',
src: '/static/images/examples/gatsby.svg',
},
{
name: 'Preact',
label: 'View example',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-preact',
src: '/static/images/examples/preact.svg',
},
{
name: 'CDN',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-via-cdn',
label: 'View example',
src: <FilterDramaIcon />,
},
{
name: 'Express.js (server-rendered)',
label: 'View example',
link: 'https://github.com/mui/material-ui/tree/master/examples/material-express-ssr',
src: '/static/images/examples/express.png',
},
];

export default function ExampleCollection() {
return (
<Grid container spacing={2}>
{examples.map((example) => (
<Grid key={example.name} item xs={12} sm={6}>
<Card
sx={[
{
p: 2,
height: '100%',
display: 'flex',
alignItems: 'center',
gap: 2,
bgcolor: '#fff',
backgroundImage: 'none',
borderRadius: 1,
border: '1px solid',
borderColor: 'grey.200',
boxShadow: 'none',
'&:hover': {
borderColor: 'grey.300',
boxShadow: '0px 2px 8px rgba(170, 180, 190, 0.2)',
},
},
(theme) =>
theme.applyDarkStyles({
bgcolor: 'transparent',
borderColor: 'primaryDark.700',
'&:hover': {
borderColor: 'primaryDark.600',
boxShadow: '0px 2px 8px rgba(0, 13, 26, 1)',
},
}),
]}
>
<Avatar
imgProps={{
width: '40',
height: '40',
loading: 'lazy',
}}
{...(typeof example.src === 'string'
? { src: example.src }
: { children: example.src })}
alt={example.name}
/>
<div>
<Typography variant="body" fontWeight={600} sx={{ fontFamily: 'IBM Plex Sans' }}>
danilo-leal marked this conversation as resolved.
Show resolved Hide resolved
{example.name}
</Typography>
<Box
sx={{
display: 'flex',
flexWrap: 'wrap',
alignItems: 'baseline',
}}
>
<Link
href={example.link}
variant="body2"
sx={{
fontFamily: 'IBM Plex Sans',
fontWeight: 500,
display: 'flex',
alignItems: 'center',
mt: 0.5,
}}
>
{example.label}
<ChevronRightRoundedIcon fontSize="small" />
</Link>
{!!example.tsLink && (
<React.Fragment>
<Typography
variant="caption"
sx={{
fontFamily: 'IBM Plex Sans',
display: { xs: 'none', sm: 'block' },
opacity: 0.2,
mr: 0.75,
}}
>
/
</Typography>
<Link
href={example.tsLink}
variant="body2"
sx={{
fontFamily: 'IBM Plex Sans',
fontWeight: 500,
display: 'flex',
alignItems: 'center',
}}
>
{example.tsLabel}
<ChevronRightRoundedIcon fontSize="small" />
</Link>
</React.Fragment>
)}
</Box>
</div>
</Card>
</Grid>
))}
</Grid>
);
}
4 changes: 3 additions & 1 deletion packages/markdown/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,9 @@ module.exports = async function demoLoader() {
);

componentNames.forEach((componentName) => {
const moduleID = path.join(this.rootContext, 'src', componentName).replace(/\\/g, '/');
const moduleID = path
.join(this.rootContext, 'src', componentName.replace(/^docs\/src/, ''))
.replace(/\\/g, '/');
Comment on lines +222 to +224
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change needed? https://github.com/mui/material-ui/pull/37007/files#r1205292380

Suggested change
const moduleID = path
.join(this.rootContext, 'src', componentName.replace(/^docs\/src/, ''))
.replace(/\\/g, '/');
const moduleID = path.join(this.rootContext, 'src', componentName).replace(/\\/g, '/');
``


components[moduleID] = componentName;
componentModuleIDs.add(moduleID);
Expand Down