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
[pigment-css][react] Add a How Pigment CSS works guide #41683
base: next
Are you sure you want to change the base?
Conversation
brijeshb42
commented
Mar 27, 2024
- I have followed (at least) the PR section of the contributing guide.
Netlify deploy previewhttps://deploy-preview-41683--material-ui.netlify.app/ Bundle size report |
e5caf4a
to
d6208be
Compare
b746b86
to
f3992d0
Compare
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.
👍 very useful.
If the same was done using the `styled` call instead of `css` for the source: | ||
|
||
```js | ||
// app.js | ||
import { styled } from '@pigment-css/react'; | ||
|
||
const Paragraph = styled.p(({ theme }) => ({ | ||
lineHeight: '1.4375em', | ||
padding: 0, | ||
position: 'relative', | ||
color: (theme.vars || theme).palette.text.secondary, | ||
...theme.typography.body1, | ||
})); | ||
``` | ||
|
||
The transformed output would look like: | ||
|
||
```js | ||
// app.js | ||
import { styled } from '@pigment-css/react'; | ||
|
||
const Paragraph = styled('p')({ | ||
baseClasses: ['c1aiqtje'], | ||
}); | ||
``` | ||
|
||
You can notice above that now the runtime code, that finally ends up in the output bundle, doesn't involve any kind of CSS generation and it only needs to deal with primitive strings to apply it to the `p` that it'd render in the end. |
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.
I feel like this can be replaced with an ending for the css
explanation. Maybe creating an example section for other processors would be better.
Like:
## Example transformation
### styled
…
### keyframes
### generateAtomics
c93df81
to
87e6977
Compare
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.
I'll leave the more thorough writing review to Sam, but given this is the first branched-off page from the Pigment CSS docs, it rings as the call for a standalone doc space :) I've created a draft issue on the project for that, which we can talk about later! Either way, I appreciate we're explaining how the library works, and it'd be nice to really break down concepts such as the runtime vs. no-runtime scenario—maybe I can chime in here with some visual representation of them and others!
I was thinking of adding animations using Shiki to showcase the code-transforms. But since we are limited by plain markdown files, I didn't add it. It would be great if we are able to set-up Pigment CSS documentation within Screen.Recording.2024-03-29.at.6.07.17.PM.mov |
That looks so good! I'd definitely be interested to have this on the docs-infra stack, too! |
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.
Nice doc! I learned a lot by reading it :)
8697698
to
7637207
Compare
7637207
to
ea98cc4
Compare
14f6692
to
64c9c9f
Compare
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 great to me! (Would wait for Sam's final review, though)
|
||
## Processor | ||
|
||
Pigment CSS uses the [WyW-in-JS](https://wyw-in-js.dev/) library that also powers [Linaria](https://linaria.dev/). It features a [processor](https://wyw-in-js.dev/how-to/custom-tagged-template#creating-a-processor) which makes it possible to create custom logic that's triggered by the presence of different imports from the library. The processor looks through the source code for `styled()`, `css()`, and other function calls and extracts the arguments to be evaluated. These evaluated values are then handed back to Pigment CSS for additional customization on top. |
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 final nitpick on style—I just realized that this is the only place where we refer to these functions as styled()
and css()
. Everywhere else we just write styled
and css
. Which one is your preference @brijeshb42 ? I like ()
since it makes it obvious that we're talking about functions, but I don't have a strong opinion either way.
Pigment CSS uses the [WyW-in-JS](https://wyw-in-js.dev/) library that also powers [Linaria](https://linaria.dev/). It features a [processor](https://wyw-in-js.dev/how-to/custom-tagged-template#creating-a-processor) which makes it possible to create custom logic that's triggered by the presence of different imports from the library. The processor looks through the source code for `styled()`, `css()`, and other function calls and extracts the arguments to be evaluated. These evaluated values are then handed back to Pigment CSS for additional customization on top. | |
Pigment CSS uses the [WyW-in-JS](https://wyw-in-js.dev/) library that also powers [Linaria](https://linaria.dev/). It features a [processor](https://wyw-in-js.dev/how-to/custom-tagged-template#creating-a-processor) which makes it possible to create custom logic that's triggered by the presence of different imports from the library. The processor looks through the source code for `styled`, `css`, and other function calls and extracts the arguments to be evaluated. These evaluated values are then handed back to Pigment CSS for additional customization on top. |
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.
There are two different types of references here. One is where we tell about the import of styled
/css
. In that case, it would be the same.
But in any other case, it would be a function call. So it should be styled()
/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.
Ah ok that makes sense. Thanks for clarifying! Would you mind looking over the piece one last time to make sure we're referring to styled
vs styled()
and css
vs css()
accordingly? I didn't take that into account when I was editing before.
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.
Updated.
034d6fc
to
68cacd0
Compare
Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com> Signed-off-by: Brijesh Bittu <brijeshb42@gmail.com>
@samuelsycamore I've applied all your suggestions. Could you +1 if there's nothing else? |
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.
let's fix the nbsp and then I think this is good to go 👍
Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com> Signed-off-by: Brijesh Bittu <brijeshb42@gmail.com>