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

[system] Add color manipulators #26668

Merged
merged 2 commits into from
Jun 11, 2021

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Jun 9, 2021

Exporting the color utils from @material-ui/system. These are not specific to MD, and are useful for building design system.

The package grow is around +7.32%. If we think this is too big, we can export them from a new package, something like @material-ui/color-utils or something similar.

Resonates a bit with #13039.

@mui-pr-bot
Copy link

mui-pr-bot commented Jun 9, 2021

Details of bundle changes (experimental)

@material-ui/system: parsed: +7.32% , gzip: +7.12%

Generated by 🚫 dangerJS against e574f7f

@mnajdova mnajdova marked this pull request as ready for review June 9, 2021 11:23
@mnajdova mnajdova added the package: system Specific to @mui/system label Jun 9, 2021
@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 9, 2021

The package grow is around +7.32%. If we think this is too big, we can export them from a new package, something like @material-ui/color-utils or something similar.

To follow up on the discussion we had in #26490 (comment) with @eps1lon. This comment makes me realized that I wasn't clear on what I had in mind. I don't think that the size of the system package matter for the argument that Sebastian used: tree-shaking. Here the color utilities are tree-shakable. It wasn't the case with the default theme, it's a direct dependency of the Box/styled.

Actually, maybe we should have a custom entry point to make sure the bundle size of @material-ui/system/Box isn't going through the root. As it's done in https://github.com/mui-org/material-ui/blob/32c903ee0af6897f7bc223b1e7130a5edc706086/scripts/sizeSnapshot/webpack.config.js#L55


Continuing with bundle size, we might want to change this path:

https://github.com/mui-org/material-ui/blob/32c903ee0af6897f7bc223b1e7130a5edc706086/scripts/sizeSnapshot/webpack.config.js#L84


The idea of the standalone color manipulator is interesting, we talked about it in #13039. I personally feel like we are already doing it with the current state of this PR 😁.


return recomposeColor(color);
}
export {
Copy link
Member

Choose a reason for hiding this comment

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

Developers can't import deep this file so we could remove it and reexport it from packages/material-ui/src/styles/index.js. Would it be simpler?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was’t sure after this one #26648 Looked like with not exporting those typings from the original file I introduced breaking changes. Or maybe the usage in the issue was not something we support?

Copy link
Member

@oliviertassinari oliviertassinari Jun 9, 2021

Choose a reason for hiding this comment

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

I think that it's actually great that we broke this nested import for this user. It has always been private, a good feedback loop for him to stop doing it. We could enforce the constraints on all the modules with #26254.

Copy link
Member Author

@mnajdova mnajdova Jun 9, 2021

Choose a reason for hiding this comment

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

Ok, that’s what I thought but wasn’t sure. I will then export these from index

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, I needed to update the imports from core, but apart from that looks good :)

Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

Looks good

@@ -2,9 +2,9 @@ import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { unstable_composeClasses as composeClasses } from '@material-ui/unstyled';
import { alpha } from '@material-ui/system';
Copy link
Member

@oliviertassinari oliviertassinari Jun 10, 2021

Choose a reason for hiding this comment

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

I was wondering about doing

Suggested change
import { alpha } from '@material-ui/system';
import { alpha } from '@material-ui/system/colorManipulator';

to help on the tree-shaking in dev mode, but since we likely include the whole system anyway in the core for a single component, I'm not sure we need to care.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if it will have any impact.. The styled() util already depends on styleFunctionSx which basically composes the whole system, so not sure if it is worthed..

Copy link
Member

Choose a reason for hiding this comment

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

I think if the system is not that big, I would rather use from root.
import { alpha } from '@material-ui/system' is more convenient.

Copy link
Member

Choose a reason for hiding this comment

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

@siriwatknp I think that we could have a different policy for what we document and what we use internally: #24147.

@oliviertassinari oliviertassinari added the new feature New feature or request label Jun 10, 2021
@mnajdova mnajdova requested a review from siriwatknp June 10, 2021 14:47
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.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants