Skip to content

Commit 963f2e9

Browse files
authored
[withWidth] Remove API (#26136)
1 parent 2b50b0f commit 963f2e9

File tree

16 files changed

+4
-542
lines changed

16 files changed

+4
-542
lines changed

docs/src/pages/customization/breakpoints/WithWidth.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/src/pages/customization/breakpoints/WithWidth.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/src/pages/customization/breakpoints/breakpoints.md

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,6 @@ You might want to change the React rendering tree based on the breakpoint value,
6262

6363
You can learn more on the [useMediaQuery](/components/use-media-query/) page.
6464

65-
### withWidth()
66-
67-
> ⚠️ This higher-order component will be deprecated for the [useMediaQuery](/components/use-media-query/) hook.
68-
69-
```jsx
70-
import withWidth from '@material-ui/core/withWidth';
71-
72-
function MyComponent(props) {
73-
return <div>{`Current width: ${props.width}`}</div>;
74-
}
75-
76-
export default withWidth()(MyComponent);
77-
```
78-
79-
In the following demo, we change the rendered DOM element (_em_, <u>u</u>, ~~del~~ & span) based on the screen width.
80-
81-
{{"demo": "pages/customization/breakpoints/WithWidth.js"}}
82-
8365
## Custom breakpoints
8466

8567
You define your project's breakpoints in the `theme.breakpoints` section of your theme.
@@ -241,77 +223,6 @@ const styles = (theme) => ({
241223
});
242224
```
243225

244-
### `withWidth([options]) => higher-order component`
245-
246-
Inject a `width` prop.
247-
It does not modify the component passed to it; instead, it returns a new component.
248-
This `width` breakpoint prop matches the current screen width.
249-
It can be one of the following breakpoints:
250-
251-
```ts
252-
type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
253-
```
254-
255-
Some implementation details that might be interesting to being aware of:
256-
257-
- It forwards _non React static_ properties so this HOC is more "transparent".
258-
For instance, it can be used to define a `getInitialProps()` static method (next.js).
259-
260-
#### Arguments
261-
262-
1. `options` (_object_ [optional]):
263-
264-
- `options.withTheme` (_bool_ [optional]): Defaults to `false`. Provide the `theme` object to the component as a prop.
265-
- `options.noSSR` (_bool_ [optional]): Defaults to `false`.
266-
In order to perform the server-side rendering reconciliation, it needs to render twice.
267-
A first time with nothing and a second time with the children.
268-
This double pass rendering cycle comes with a drawback. The UI might blink.
269-
You can set this flag to `true` if you are not doing server-side rendering.
270-
- `options.initialWidth` (_Breakpoint_ [optional]):
271-
As `window.innerWidth` is unavailable on the server,
272-
we default to rendering an empty component during the first mount.
273-
You might want to use a heuristic to approximate
274-
the screen width of the client browser screen width.
275-
For instance, you could be using the user-agent or the [client-hints](https://caniuse.com/#search=client%20hint).
276-
we also can set the initial width globally using [`custom props`](/customization/theme-components/#default-props) in the theme.
277-
In order to set the initialWidth we need to pass a custom prop with this shape:
278-
279-
```js
280-
const theme = createTheme({
281-
components: {
282-
// withWidth component ⚛️
283-
MuiWithWidth: {
284-
defaultProps: {
285-
// Initial width prop
286-
initialWidth: 'lg', // Breakpoint being globally set 🌎!
287-
},
288-
},
289-
},
290-
});
291-
```
292-
293-
- `options.resizeInterval` (_number_ [optional]): Defaults to 166, corresponds to 10 frames at 60 Hz. Number of milliseconds to wait before responding to a screen resize event.
294-
295-
#### Returns
296-
297-
`higher-order component`: Should be used to wrap a component.
298-
299-
#### Examples
300-
301-
```jsx
302-
import withWidth, { isWidthUp } from '@material-ui/core/withWidth';
303-
304-
function MyComponent(props) {
305-
if (isWidthUp('sm', props.width)) {
306-
return <span />;
307-
}
308-
309-
return <div />;
310-
}
311-
312-
export default withWidth()(MyComponent);
313-
```
314-
315226
## Default values
316227

317228
You can explore the default values of the breakpoints using [the theme explorer](/customization/default-theme/?expand-path=$.breakpoints) or by opening the dev tools console on this page (`window.theme.breakpoints`).

docs/src/pages/guides/migration-v4/migration-v4.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,10 @@ Note: If you would like to move
16131613
}
16141614
```
16151615

1616+
#### withWidth
1617+
1618+
- This HOC was removed. There's an alternative using the `useMediaQuery` hook on [this page](/components/use-media-query/#migrating-from-withwidth).
1619+
16161620
### `@material-ui/types`
16171621

16181622
- Rename the exported `Omit` type in `@material-ui/types`. The module is now called `DistributiveOmit`. The change removes the confusion with the built-in `Omit` helper introduced in TypeScript v3.5. The built-in `Omit`, while similar, is non-distributive. This leads to differences when applied to union types. [See this StackOverflow answer for further details](https://stackoverflow.com/a/57103940/1009797).

packages/material-ui-codemod/src/v4.0.0/top-level-imports.test/actual.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ import InputLabel from '@material-ui/core/InputLabel';
5151
import Input from '@material-ui/core/Input';
5252
import Grow from '@material-ui/core/Grow';
5353
import TableFooter from '@material-ui/core/TableFooter';
54-
import withWidth from '@material-ui/core/withWidth';
55-
import { isWidthUp } from '@material-ui/core/withWidth';
5654
import Zoom from '@material-ui/core/Zoom';
5755
import ClickAwayListener from '@material-ui/core/ClickAwayListener';
5856
import ListSubheader from '@material-ui/core/ListSubheader';

packages/material-ui-codemod/src/v4.0.0/top-level-imports.test/expected.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ import {
5353
Input,
5454
Grow,
5555
TableFooter,
56-
withWidth,
57-
isWidthUp,
5856
Zoom,
5957
ClickAwayListener,
6058
ListSubheader,

packages/material-ui/src/index.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,6 @@ export * from './useMediaQuery';
453453
export { default as useScrollTrigger } from './useScrollTrigger';
454454
export * from './useScrollTrigger';
455455

456-
export { default as withWidth } from './withWidth';
457-
export * from './withWidth';
458-
459456
export { default as Zoom } from './Zoom';
460457
export * from './Zoom';
461458

packages/material-ui/src/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,6 @@ export * from './usePagination';
389389
export { default as useScrollTrigger } from './useScrollTrigger';
390390
export * from './useScrollTrigger';
391391

392-
export { default as withWidth } from './withWidth';
393-
export * from './withWidth';
394-
395392
export { default as Zoom } from './Zoom';
396393
export * from './Zoom';
397394

packages/material-ui/src/styles/components.d.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,4 @@ export interface Components {
464464
MuiUseMediaQuery?: {
465465
defaultProps?: ComponentsProps['MuiUseMediaQuery'];
466466
};
467-
MuiWithWidth?: {
468-
defaultProps?: ComponentsProps['MuiWithWidth'];
469-
};
470467
}

packages/material-ui/src/styles/props.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ import { ToolbarProps } from '../Toolbar';
113113
import { TooltipProps } from '../Tooltip';
114114
import { TouchRippleProps } from '../ButtonBase/TouchRipple';
115115
import { TypographyProps } from '../Typography';
116-
import { WithWidthOptions } from '../withWidth';
117116

118117
export type ComponentsProps = {
119118
[Name in keyof ComponentsPropsList]?: Partial<ComponentsPropsList[Name]>;
@@ -235,5 +234,4 @@ export interface ComponentsPropsList {
235234
MuiTouchRipple: TouchRippleProps;
236235
MuiTypography: TypographyProps;
237236
MuiUseMediaQuery: useMediaQueryOptions;
238-
MuiWithWidth: WithWidthOptions;
239237
}

0 commit comments

Comments
 (0)