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

[core] v5 emotion-less css & styled prototype #44269

Open
wants to merge 3 commits into
base: v5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/mui-system/src/createStyled.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ export default function createStyled<Theme extends object = DefaultTheme>(option
slotShouldForwardProp?: (prop: PropertyKey) => boolean;
styleFunctionSx?: typeof styleFunctionSx;
}): CreateMUIStyled<Theme>;

// eslint-disable-next-line @typescript-eslint/naming-convention
export function internal_applyStyled(props: any, componentName: string, overridesResolver: Function): string;
59 changes: 42 additions & 17 deletions packages/mui-system/src/createStyled.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/* eslint-disable no-underscore-dangle */
import styledEngineStyled, { internal_processStyles as processStyles } from '@mui/styled-engine';
import styledEngineStyled, {
css,
internal_processStyles as processStyles,
} from '@mui/styled-engine';
import { isPlainObject } from '@mui/utils/deepmerge';
import capitalize from '@mui/utils/capitalize';
import getDisplayName from '@mui/utils/getDisplayName';
Expand Down Expand Up @@ -181,28 +184,14 @@ export default function createStyled(input = {}) {
if (componentName && overridesResolver) {
expressionsWithDefaultTheme.push((props) => {
const theme = resolveTheme({ ...props, defaultTheme, themeId });
if (
!theme.components ||
!theme.components[componentName] ||
!theme.components[componentName].styleOverrides
) {
return null;
}
const styleOverrides = theme.components[componentName].styleOverrides;
const resolvedStyleOverrides = {};
// TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, { ...props, theme });
});
return overridesResolver(props, resolvedStyleOverrides);
return applyThemeOverrides(theme, props, componentName, overridesResolver);
});
}

if (componentName && !skipVariantsResolver) {
expressionsWithDefaultTheme.push((props) => {
const theme = resolveTheme({ ...props, defaultTheme, themeId });
const themeVariants = theme?.components?.[componentName]?.variants;
return processStyleArg({ variants: themeVariants }, { ...props, theme });
return applyThemeVariants(theme, props, componentName);
});
}

Expand Down Expand Up @@ -245,3 +234,39 @@ export default function createStyled(input = {}) {
return muiStyledResolver;
};
}

// eslint-disable-next-line @typescript-eslint/naming-convention
export function internal_applyStyled(props, componentName, overridesResolver) {
const styles = [
applyThemeOverrides(props, componentName, overridesResolver),
applyThemeVariants(props, componentName),
// applySystemSx(props, componentName),
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 we may need to enable this one as well, but I am ok with waiting for a request.

Copy link
Contributor Author

@romgrk romgrk Oct 31, 2024

Choose a reason for hiding this comment

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

The sx prop is more complicated than the rest because it needs to modify props, see the note on slack. It won't be as simple as uncommenting that line.

]

return css(styles);
}

function applyThemeOverrides(theme, props, componentName, overridesResolver) {
if (
!theme.components ||
!theme.components[componentName] ||
!theme.components[componentName].styleOverrides
) {
return null;
}
const styleOverrides = theme.components[componentName].styleOverrides;
const resolvedStyleOverrides = {};
// TODO: v7 remove iteration and use `resolveStyleArg(styleOverrides[slot])` directly
Object.entries(styleOverrides).forEach(([slotKey, slotStyle]) => {
resolvedStyleOverrides[slotKey] = processStyleArg(slotStyle, { ...props, theme });
});
return overridesResolver(props, resolvedStyleOverrides);
}

function applyThemeVariants(theme, props, componentName) {
const themeVariants = theme?.components?.[componentName]?.variants;
if (!themeVariants) {
return null;
}
return processStyleArg({ variants: themeVariants }, { ...props, theme });
}