-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
[RFC] Pigment CSS v1: Package Structure and API Design #362
Comments
Hey, could you emphasize more on how will this work with nextjs |
As part of the move to the Stitches-like API for variants, do you have plans to support responsive variants? It could still be static, for example: const Button = styled.button({
variants: {
size: {
small: {padding: '4px'},
medium: {padding: '6px'},
large: {padding: '8px'},
},
},
defaultVariants: {size: 'medium'},
});
const ResponsiveButton = styled(Button)({
defaultVariants: {
size: {
'@initial': 'small',
'@media (min-width: 1024px)': 'medium',
'@media (min-width: 1400px)': 'large',
},
},
}) Output CSS@layer pigment.base {
.Button {}
.ResponsiveButton {}
}
@layer pigment.variants {
.Button-variant-size-small {
padding: 4px;
}
.Button-variant-size-medium {
padding: 8px;
}
.Button-variant-size-large {
padding: 16px;
}
.ResponsiveButton-responsive-variant-size {
@media (min-width: 1024px) {
padding: 8px;
}
@media (min-width: 1400px) {
padding: 8px;
}
}
} |
This particular aspect hasn't been considered yet but seems like a nice addition. We can re-visit this after the release of first version since we don't want to delay the first release. |
I'll also mention here that this pattern has a future of first class support in css, removing the need for rule duplication, once style queries gains wide browser support. @layer pigment.base {
.Button {
@container style(--Button-variant-size: small) {
padding: 4px;
}
@container style(--Button-variant-size: medium) {
padding: 6px;
}
@container style(--Button-variant-size: large) {
padding: 8px;
}
}
.ResponsiveButton {}
}
@layer pigment.variants {
.Button-variant-size-small {
--Button-variant-size: small;
}
.Button-variant-size-medium {
--Button-variant-size: medium;
}
.Button-variant-size-large {
--Button-variant-size: large;
}
.ResponsiveButton-responsive-variant-size {
@media (min-width: 1024px) {
--Button-variant-size: medium;
}
@media (min-width: 1400px) {
--Button-variant-size: large;
}
}
} |
Apologies for the naive question, but is this RFC what we can expect the new API to look like? Specifically with regards to the |
What's the problem?
The current Pigment CSS implementation is tightly coupled with Material-UI specific paradigms:
styleOverrides
andcomponents
handling for Material UI's themeslot
functionality that's not core to CSS-in-JSThe current architecture makes it difficult to:
What are the requirements?
Core Functionality:
Developer Experience:
Performance:
What are our options?
Option 1: Enhance Current Architecture
Option 2: Complete Rewrite
Option 3: Modular Refactor (Proposed)
Proposed solution
1. Package Structure
2. Core APIs
Theme Management
Styling
Digressing for the currently released version
theme
-> In current version or the one supporting Material UI, the theme object, besides the tokens itself contains a lot of configuration, likesxConfig
, utils liketheme.breakpoints.up/down
, component styling liketheme.components
, component's default props throughtheme.props
.In v1, theme will purely be a nested collection of tokens and will mostly involve primitive values like
string
ornumber
. You can still add methods to the theme but they won't be part of the final runtime. You can only use those methods in your css definition (same as theme.breakpoints.up). They won't carry any extra meaning for any of the components.css
orstyled
calls will be part of css layers that'll decide the precedence so that it is easier to override base styles of derived styled components. This does not happen in the current release.Stitches
like API instead of just allowing variants array (similar to compound variants).3. Bundler Integration
Mostly same as the current configuration with more options to customize the output css or class names, like
This will also be through typescript to get suggestions in the code.
4. CSS Output Structure
The layers will help users to easily override the base or variant styles of derived styled components like -
This can be easily achieved with layers in context of build time css extraction.
Output CSS
Migration Strategy
Resources and benchmarks
https://github.com/mui/pigment-css/tree/master/packages/pigment-css-theme
#345
Core Package
React package
The text was updated successfully, but these errors were encountered: