mui / pigment-css Goto Github PK
View Code? Open in Web Editor NEWPigment CSS is a zero-runtime CSS-in-JS library that extracts the colocated styles to their own CSS files at build time.
License: MIT License
Pigment CSS is a zero-runtime CSS-in-JS library that extracts the colocated styles to their own CSS files at build time.
License: MIT License
When you add a pigment to a new Vite project, following the instructions in the README.md, you get the following error on build:
TypeError: [vite-mui-theme-injection-plugin] Could not load �zero-runtime-styles.css (imported by src/app/main.jsx): Cannot read properties of undefined (reading 'generateStyleSheets')
Turns out the plugin blows up right now unless you add a theme into the config:
// This fails
export default defineConfig({
plugins: [
pigment({}),
react()
]
});
// This works
export default defineConfig({
plugins: [
pigment({
theme: {}
}),
react()
]
});
I'm not entirely sure if this is a documentation issue or an actual bug, but I feel like it's nice to not require a project to always supply a theme.
Steps:
yarn create vite my-vue-app --template react
yarn build
Repro available in this codespace: https://musical-guacamole-45qr7r77xq2jpg5.github.dev/
Following the README's instructions for a Vite project, you will get a build error instead of a cleanly built project.
Ideally not including a template doesn't throw an error at build time. Otherwise the README should specify that a theme is required
No response
npx @mui/envinfo
System:
OS: macOS 14.2.1
Binaries:
Node: 21.7.3 - ~/.nvm/versions/node/v21.7.3/bin/node
Yarn: 4.1.1
pnpm: Not Found
Browsers:
Chrome: 124.0.6367.119
Safari: 17.2.1
npmPackages:
@pigment-css/react: ^0.0.10
@vite: ^5.2.0
@emotion/react: latest => 11.11.4
@emotion/styled: latest => 11.11.5
@mui/base: 5.0.0-beta.43
@mui/core-downloads-tracker: 6.0.0-dev.240424162023-9968b4889d
@mui/material: next => 6.0.0-alpha.5
@mui/private-theming: 6.0.0-alpha.5
@mui/styled-engine: 6.0.0-alpha.5
@mui/system: 6.0.0-dev.240424162023-9968b4889d
@mui/types: 7.2.14
@mui/utils: 6.0.0-alpha.5
@types/react: ^18.2.66 => 18.3.1
react: ^18.2.0 => 18.3.1
react-dom: ^18.2.0 => 18.3.1
typescript: 5.4.5
Search keywords: theme pigment
When using next dev --turbo
, I get the error: Error: @pigment-css/react: You were trying to call "css" function without configuring your bundler.
because withPigment
from @pigment-css/nextjs-plugin
works by adding a webpack plugin which is not supported yet by Turbopack as stated in their docs: Will we be able to use webpack plugins?.
N/A
I want to benefit from dev server performance improvements of Turbopack while using @pigment-css/react
Search keywords: pigment, turbopack
Regardless of whether they are built with PIgment CSS's styled API or not
Search keywords:
npx create-next-app@latest
import { withPigment, extendTheme } from '@pigment-css/nextjs-plugin';
const nextConfig = {
output: "export",
};
export default withPigment(nextConfig, {
theme: extendTheme({
colors: {
primary: 'tomato',
secondary: 'cyan',
},
spacing: {
unit: 8,
},
typography: {
fontFamily: 'Inter, sans-serif',
},
}),
});
'use client'
import styles from "./page.module.css";
import { css } from "@pigment-css/react";
const description = css`
display: inherit;
justify-content: inherit;
align-items: inherit;
font-size: 0.85rem;
max-width: var(--max-width);
width: 100%;
z-index: 1;
font-family: var(--font-mono);
`;
......
export default function Home() {
return (
......
<div className={description}>Test</div>
......
}
}
No response
No response
System:
OS: macOS 14.3
Binaries:
Node: 20.12.2 - ~/.nvm/versions/node/v20.12.2/bin/node
npm: 10.5.0 - ~/.nvm/versions/node/v20.12.2/bin/npm
pnpm: 8.9.0 - ~/.nvm/versions/node/v20.12.2/bin/pnpm
Browsers:
Chrome: 124.0.6367.60
Edge: Not Found
Safari: 17.3
npmPackages:
@types/react: ^18 => 18.2.61
react: ^18 => 18.2.0
react-dom: ^18 => 18.2.0
typescript: ^5 => 5.3.3
Search keywords: @pigment-css/nextjs-plugin use client
React 19 adds support for loading stylesheets in a specified order AND ability to wait using Suspense wrapper until CSS is loaded.
Please consider to:
Disable FOUC when needed
Search keywords: react 19 fouc suspense
See https://github.com/mui/material-ui/actions/runs/8794041697/job/24132847084?pr=42001 from mui/material-ui#42001
Build errors on components that contain !important
in the style.
The build should pass.
No response
npx @mui/envinfo
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Search keywords: important
Hello,
I was loonking to change the pointer-events
property on a component with the following code:
const disableContextMenu = css({
pointerEvents: "none",
});
But unfortunately, at build time, it throws the following error:
Type error: No overload matches this call.
Overload 1 of 2, '(arg: TemplateStringsArray, ...templateArgs: (Primitve | CssFn)[]): string', gave the following error.
Object literal may only specify known properties, and 'pointerEvents' does not exist in type 'TemplateStringsArray'.
const disableContextMenu = css({
> pointerEvents: "none",
^
});
I'm a bit puzzled as pointer-events
is a standard CSS property and using it in React's style
prop works as expected.
I tried the following code as well, but it doesn't work either:
const disableContextMenu = css({
"pointer-events": "none",
});
I'm not sure if it is relevant to this issue, but I think there should be a way to set non-standard CSS properties such as -webkit-touch-callout
or experimental properties.
next info
outputOperating System:
Platform: linux
Arch: x64
Version: #28-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 7 18:21:00 UTC 2024
Available memory (MB): 15685
Available CPU cores: 8
Binaries:
Node: 20.12.2
npm: 10.5.0
Yarn: N/A
pnpm: 8.15.4
Relevant Packages:
next: 14.2.0
eslint-config-next: 14.2.0
react: 18.2.0
react-dom: 18.2.0
typescript: 5.4.3
@pigment-css/react: 0.0.6
Next.js Config:
output: N/A
A framework like Next.js transpile the code from ArrowFunction
to FunctionDeclaration
that developers don't have control:
⨯ unhandledRejection: SyntaxError: /Users/siriwatknp/practice-repos/nextjs-tailwind-v4/src/app/landing-page/components/Features.tsx: @pigment-css/react: sx prop only supports arrow functions directly returning an object, for example () => ({color: 'red'}). You can accept theme object in the params if required.
171 | children: [
172 | /*#__PURE__*/ _jsxDEV(Box, {
> 173 | sx: (param)=>{
| ^
174 | let { theme } = param;
175 | return {
176 | backgroundSize: "cover",
The original code is:
<Box
sx={({ theme }) => ({
backgroundSize: 'cover',
backgroundPosition: 'center',
minHeight: 280,
backgroundImage: 'var(--Image-light)',
...theme.applyStyles('dark', {
backgroundImage: 'var(--Image-dark)',
}),
})}
The sx
prop should work with function declaration too.
No response
No response
Search keywords: sx function declaration
Links to live example:
Next.JS: https://stackblitz.com/edit/stackblitz-starters-e6kyr6?description=The%20React%20framework%20for%20production&file=app%2Fpage.tsx&title=Next.js%20Starter
Vite: https://stackblitz.com/edit/vitejs-vite-14nhvq?file=src%2FApp.tsx
Steps: just click the link and let the app start.
There appears to be a bug when trying to wrap styled
function from "@pigment-css/react"
.
Here's the screenshot from Vite environment
The CSS should be applied to the element.
I am trying to have a simple wrapper for styled
function from "@pigment-css/react"
.
Since it doesn't work, I'm wondering whether is it a bug or is it simply not supported?
npx @mui/envinfo
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Search keywords: pigment-css wrapper
The sx
prop should support array format to cover these cases:
array of styles
// developer's codebase
<div
sx={[
{ display: 'flex', },
numSelected > 0 && {
bgcolor: 'white',
},
]}
/>
// transformed
<div {...sx(['s1o8xp19', 's1o8xp19-1'], {})} />
array of function
// developer's codebase
<div
sx={[
theme => ({ display: 'flex', fontSize: theme.vars.font.xl }),
numSelected > 0 && (theme => {
bgcolor: theme.vars.palette.primary.main,
…theme.applyStyles('dark', {
bgcolor: theme.vars.palette.primary.light,
})
}),
]}
/>
// transformed
<div {...sx(['s1xbsywq', numSelected > 0 && 's1xbsywq-0'], {})} />
No response
To ease v5 to v6 migration and ensure feature parity with the current MUI system's sx
.
Search keywords: array sx prop
Render any component with sx
usage like this will throw an Error Cannot read property 'applyStyles' of undefined
:
<Box
sx={theme => ({
backgroundSize: 'cover',
backgroundPosition: 'center',
minHeight: 280,
backgroundImage: 'var(--Image-light)',
...theme.applyStyles('dark', {
backgroundImage: 'var(--Image-dark)',
}),
})}
The correct syntax for using theme
from sx
prop is to declare a parameter, not object pattern ({ theme })
The sx
prop should work with sx={theme => …}
I am working on a codemod for transforming sx
prop and I stumbled on this error.
npx @mui/envinfo
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Search keywords: sx theme
import * as something from "example.ts"
namespaces
Currently, you must pass to the vite plugin:
pigment({
babelOptions: {
plugins: [`@babel/plugin-transform-export-namespace-from`],
},
})
The babel plugin @babel/plugin-transform-export-namespace-from
should be added by default.
In:
https://github.com/mui/material-ui/blob/f3cb496c999acbc8f19533e38df20be12e56d059/packages/pigment-css-vite-plugin/src/vite-plugin.ts#L194
Related issues:
npx @mui/envinfo
System:
OS: macOS 14.4
Binaries:
Node: 21.7.1 - /opt/homebrew/bin/node
npm: 10.5.0 - /opt/homebrew/bin/npm
pnpm: 8.15.5 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 123.0.6312.87
Edge: 112.0.1722.39
Safari: 17.4
npmPackages:
@pigment-css/react: 0.0.5
@pigment-css/vite-plugin: 0.0.5
@emotion/react: 11.11.4
@emotion/styled: 11.11.5
@mui/styled-engine: 6.0.0-alpha.1
@mui/system: 6.0.0-alpha.1
@mui/types: 7.2.14
@types/react: 18.2.73 => 18.2.73
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
typescript: 5.4.3 => 5.4.3
Search keywords: pigment barrel
See https://github.com/mui/material-ui/actions/runs/8837080528/job/24265117421?pr=41663 in mui/material-ui#41663
ownerState
is undefined in InputBase
styles when FilledInput
(Pigment) is wrapping Input
(MUI System).
const FilledInputRoot = styled(InputBase)(…)
The root cause is that FilledInputRoot does not forward ownerState
to InputBase which causes an error from the InputBase.
They should work together, both MUI System wrappin Pigment or Pigment wrapping MUI System.
Found this issue when trying to migrate only FilledInput to support Pigment CSS.
npx @mui/envinfo
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Search keywords: styled
Steps:
npm install
(from repo's root)npm run start
(from pkg1
)Error: @pigment-css/react: You were trying to call "css" function without configuring your bundler
theme
in vite.config.ts
npm run start
(it will run without issues)pigment-css-vite-plugin
doesn't work when a theme is connected directly (imports a value) or imports a type from one of the files that is importing from a file with @pigment-css/react
's css
.
Theme should be shareable and references shouldn't break the pigment-css-vite-plugin
unexpectedly.
Btw, the bug exists in both pigment's 0.0.4
and the latest state of mui's next
branch (checked a couple of hours ago)
npx @mui/envinfo
System:
OS: macOS 14.4
Binaries:
Node: 21.7.1 - /opt/homebrew/bin/node
npm: 10.5.0 - /opt/homebrew/bin/npm
pnpm: 8.15.5 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 123.0.6312.87
Edge: 112.0.1722.39
Safari: 17.4
npmPackages:
@pigment-css/react: 0.0.4
@pigment-css/vite-plugin: 0.0.4
@emotion/react: 11.11.4
@emotion/styled: 11.11.5
@mui/private-theming: 5.15.14
@mui/styled-engine: 6.0.0-alpha.0
@mui/system: 6.0.0-alpha.0
@mui/types: 7.2.14
@mui/utils: 5.15.14
@types/react: 18.2.73 => 18.2.73
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
typescript: 5.4.3 => 5.4.3
Search keywords: pigment vite monorepo
Steps:
theme.colorSchemes
theme.colorSchemes.dark.mixins.example = {
"&:hover": {
background: `rgba(0, 0, 0, 0.26)`,
},
}
[WARNING] Expected ":" [css-syntax-error]
(it's actually an error; CSS is invalid & also won't be minified) during CSS minification, because the above ends up as --mixins-example-&:hover-background
(notice the invalid &
symbol in the variable name)npx @mui/envinfo
System:
OS: macOS 14.4
Binaries:
Node: 21.7.1 - /opt/homebrew/bin/node
npm: 10.5.0 - /opt/homebrew/bin/npm
pnpm: 8.15.5 - /opt/homebrew/bin/pnpm
Browsers:
Chrome: 123.0.6312.87
Edge: 112.0.1722.39
Safari: 17.4
npmPackages:
@pigment-css/react: 0.0.4
@pigment-css/vite-plugin: 0.0.4
@emotion/react: 11.11.4
@emotion/styled: 11.11.5
@mui/private-theming: 5.15.14
@mui/styled-engine: 6.0.0-alpha.0
@mui/system: 6.0.0-alpha.0
@mui/types: 7.2.14
@mui/utils: 5.15.14
@types/react: 18.2.73 => 18.2.73
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
typescript: 5.4.3 => 5.4.3
Search keywords: pigment theme vars
Link to repo: https://github.com/siriwatknp/nextjs-mui-v6
Steps:
pnpm install && pnpm run dev
diff --git a/src/app/checkout/page.tsx b/src/app/checkout/page.tsx
index 656df43..accc080 100644
--- a/src/app/checkout/page.tsx
+++ b/src/app/checkout/page.tsx
@@ -141,7 +141,7 @@ export default function Checkout() {
<Box
sx={{
display: 'flex',
- alignItems: 'end',
+ alignItems: 'flex-end',
height: 150,
}}
>
There should be no error.
No response
npx @mui/envinfo
Don't forget to mention which browser you used.
Output from `npx @mui/envinfo` goes here.
Search keywords: pigment-css redefine toString
Provide a similar API to Emotion/Styled-components GlobalStyles
.
https://mui.com/material-ui/customization/how-to-customize/#4-global-css-override
Feature parity for migrating from Emotion/Styled-components.
Search keywords: pigment-css global styles
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.