Comments (6)
This is expected by design. We should do better at documenting it.
The theme.colorSchemes
should contain only tokens (to be converted to CSS variables). What you provided is a stylesheet that could not be converted to a CSS variable.
If you want to create a reusable styles, you can:
- create a new nodes, e.g.
theme.styles.*
- use
css()
and reexport it.
from pigment-css.
Importing mixins from colorSchemes directly as-is won’t work, because the background might be different for each colorScheme.
So either the design of Pigment should change to allow this case, or there should be a converter of a path to a token from colorSchemes into a variable name to be used in mixins
from pigment-css.
Importing mixins from colorSchemes directly as-is won’t work, because the background might be different for each colorScheme.
So either the design of Pigment should change to allow this case, or there should be a converter of a path to a token from colorSchemes into a variable name to be used in mixins
Thanks for the feedback, before going into the solution, can you explain in more detail about your use case? Do you want to customize a background based on a different color scheme?
theme.vars
contains fields that refer to CSS variables. It cannot contain stylesheets.
from pigment-css.
@siriwatknp Since you mentioned using mixins within colorSchemes
is prohibited by design, please refer to the example below for the proposal on reusing css variables in mixins outside of colorSchemes.
const theme = extendTheme({
colorSchemes: {
dark: {
// these are the colorScheme-dependent tokens you want to use in mixins
palette: {
overlay: `black`,
primary: {
main: `#fafafa`,
}
}
}
},
// then you want to define a reusable stylesheet within mixins
mixins: {
example: {
/**
* Pigment should have a function to make it type-safe.
* - you could also infer the type automatically from the theme.colorSchemes[string] and allow dot notation reference w/o a function (ex. `getVar`)
*
* If a function is your preference, then Pigment (`getVar` below) also needs to take into account the `cssVarPrefix` bundler's option see: https://github.com/mui/material-ui/tree/master/packages/pigment-css-react#adding-a-prefix-to-css-variables
*
* In the example below, the function is named as `getVar`
* the type of the parameter can be
* import type { Paths } from "type-fest" // see: https://github.com/sindresorhus/type-fest/blob/main/source/paths.d.ts
* type getVar = (key: Paths<PigmentTheme["colorSchemes"][keyof PigmentTheme["colorSchemes"]]>) => `var(${string})`
*
* @example how it would look like in the code
* backgroundColor: getVar("palette.overlay")
* "&:hover": {
* backgroundColor: getVar("palette.primary.main")
* }
*
* Below, how it's currently must be done.
* It is not type-safe, but it works.
*/
backgroundColor: `var(--palette-overlay)`,
"&:hover": {
backgroundColor: `var(--palette-primary-main)`,
}
}
}
})
from pigment-css.
@o-alexandrov Could you also add a code example on how you'd use these mixins in your css
or styled
definitions ?
from pigment-css.
@brijeshb42 in this case, it'd be:
export const classNameWithMixin = pigment.css(({ theme }) => ({
...theme.mixins.example,
display: `flex`
}))
from pigment-css.
Related Issues (20)
- [docs] Fix transformation link in HOW_PIGMENT_CSS_WORKS.md
- Shadow dom support HOT 1
- withPigment causes tsconfig compiler path option to not work HOT 10
- `useTheme` returns undefined for theme values HOT 4
- It prompts that "Uncaught SyntaxError" when using Pigment css v0.0.17 and vite. HOT 5
- Bugs with incremental adoption alongside styled-components HOT 4
- Storybook Vite / AntD incompatibility HOT 1
- [docs] How to use MUI themeProvider with Pigment CSS HOT 6
- Type errors when interpolating into tagged template literal
- Cannot style next/link component HOT 2
- Type error is thrown when using shorthand alias in sx prop HOT 1
- [bug] `Stack`, `Grid`, `Container` aren't usable as base for additional components
- [nextjs] Cannot use `sx` prop on layout components
- sx style delay with Button HOT 1
- Next/font breaks with pigment CSS
- Component styles are overridden when rendered inside Next.js layout HOT 1
- Color mode is not respected when using theme arg in sx prop HOT 1
- [docs] variables and selector like [theme.breakpoints.down('md')], how to use in Pigment CSS ? HOT 2
- Importing next/link in `async` component produces error HOT 4
- V6 Using Paper overrides style of unrelated components HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pigment-css.