-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[zero][system] Implementation of styled tag processor for linaria #38378
Conversation
@mnajdova @oliviertassinari One point to note in the |
/** | ||
* Order of processing styles - | ||
* 1. CSS directly declared in styled call | ||
* 2. CSS declared in theme object's styledOverrides | ||
* 3. Variants declared in styled call | ||
* 3. Variants declared in theme object | ||
*/ |
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 will need to review this order. For e.g. now, whatever is defined in the theme would override the styles defined in the component (including "variants" styles). What I mean by this is:
const theme = createTheme({
components: {
MuiButton: {
styleOverrides: { // or variants with props {}
root: {
background: '#00FF00',
}
}
}
}
});
Will override the button's background regardless of what color is used. We can come back to this later tough, I am just mentioning it for awareness.
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.
One more question, how do we make sure that the component that is wrapped has it's styles defined previously? In cases like:
styled(Slider)
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.
Even if you define variants
in base css, they get added after styleOverrides
css.
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.
One more question...
It's made sure by virtue of the bundler. If a component A
is imported from A.ts
like -
A.tsx
export const A = styled()...
and imported in B.tsx
import {} from './A';
const B = styled(A)(...)
CSS class ordering is in the order of the import. So first styled
call in A gets processed and then in B
.class-A {}
.class-B {}
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.
Even if you define variants in base css, they get added after styleOverrides css.
This makes sense to me, however is different than the current behavior, which may cause some issues. But again, let's revisit this later and focus on the other aspects.
4c74c5e
to
3e49813
Compare
Netlify deploy previewhttps://deploy-preview-38378--material-ui.netlify.app/ Bundle size report |
f8e6abb
to
a6d2efa
Compare
Added 3 new commits in the PR to
|
91ac318
to
23870e9
Compare
@mnajdova Moved over some of the TODOs to the package README as it would be better reviewable individually. So for now, this PR is feature complete. |
inside runtime functions. Also, export a function to be used in bundler to generate css for theme tokens.
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.
two nits, implementation wise I think we can go with this for a first iteration. For me, the most important bit is to plan out the testing strategy for it.
object inside runtime css functions. Also remove default export eslint rule.
ad99766
to
9743885
Compare
@mnajdova Builds are passing now. I'll merge once you approve. |
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.
Looks good for a first iteration. I would propose creating a page next for the lighthouse score performance test. For the next iteration, would be great to add next.js integration too.
There's one more PR for |
This PR introduces two main packages
zero-tag-processor
- Package to contain all tag processors to be used by linaria for build time manipulationzero-runtime
- The actual runtime implementation ofstyled
that ends up in the user bundle.What's done in the implementation -
styled
calls, theme overrides,variants
in styled call as well as theme object.What's left to implement (only in context of
styled
call) -palette.primary.main
(theme tokens) inside the dynamic functions with equivalent css variables at build time.theme
object inside above functionsMoving some of the todos to independent PRs for easy review -
@mui/system
to the packagestyled
There is also a test vite app to verify the changes in development. Note that this is not a workspace project yet as I need to figure out how to import items from
ts
file so that it can be used invite.config.ts
. So we need to manually runyarn install
and thenyarn dev
to start the app.