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 pigment-css-nextjs-ts starter project #41105

Merged
merged 27 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b9dd1ff
init zero-nextjs example
siriwatknp Feb 7, 2024
3e34f13
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp Feb 7, 2024
6bec039
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp Feb 13, 2024
de7ff2e
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp Feb 14, 2024
839a284
add keyframes to README
siriwatknp Feb 15, 2024
69ebd43
add zero-nextjs starter
siriwatknp Feb 15, 2024
c294dfb
update project README
siriwatknp Feb 15, 2024
a8e8f09
add styles import to the docs
siriwatknp Feb 15, 2024
272e1bc
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp Feb 19, 2024
539e5c3
convert to object styles
siriwatknp Feb 19, 2024
3a1e93e
move global css to zero-runtime
siriwatknp Feb 19, 2024
85087cc
test server action
siriwatknp Feb 19, 2024
cd8ddd2
Revert "test server action"
siriwatknp Feb 20, 2024
47e1c1a
add comment
siriwatknp Feb 20, 2024
e3f4ba0
update tsconfig
siriwatknp Feb 20, 2024
75c67f3
update version to 'latest'
siriwatknp Feb 20, 2024
3013638
add `applyStyles` to README
siriwatknp Feb 20, 2024
7585b0e
Apply suggestions from code review
siriwatknp Feb 26, 2024
ad28f60
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp Feb 26, 2024
3bba2e1
run prettier
siriwatknp Feb 26, 2024
c88f7e9
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp Feb 27, 2024
cf7d148
add types comment
siriwatknp Feb 27, 2024
cea6412
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp Mar 4, 2024
4114c83
replace zero with pigment
siriwatknp Mar 4, 2024
178a00a
use pigment-css
siriwatknp Mar 4, 2024
8288b23
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp Mar 8, 2024
bcd0182
update readme
siriwatknp Mar 8, 2024
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
36 changes: 36 additions & 0 deletions examples/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
38 changes: 38 additions & 0 deletions examples/pigment-css-nextjs-ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Pigment CSS - Next.js App Router with TypeScript example project

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 TypeScript and MUI's zero-runtime CSS-in-JS 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/master | tar -xz --strip=2 material-ui-master/examples/pigment-css-nextjs-ts
cd 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/master/examples/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/master/examples/pigment-css-nextjs-ts)

## Learn more

To learn more about this example:

- [Pigment CSS documentation](https://github.com/mui/material-ui/blob/master/packages/pigment-react/README.md) - learn more about Pigment CSS features and APIs.
- [Next.js documentation](https://nextjs.org/docs) - learn about Next.js features and APIs.
5 changes: 5 additions & 0 deletions examples/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.
28 changes: 28 additions & 0 deletions examples/pigment-css-nextjs-ts/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { withPigment, extendTheme } = require('@pigment-css/nextjs-plugin');

// To learn more about theming, visit https://github.com/mui/material-ui/blob/master/packages/zero-runtime/README.md#theming
const theme = extendTheme({
colorSchemes: {
light: {
palette: {
background: '0 0% 100%',
foreground: '240 10% 3.9%',
primary: '240 5.9% 10%',
border: '240 5.9% 90%',
},
},
dark: {
palette: {
background: '240 10% 3.9%',
foreground: '0 0% 80%',
primary: '0 0% 98%',
border: '240 3.7% 15.9%',
},
},
},
});

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

module.exports = withPigment(nextConfig, { theme });
27 changes: 27 additions & 0 deletions examples/pigment-css-nextjs-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "pigment-css-nextjs-ts",
"version": "5.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"post-update": "echo \"codesandbox preview only, need an update\" && pnpm update --latest"
},
"dependencies": {
"@pigment-css/react": "latest",
"react": "latest",
"react-dom": "latest",
"next": "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 added examples/pigment-css-nextjs-ts/src/app/favicon.ico
Binary file not shown.
10 changes: 10 additions & 0 deletions examples/pigment-css-nextjs-ts/src/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

a {
color: inherit;
text-decoration: none;
}
31 changes: 31 additions & 0 deletions examples/pigment-css-nextjs-ts/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react';
import type { Metadata } from 'next';
import '@pigment-css/react/styles.css';
import { css } from '@pigment-css/react';

import './globals.css';

export const metadata: Metadata = {
title: 'Create Next App',
description: 'Generated by create next app',
};

export default function RootLayout(props: { children: React.ReactNode }) {
return (
<html lang="en">
<body
className={css(({ theme }) => ({
color: 'hsl(var(--palette-foreground))',
backgroundColor: 'hsl(var(--palette-background))',
fontFamily:
"system-ui, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'",
...theme.applyStyles('dark', {
colorScheme: 'dark',
}),
}))}
>
{props.children}
</body>
</html>
);
}
204 changes: 204 additions & 0 deletions examples/pigment-css-nextjs-ts/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
import * as React from 'react';
import { Kalnia, Josefin_Sans } from 'next/font/google';
import { styled, css, keyframes } from '@pigment-css/react';

const kalnia = Kalnia({ subsets: ['latin'] });
const josefin = Josefin_Sans({ subsets: ['latin'] });

const scale = keyframes({
to: { scale: 'var(--s2)' },
});

const Link = styled('a', { shouldForwardProp: (prop) => prop !== 'outlined' })<{
outlined?: boolean;
}>(({ theme }) => ({
fontSize: '1rem',
background: 'rgba(0 0 0 / 0.04)',
padding: '0.5rem 1rem',
letterSpacing: '1px',
borderRadius: '4px',
textAlign: 'center',
...theme.applyStyles('dark', {
background: 'rgba(255 255 255 / 0.1)',
}),
variants: [
{
props: { outlined: true },
style: {
background: 'transparent',
color: `hsl(${theme.vars.palette.primary})`,
border: `1px solid hsl(${theme.vars.palette.border})`,
},
},
],
}));

const Bubble = styled('span')({
height: 'var(--size, 100%)',
aspectRatio: '1',
background: 'radial-gradient(hsl(var(--h) 100% 70%) 25%, transparent 50%)',
position: 'absolute',
display: 'inline-block',
left: 'var(--x, 0)',
top: 'var(--y, 0)',
scale: '0',
translate: '-50% -50%',
mixBlendMode: 'multiply',
filter: 'blur(2px)',
animation: `${scale} var(--s, 2s) var(--d, 0s) infinite alternate`,
});

function randomBetween(min: number, max: number) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
function generateBubbleVars() {
return `
--x: ${randomBetween(10, 90)}%;
--y: ${randomBetween(15, 85)}%;
--h: ${randomBetween(0, 360)};
--s2: ${randomBetween(2, 6)};
--d: -${randomBetween(250, 400) / 1000}s;
--s: ${randomBetween(3, 6)}s;
`;
}

export default function Home() {
return (
<main
className={css({
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
height: '100lvh',
padding: '20px',
})}
>
<h1
className={`
${kalnia.className}
${css(({ theme }) => ({
fontSize: 'clamp(3rem, 1.9503rem + 4.4789vw, 6.25rem)',
fontWeight: 500,
textAlign: 'center',
position: 'relative',
display: 'flex',
alignItems: 'center',
color: '#888',
marginBottom: '1rem',
...theme.applyStyles('dark', { color: '#fff' }),
}))}`}
>
Pigment CSS
<span
className={css(({ theme }) => ({
position: 'absolute',
inset: '0',
background: 'white',
mixBlendMode: 'color-burn',
overflow: 'hidden',
pointerEvents: 'none',
...theme.applyStyles('dark', {
mixBlendMode: 'darken',
filter: 'brightness(2)',
}),
}))}
>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
<Bubble
className={css`
${generateBubbleVars()}
`}
/>
</span>
</h1>
<div
className={`
${josefin.className}
${css({
letterSpacing: '2px',
fontSize: 'clamp(0.75rem, 0.5885rem + 0.6891vw, 1.25rem)',
textTransform: 'uppercase',
fontWeight: 500,
opacity: 0.5,
lineHeight: 2,
textAlign: 'center',
textWrap: 'balance',
})}
`}
>
CSS-in-JS library with static extraction
</div>

<div
className={css({
display: 'flex',
flexWrap: 'wrap',
gap: '1rem',
marginTop: '3rem',
'& > *': { flex: 'auto' },
})}
>
<Link
href="https://github.com/mui/material-ui/blob/master/packages/pigment-react/README.md"
target="_blank"
rel="noopener noreferrer"
>
Documentation
</Link>
<Link
outlined
href="https://github.com/orgs/mui/projects/27/views/1"
target="_blank"
rel="noopener noreferrer"
>
Roadmap
</Link>
</div>
</main>
);
}
Loading
Loading