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

[examples] Add material-ui-pigment-css for Next.js and Vite #43065

Merged
merged 20 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
# next-env.d.ts
45 changes: 45 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Material UI x Pigment CSS - Next.js App Router example in TypeScript

Check failure on line 1 in examples/material-ui-pigment-css-nextjs-ts/README.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Pigment CSS' instead of 'Pigment CSS') Raw Output: {"message": "[MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Pigment CSS' instead of 'Pigment CSS')", "location": {"path": "examples/material-ui-pigment-css-nextjs-ts/README.md", "range": {"start": {"line": 1, "column": 17}}}, "severity": "ERROR"}

This is a [Next.js](https://nextjs.org/) project bootstrapped using [`create-next-app`](https://github.com/vercel/next.js/tree/HEAD/packages/create-next-app) with Material UI installed.

## How to use

Download the example [or clone the repo](https://github.com/mui/material-ui):

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

```bash
curl https://codeload.github.com/mui/material-ui/tar.gz/next | tar -xz --strip=2 material-ui-next/examples/material-ui-pigment-css-nextjs-ts
cd material-ui-pigment-css-nextjs-ts
```

Install it and run:

```bash
npm install
npm run dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

or:

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

[![Edit on StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/mui/material-ui/tree/next/examples/material-ui-pigment-css-nextjs-ts)

[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/github/mui/material-ui/tree/next/examples/material-ui-pigment-css-nextjs-ts)

## Learn more

To learn more about this example:

- [Next.js documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Customizing Material UI](https://mui.com/material-ui/customization/how-to-customize/) - approaches to customizing Material UI.

## What's next?

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

You now have a working example project.
You can head back to the documentation and continue by browsing the [templates](https://next.mui.com/material-ui/getting-started/templates/) section.
5 changes: 5 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
14 changes: 14 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { withPigment } from '@pigment-css/nextjs-plugin';
import { extendTheme } from '@mui/material';

/** @type {import('next').NextConfig} */
const nextConfig = {};

export default withPigment(nextConfig, {
theme: extendTheme({
typography: {
fontFamily: 'var(--font-family)',
},
}),
transformLibraries: ['@mui/material'],
});
27 changes: 27 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "material-ui-pigment-css-nextjs-ts",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@mui/material": "next",
"@mui/material-pigment-css": "next",
"next": "latest",
"react": "latest",
"react-dom": "latest"
},
"devDependencies": {
"@pigment-css/nextjs-plugin": "latest",
"@types/node": "latest",
"@types/react": "latest",
"@types/react-dom": "latest",
"eslint": "latest",
"eslint-config-next": "latest",
"typescript": "latest"
}
}
Empty file.
Binary file not shown.
22 changes: 22 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Metadata } from 'next';
import { Roboto } from 'next/font/google';
import '@mui/material-pigment-css/styles.css';

const roboto = Roboto({ subsets: ['latin'], weight: ['400', '500', '700'] });

export const metadata: Metadata = {
title: 'Material UI x Pigment CSS',
description: 'Generated by create next app',
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body style={{ '--font-family': roboto.style.fontFamily } as any}>{children}</body>
</html>
);
}
111 changes: 111 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import CssBaseline from '@mui/material/CssBaseline';
import Container from '@mui/material-pigment-css/Container';
import Grid from '@mui/material-pigment-css/Grid';
import Typography from '@mui/material/Typography';
import Chip from '@mui/material/Chip';

export default function Home() {
return (
<main sx={{ minHeight: '100lvh', display: 'grid', placeItems: 'center' }}>
<CssBaseline />
<Container>
<Grid container spacing={{ xs: 2, sm: 3, md: 4 }}>
<Grid size={{ xs: 12, md: 6 }}>
<Chip
label="Available in v6"
color="primary"
sx={(theme) => ({
mb: 2,
fontWeight: 600,
bgcolor: `rgba(${theme.vars.palette.primary.mainChannel} / 0.1)`,
color: 'primary.dark',
})}
/>
<Typography
variant="h1"
sx={{
fontWeight: 500,
fontSize: 'clamp(3rem, 2.354rem + 2.7562vw, 5rem)',
textWrap: 'balance',
letterSpacing: '-0.025em',
}}
>
<span
sx={(theme) => ({
display: 'block',
background: `linear-gradient(145deg, ${
(theme.vars || theme).palette.primary.light
} 5%, ${(theme.vars || theme).palette.primary.dark} 90%)`,
// `Webkit` has to come later
WebkitBackgroundClip: 'text',
WebkitTextFillColor: 'transparent',
})}
>
Material UI
</span>
Pigment CSS
</Typography>
</Grid>
<Grid size={{ xs: 12, md: 6 }}>
<ul
sx={{
m: 0,
pl: 3,
color: 'text.secondary',
'& li': {
pl: 2,
fontSize: '1.5rem',
fontWeight: 500,
'&:not(:first-child)': {
marginTop: 2,
},
'&::marker': {
color: 'text.primary',
},
'& > div': {
color: 'text.primary',
fontSize: '1.5rem',
lineHeight: 1.7,
},
siriwatknp marked this conversation as resolved.
Show resolved Hide resolved
},
}}
>
<li
sx={{
'&::marker': { content: '"⚡️"' },
}}
>
<Typography component="div">Build-time CSS Extraction</Typography>
<Typography>
Pigment CSS will look through Material UI components used in the project and
extract the styles into plain CSS.
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 accurate? Wouldn't Pigment also extract styles from styled, css, sx even if they're non-Material UI components?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's accurate, my intention is to point out the integration. We can add more to cover your point, what do you have in mind?

Copy link
Member

Choose a reason for hiding this comment

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

With the current wording some developers might get confused and think that Pigment CSS only works for Material UI components.

</Typography>
</li>
<li
sx={{
'&::marker': { content: '"🚀"' },
}}
>
<Typography component="div">React Server Components</Typography>
<Typography>
Material UI provides a separate set of layout components that integrated with
siriwatknp marked this conversation as resolved.
Show resolved Hide resolved
Pigment CSS to support React Server Components.
</Typography>
</li>
<li
sx={{
'&::marker': { content: '"📦"' },
}}
>
<Typography component="div" variant="subtitle1">
siriwatknp marked this conversation as resolved.
Show resolved Hide resolved
Emotionless
</Typography>
<Typography>Emotion will be removed from the final bundle, saved ~15kB.</Typography>
siriwatknp marked this conversation as resolved.
Show resolved Hide resolved
</li>
</ul>
</Grid>
</Grid>
</Container>
</main>
);
}
16 changes: 16 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/src/augment.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Theme, SxProps } from '@mui/material/styles';
import {} from '@mui/material/themeCssVarsAugmentation';

declare module '@mui/material-pigment-css/theme' {
interface ThemeArgs {
theme: Theme;
}
}

declare global {
namespace React {
interface HTMLAttributes<T> {
sx?: SxProps<Theme>;
}
}
}
26 changes: 26 additions & 0 deletions examples/material-ui-pigment-css-nextjs-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
18 changes: 18 additions & 0 deletions examples/material-ui-pigment-css-vite-ts/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions examples/material-ui-pigment-css-vite-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
39 changes: 39 additions & 0 deletions examples/material-ui-pigment-css-vite-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Material UI x Pigment CSS - Vite.js example

Check failure on line 1 in examples/material-ui-pigment-css-vite-ts/README.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Pigment CSS' instead of 'Pigment CSS') Raw Output: {"message": "[MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Pigment CSS' instead of 'Pigment CSS')", "location": {"path": "examples/material-ui-pigment-css-vite-ts/README.md", "range": {"start": {"line": 1, "column": 17}}}, "severity": "ERROR"}

## How to use

Download the example [or clone the repo](https://github.com/mui/material-ui):

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

```bash
curl https://codeload.github.com/mui/material-ui/tar.gz/next | tar -xz --strip=2 material-ui-next/examples/material-ui-pigment-css-vite-ts
cd material-ui-pigment-css-vite-ts
```

Install it and run:

```bash
npm install
npm run dev
```

or:

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

[![Edit on StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/mui/material-ui/tree/next/examples/material-ui-pigment-css-vite-ts)

[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/github/mui/material-ui/tree/next/examples/material-ui-pigment-css-vite-ts)

## The idea behind the example

This example uses [Vite.js](https://github.com/vitejs/vite).
siriwatknp marked this conversation as resolved.
Show resolved Hide resolved
It includes `@mui/material` and [Pigment CSS](https://github.com/mui/pigment-css) as the style engine.

Check failure on line 32 in examples/material-ui-pigment-css-vite-ts/README.md

View workflow job for this annotation

GitHub Actions / runner / vale

[vale] reported by reviewdog 🐶 [MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Pigment CSS' instead of 'Pigment CSS') Raw Output: {"message": "[MUI.MuiBrandName] Use a non-breaking space (option+space on Mac, Alt+0160 on Windows or AltGr+Space on Linux, instead of space) for brand name ('Pigment CSS' instead of 'Pigment CSS')", "location": {"path": "examples/material-ui-pigment-css-vite-ts/README.md", "range": {"start": {"line": 32, "column": 34}}}, "severity": "ERROR"}

## What's next?

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

You now have a working example project.
You can head back to the documentation and continue by browsing the [templates](https://next.mui.com/material-ui/getting-started/templates/) section.
Loading
Loading