Skip to content

Commit

Permalink
remove warning
Browse files Browse the repository at this point in the history
  • Loading branch information
DarhkVoyd committed Oct 16, 2023
1 parent 1debd25 commit 9695219
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 108 deletions.
14 changes: 0 additions & 14 deletions packages/mui-material/src/Typography/Typography.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,6 @@ describe('<Typography />', () => {
});
});

describe('prop: color', () => {
it('should check for invalid color value', () => {
const msg =
'MUI: The value found in theme for prop: "background" is an [Object] instead of string or number. Check if you forgot to add the correct dotted notation, e.g., "background.paper" instead of "background".';
expect(() => {
render(
<Typography variant="h6" color="background">
Hello
</Typography>,
);
}).toWarnDev([msg, msg]);
});
});

it('combines system properties with the sx prop', () => {
const { container } = render(<Typography mt={2} mr={1} sx={{ marginRight: 5, mb: 2 }} />);

Expand Down
13 changes: 4 additions & 9 deletions packages/mui-system/src/palette.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ const theme = {

describe('palette', () => {
it('should treat grey as CSS color', () => {
let output;
expect(() => {
output = palette({
theme,
backgroundColor: 'grey',
});
}).toWarnDev(
'MUI: The value found in theme for prop: "grey" is an [Object] instead of string or number. Check if you forgot to add the correct dotted notation, e.g., "background.paper" instead of "background".',
);
const output = palette({
theme,
backgroundColor: 'grey',
});

expect(output).to.deep.equal({
backgroundColor: 'grey',
Expand Down
22 changes: 0 additions & 22 deletions packages/mui-system/src/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,6 @@ export function getStyleValue(themeMapping, transform, propValueFinal, userValue
value = getPath(themeMapping, propValueFinal) || userValue;
}

if (process.env.NODE_ENV !== 'production') {
if (value && typeof value === 'object' && isColor(Object.values(value)[0])) {
console.warn(
`MUI: The value found in theme for prop: "${propValueFinal}" is an [Object] instead of string or number. Check if you forgot to add the correct dotted notation, e.g., "background.paper" instead of "background".`,
);
}
}

if (transform) {
value = transform(value, userValue, themeMapping);
}
Expand Down Expand Up @@ -100,18 +92,4 @@ function style(options) {
return fn;
}

function isColor(str) {
// Regular expressions to match different color patterns
const colorPatterns = [
/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/, // Hex color
/^rgb\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*\)$/, // RGB color
/^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*0?(\.\d+)?\s*\)$/, // RGBA color
/^(red|green|blue|yellow|orange|purple|pink|white|black|gray|grey|transparent)$/, // CSS color keyword
/^\$[a-zA-Z_][a-zA-Z0-9_]*$/, // SCSS variable reference
/^var\(--[^)]+\)$/, // CSS variable reference (e.g., var(--main-color))
];

return colorPatterns.some((pattern) => pattern.test(str));
}

export default style;
56 changes: 1 addition & 55 deletions packages/mui-system/src/style.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import style, { getStyleValue } from './style';
import style from './style';

describe('style', () => {
const bgcolor = style({
Expand Down Expand Up @@ -258,58 +258,4 @@ describe('style', () => {
});
});
});
describe('getStyleValue', () => {
it('should not warn on acceptable object', () => {
const round = (value) => Math.round(value * 1e5) / 1e5;
let output;

expect(() => {
output = getStyleValue(
{
body1: {
fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif',
fontSize: '1rem',
letterSpacing: `${round(0.15 / 16)}em`,
fontWeight: 400,
lineHeight: 1.5,
},
},
null,
'body1',
);
}).not.toWarnDev();

expect(output).to.deep.equal({
fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif',
fontSize: '1rem',
letterSpacing: `${round(0.15 / 16)}em`,
fontWeight: 400,
lineHeight: 1.5,
});
});

it('should warn on objects that directly contain colors', () => {
const theme = {
palette: {
grey: { 100: '#f5f5f5' },
},
};

const paletteTransform = (value, userValue) => {
if (userValue === 'grey') {
return userValue;
}
return value;
};
let output;

expect(() => {
output = getStyleValue(theme.palette, paletteTransform, 'grey');
}).toWarnDev(
'MUI: The value found in theme for prop: "grey" is an [Object] instead of string or number. Check if you forgot to add the correct dotted notation, e.g., "background.paper" instead of "background".',
);

expect(output).to.be.equal('grey');
});
});
});
12 changes: 4 additions & 8 deletions packages/mui-system/src/styleFunctionSx/styleFunctionSx.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,10 @@ describe('styleFunctionSx', () => {
});

it('resolves system typography', () => {
let result;

expect(() => {
result = styleFunctionSx({
theme,
sx: { typography: ['body2', 'body1'] },
});
}).not.toWarnDev();
const result = styleFunctionSx({
theme,
sx: { typography: ['body2', 'body1'] },
});

expect(result).to.deep.equal({
'@media (min-width:0px)': {
Expand Down

0 comments on commit 9695219

Please sign in to comment.