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

[Box] Fix TypeScript error on maxWidth prop #26859

Merged
merged 7 commits into from Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
56 changes: 27 additions & 29 deletions packages/material-ui-system/src/Box/Box.d.ts
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
4 changes: 3 additions & 1 deletion packages/material-ui-system/src/Box/Box.spec.tsx
@@ -1,5 +1,6 @@
import * as React from 'react';
import { Box } from '@material-ui/system';

oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
import { Box, Theme } from '@material-ui/system';

interface TestProps {
test?: string;
Expand Down Expand Up @@ -46,4 +47,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} />;
}
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
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
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
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
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