Skip to content

Commit

Permalink
[Box] Fix TypeScript error on maxWidth prop (#26859)
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Tassinari <[email protected]>
  • Loading branch information
ansh-saini and oliviertassinari authored Jun 25, 2021
1 parent 409410e commit d17a055
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 38 deletions.
56 changes: 27 additions & 29 deletions packages/material-ui-system/src/Box/Box.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { OverridableComponent, OverrideProps } from '@material-ui/types';
import { Theme } from '../createTheme';
import {
SxProps,
StandardCSSProperties,
AllSystemCSSProperties,
ResponsiveStyleValue,
OverwriteCSSProperties,
AliasesCSSProperties,
Expand Down Expand Up @@ -140,40 +140,38 @@ export type ComposedStyleFunction<T extends Array<StyleFunction<any>>> = StyleFu
ComposedStyleProps<T>
>;

export type CustomSystemProps = OverwriteCSSProperties & AliasesCSSProperties;

export type SimpleSystemKeys = keyof Omit<
PropsFor<
ComposedStyleFunction<
[
typeof borders,
typeof display,
typeof flexbox,
typeof grid,
typeof palette,
typeof positions,
typeof shadows,
typeof sizing,
typeof spacing,
typeof typography,
]
>
>,
keyof CustomSystemProps
export interface CustomSystemProps extends AliasesCSSProperties, OverwriteCSSProperties {}

export type SimpleSystemKeys = keyof PropsFor<
ComposedStyleFunction<
[
typeof borders,
typeof display,
typeof flexbox,
typeof grid,
typeof palette,
typeof positions,
typeof shadows,
typeof sizing,
typeof spacing,
typeof typography,
]
>
>;

// The SimpleSystemKeys are subset of the StandardCSSProperties, so this should be ok
// This is needed as these are used as keys inside StandardCSSProperties
type StandardSystemKeys = Extract<SimpleSystemKeys, keyof StandardCSSProperties>;
// The SimpleSystemKeys are subset of the AllSystemCSSProperties, so this should be ok
// This is needed as these are used as keys inside AllSystemCSSProperties
type StandardSystemKeys = Extract<SimpleSystemKeys, keyof AllSystemCSSProperties>;

export type SystemProps = {
[K in StandardSystemKeys]?: ResponsiveStyleValue<StandardCSSProperties[K]>;
} &
CustomSystemProps;
export type SystemProps<Theme extends object = {}> = {
[K in StandardSystemKeys]?:
| ResponsiveStyleValue<AllSystemCSSProperties[K]>
| ((theme: Theme) => ResponsiveStyleValue<AllSystemCSSProperties[K]>);
};

export interface BoxTypeMap<P = {}, D extends React.ElementType = 'div'> {
props: P &
SystemProps & {
SystemProps<Theme> & {
children?: React.ReactNode;
component?: React.ElementType;
ref?: React.Ref<unknown>;
Expand Down
3 changes: 2 additions & 1 deletion packages/material-ui-system/src/Box/Box.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Box } from '@material-ui/system';
import { Box, Theme } from '@material-ui/system';

interface TestProps {
test?: string;
Expand Down Expand Up @@ -46,4 +46,5 @@ function GapTest() {
function ComponentPropTest() {
<Box component="img" src="https://material-ui.com/" alt="Material UI" />;
<Box component={Test} test="Test string" />;
<Box maxWidth={(theme: Theme) => theme.breakpoints.values.sm} />;
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ export interface AliasesCSSProperties {
* @see https://developer.mozilla.org/docs/Web/CSS/padding-bottom
*/
paddingY?: StandardCSSProperties['paddingTop'];

/**
* The **`typography`** property is shorthand for the CSS properties **`font-family`**, **`font-weight`**, **`font-size`**, **`line-height`**, **`letter-spacing`** and **`text-transform``**.
* It takes the values defined under `theme.typography` and spreads them on the element.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export interface CSSSelectorObject<Theme extends object = {}> {

/**
* Map of all available CSS properties (including aliases) and their raw value.
* Only used internally to map CCS properties to input types (responsive value,
* Only used internally to map CSS properties to input types (responsive value,
* theme function or nested) in `SystemCssProperties`.
*/
export interface AllSystemCSSProperties
extends Omit<StandardCSSProperties, keyof OverwriteCSSProperties>,
AliasesCSSProperties,
OverwriteCSSProperties {}
OverwriteCSSProperties,
AliasesCSSProperties {}

export type SystemCssProperties<Theme extends object = {}> = {
[K in keyof AllSystemCSSProperties]:
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Box/Box.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Theme } from '../styles';

export interface BoxTypeMap<P = {}, D extends React.ElementType = 'div'> {
props: P &
SystemProps & {
SystemProps<Theme> & {
children?: React.ReactNode;
component?: React.ElementType;
ref?: React.Ref<unknown>;
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Grid/Grid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type GridSize = 'auto' | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12

export interface GridTypeMap<P = {}, D extends React.ElementType = 'div'> {
props: P &
SystemProps & {
SystemProps<Theme> & {
/**
* The content of the component.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Stack/Stack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Theme } from '../styles/createTheme';

export interface StackTypeMap<P = {}, D extends React.ElementType = 'div'> {
props: P &
SystemProps & {
SystemProps<Theme> & {
ref?: React.Ref<unknown>;
/**
* The content of the component.
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Typography/Typography.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface TypographyPropsVariantOverrides {}

export interface TypographyTypeMap<P = {}, D extends React.ElementType = 'span'> {
props: P &
SystemProps & {
SystemProps<Theme> & {
/**
* Set the text-align on the component.
* @default 'inherit'
Expand Down

0 comments on commit d17a055

Please sign in to comment.