@@ -132,12 +132,6 @@ export default function createPalette(palette) {
132132 // Bootstrap: https://github.com/twbs/bootstrap/blob/1d6e3710dd447de1a200f29e8fa521f8a0908f70/scss/_functions.scss#L59
133133 // and material-components-web https://github.com/material-components/material-components-web/blob/ac46b8863c4dab9fc22c4c662dc6bd1b65dd652f/packages/mdc-theme/_functions.scss#L54
134134 function getContrastText ( background ) {
135- if ( ! background ) {
136- throw new TypeError (
137- `Material-UI: missing background argument in getContrastText(${ background } ).` ,
138- ) ;
139- }
140-
141135 const contrastText =
142136 getContrastRatio ( background , dark . text . primary ) >= contrastThreshold
143137 ? dark . text . primary
@@ -159,21 +153,48 @@ export default function createPalette(palette) {
159153 return contrastText ;
160154 }
161155
162- function augmentColor ( color , mainShade = 500 , lightShade = 300 , darkShade = 700 ) {
156+ const augmentColor = ( color , mainShade = 500 , lightShade = 300 , darkShade = 700 ) => {
163157 color = { ...color } ;
164158 if ( ! color . main && color [ mainShade ] ) {
165159 color . main = color [ mainShade ] ;
166160 }
167161
168- if ( process . env . NODE_ENV !== 'production' ) {
169- if ( ! color . main ) {
170- throw new Error (
162+ if ( ! color . main ) {
163+ if ( process . env . NODE_ENV !== 'production' ) {
164+ console . error (
171165 [
172166 'Material-UI: the color provided to augmentColor(color) is invalid.' ,
173167 `The color object needs to have a \`main\` property or a \`${ mainShade } \` property.` ,
174168 ] . join ( '\n' ) ,
175169 ) ;
176170 }
171+ color . main = indigo [ 500 ] ;
172+ }
173+
174+ if ( typeof color . main !== 'string' ) {
175+ if ( process . env . NODE_ENV !== 'production' ) {
176+ console . error (
177+ [
178+ 'Material-UI: the color provided to augmentColor(color) is invalid.' ,
179+ `\`color.main\` should be a string, but \`${ JSON . stringify (
180+ color . main ,
181+ ) } \` was provided instead.`,
182+ '' ,
183+ 'Did you intent to do one of the followings?' ,
184+ '' ,
185+ 'import { green } from "@material-ui/core/colors";' ,
186+ '' ,
187+ 'const theme1 = createMuiTheme({ palette: {' ,
188+ ' primary: green,' ,
189+ '} });' ,
190+ '' ,
191+ 'const theme2 = createMuiTheme({ palette: {' ,
192+ ' primary: { main: green[500] },' ,
193+ '} });' ,
194+ ] . join ( '\n' ) ,
195+ ) ;
196+ }
197+ color . main = indigo [ 500 ] ;
177198 }
178199
179200 addLightOrDark ( color , 'light' , lightShade , tonalOffset ) ;
@@ -183,7 +204,7 @@ export default function createPalette(palette) {
183204 }
184205
185206 return color ;
186- }
207+ } ;
187208
188209 const types = { dark, light } ;
189210
0 commit comments