-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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-vite-ts starter example #41196
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
120a960
add zero-vite example
siriwatknp 7719304
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp 285a992
update index.html
siriwatknp 6e130f2
update readme
siriwatknp 5e9dfe9
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp da55b52
replace zero with pigment
siriwatknp 921cc02
update README
siriwatknp 98ed4cf
use -
siriwatknp 24922f7
Merge branch 'master' of https://github.com/mui/material-ui into zero…
siriwatknp 09cda44
update readme
siriwatknp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Zero-runtime CSS-in-JS - Vite with TypeScript example project | ||
|
||
## 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/pigmentcss-vite-ts | ||
cd pigmentcss-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/master/examples/pigmentcss-vite-ts) | ||
|
||
[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/github/mui/material-ui/tree/master/examples/pigmentcss-vite-ts) | ||
|
||
## Learn more | ||
|
||
To learn more about this example: | ||
|
||
- [`@pigmentcss/react` documentation](https://github.com/mui/material-ui/blob/master/packages/pigment-react/README.md) - learn more about MUI's Pigment CSS features. | ||
- [Vite documentation](https://vitejs.dev/guide/) - learn about Vite features and API. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="initial-scale=1, width=device-width" /> | ||
<!-- Fonts to support Material Design --> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | ||
<link | ||
href="https://fonts.googleapis.com/css2?family=Josefin+Sans:ital,wght@0,100..700;1,100..700&family=Kalnia:[email protected]&display=swap" | ||
rel="stylesheet" | ||
/> | ||
<title>Vite + Zero + TS</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "zero-vite", | ||
"private": true, | ||
"version": "5.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@pigmentcss/react": "latest", | ||
"react": "latest", | ||
"react-dom": "latest" | ||
}, | ||
"devDependencies": { | ||
"@pigmentcss/vite-plugin": "latest", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
"@types/react": "latest", | ||
"@types/react-dom": "latest", | ||
"@vitejs/plugin-react": "latest", | ||
"typescript": "latest", | ||
"vite": "latest" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
import * as React from 'react'; | ||
import { styled, css, keyframes } from '@pigmentcss/react'; | ||
|
||
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', | ||
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'", | ||
})} | ||
> | ||
<h1 | ||
className={` | ||
${css(({ theme }) => ({ | ||
fontFamily: 'Kalnia, sans-serif', | ||
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={css({ | ||
fontFamily: 'Josefin Sans, sans-serif', | ||
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-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/zero-runtime/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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type {} from '@pigmentcss/react/theme'; | ||
import type { ExtendTheme } from '@pigmentcss/react'; | ||
|
||
declare module '@pigmentcss/react/theme' { | ||
export interface ThemeArgs { | ||
theme: ExtendTheme<{ | ||
colorScheme: 'light' | 'dark'; | ||
tokens: { | ||
palette: { | ||
background: string; | ||
foreground: string; | ||
primary: string; | ||
primaryForeground: string; | ||
border: string; | ||
}; | ||
}; | ||
}>; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
* { | ||
box-sizing: border-box; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
|
||
a { | ||
color: inherit; | ||
text-decoration: none; | ||
} | ||
|
||
@media (prefers-color-scheme: dark) { | ||
html { | ||
color-scheme: dark; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom/client'; | ||
import '@pigmentcss/react/styles.css'; | ||
import './globals.css'; | ||
import App from './App'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root')!).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/// <reference types="vite/client" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"useDefineForClassFields": true, | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"allowJs": false, | ||
"skipLibCheck": true, | ||
"esModuleInterop": false, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "react-jsx" | ||
}, | ||
"include": ["src"], | ||
"references": [{ "path": "./tsconfig.node.json" }] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have renamed the package, again :)