-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[typescript] [createMuiTheme] Fix typings & deepmerge shape #11993
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { Mixins, MixinsOptions } from './createMixins'; | |
import { Palette, PaletteOptions } from './createPalette'; | ||
import { Typography, TypographyOptions } from './createTypography'; | ||
import { Shadows } from './shadows'; | ||
import { Shape, ShapeOptions } from './shape'; | ||
import { Shape } from './shape'; | ||
import { Spacing, SpacingOptions } from './spacing'; | ||
import { Transitions, TransitionsOptions } from './transitions'; | ||
import { ZIndex, ZIndexOptions } from './zIndex'; | ||
|
@@ -13,7 +13,7 @@ import { ComponentsProps } from './props'; | |
export type Direction = 'ltr' | 'rtl'; | ||
|
||
export interface ThemeOptions { | ||
shape?: ShapeOptions; | ||
shape?: Shape; | ||
breakpoints?: BreakpointsOptions; | ||
direction?: Direction; | ||
mixins?: MixinsOptions; | ||
|
@@ -25,6 +25,7 @@ export interface ThemeOptions { | |
transitions?: TransitionsOptions; | ||
typography?: TypographyOptions | ((palette: Palette) => TypographyOptions); | ||
zIndex?: ZIndexOptions; | ||
status?: Record<string, string>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's too specific. |
||
} | ||
|
||
export interface Theme { | ||
|
@@ -40,6 +41,7 @@ export interface Theme { | |
transitions: Transitions; | ||
typography: Typography; | ||
zIndex: ZIndex; | ||
status?: Record<string, string>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's too specific. |
||
} | ||
|
||
export default function createMuiTheme(options?: ThemeOptions): Theme; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,8 @@ interface TypeBackground { | |
paper: string; | ||
} | ||
|
||
type TypeDivider = string; | ||
|
||
export type PaletteColorOptions = SimplePaletteColorOptions | Partial<Color>; | ||
|
||
export interface SimplePaletteColorOptions { | ||
|
@@ -40,6 +42,7 @@ export interface PaletteColor { | |
export interface TypeObject { | ||
text: TypeText; | ||
action: TypeAction; | ||
divider: TypeDivider; | ||
background: TypeBackground; | ||
} | ||
|
||
|
@@ -56,7 +59,7 @@ export interface Palette { | |
error: PaletteColor; | ||
grey: Color; | ||
text: TypeText; | ||
divider: string; | ||
divider: TypeDivider; | ||
action: TypeAction; | ||
background: TypeBackground; | ||
getContrastText: (background: string) => string; | ||
|
@@ -85,6 +88,4 @@ export interface PaletteOptions { | |
getContrastText?: (background: string) => string; | ||
} | ||
|
||
//export type PaletteOptions = DeepPartial<Palette>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was commented out. Why do we want to preserve the commented out code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering why it was commented out; Let's remove it then :) |
||
|
||
export default function createPalette(palette: PaletteOptions): Palette; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we still need the partial? Like we do for the Spacing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike
spacing
, which isdeepmerge
d,shape
is not.https://github.com/mui-org/material-ui/blob/ca33d9773581a8b0ff37c92260b48c9f72b42de9/packages/material-ui/src/styles/createMuiTheme.js#L38-L44
https://github.com/mui-org/material-ui/blob/ca33d9773581a8b0ff37c92260b48c9f72b42de9/packages/material-ui/src/styles/createMuiTheme.js#L36
This means that for
spacing
, we can specify just partial of it, but forshadow
, we need to specify the full props, from what I understand.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI - if you take a look at
shadow
type definition under theThemeOptions
interface, it is notPartial<>
either.https://github.com/mui-org/material-ui/blob/ca33d9773581a8b0ff37c92260b48c9f72b42de9/packages/material-ui/src/styles/createMuiTheme.d.ts#L23
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for raising the issue! Should we fix the implementation over the TypeScript definition then? I have missed this part. I think that spacing and shape should behave the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I'll do this. BTW, what about
shadows
? Should it also be a partial in theThemeOptions
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that it's the behavior people expect. We need to fix the
shape
key :).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NVM.
shadows
is different.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the shadows, yeah it's fine. Relative values are important, people need to provide the full property.