Skip to content
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

Open
wants to merge 5 commits into
base: next
Choose a base branch
from

Conversation

brijeshb42
Copy link
Contributor

@brijeshb42 brijeshb42 added the package: pigment-css Specific to @pigment-css/* label Mar 27, 2024
@danilo-leal danilo-leal added the docs Improvements or additions to the documentation label Mar 27, 2024
@mui-bot
Copy link

mui-bot commented Mar 27, 2024

Netlify deploy preview

https://deploy-preview-41683--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 68cacd0

@brijeshb42 brijeshb42 force-pushed the pigment/how-it-works branch 2 times, most recently from e5caf4a to d6208be Compare March 27, 2024 13:03
@brijeshb42 brijeshb42 changed the title [pigment-css][react] Add a How Pigment works guide [pigment-css][react] Add a How Pigment CSS works guide Mar 27, 2024
@brijeshb42 brijeshb42 force-pushed the pigment/how-it-works branch 2 times, most recently from b746b86 to f3992d0 Compare March 27, 2024 13:55
Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 very useful.

packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
Comment on lines 98 to 124
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.
Copy link
Member

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

@brijeshb42 brijeshb42 force-pushed the pigment/how-it-works branch 5 times, most recently from c93df81 to 87e6977 Compare March 28, 2024 13:09
Copy link
Contributor

@danilo-leal danilo-leal left a 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!

@brijeshb42
Copy link
Contributor Author

brijeshb42 commented Mar 29, 2024

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 mui.com but using Pigment itself.

Screen.Recording.2024-03-29.at.6.07.17.PM.mov

@danilo-leal
Copy link
Contributor

That looks so good! I'd definitely be interested to have this on the docs-infra stack, too!

Copy link
Member

@samuelsycamore samuelsycamore left a 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 :)

packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
packages/pigment-css-react/README.md Outdated Show resolved Hide resolved
@brijeshb42 brijeshb42 force-pushed the pigment/how-it-works branch 2 times, most recently from 8697698 to 7637207 Compare March 30, 2024 05:57
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 2, 2024
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 2, 2024
Copy link
Contributor

@danilo-leal danilo-leal left a 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.
Copy link
Member

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.

Suggested change
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.

Copy link
Contributor Author

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().

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com>
Signed-off-by: Brijesh Bittu <brijeshb42@gmail.com>
@brijeshb42
Copy link
Contributor Author

@samuelsycamore I've applied all your suggestions. Could you +1 if there's nothing else?

Copy link
Member

@samuelsycamore samuelsycamore left a 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 👍

packages/pigment-css-react/HOW_PIGMENT_CSS_WORKS.md Outdated Show resolved Hide resolved
Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com>
Signed-off-by: Brijesh Bittu <brijeshb42@gmail.com>
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation package: pigment-css Specific to @pigment-css/* PR: out-of-date The pull request has merge conflicts and can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants