Skip to content

Commit

Permalink
[theme] Add warning for theme.breakpoints.width deprecation (#25993)
Browse files Browse the repository at this point in the history
  • Loading branch information
m4theushw committed Apr 28, 2021
1 parent f731e9d commit f5ffbec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/material-ui/src/styles/createBreakpoints.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export interface Breakpoints {
down: (key: Breakpoint | number) => string;
between: (start: Breakpoint | number, end: Breakpoint | number) => string;
only: (key: Breakpoint) => string;
/**
* @deprecated
* Use the `values` prop instead
*/
width: (key: Breakpoint) => number;
}

Expand Down
14 changes: 14 additions & 0 deletions packages/material-ui/src/styles/createBreakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,21 @@ export default function createBreakpoints(breakpoints) {
return between(key, key);
}

let warnedOnce = false;

function width(key) {
if (process.env.NODE_ENV !== 'production') {
if (!warnedOnce) {
warnedOnce = true;
console.warn(
[
"Material-UI: The `theme.breakpoints.width` utility is deprecated because it's redundant.",
'Use the `theme.breakpoints.values` instead.',
].join('\n'),
);
}
}

return values[key];
}

Expand Down
4 changes: 4 additions & 0 deletions packages/material-ui/src/styles/createBreakpoints.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from 'chai';
import { stub } from 'sinon';
import createBreakpoints from './createBreakpoints';

describe('createBreakpoints', () => {
Expand Down Expand Up @@ -62,7 +63,10 @@ describe('createBreakpoints', () => {

describe('width', () => {
it('should work', () => {
// Ignore deprecation warning.
stub(console, 'warn');
expect(breakpoints.width('md')).to.equal(960);
console.warn.restore();
});
});
});

0 comments on commit f5ffbec

Please sign in to comment.