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

[material-ui] Migrate components to support CSS extraction #42001

Merged
merged 66 commits into from May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
b2507ee
migrate Icon
siriwatknp Apr 22, 2024
43803b1
migrate Dialog
siriwatknp Apr 22, 2024
317d955
migrate DialogActions
siriwatknp Apr 22, 2024
e59eee1
fix MemberExpression case
siriwatknp Apr 22, 2024
fc9c76d
migrate DialogContent
siriwatknp Apr 22, 2024
956f331
migrate DialogContentText
siriwatknp Apr 22, 2024
76a6ecb
migrate Drawer
siriwatknp Apr 22, 2024
83d8839
migrate Input
siriwatknp Apr 22, 2024
9206dd0
migrate InputAdornment
siriwatknp Apr 22, 2024
da3fef1
migrate InputBase
siriwatknp Apr 22, 2024
5f3d249
migrate OutlinedInput
siriwatknp Apr 22, 2024
2fce0ca
migrate TablePagination
siriwatknp Apr 22, 2024
41e9737
migrate InputLabel
siriwatknp Apr 22, 2024
eb821da
migrate Menu
siriwatknp Apr 22, 2024
c02207e
migrate Paper
siriwatknp Apr 22, 2024
ee3f1b6
migrate Skeleton
siriwatknp Apr 22, 2024
6d7989f
migrate Snackbar
siriwatknp Apr 22, 2024
f1eb8bf
migrate SpeedDial
siriwatknp Apr 22, 2024
988a6bf
migrate Tabs
siriwatknp Apr 22, 2024
a50ba76
migrate Tooltip
siriwatknp Apr 22, 2024
a6133d5
run docs:api
siriwatknp Apr 23, 2024
1c56fe5
fix lint
siriwatknp Apr 23, 2024
984e7ca
fix snackbar
siriwatknp Apr 23, 2024
6c17d04
remove xs
siriwatknp Apr 23, 2024
d9a858f
shorten icon
siriwatknp Apr 23, 2024
7c0fa9d
fix comment
siriwatknp Apr 23, 2024
6c2ea6f
fix Icon metadata
siriwatknp Apr 24, 2024
68c95ea
add explicit disableRipple
siriwatknp Apr 25, 2024
089feb5
migrate SwitchBase
siriwatknp Apr 25, 2024
942490b
add demo pages
siriwatknp Apr 25, 2024
c554e62
Merge branch 'next' of https://github.com/mui/material-ui into mui/cs…
siriwatknp Apr 29, 2024
3392cbe
migrate FilledInput
siriwatknp Apr 29, 2024
8685c92
use direct module
siriwatknp Apr 29, 2024
1a10ef5
migrate the rest
siriwatknp Apr 29, 2024
920a703
migrate Collapse
siriwatknp Apr 30, 2024
7e6e5fa
migrate BreadcrumbCollapsed
siriwatknp Apr 30, 2024
3727c6f
migrate the rest
siriwatknp Apr 30, 2024
6e2269d
fixes
siriwatknp Apr 30, 2024
023c2a8
remove unparsable sx demo
siriwatknp Apr 30, 2024
2b91598
add component check
siriwatknp Apr 30, 2024
7832e33
remove unparsable sx demos
siriwatknp May 1, 2024
91034bf
update pigment to latest
siriwatknp May 1, 2024
ea0a80d
pnpm dedupe
siriwatknp May 1, 2024
9e78be7
Merge branch 'next' of https://github.com/mui/material-ui into mui/cs…
siriwatknp May 1, 2024
33445aa
update lock file
siriwatknp May 1, 2024
6be45c1
fix FormLabel
siriwatknp May 1, 2024
fb84a93
Merge branch 'next' of https://github.com/mui/material-ui into mui/cs…
siriwatknp May 2, 2024
c62d85a
revert demo pages
siriwatknp May 2, 2024
002bf22
test ci without macos
siriwatknp May 2, 2024
f9e5c59
remove unnecessary change
siriwatknp May 2, 2024
e59210f
fix FormLabel
siriwatknp May 2, 2024
0cb1f75
Fix NativeSelectInput
siriwatknp May 2, 2024
f76758f
revert ci change
siriwatknp May 2, 2024
0eefa24
set mem to 4GB
siriwatknp May 2, 2024
2ea2584
migrate Typography
siriwatknp May 3, 2024
444a60f
migrate Link
siriwatknp May 3, 2024
d07e032
add workaround for toString error
siriwatknp May 3, 2024
15c782e
migrate LoadingButton
siriwatknp May 3, 2024
e7b3f84
fix test
siriwatknp May 3, 2024
1ea30b0
bring back sx insertion
siriwatknp May 3, 2024
11f5c47
run proptypes
siriwatknp May 3, 2024
6d0c54d
fix lint
siriwatknp May 3, 2024
279e4cc
Merge branch 'next' of https://github.com/mui/material-ui into mui/cs…
siriwatknp May 3, 2024
fb57ad7
move other.style to last
siriwatknp May 6, 2024
1276d4e
update comment as suggeste
siriwatknp May 6, 2024
cb85122
Merge branch 'next' of https://github.com/mui/material-ui into mui/cs…
siriwatknp May 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -38,6 +38,8 @@ jobs:
cache: 'pnpm' # https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-dependencies
- run: pnpm install
- run: pnpm build:ci
env:
NODE_OPTIONS: --max_old_space_size=4096
- run: pnpm release:changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
27 changes: 27 additions & 0 deletions apps/pigment-css-next-app/next.config.js
Expand Up @@ -96,6 +96,13 @@ theme.getColorSchemeSelector = (colorScheme) => {
return `@media (prefers-color-scheme: ${colorScheme})`;
};

function innerNoop() {
return null;
}
function outerNoop() {
return innerNoop;
}

/**
* @type {PigmentOptions}
*/
Expand All @@ -104,6 +111,26 @@ const pigmentOptions = {
transformLibraries: ['local-ui-lib'],
sourceMap: true,
displayName: true,
overrideContext: (context) => {
Copy link
Member Author

Choose a reason for hiding this comment

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

A workaround for mui/pigment-css#10

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding this here fixes the issue? Should this then be made part of the library itself?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I can confirm that this prevents the error. I added here just to be a workaround but if you think it should be a part of Pigment, I am happy to add it. However, I think it should be a separate package for integrating with MUI system, not a part of nextjs/vite plugin.

Copy link
Member

Choose a reason for hiding this comment

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

If this would be required for every project that uses Material UI and Pigment CSS, we should make it part of the library. Do we know why it is required tough? Maybe we are fixing a symptom, not the problem

Copy link

Choose a reason for hiding this comment

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

probably related issue: mui/pigment-css#8

if (!context.$RefreshSig$) {
context.$RefreshSig$ = outerNoop;
}
return {
...context,
require: (id) => {
if (id === '@mui/styled-engine' || id === '@mui/styled-engine-sc') {
return {
__esModule: true,
default: () => () => () => null,
internal_processStyles: () => {},
keyframes: () => '',
css: () => '',
};
}
return context.require(id);
},
};
},
};

/** @type {import('next').NextConfig} */
Expand Down
4 changes: 2 additions & 2 deletions apps/pigment-css-next-app/package.json
Expand Up @@ -9,7 +9,7 @@
"clean": "rimraf .next"
},
"dependencies": {
"@pigment-css/react": "^0.0.9",
"@pigment-css/react": "^0.0.10",
"@mui/utils": "workspace:^",
"@mui/base": "workspace:^",
"@mui/lab": "workspace:^",
Expand All @@ -24,7 +24,7 @@
"next": "latest"
},
"devDependencies": {
"@pigment-css/nextjs-plugin": "^0.0.9",
"@pigment-css/nextjs-plugin": "^0.0.10",
"@types/node": "^20.5.7",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.3.0",
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/material-ui/api/filled-input.json
Expand Up @@ -19,7 +19,7 @@
},
"defaultValue": { "type": { "name": "any" } },
"disabled": { "type": { "name": "bool" } },
"disableUnderline": { "type": { "name": "bool" } },
"disableUnderline": { "type": { "name": "bool" }, "default": "false" },
"endAdornment": { "type": { "name": "node" } },
"error": { "type": { "name": "bool" } },
"fullWidth": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/material-ui/api/input.json
Expand Up @@ -19,7 +19,7 @@
},
"defaultValue": { "type": { "name": "any" } },
"disabled": { "type": { "name": "bool" } },
"disableUnderline": { "type": { "name": "bool" } },
"disableUnderline": { "type": { "name": "bool" }, "default": "false" },
"endAdornment": { "type": { "name": "node" } },
"error": { "type": { "name": "bool" } },
"fullWidth": { "type": { "name": "bool" }, "default": "false" },
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -111,7 +111,7 @@
"@mui/utils": "workspace:^",
"@next/eslint-plugin-next": "^14.2.3",
"@octokit/rest": "^20.1.0",
"@pigment-css/react": "^0.0.9",
"@pigment-css/react": "^0.0.10",
"@playwright/test": "1.43.1",
"@types/enzyme": "^3.10.18",
"@types/fs-extra": "^11.0.4",
Expand Down
186 changes: 122 additions & 64 deletions packages/mui-lab/src/LoadingButton/LoadingButton.js
Expand Up @@ -4,13 +4,15 @@ import PropTypes from 'prop-types';
import { chainPropTypes } from '@mui/utils';
import { capitalize, unstable_useId as useId } from '@mui/material/utils';
import { unstable_composeClasses as composeClasses } from '@mui/base';
import { styled, useThemeProps } from '@mui/material/styles';
import Button from '@mui/material/Button';
import { ButtonGroupContext } from '@mui/material/ButtonGroup';
import CircularProgress from '@mui/material/CircularProgress';
import resolveProps from '@mui/utils/resolveProps';
import { styled, createUseThemeProps } from '../zero-styled';
import loadingButtonClasses, { getLoadingButtonUtilityClass } from './loadingButtonClasses';

const useThemeProps = createUseThemeProps('MuiLoadingButton');

const useUtilityClasses = (ownerState) => {
const { loading, loadingPosition, classes } = ownerState;

Expand All @@ -32,7 +34,7 @@ const useUtilityClasses = (ownerState) => {
};
};

// TODO use `import { rootShouldForwardProp } from '../styles/styled';` once move to core
// TODO use `import rootShouldForwardProp from '../styles/rootShouldForwardProp';` once move to core
const rootShouldForwardProp = (prop) =>
prop !== 'ownerState' && prop !== 'theme' && prop !== 'sx' && prop !== 'as' && prop !== 'classes';
const LoadingButtonRoot = styled(Button, {
Expand All @@ -50,44 +52,55 @@ const LoadingButtonRoot = styled(Button, {
},
];
},
})(({ ownerState, theme }) => ({
})(({ theme }) => ({
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]:
{
transition: theme.transitions.create(['opacity'], {
duration: theme.transitions.duration.short,
}),
opacity: 0,
},
...(ownerState.loadingPosition === 'center' && {
transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color'], {
duration: theme.transitions.duration.short,
}),
[`&.${loadingButtonClasses.loading}`]: {
color: 'transparent',
},
}),
...(ownerState.loadingPosition === 'start' &&
ownerState.fullWidth && {
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]:
{
transition: theme.transitions.create(['opacity'], {
duration: theme.transitions.duration.short,
}),
opacity: 0,
marginRight: -8,
},
}),
...(ownerState.loadingPosition === 'end' &&
ownerState.fullWidth && {
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]:
{
transition: theme.transitions.create(['opacity'], {
duration: theme.transitions.duration.short,
}),
opacity: 0,
marginLeft: -8,
variants: [
{
props: {
loadingPosition: 'center',
},
style: {
transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color'], {
duration: theme.transitions.duration.short,
}),
[`&.${loadingButtonClasses.loading}`]: {
color: 'transparent',
},
}),
},
},
{
props: ({ ownerState }) => ownerState.loadingPosition === 'start' && ownerState.fullWidth,
style: {
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]:
{
transition: theme.transitions.create(['opacity'], {
duration: theme.transitions.duration.short,
}),
opacity: 0,
marginRight: -8,
},
},
},
{
props: ({ ownerState }) => ownerState.loadingPosition === 'end' && ownerState.fullWidth,
style: {
[`& .${loadingButtonClasses.startIconLoadingStart}, & .${loadingButtonClasses.endIconLoadingEnd}`]:
{
transition: theme.transitions.create(['opacity'], {
duration: theme.transitions.duration.short,
}),
opacity: 0,
marginLeft: -8,
},
},
},
],
}));

const LoadingButtonLoadingIndicator = styled('span', {
Expand All @@ -100,41 +113,86 @@ const LoadingButtonLoadingIndicator = styled('span', {
styles[`loadingIndicator${capitalize(ownerState.loadingPosition)}`],
];
},
})(({ theme, ownerState }) => ({
})(({ theme }) => ({
position: 'absolute',
visibility: 'visible',
display: 'flex',
...(ownerState.loadingPosition === 'start' &&
(ownerState.variant === 'outlined' || ownerState.variant === 'contained') && {
left: ownerState.size === 'small' ? 10 : 14,
}),
...(ownerState.loadingPosition === 'start' &&
ownerState.variant === 'text' && {
left: 6,
}),
...(ownerState.loadingPosition === 'center' && {
left: '50%',
transform: 'translate(-50%)',
color: (theme.vars || theme).palette.action.disabled,
}),
...(ownerState.loadingPosition === 'end' &&
(ownerState.variant === 'outlined' || ownerState.variant === 'contained') && {
right: ownerState.size === 'small' ? 10 : 14,
}),
...(ownerState.loadingPosition === 'end' &&
ownerState.variant === 'text' && {
right: 6,
}),
...(ownerState.loadingPosition === 'start' &&
ownerState.fullWidth && {
position: 'relative',
left: -10,
}),
...(ownerState.loadingPosition === 'end' &&
ownerState.fullWidth && {
position: 'relative',
right: -10,
}),
variants: [
{
props: {
loadingPosition: 'start',
size: 'small',
},
style: {
left: 10,
},
},
{
props: ({ loadingPosition, ownerState }) =>
loadingPosition === 'start' && ownerState.size !== 'small',
style: {
left: 14,
},
},
{
props: {
variant: 'text',
loadingPosition: 'start',
},
style: {
left: 6,
},
},
{
props: {
loadingPosition: 'center',
},
style: {
left: '50%',
transform: 'translate(-50%)',
color: (theme.vars || theme).palette.action.disabled,
},
},
{
props: {
loadingPosition: 'end',
size: 'small',
},
style: {
right: 10,
},
},
{
props: ({ loadingPosition, ownerState }) =>
loadingPosition === 'end' && ownerState.size !== 'small',
style: {
right: 14,
},
},
{
props: {
variant: 'text',
loadingPosition: 'end',
},
style: {
right: 6,
},
},
{
props: ({ ownerState }) => ownerState.loadingPosition === 'start' && ownerState.fullWidth,
style: {
position: 'relative',
left: -10,
},
},
{
props: ({ ownerState }) => ownerState.loadingPosition === 'end' && ownerState.fullWidth,
style: {
position: 'relative',
right: -10,
},
},
],
}));

const LoadingButton = React.forwardRef(function LoadingButton(inProps, ref) {
Expand Down
8 changes: 8 additions & 0 deletions packages/mui-lab/src/zero-styled/index.ts
@@ -0,0 +1,8 @@
import { useThemeProps } from '@mui/material/styles';

export { styled } from '@mui/material/styles';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function createUseThemeProps(name: string) {
return useThemeProps;
}
Expand Up @@ -2,7 +2,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { emphasize } from '@mui/system/colorManipulator';
import styled from '../styles/styled';
import { styled } from '../zero-styled';
import MoreHorizIcon from '../internal/svg-icons/MoreHoriz';
import ButtonBase from '../ButtonBase';

Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Button/Button.js
Expand Up @@ -5,7 +5,7 @@ import clsx from 'clsx';
import resolveProps from '@mui/utils/resolveProps';
import composeClasses from '@mui/utils/composeClasses';
import { alpha } from '@mui/system/colorManipulator';
import { rootShouldForwardProp } from '../styles/styled';
import rootShouldForwardProp from '../styles/rootShouldForwardProp';
import { styled, createUseThemeProps } from '../zero-styled';
import ButtonBase from '../ButtonBase';
import capitalize from '../utils/capitalize';
Expand Down
2 changes: 2 additions & 0 deletions packages/mui-material/src/Checkbox/Checkbox.js
Expand Up @@ -117,6 +117,7 @@ const Checkbox = React.forwardRef(function Checkbox(inProps, ref) {
indeterminateIcon: indeterminateIconProp = defaultIndeterminateIcon,
inputProps,
size = 'medium',
disableRipple = false,
Copy link
Member

Choose a reason for hiding this comment

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

What's with this change?

Copy link
Member Author

@siriwatknp siriwatknp May 6, 2024

Choose a reason for hiding this comment

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

Otherwise, variants won't work because disabled=undefined

variants: [
  { props: { color: 'default', disableRipple: false } }, style: {} },
]

className,
...other
} = props;
Expand All @@ -126,6 +127,7 @@ const Checkbox = React.forwardRef(function Checkbox(inProps, ref) {

const ownerState = {
...props,
disableRipple,
color,
indeterminate,
size,
Expand Down