From 53adeaa2b5d9a4a373ed52b8ee282ac2dab7c446 Mon Sep 17 00:00:00 2001 From: Raffael Wannenmacher Date: Thu, 18 Jan 2024 16:35:37 +0100 Subject: [PATCH] Fix types of theme prop --- packages/mui-material/src/styles/index.d.ts | 8 +++- packages/mui-styled-engine-sc/src/index.d.ts | 41 ++++++++++---------- packages/mui-styled-engine/src/index.d.ts | 5 ++- packages/mui-system/src/index.d.ts | 10 ++++- 4 files changed, 40 insertions(+), 24 deletions(-) diff --git a/packages/mui-material/src/styles/index.d.ts b/packages/mui-material/src/styles/index.d.ts index 234aed07d592ce..ba90ebe5aef5d4 100644 --- a/packages/mui-material/src/styles/index.d.ts +++ b/packages/mui-material/src/styles/index.d.ts @@ -1,3 +1,10 @@ +import { MUICssWithTheme } from '@mui/system'; +import { Theme } from './createTheme'; + +declare const css: MUICssWithTheme; + +export { css }; + export { default as THEME_ID } from './identifier'; export { default as createTheme, @@ -47,7 +54,6 @@ export { Interpolation, CSSInterpolation, CSSObject, - css, keyframes, // color manipulators hexToRgb, diff --git a/packages/mui-styled-engine-sc/src/index.d.ts b/packages/mui-styled-engine-sc/src/index.d.ts index 3e22e9db1e6c66..da4021d835e94a 100644 --- a/packages/mui-styled-engine-sc/src/index.d.ts +++ b/packages/mui-styled-engine-sc/src/index.d.ts @@ -1,7 +1,6 @@ import * as React from 'react'; import * as CSS from 'csstype'; import * as hoistNonReactStatics from 'hoist-non-react-statics'; -import { DefaultTheme } from 'styled-components'; type WithOptionalTheme

= OmitU & { theme?: T | undefined; @@ -273,26 +272,6 @@ export interface ThemedStyledFunctionBase< ): StyledComponent; } -type RuleSet = Interpolation[]; - -declare function css( - styles: - | TemplateStringsArray - | CSSObject - | InterpolationFunction>, - ...interpolations: Interpolation>[] -): RuleSet; - -declare function css( - styles: - | TemplateStringsArray - | CSSObject - | InterpolationFunction>, - ...interpolations: Interpolation>[] -): RuleSet; - -export { css }; - // same as ThemedStyledFunction in styled-components, but without attrs, and withConfig export interface ThemedStyledFunction< C extends keyof JSX.IntrinsicElements | React.ComponentType, @@ -418,3 +397,23 @@ export interface MUIStyledComponent< tag: Tag, ): MUIStyledComponent; } + +type RuleSet = Interpolation[]; + +export type MUICssWithTheme = { + ( + styles: + | TemplateStringsArray + | CSSObject + | InterpolationFunction>, + ...interpolations: Interpolation>[] + ): RuleSet; + + ( + styles: + | TemplateStringsArray + | CSSObject + | InterpolationFunction>, + ...interpolations: Interpolation>[] + ): RuleSet; +}; diff --git a/packages/mui-styled-engine/src/index.d.ts b/packages/mui-styled-engine/src/index.d.ts index 47f30b590e827d..91b58a21b7a917 100644 --- a/packages/mui-styled-engine/src/index.d.ts +++ b/packages/mui-styled-engine/src/index.d.ts @@ -1,6 +1,6 @@ import * as CSS from 'csstype'; import { StyledComponent, StyledOptions } from '@emotion/styled'; -import { PropsOf } from '@emotion/react'; +import { css, PropsOf } from '@emotion/react'; export * from '@emotion/styled'; export { default } from '@emotion/styled'; @@ -214,3 +214,6 @@ export interface CreateMUIStyled< options?: StyledOptions & MuiStyledOptions, ): CreateStyledComponent; } + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export type MUICssWithTheme = typeof css; diff --git a/packages/mui-system/src/index.d.ts b/packages/mui-system/src/index.d.ts index 7f24359229a63d..0636f0ed357e9f 100644 --- a/packages/mui-system/src/index.d.ts +++ b/packages/mui-system/src/index.d.ts @@ -1,3 +1,5 @@ +import { MUICssWithTheme as MUICssWithThemeStyledEngine } from '@mui/styled-engine'; +import { Theme as DefaultTheme } from './createTheme'; import { ComposedStyleFunction, StyleFunction, @@ -96,7 +98,6 @@ export type ResponsiveStyleValue = T | Array | { [key: string]: T | export { DefaultTheme } from '@mui/private-theming'; export { - css, keyframes, StyledEngineProvider, Interpolation, @@ -106,6 +107,13 @@ export { export { default as GlobalStyles } from './GlobalStyles'; export type { GlobalStylesProps } from './GlobalStyles'; +export type MUICssWithTheme = + MUICssWithThemeStyledEngine; + +declare const css: MUICssWithTheme; + +export { css }; + export * from './style'; export * from './spacing';