-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webpack] Fix support for webpack and add example app (#174)
- Loading branch information
1 parent
ae72eea
commit 47d3098
Showing
13 changed files
with
585 additions
and
42 deletions.
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 @@ | ||
# Pigment CSS - Vite with TypeScript example project | ||
|
||
## How to use | ||
|
||
Download the example [or clone the repo](https://github.com/mui/pigment-css): | ||
|
||
<!-- #default-branch-switch --> | ||
|
||
```bash | ||
curl https://codeload.github.com/mui/pigment-css/tar.gz/master | tar -xz --strip=2 pigment-css-master/examples/pigment-css-vite-ts | ||
cd 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/pigment-css/tree/master/examples/pigment-css-vite-ts) | ||
|
||
[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/p/sandbox/github/mui/pigment-css/tree/master/examples/pigment-css-vite-ts) | ||
|
||
## Learn more | ||
|
||
To learn more about this example: | ||
|
||
- [Pigment CSS documentation](https://github.com/mui/pigment-css/blob/master/README.md) - learn more about Pigment CSS features and APIs. | ||
- [Vite documentation](https://vitejs.dev/guide/) - learn about Vite features and APIs. |
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 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="initial-scale=1, width=device-width" /> | ||
<title>Pigment CSS + Webpack + TypeScript</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</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,28 @@ | ||
{ | ||
"name": "@app/wp-app", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "webpack serve --mode development", | ||
"build": "webpack build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@pigment-css/react": "latest", | ||
"react": "latest", | ||
"react-dom": "latest" | ||
}, | ||
"devDependencies": { | ||
"@pigment-css/unplugin": "latest", | ||
"@types/react": "latest", | ||
"@types/react-dom": "latest", | ||
"css-loader": "^7.1.2", | ||
"html-webpack-plugin": "^5.6.0", | ||
"style-loader": "^4.0.0", | ||
"ts-loader": "^9.5.1", | ||
"typescript": "latest", | ||
"webpack": "^5.91.0", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-dev-server": "^5.0.4" | ||
} | ||
} |
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,197 @@ | ||
import * as React from 'react'; | ||
import { styled, css, keyframes } from '@pigment-css/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.8rem 1rem', | ||
letterSpacing: '1px', | ||
borderRadius: '8px', | ||
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={`my-custom-class ${css(({ theme }) => ({ | ||
fontFamily: 'system-ui, sans-serif', | ||
fontSize: '4rem', | ||
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: 'system-ui, sans-serif', | ||
letterSpacing: '2px', | ||
opacity: 0.6, | ||
lineHeight: 2, | ||
textAlign: 'center', | ||
textWrap: 'balance', | ||
})} | ||
> | ||
CSS-in-JS library with static extraction | ||
</div> | ||
<div | ||
className={css({ | ||
display: 'flex', | ||
flexWrap: 'wrap', | ||
gap: '1rem', | ||
marginTop: '2rem', | ||
})} | ||
> | ||
<Link | ||
href="https://github.com/mui/pigment-css/blob/master/README.md" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
Documentation | ||
</Link> | ||
<Link | ||
outlined | ||
href="https://github.com/orgs/mui/projects/27/views/3" | ||
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 '@pigment-css/react/theme'; | ||
import type { ExtendTheme } from '@pigment-css/react'; | ||
|
||
declare module '@pigment-css/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 '@pigment-css/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,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./dist/", | ||
"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, | ||
"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,8 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"allowSyntheticDefaultImports": true | ||
} | ||
} |
Oops, something went wrong.